Autotools: using -D with variables works for all but one compiler (C programming)
I'm going to convert the old autotools setup from handwritten Makefile.in
(and of course a configure.in
) to the latter ( Makefile.am
and configure.ac
). Everything looked good so far, but I ran into something that I cannot find the answer to in other questions.
I added a definition to Makefile.am
, which is included in the compilation of all c-modules mentioned in _SOURCES
, but one. I see absolutely no difference between c sources, except that the main focus of the program is where the definition is not included in the compilation.
Below is the code for Makefile.am
(relevant part):
bin_PROGRAMS = wpe we
lib_LTLIBRARIES = libxwpe-x11.la libxwpe-term.la
libxwpe_x11_la_SOURCES = we_xterm.c WeXterm.c
libxwpe_x11_la_CPPFLAGS = -DLIBRARY_DIR=\"@libdir@/xwpe\"
libxwpe_term_la_SOURCES = we_term.c
libxwpe_term_la_CPPFLAGS = -DLIBRARY_DIR=\"@libdir@/xwpe\"
wpe_SOURCES = we_main.c we_block.c we_unix.c we_e_aus.c \
we_edit.c we_fl_fkt.c we_fl_unix.c we_hfkt.c \
we_menue.c we_mouse.c we_opt.c we_wind.c \
we_prog.c we_progn.c we_debug.c WeString.c \
WeSyntax.c WeExpArr.c WeLinux.c we_gpm.c
wpe_LDADD = libxwpe-x11.la libxwpe-term.la
wpe_CPPFLAGS = -DLIBRARY_DIR=\"@libdir@/xwpe\"
we_SOURCES = we_main.c we_block.c we_unix.c we_e_aus.c \
we_edit.c we_fl_fkt.c we_fl_unix.c we_hfkt.c \
we_menue.c we_mouse.c we_opt.c we_wind.c \
we_prog.c we_progn.c we_debug.c WeString.c \
WeSyntax.c WeExpArr.c WeLinux.c we_gpm.c
The result of compilation is that all c sources are compiled with the definition of LIBRARY_DIR, except we_main.c
that compiled without this definition.
Does anyone know what might be causing this difference? What am I doing wrong? Should I define wpe_CPPFLAGS
but some other flag?
EDIT 1: Looking at the Makefile I noticed that it compiles we_main multiple times! He creates we-we_main.o
, wpe-we_main.o
and xwe-we_main.o
. These files are all compiled correctly, but the only thing I don't understand is compilation we_main.o
which is compiled without definition. It looks like I am missing a flag that I should have defined. Perhaps I misunderstood the automaton entry in the Makefile.am. Should I define an additional flag? If so, which one?
EDIT 2: Multiple compilers seem a bit wasteful. I'm new to autotools so there might be a better solution. If necessary, I will ask another question on this issue.
source to share
I found the answer due to observation in EDIT 1
. I first used CPPFLAGS = -DLIBRARY_DIR=\"@libdir@/xwpe\".
autoreconf warned me to better use
AM_CPPFLAGS`, so I did that and it solved the problem.
Also, I found that I didn’t need everything specific to the program we_CPPFLAGS
, wpe_CPPFLAGS
and xwe_CPPFLAGS
because it AM_CPPFLAGS
adds to all.
This way, you only need specific xxx_CPPFLAGS
if xxx is different from other programs.
Sorry to bother you. Hope this helps someone else who has the same request.
Edit 1: This change also removed several compilations from the same sources. In hindsight, it makes sense: if they xxx_CPPFLAGS
are specific to one program, then the program xxx
must be compiled separately. If they all have the same flags, this is no longer needed.
source to share