help-make
[Top][All Lists]
Advanced

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

Re: When some files need special compilation flags, ...


From: Garrett Cooper
Subject: Re: When some files need special compilation flags, ...
Date: Tue, 8 Jul 2008 19:42:48 -0700

On Tue, Jul 8, 2008 at 6:31 AM, Greg Chicares <address@hidden> wrote:
> [Reformatted--please break lines at a reasonable length,
> especially when quoting source code. Thanks.]
>
> On 2008-07-08 05:20Z, x z wrote:
>> 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 $@
>
> special1.o: extra_cpp_flags := -D_POSIX_PTHREAD_SEMANTICS
> special2.o: extra_cpp_flags := -D_POSIX_C_SOURCE
>
> Then pass $(extra_cpp_flags) to the generic command, e.g.:
>        $(CC) $(extra_cpp_flags) -c $< -o $@

Or...

special1.o: CFLAGS += -D_POSIX_PTHREAD_SEMANTICS

special2.o: CFLAGS += -D_POSIX_C_SOURCE

... assuming you don't have built-in rules turned off.

-Garrett




reply via email to

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