浓缩 Makefile.am

Condense Makefile.am

我正在使用 autotools 构建项目。我有 configure.acmakefile.amautogen.sh。这一切都很好。我的 Jenkins 管道可以选择它并 运行 它。我的问题是 makefile.am 越来越长。最近我在我的项目中添加了一些第三部分供应商代码。

这是当前的makefile.am

AUTOMAKE_OPTIONS = foreign subdir-objects

bin_PROGRAMS = MAIN_Application

MAIN_Application_LDADD = -lsocketcan -lpthread -lm

AM_CPPFLAGS = \
-I$(srcdir)/include \
-I$(srcdir)/include/utilities \
-I$(srcdir)/include/comms \
-I$(srcdir)/include/config_parsing \
-I$(srcdir)/vendor/my_vendor/host/include \
-I$(srcdir)/vendor/my_vendor/host/source/lib/comm_mgr/inc \
-I$(srcdir)/vendor/my_vendor/host/source/lib/mem_pool/inc \
-I$(srcdir)/vendor/my_vendor/host/source/lib/osal/inc \
-I$(srcdir)/vendor/my_vendor/production/source/lib/FFT \
-I$(srcdir)/vendor/my_vendor/public/common \
-I$(srcdir)/vendor/my_vendor/public/host \
-I$(srcdir)/vendor/my_vendor/public/production

MAIN_Application_SOURCES = \
src/main.cpp \
src/scheduler.c \
src/thread_health.c \
src/signal_handler.c \
src/utilities/time_conversions.c \
src/utilities/ring_buffer.c \
src/utilities/logger.c \
src/utilities/string_operations.c \
src/config_parsing/file_operations.c \
src/config_parsing/config_parser.c \
src/comms/can.c \
src/comms/can_ring_buffer.c \
vendor/my_vendor/production/source/lib/FFT/FFT.c \
vendor/my_vendor/production/source/PROD_lib.c \
vendor/my_vendor/host/source/HLB_helper.c \
vendor/my_vendor/host/source/HLB_nscm.c \
vendor/my_vendor/host/source/HLB_apcm.c \
vendor/my_vendor/host/source/HLB_fwload.c \
vendor/my_vendor/host/source/HLB_host.c \
vendor/my_vendor/host/source/HLB_noise_floor.c \
vendor/my_vendor/host/source/lib/mem_pool/src/mem_pool.c \
vendor/my_vendor/host/source/lib/comm_mgr/src/comm_mgr_lib.c \
vendor/my_vendor/host/source/lib/osal/src/osal.c \
vendor/my_vendor/host/source/HLB_legacy_commands.c \
vendor/my_vendor/host/source/HLB_protocol.c 

我真的必须单独包含每个 .c 文件吗?为什么 vendor/my_vendor/host/*/** 不起作用?我怎样才能压缩这个 makefile.am?

Autotools 开发人员认为明确列出所有源文件是最佳做法。这避免了诸如测试或调试源之类的东西进入分发包。

您不能使用 **,因为此语法是 non-standard 扩展,特别适用于 bashzsh 等 shell,标准 POSIX globbing(make 用于其 glob 扩展)。

我认为在 Makefile.am 中使用简单的 globbing(即 *.c)会奏效,但当然你仍然需要使用每个目录。

补充一下:

您还可以通过将源代码分成多个部分来使您的 makefile 更“整洁”。所以例如你可能有这样的东西:

MAIN_Application_SOURCES = \
    src/main.cpp \
    src/scheduler.c \
    src/thread_health.c \
    src/signal_handler.c

MAIN_Application_SOURCES += \
    src/utilities/time_conversions.c \
    src/utilities/ring_buffer.c \
    src/utilities/logger.c \
    src/utilities/string_operations.c

MAIN_Application_SOURCES += \
    src/config_parsing/file_operations.c \
    src/config_parsing/config_parser.c

MAIN_Application_SOURCES += \
    src/comms/can.c \
    src/comms/can_ring_buffer.c

MAIN_Application_SOURCES += \
    vendor/my_vendor/production/source/lib/FFT/FFT.c \
    vendor/my_vendor/production/source/PROD_lib.c \
    vendor/my_vendor/host/source/HLB_helper.c \
    vendor/my_vendor/host/source/HLB_nscm.c \
    vendor/my_vendor/host/source/HLB_apcm.c \
    vendor/my_vendor/host/source/HLB_fwload.c \
    vendor/my_vendor/host/source/HLB_host.c \
    vendor/my_vendor/host/source/HLB_noise_floor.c \
    vendor/my_vendor/host/source/lib/mem_pool/src/mem_pool.c \
    vendor/my_vendor/host/source/lib/comm_mgr/src/comm_mgr_lib.c \
    vendor/my_vendor/host/source/lib/osal/src/osal.c \
    vendor/my_vendor/host/source/HLB_legacy_commands.c \
    vendor/my_vendor/host/source/HLB_protocol.c

或类似的东西,或者您甚至可以使用其他变量,然后将它们相加。也许这有助于提高可读性。