You can use defines with foreach function :

SPECIAL1 = special1.c ...
SPECIAL2 = special2.c ...
OTHER_SRC = ...

define SPECIAL1_DEPS
$(patsubst %.c,%.o,$(1)): $(1)
   $(CC) -D_POSIX_PTHREAD_SEMANTICS -c $$< -o $$@
endef

define SPECIAL2_DEPS
$(patsubst %.c,%.o,$(1)): $(1)
   $(CC) -D_POSIX_C_SOURCE -c $$< -o $$@
endef

$(foreach FILE,$(SPECIAL1), \
 $(eval $(call SPECIAL1_DEPS,$(FILE))) \
)

$(foreach FILE,$(SPECIAL2), \
 $(eval $(call SPECIAL2_DEPS,$(FILE))) \
)

...

x z wrote:
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. <http://www.imtalkathon.com/?source=EML_WLH_Talkathon_BetterPlace>
--
This message has been scanned for viruses and
dangerous content by *MailScanner* <http://www.mailscanner.info/>, and is
believed to be clean.
------------------------------------------------------------------------

_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make


--
Boris Godin
*Java Developer* - Gameloft COR
Paraná 560, Nueva Córdoba (CP 5000)
Tel.: (+54 0351) 460 26 26 int. 111
MSN: [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>

--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

_______________________________________________
Help-make mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/help-make

Reply via email to