Can someone explain how to use if-then statements and for loops in Makefiles? I can't seem to find any good documentation with examples.
This question is related to
makefile
You do see for loops alot of the time, but they are usually not needed. Here is an example of how one might perform a for loop without resorting to the shell
LIST_OF_THINGS_TO_DO = do_this do_that
$(LIST_OF_THINGS_TO_DO):
run $@ > [email protected]
SUBDIRS = snafu fubar
$(SUBDIRS):
cd $@ && $(MAKE)
Here's an example if:
ifeq ($(strip $(OS)),Linux)
PYTHON = /usr/bin/python
FIND = /usr/bin/find
endif
Note that this comes with a word of warning that different versions of Make have slightly different syntax, none of which seems to be documented very well.
Have you tried the GNU make documentation? It has a whole section about conditionals with examples.
Here's an example if:
ifeq ($(strip $(OS)),Linux)
PYTHON = /usr/bin/python
FIND = /usr/bin/find
endif
Note that this comes with a word of warning that different versions of Make have slightly different syntax, none of which seems to be documented very well.
Have you tried the GNU make documentation? It has a whole section about conditionals with examples.
You do see for loops alot of the time, but they are usually not needed. Here is an example of how one might perform a for loop without resorting to the shell
LIST_OF_THINGS_TO_DO = do_this do_that
$(LIST_OF_THINGS_TO_DO):
run $@ > [email protected]
SUBDIRS = snafu fubar
$(SUBDIRS):
cd $@ && $(MAKE)
Have you tried the GNU make documentation? It has a whole section about conditionals with examples.
Have you tried the GNU make documentation? It has a whole section about conditionals with examples.
Here's an example if:
ifeq ($(strip $(OS)),Linux)
PYTHON = /usr/bin/python
FIND = /usr/bin/find
endif
Note that this comes with a word of warning that different versions of Make have slightly different syntax, none of which seems to be documented very well.
Here's an example if:
ifeq ($(strip $(OS)),Linux)
PYTHON = /usr/bin/python
FIND = /usr/bin/find
endif
Note that this comes with a word of warning that different versions of Make have slightly different syntax, none of which seems to be documented very well.
Source: Stackoverflow.com