Linux has a function to determine whether a file exists; this function is the wildcard function of the makefile. The wildcard function can match the file list. If there is no file matching the specified pattern, the function will return empty, and the syntax is "$(wildcard PATTERN...)".
#The operating environment of this tutorial: linux7.3 system, Dell G3 computer.
Linux has a function to determine the existence of a file
Use the wildcard function of makefile
ifneq ($(wildcard FILE,) #文件存在 endif
$(wildcard FILE) means the file expansion matching the FILE file under the current path.
Assume that a.c and b.c exist in the current path, then execute src=$(wildcard *.c), the value of src will be a.c b.c;
If you do not use wildcards, such as src=$ (wildcard c.c); then you need to expand the file named c.c under the current path. Because the file does not exist under the current path, src is an empty string.
Examples are as follows:
Use the above two methods to determine whether the depend.mk file in the obj folder exists. If it exists, create a.c and b.c files.
The makefile written is as follows:
OBJ_DIR=obj fileNames = $(wildcard $(OBJ_DIR)/depend.mk) all: @echo "this is all " @echo ${fileNames} @if [ -e $(OBJ_DIR)/depend.mk ]; then touch b.c; fi ifneq ($(wildcard $(OBJ_DIR)/depend.mk),) touch a.c endif
After execution, a.c and b.c were successfully created.
Recommended learning: Linux video tutorial
The above is the detailed content of Does Linux have a function to determine the existence of a file?. For more information, please follow other related articles on the PHP Chinese website!