help-make
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

When some files need special compilation flags, ...


From: x z
Subject: When some files need special compilation flags, ...
Date: Tue, 8 Jul 2008 05:20:58 +0000

I am compiling C programs using gcc on Solaris.  Solaris need some special compilation flags to ensure POSIX conformance.  For example, if one needs to call sigwait() with the POSIX syntax (and semantics too?), one needs to add a -D_POSIX_PTHREAD_SEMANTICS flag to the compilation command, according to sigwait()'s man page.  In other cases, one may need to add -D_POSIX_C_SOURCE for multithreaded programs.
Based on my experience, Solaris does not seem to be very robust and the definition of these flags may produce a compilation error when included in compiling files that do not need these flags.
So, how to write a Makefile that can accomodate the inclusion of certain flags when compiling certain files?
Of course, one can always set up separate rules for these special files, and a general rule (without those flags) for the rest.  But that looks clumsy:
SRCS    =       file1.c file2.c file3.c .....
OBJ     =       ${SRCS:.c=.o}
$(OBJ): %.o: %.c
        $(CC) -c $< -o $@
special1.o: special1.c
        $(CC) -D_POSIX_PTHREAD_SEMANTICS -c $< -o $@
special2.o: special2.c
        $(CC) -D_POSIX_C_SOURCE -c $< -o $@
...


Making the world a better place one message at a time. Check out the i'm Talkathon.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]