强制结束循环依赖之前先查看文件

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

我有一个使用make的循环依赖项:

CC              = gcc
IFLAGS          = -Iinclude
CFLAGS          = -Wall -g -c -fPIC -pedantic
AFLAGS          = -shared
LFLAGS          =
VERSION         = $(shell cat desc/major).$(shell cat desc/minor).$(shell cat desc/patch)
DFLAGS          = -D_XOPEN_SOURCE=700 -DLTKVER=\"$(VERSION)\"

OBJECTS         = $(patsubst src/%.c,tmp/%.o, $(shell ls -1 src/*.c))

#OUTPUT         = tmp/$(lastword $(subst /, ,$(shell pwd)))
OUT_BIN         = install/usr/lib/libLTK.so
OUT_MAN         = $(patsubst man/%,install/usr/share/man/%.gz, $(shell find man -type f))
PATH_INCLUDE    = install/usr/include/LTK-$(VERSION)
OUT_INCLUDE     = $(patsubst %,$(PATH_INCLUDE)/%, $(shell find include -type f -printf "%f\n"))
PC              = %

all: $(OUT_BIN) $(OUT_MAN) $(OUT_INCLUDE)
#   chmod 755 install/usr/lib/libLTK.so.$(VERSION)
    ln -sf install/usr/lib/libLTK.so.$(VERSION) install/usr/lib/libLTK.so
#   chmod 755 install/usr/include/LTK-$(VERSION)
#   chmod 644 install/usr/include/LTK-$(VERSION)/*
    ln -sf install/usr/include/LTK-$(VERSION) install/usr/include/LTK

$(OUT_BIN): $(OBJECTS)
    mkdir -p $(shell dirname $@)
    $(CC) $(AFLAGS) -o $@.$(VERSION) $^ $(LFLAGS)

tmp/%.o : src/%.c
    mkdir -p $(shell dirname $@)
    $(CC) $(CFLAGS) -o $@ $< $(DFLAGS) $(IFLAGS)

install/usr/share/%.gz : %
    mkdir -p $(shell dirname $@)
    gzip -c $< > $@

.SECONDEXPANSION:
%.h : $$(patsubst $(PATH_INCLUDE)/$$(PC),include/$$(PC),$$@)
    mkdir -p $(shell dirname $$@)
    cp $< $$@

clean:
    rm -rf tmp install

在第二个扩展头文件中,从第二个扩展生成了先决条件。但这是一个生成另一个头的标头,并且可以在磁盘上找到这个新头。但是make宁愿考虑考虑循环依赖而忽略它。我如何强制make在搜索目标以生成文件之前先查看该文件是否存在?

makefile
1个回答
0
投票
最后通过将$(OUT_INCLUDE)替换为%.h来解决。

保留了自动复制包含文件的目标。替换为:

.SECONDEXPANSION: $(OUT_INCLUDE) : $$(patsubst $(PATH_INCLUDE)/$$(PERCENT),include/$$(PERCENT),$$@) mkdir -p $(shell dirname $@) cp $< $@

为此:

.SECONDEXPANSION: %.h : $$(patsubst $(PATH_INCLUDE)/$$(PC),include/$$(PC),$$@) mkdir -p $(shell dirname $$@) cp $< $$@

但是我仍然在问自己“有什么要在依赖之前强制执行文件”的问题。看完代码后,看起来好像没有,除非我省略一些内容。
© www.soinside.com 2019 - 2024. All rights reserved.