Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to conditional set up a Makefile variable by testing if a file exists

Tags:

makefile

For example: I want:

if file1 exists:

CLEAN_SRC = *.h file3 

else

CLEAN_SRC =  
like image 614
Sam Liao Avatar asked Jul 03 '09 03:07

Sam Liao


People also ask

How do I know if a file is present in makefile?

just do @rm -f myfile. Because of the "-f" flag, "rm" will exit with 0 regardless of whether the file exists or not. Or, -rm myfile the lead dash telling make to ignore any error.

What is include in makefile?

The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this: include filenames ... filenames can contain shell file name patterns.

What is makefile target?

A simple makefile consists of “rules” with the following shape: target … : prerequisites … recipe … … A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ' clean ' (see Phony Targets).

What are dependencies in makefiles?

A dependency is a file that is used as input to create the target. A target often depends on several files. A command is an action that make carries out. A rule may have more than one command, each on its own line.


1 Answers

If file1 does not exist then $(wildcard file1) will evaluate to an empty string.

ifeq ($(wildcard file1),)      CLEAN_SRC = else      CLEAN_SRC = *.h file3 endif  
like image 72
John Kugelman Avatar answered Sep 24 '22 08:09

John Kugelman