2016-06-13 68 views
-1

我有一組生成的文件。在Makefile依賴中包含生成的文件

GENERATED = log/loga.c log/logb.h include/loga.h 

我下面initproc目標依賴於上述GENERATED。但我不能在下面包含$(GENERATED),如$(INIT_OBJS)。它說

fatal error: include/loga.h: No such file or directory當我做make initproc

initproc: $(INIT_OBJS) log/loga.o init/initb.o settings/settingc.o 
      $(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(LDLIBSXX) -o [email protected] 

怎樣包括上面的依賴?

+1

郵報[mvce(http://stackoverflow.com/help/mcve),還有你的鏈接規則,但這個錯誤顯然是指一個編譯錯誤。 – user657267

回答

2

你必須添加一個$(GENERATED)目標的一些規則來解釋如何生成這些文件。此外,您必須使用一些patsusbtfilter函數來管理標題,源文件和目標文件。類似的東西應該工作:

# All the generated files (source and header files) 
GENERATED := log/loga.c log/logb.h include/loga.h 

# The rules to generate this files 
$(GENERATED): 
     <some commands to generate the files ...> 

# The rules to generate object files from the generated source files 
# This could be merge with another rule from your Makefile 
GENERATED_SRC := $(filter %.c,$(GENERATED)) 
GENERATED_OBJ := $(patsubst %.c,%.o,$(GENERATED_SRC)) 

$(GENERATED_OBJ): $(GENERATED_SRC) 
     $(CXX) $(CXXFLAGS) -c $^ -o [email protected] 

# The final target depends on the generated object files 
initproc: $(INIT_OBJS) <other objects ...> $(GENERATED_OBJ) 
     $(CXX) $(CXXFLAGS) $(LDFLAGS) $^ $(LDLIBSXX) -o [email protected]