[ACCEPTED]-Adding a directory for the headers in a Makefile-header

Accepted answer
Score: 22

At least for GNU make, try the implicit 1 variable CFLAGS, as in:

Score: 15

Although the goal is ultimately to affect 43 the value of CFLAGS (as suggested by @unwind), it 42 is often not a good idea to simply set the 41 value of CFLAGS as it is often built out 40 of many pieces. You have to understand 39 the structure of the makefile, and the set 38 of macros used.


Eduardo asked: Can you 37 post macros to do the same?

Yes, but whether 36 they are helpful depends on how your makefiles 35 are structured. Here's a moderately complex 34 example from one of my makefiles.

CC        = gcc -g
XFLAGS    = -Wall -Wshadow -Wstrict-prototypes -Wmissing-prototypes \
            -DDEBUG -Wredundant-decls
#CC        = cc -g
#XFLAGS    =
UFLAGS    = # Always overrideable on the command line

DEPEND.mk  = sqlcmd-depend.mk
INSTALL.mk = sqlcmd-install.mk

ESQLC_VERSION = `esqlcver`
OFLAGS    = -g -DDEBUG -O4
OFILES.o  = # rfnmanip.o # malloc.o # strdup.o # memmove.o
#INC1     = <defined in sqlcmd-depend.mk>
#INC2     = <defined in sqlcmd-depend.mk>
INC3      = /usr/gnu/include
INC4      = ${INFORMIXDIR}/incl/esql
INC5      = . #${INFORMIXDIR}/incl
INCDIRS   = -I${INC3} -I${INC1} -I${INC2} -I${INC4} -I${INC5}
LIBSQLCMD = libsqlcmd.a
STRIP     = #-s
LIBC      = #-lc_s
LIBMALLOC = #-lefence
LIBRDLN   = -lreadline
LIBCURSES = -lcurses
LIBPOSIX4 = -lposix4
LIBG      = #-lg
LIBDIR1   = ${HOME}/lib
LIBDIR2   = /usr/gnu/lib
LIBJL1    = ${LIBDIR1}/libjl.a
LIBJL2    = ${LIBDIR1}/libjlss-${ESQLC_VERSION}.a
            ${LIBPOSIX4} ${LIBC} ${STRIP}

This a 33 makefile for a program of mine called sqlcmd (a 32 name chosen a decade and more before Microsoft 31 created a command of the same name). I 30 assume that the make program has a rule for 29 compiling C code to object like:

${CC} ${CFLAGS} -c $*.c

and that 28 the rule for linking a program from a set 27 of object files listed in the macro OBJECTS 26 looks like:


As you can see, there are separately 25 settable macros for the ESQLC_VERSION (the 24 version of Informix ESQL/C in use, derived 23 by default by runing a script esqlcver), then the 22 include directories via INC1 to INC5 and 21 INCFLAGS (there can be quite a lot of these, depending 20 on platform), and optimizer flags (OFLAGS), extra 19 flags (CFLAGS), user-defined flags (UFLAGS 18 - an idiom I use in most of my makefiles; it 17 allows the user to set UFLAGS on the make command 16 line and add an extra flag to the build), and 15 a bunch of library-related macros. This 14 is what it takes for my development makefile 13 to be tunable with minimal fuss to my development 12 platform, which can be Linux, Solaris or 11 MacOS X. For consumers of the program, there 10 is a configure script generated by autoconf, so they don't 9 have to worry about getting those bits right. However, that 8 has a strong genetic resemblance to this 7 code, including the UFLAGS option.

Note that 6 many systems for makefile building have 5 a mechanism for setting CFLAGS faintly similar 4 to this - and simply assigning to CFLAGS 3 undoes the good work done by the system. But 2 you have to understand your makefile to 1 be able to modify it sanely.


More Related questions