如何在Makefile规则之外检查文件是否存在?

问题描述 投票:1回答:2

这是一个伪代码:

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
  1. Testing if a file exists in a make file
  2. Testing if a file exists in makefile target, and quitting if not present
  3. How to check if a file exists in a makefile
file if-statement makefile gnu-make
2个回答
2
投票

单行:

GITIGNORE_PATH := $(if $(wildcard .gitignore),,../).gitignore

1
投票

这有效:

# Read it as `if .gitignore file exists`
ifneq (,$(wildcard .gitignore))
    GITIGNORE_PATH := .gitignore
else
    GITIGNORE_PATH := ../.gitignore
endif

all:
    echo GITIGNORE_PATH ${GITIGNORE_PATH}

从这个回答:https://stackoverflow.com/a/17712774/4934640

© www.soinside.com 2019 - 2024. All rights reserved.