简体   繁体   English

压缩 Makefile.am

[英]Condense Makefile.am

I am using autotools to build a project.我正在使用自动工具来构建一个项目。 I have a configure.ac , makefile.am and autogen.sh .我有一个configure.acmakefile.amautogen.sh This all works great.这一切都很好。 My Jenkins pipeline can pick this up and run it.我的 Jenkins 管道可以选择并运行它。 My issue is the makefile.am is getting longer and longer.我的问题是makefile.am越来越长。 Recently I added some 3rd part vendor code to my project.最近我在我的项目中添加了一些第 3 部分供应商代码。

This is the current 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 

Do I really have to include each .c file individually?我真的必须单独包含每个.c文件吗? Why does vendor/my_vendor/host/*/** not work?为什么vendor/my_vendor/host/*/**不起作用? How can I compress this makefile.am ?如何压缩这个makefile.am

Autotools developers consider it to be best practice to explicitly list all the source files. Autotools 开发人员认为明确列出所有源文件是最佳实践。 This avoids things like test or debug sources etc. creeping into distribution packages.这避免了诸如测试或调试源等之类的东西潜入分发包。

You can't use ** because this syntax is a non-standard extension available specifically in shells like bash and zsh , that is not supported by standard POSIX globbing (which is what make uses for its glob expansion).您不能使用**因为此语法是专门在bashzsh等 shell 中可用的非标准扩展,标准 POSIX 通配符不支持(这是 make 用于其 glob 扩展的原因)。

I think it would work to use simple globbing (that is, *.c ) in Makefile.am but of course you'd still need to use each directory.我认为在Makefile.am中使用简单的通配符(即*.c )会起作用,但当然你仍然需要使用每个目录。

Just to add:只需添加:

You can also make your makefile "tidier" by breaking up the sources into sections.您还可以通过将源代码分成多个部分来使您的 makefile 更“整洁”。 So for example you might have something like:因此,例如,您可能有类似的东西:

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

or something like that, or you could even use other variables and then add them together.或类似的东西,或者你甚至可以使用其他变量,然后将它们加在一起。 Maybe that helps with readability.也许这有助于提高可读性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM