Makefile 依赖项和时间戳

发布于 2024-12-12 02:14:45 字数 3026 浏览 0 评论 0原文

我有一个 makefile,用于使用第三方 IDL 编译器 (rtiddsgen) 生成工件。它接收 idl 文件并输出与其相关的 C/Ada 文件。然后编译 C 文件并将其放入库 (idl_dds_types.a)

我在 IDL_TYPES 变量中列出了 IDL 文件。每个 IDL_TYPES 文件将生成(通过 rtiddsgen)以下形式的文件(例如使用alerts.idl):

alerts.c
alerts.h
alerts_idl.ads
alerts_idl.adb

因此,我想要发生的是当alerts.idl的时间戳比alerts.c(或obj.Linux- i686/alerts.o) 文件,然后重新生成alerts.c 文件。这似乎并没有发生。有什么想法我需要做什么才能实现这一点?我已经通过“touch”-ing idl 文件然后重新运行 make 进行了测试。

这是生成文件:

DDS_OUT_DIR = $(MY_HOME)/DDS/DDS_Types/src

IDL_DIR=$(MY_HOME)/DDS/DDS_Types/IDL
IDL_TYPES=common.idl alerts.idl summary.idl
GENERATED_SOURCES =  $(IDL_TYPES:%.idl=%.c)
GENERATED_HEADERS =  $(IDL_TYPES:%.idl=%.h)

LIBNAME  = idl_dds_types

OBJS_DIR       = obj.$(CPUTYPE)

GENERATED_OBJS = $(GENERATED_SOURCES:%.c=$(OBJS_DIR)/%.o)

LIBDIR   = $(DDS_OUT_DIR)/../../lib.$(CPUTYPE)
BINDIR   = $(DDS_OUT_DIR)/../../../../bin.$(CPUTYPE)
CC       = $(C_COMPILER)
CXX      = $(CPP_COMPILER)
OS       = $(shell uname)
DDSCOMMON = $(DDS_OUT_DIR)/../../Common/src

CFLAGS   = -m32 -g -DRTI_UNIX -DRTI_32BIT
CXXFLAGS = -m32 -g
LDFLAGS  = -m32 -static-libgcc
SYSLIBS  = -ldl -lnsl -lpthread -lm -lc


DEFINES_ARCH_SPECIFIC = -DRTI_UNIX

DEFINES = $(DEFINES_ARCH_SPECIFIC) $(cxx_DEFINES_ARCH_SPECIFIC)

INCLUDES  = -I. -I$(NDDSHOME)/include -I$(NDDSHOME)/include/ndds
INCLUDES += -I$(DDSCOMMON)

LIBS = -L$(NDDSLIBDIR) -L$(LIBDIR) -lrt \
      -lnddscppz -lnddscz -lnddscorez $(SYSLIBS) $(OS_SPECIFIC_LIBS)

COMMONLIBSRC  = $(DDSCOMMON)/dds_common.cxx
COMMONLIBOBJS = $(DDSCOMMON)/obj.$(CPUTYPE)/%.o

$(shell mkdir -p $(OBJS_DIR) $(DDSCOMMON)/obj.$(CPUTYPE) $(DDS_CPP_DIR))

default:        $(GENERATED_OBJS) $(LIBDIR)/lib$(LIBNAME).a

$(OBJS_DIR)/%.o : %.idl $(DDSCOMMON)/dds_common.h
       $(C_COMPILER)  -o $(OBJS_DIR)/$(*F).o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F).c; \
       $(C_COMPILER)  -o $(OBJS_DIR)/$(*F)Support.o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F)Support.c; \
       $(C_COMPILER)  -o $(OBJS_DIR)/$(*F)Plugin.o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F)Plugin.c; \

$(LIBDIR)/lib$(LIBNAME).a: $(GENERATED_OBJS) $(CPP_OBJS)
       @echo "Adding these to lib: " $(OBJS_DIR)/*.o; \
       mkdir -p $(LIBDIR)
       rm -f $(LIBDIR)/lib$(LIBNAME).a
       $(AR) -cr $(LIBDIR)/lib$(LIBNAME).a $(OBJS_DIR)/*.o
       ranlib $(LIBDIR)/lib$(LIBNAME).a

%.idl:
       @echo "Generating C and Ada from $@ ..."; \
       $(NDDSHOME)/scripts/rtiddsgen ${IDL_DIR}/$@ -d $(DDS_OUT_DIR) -I ${IDL_DIR} -replace -language Ada; # -example i86Linux2.6gcc4.1.2;



clean:
       rm -rf $(LIBDIR)/lib$(LIBNAME).a; \
       rm -rf $(DDS_OUT_DIR)/*.h; \
   rm -rf $(DDS_OUT_DIR)/*.c; \
       rm -rf $(DDS_OUT_DIR)/*.gpr; \
       rm -rf $(DDS_OUT_DIR)/samples; \
       rm -rf $(DDS_OUT_DIR)/*.xml; \
       rm -rf $(DDS_OUT_DIR)/makefile_*; \
       rm -rf $(DDS_OUT_DIR)/bin; \
       rm -rf $(DDS_OUT_DIR)/summary_idl*; \
       rm -rf $(DDS_OUT_DIR)/common_idl*; \
       rm -rf $(DDS_OUT_DIR)/alerts_idl*; \
       rm -rf $(DDS_OUT_DIR)/$(OBJS_DIR);

I have a makefile that I am using to generate artifacts using a third party IDL compiler (rtiddsgen). This takes in idl files and spits out C/Ada files relating to them. The C files are then compiled and put into a library (idl_dds_types.a)

I have the IDL files listed in the IDL_TYPES variable. Each IDL_TYPES file will generate (through rtiddsgen) files of the following form (For example with alerts.idl):

alerts.c
alerts.h
alerts_idl.ads
alerts_idl.adb

So, what I want to happen is when alerts.idl's timestamp is newer than the alerts.c (or the obj.Linux-i686/alerts.o) file, then the alerts.c file is regenerated. This doesn't seem to be happening. Any ideas what I need to do to make this happen? I've tested by "touch"-ing the idl file and then re-running make.

Here is the makefile:

DDS_OUT_DIR = $(MY_HOME)/DDS/DDS_Types/src

IDL_DIR=$(MY_HOME)/DDS/DDS_Types/IDL
IDL_TYPES=common.idl alerts.idl summary.idl
GENERATED_SOURCES =  $(IDL_TYPES:%.idl=%.c)
GENERATED_HEADERS =  $(IDL_TYPES:%.idl=%.h)

LIBNAME  = idl_dds_types

OBJS_DIR       = obj.$(CPUTYPE)

GENERATED_OBJS = $(GENERATED_SOURCES:%.c=$(OBJS_DIR)/%.o)

LIBDIR   = $(DDS_OUT_DIR)/../../lib.$(CPUTYPE)
BINDIR   = $(DDS_OUT_DIR)/../../../../bin.$(CPUTYPE)
CC       = $(C_COMPILER)
CXX      = $(CPP_COMPILER)
OS       = $(shell uname)
DDSCOMMON = $(DDS_OUT_DIR)/../../Common/src

CFLAGS   = -m32 -g -DRTI_UNIX -DRTI_32BIT
CXXFLAGS = -m32 -g
LDFLAGS  = -m32 -static-libgcc
SYSLIBS  = -ldl -lnsl -lpthread -lm -lc


DEFINES_ARCH_SPECIFIC = -DRTI_UNIX

DEFINES = $(DEFINES_ARCH_SPECIFIC) $(cxx_DEFINES_ARCH_SPECIFIC)

INCLUDES  = -I. -I$(NDDSHOME)/include -I$(NDDSHOME)/include/ndds
INCLUDES += -I$(DDSCOMMON)

LIBS = -L$(NDDSLIBDIR) -L$(LIBDIR) -lrt \
      -lnddscppz -lnddscz -lnddscorez $(SYSLIBS) $(OS_SPECIFIC_LIBS)

COMMONLIBSRC  = $(DDSCOMMON)/dds_common.cxx
COMMONLIBOBJS = $(DDSCOMMON)/obj.$(CPUTYPE)/%.o

$(shell mkdir -p $(OBJS_DIR) $(DDSCOMMON)/obj.$(CPUTYPE) $(DDS_CPP_DIR))

default:        $(GENERATED_OBJS) $(LIBDIR)/lib$(LIBNAME).a

$(OBJS_DIR)/%.o : %.idl $(DDSCOMMON)/dds_common.h
       $(C_COMPILER)  -o $(OBJS_DIR)/$(*F).o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F).c; \
       $(C_COMPILER)  -o $(OBJS_DIR)/$(*F)Support.o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F)Support.c; \
       $(C_COMPILER)  -o $(OBJS_DIR)/$(*F)Plugin.o $(DEFINES) $(INCLUDES) $(CFLAGS) -c $(*F)Plugin.c; \

$(LIBDIR)/lib$(LIBNAME).a: $(GENERATED_OBJS) $(CPP_OBJS)
       @echo "Adding these to lib: " $(OBJS_DIR)/*.o; \
       mkdir -p $(LIBDIR)
       rm -f $(LIBDIR)/lib$(LIBNAME).a
       $(AR) -cr $(LIBDIR)/lib$(LIBNAME).a $(OBJS_DIR)/*.o
       ranlib $(LIBDIR)/lib$(LIBNAME).a

%.idl:
       @echo "Generating C and Ada from $@ ..."; \
       $(NDDSHOME)/scripts/rtiddsgen ${IDL_DIR}/$@ -d $(DDS_OUT_DIR) -I ${IDL_DIR} -replace -language Ada; # -example i86Linux2.6gcc4.1.2;



clean:
       rm -rf $(LIBDIR)/lib$(LIBNAME).a; \
       rm -rf $(DDS_OUT_DIR)/*.h; \
   rm -rf $(DDS_OUT_DIR)/*.c; \
       rm -rf $(DDS_OUT_DIR)/*.gpr; \
       rm -rf $(DDS_OUT_DIR)/samples; \
       rm -rf $(DDS_OUT_DIR)/*.xml; \
       rm -rf $(DDS_OUT_DIR)/makefile_*; \
       rm -rf $(DDS_OUT_DIR)/bin; \
       rm -rf $(DDS_OUT_DIR)/summary_idl*; \
       rm -rf $(DDS_OUT_DIR)/common_idl*; \
       rm -rf $(DDS_OUT_DIR)/alerts_idl*; \
       rm -rf $(DDS_OUT_DIR)/$(OBJS_DIR);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

凉墨 2024-12-19 02:14:45

%.idl: 规则这样的规则告诉 make 如何生成 .idl 文件,而不是如何从 .idl 文件生成内容。您想将其更改为 %.c: %.idl ——如何从 .idl 文件生成 .c 文件。

这将完成您想要的大部分操作 - 唯一的问题是您是否希望能够生成 .ads/.adb 文件而不生成 .c 文件或重建库。

A rule like your %.idl: rule tells make how to generate .idl files, not how to generate things from .idl files. You want to change this to %.c: %.idl -- how to generate .c files from .idl files.

That will do most of what you want -- the only problem is if you ever want to be able to generate .ads/.adb files WITHOUT generating .c files or rebuilding the library.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文