Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write multiple conditions in Makefile.am with "else if"

Tags:

automake

I want to compile my project with autoconf/automake. There are 2 conditions defined in my configure.ac

AM_CONDITIONAL(HAVE_CLIENT, test $enable-client -eq 1) AM_CONDITIONAL(HAVE_SERVER, test $enable-server -eq 1) 

I want to separate _LIBS from these 2 conditions in Makefile.am

if HAVE_CLIENT  libtest_LIBS = \      $(top_builddir)/libclient.la  else if HAVE_SERVER  libtest_LIBS = \      $(top_builddir)/libserver.la  else  libtest_LIBS =   endif 

but else if HAVE_SERVER does NOT work.

How to write 'else if' in makefile.am?

like image 366
Wind Avatar asked Nov 09 '11 02:11

Wind


People also ask

How do I add a condition in Makefile?

Syntax of Conditionals Directives The text-if-true may be any lines of text, to be considered as part of the makefile if the condition is true. If the condition is false, no text is used instead. If the condition is true, text-if-true is used; otherwise, text-if-false is used.

What is IFEQ in Makefile?

The ifeq directive begins the conditional, and specifies the condition. It contains two arguments, separated by a comma and surrounded by parentheses. Variable substitution is performed on both arguments and then they are compared.


2 Answers

ptomato's code can also be written in a cleaner manner like:

 ifeq ($(TARGET_CPU),x86)   TARGET_CPU_IS_X86 := 1 else ifeq ($(TARGET_CPU),x86_64)   TARGET_CPU_IS_X86 := 1 else   TARGET_CPU_IS_X86 := 0 endif 

This doesn't answer OP's question but as it's the top result on google, I'm adding it here in case it's useful to anyone else.

like image 151
R.D. Avatar answered Sep 18 '22 20:09

R.D.


I would accept ldav1s' answer if I were you, but I just want to point out that 'else if' can be written in terms of 'else's and 'if's in any language:

if HAVE_CLIENT   libtest_LIBS = $(top_builddir)/libclient.la else   if HAVE_SERVER     libtest_LIBS = $(top_builddir)/libserver.la   else     libtest_LIBS =    endif endif 

(The indentation is for clarity. Don't indent the lines, they won't work.)

like image 36
ptomato Avatar answered Sep 20 '22 20:09

ptomato