我想僅將include指令用於特定目標。當不需要目標時,我不想運行其他makefile,因爲這意味着makefile不必要地生成。如何在特定目標的makefile中使用include指令
那麼有沒有一種方法可以有條件地使用包含指令,這是有條件的目標?或者以某種方式使include指令成爲目標的先決條件。
這是我到目前爲止有:
# Flags
INCDIR = $(CURDIR)/include
CFLAGS = -Wall -Wno-overflow -Wno-uninitialized -pedantic -std=c99 -I$(INCDIR) -O3
LFLAGS = -flat_namespace -dynamiclib -undefined dynamic_lookup
# Directory names
# Set vpath search paths
vpath %.h include
vpath %.c src
vpath %.o build
vpath %.d build
# Get files for the core library
CORE_FILES = $(wildcard src/*.c)
CORE_OBJS = $(patsubst src/%.c, build/%.o, $(CORE_FILES))
CORE_DEPS = $(CORE_OBJS:.o=.d)
# Core library target linking
core : $(CORE_OBJS) | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin.2.0.dylib $(CORE_OBJS)
# Include header prerequisites (How to do only for "core" target?)
include $(CORE_DEPS)
# Makefiles for header dependencies.
$(CORE_DEPS): build/%.d: src/%.c | build
rm -f [email protected]; \
$(CC) -I$(INCDIR) -MM $< -MT '$(@:.d=.o) [email protected]' > [email protected]
# Objects depend on directory
$(CORE_OBS) : | build
# Create build directory
build:
mkdir build
# Create bin directory
bin:
mkdir bin
# Core Compilation
$(CORE_OBJS): build/%.o: src/%.c
$(CC) -c $(CFLAGS) $< -o [email protected]
# Depencies require include/CBDependencies.h as a prerequisite
build/CBOpenSSLCrypto.o: include/CBDependencies.h
# Crypto library target linking
crypto : build/CBOpenSSLCrypto.o -lcrypto -lssl | bin
$(CC) $(LFLAGS) -o bin/libcbitcoin-crypto.2.0.dylib build/CBOpenSSLCrypto.o -lcrypto -lssl
# Crypto library compile
build/CBOpenSSLCrypto.o: dependencies/crypto/CBOpenSSLCrypto.c
$(CC) -c $(CFLAGS) $< -o [email protected]
#Clean
clean:
rm -f $(CORE_OBJS) $(CORE_DEPS) build/CBOpenSSLCrypto.o
正如你應該能夠告訴我不需要包括‘加密’的「.D」的文件,但我的‘芯’做(默認目標)。
謝謝你的幫助。
你*可以*做到這一點,但你*不應該*。它違背Make的粒子,有更好的方法。你想快速簡單的方法,還是先進的和強大的? – Beta
那我可以問一下這個問題:什麼是「製造粒」和這些「更好的方法」?只要它很容易維護。這就是我想要的。我不想手動添加標題先決條件。 –