在Makefile依赖项中包含生成的文件

时间:2016-06-13 03:33:46

标签: makefile dependencies

我有一组生成的文件。

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 $@

class Upload < ActiveRecord::Base
  belongs_to :event
  attachment :upload_file
end

如何在上面添加依赖项?

1 个答案:

答案 0 :(得分: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 $@

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