如何在 Makefile 规则之外检查文件是否存在?
How to check whether a file exists, outside a Makefile rule?
这是一个伪代码:
if .gitignore exists
GITIGNORE_PATH := .gitignore
else
GITIGNORE_PATH := ../.gitignore
fi
all:
do_build...
我试图搜索这个,但他们总是显示如何在规则中执行此操作,如:
$(UBIN)/%:
@if [ -f '$@' ]; then \
$(CC) $(CFLAGS) -o '$@' $(OBJS) -L $(ORAHOME) $(ORALIBS) \
$(LNKPATH) $(DSTN_LIBS); \
echo ""; \
fi
- Testing if a file exists in a make file
- Testing if a file exists in makefile target, and quitting if not present
- How to check if a file exists in a makefile
这有效:
# Read it as `if .gitignore file exists`
ifneq (,$(wildcard .gitignore))
GITIGNORE_PATH := .gitignore
else
GITIGNORE_PATH := ../.gitignore
endif
all:
echo GITIGNORE_PATH ${GITIGNORE_PATH}
来自这个答案:
一行:
GITIGNORE_PATH := $(if $(wildcard .gitignore),,../).gitignore
这是一个伪代码:
if .gitignore exists
GITIGNORE_PATH := .gitignore
else
GITIGNORE_PATH := ../.gitignore
fi
all:
do_build...
我试图搜索这个,但他们总是显示如何在规则中执行此操作,如:
$(UBIN)/%:
@if [ -f '$@' ]; then \
$(CC) $(CFLAGS) -o '$@' $(OBJS) -L $(ORAHOME) $(ORALIBS) \
$(LNKPATH) $(DSTN_LIBS); \
echo ""; \
fi
- Testing if a file exists in a make file
- Testing if a file exists in makefile target, and quitting if not present
- How to check if a file exists in a makefile
这有效:
# Read it as `if .gitignore file exists`
ifneq (,$(wildcard .gitignore))
GITIGNORE_PATH := .gitignore
else
GITIGNORE_PATH := ../.gitignore
endif
all:
echo GITIGNORE_PATH ${GITIGNORE_PATH}
来自这个答案:
一行:
GITIGNORE_PATH := $(if $(wildcard .gitignore),,../).gitignore