[lttng-dev] [PATCH lttng-ust v2] Move include directive from CFLAGS to LOCAL_CPPFLAGS in examples' Makefiles

Jérémie Galarneau jeremie.galarneau at efficios.com
Tue May 28 18:44:54 EDT 2013


On Tue, May 28, 2013 at 6:26 PM, Mathieu Desnoyers
<mathieu.desnoyers at efficios.com> wrote:
> * Jérémie Galarneau (jeremie.galarneau at efficios.com) wrote:
>> The use of LOCAL_* flags and override directives ensures that the build
>> succeeds even if the user explicitly overrides CFLAGS/CPPFLAGS/LDFLAGS.
>
> why use LOCAL_CPPFLAGS on one hand, but "override LDFLAGS" on the other?
> What's the difference ?

LOCAL_CPPFLAGS is necessary to build the example in and out of the
lttng-ust tree. However, the LDFLAGS modification is only necessary
when building in-tree (without installing lttng-ust).

> Why should it differ ?

I expect people to use these Makefiles as templates for their own
projects and to completely strip the "ifdef BUILD_EXAMPLES_FROM_TREE"
section. I'm using "override" here to avoid introducing a superfluous
variable in the intended purpose of these examples.

It doesn't make a functional difference; I just want to keep these
examples as dead-simple as possible :)

Jérémie

>
> Thanks,
>
> Mathieu
>
>>
>> Fixes #537
>>
>> Signed-off-by: Jérémie Galarneau <jeremie.galarneau at efficios.com>
>> ---
>>  doc/examples/demo/Makefile             | 14 +++++++-------
>>  doc/examples/easy-ust/Makefile         | 10 +++++-----
>>  doc/examples/hello-static-lib/Makefile | 10 +++++-----
>>  3 files changed, 17 insertions(+), 17 deletions(-)
>>
>> diff --git a/doc/examples/demo/Makefile b/doc/examples/demo/Makefile
>> index bbc8ccb..27ca92b 100644
>> --- a/doc/examples/demo/Makefile
>> +++ b/doc/examples/demo/Makefile
>> @@ -15,14 +15,14 @@
>>  CC = gcc
>>  LIBS = -ldl  # On Linux
>>  #LIBS = -lc  # On BSD
>> -CFLAGS += -I.
>> +LOCAL_CPPFLAGS += -I.
>>
>>  # Only necessary when building from the source tree and lttng-ust is not
>>  # installed
>>  ifdef BUILD_EXAMPLES_FROM_TREE
>> -CFLAGS += -I../../../include/
>> +LOCAL_CPPFLAGS += -I../../../include/
>>  LIBLTTNG_UST_PATH = ../../../liblttng-ust/.libs/
>> -LDFLAGS += -L$(LIBLTTNG_UST_PATH) -Wl,-rpath='$$ORIGIN/$(LIBLTTNG_UST_PATH)'
>> +override LDFLAGS += -L$(LIBLTTNG_UST_PATH) -Wl,-rpath='$$ORIGIN/$(LIBLTTNG_UST_PATH)'
>>
>>  # Third-party Makefiles have to define these targets to integrate with an
>>  # automake project
>> @@ -37,22 +37,22 @@ endif
>>  all: demo lttng-ust-provider-ust-tests-demo.so lttng-ust-provider-ust-tests-demo3.so
>>
>>  tp.o: tp.c ust_tests_demo.h
>> -     $(CC) $(CPPFLAGS) $(CFLAGS) -fpic -c -o $@ $<
>> +     $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) -fpic -c -o $@ $<
>>
>>  tp2.o: tp2.c ust_tests_demo2.h
>> -     $(CC) $(CPPFLAGS) $(CFLAGS) -fpic -c -o $@ $<
>> +     $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) -fpic -c -o $@ $<
>>
>>  lttng-ust-provider-ust-tests-demo.so: tp.o tp2.o
>>       $(CC) -shared -o $@ $(LDFLAGS) -llttng-ust $^
>>
>>  tp3.o: tp3.c ust_tests_demo3.h
>> -     $(CC) $(CPPFLAGS) $(CFLAGS) -fpic -c -o $@ $<
>> +     $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) -fpic -c -o $@ $<
>>
>>  lttng-ust-provider-ust-tests-demo3.so: tp3.o
>>       $(CC) -shared -o $@ $(LDFLAGS) -llttng-ust $^
>>
>>  demo.o: demo.c
>> -     $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
>> +     $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) -c -o $@ $<
>>
>>  demo: demo.o
>>       $(CC) -o $@ $^ $(LIBS)
>> diff --git a/doc/examples/easy-ust/Makefile b/doc/examples/easy-ust/Makefile
>> index e20e53a..e3546e1 100644
>> --- a/doc/examples/easy-ust/Makefile
>> +++ b/doc/examples/easy-ust/Makefile
>> @@ -17,14 +17,14 @@
>>  CC = gcc
>>  LIBS = -ldl -llttng-ust              # On Linux
>>  #LIBS = -lc -llttng-ust              # On BSD
>> -CFLAGS += -I.
>> +LOCAL_CPPFLAGS += -I.
>>
>>  # Only necessary when building from the source tree and lttng-ust is not
>>  # installed
>>  ifdef BUILD_EXAMPLES_FROM_TREE
>> -CFLAGS += -I../../../include/
>> +LOCAL_CPPFLAGS += -I../../../include/
>>  LIBLTTNG_UST_PATH = ../../../liblttng-ust/.libs/
>> -LDFLAGS += -L$(LIBLTTNG_UST_PATH) -Wl,-rpath='$$ORIGIN/$(LIBLTTNG_UST_PATH)'
>> +override LDFLAGS += -L$(LIBLTTNG_UST_PATH) -Wl,-rpath='$$ORIGIN/$(LIBLTTNG_UST_PATH)'
>>
>>  # Third-party Makefiles have to define these targets to integrate with an
>>  # automake project
>> @@ -42,10 +42,10 @@ sample: sample.o tp.o
>>       $(CC) -o $@ $^ $(LDFLAGS) $(LIBS)
>>
>>  sample.o: sample.c sample_component_provider.h
>> -     $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
>> +     $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) -c -o $@ $<
>>
>>  tp.o: tp.c sample_component_provider.h
>> -     $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
>> +     $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) -c -o $@ $<
>>
>>  html: sample_component_provider.html sample.html tp.html
>>
>> diff --git a/doc/examples/hello-static-lib/Makefile b/doc/examples/hello-static-lib/Makefile
>> index dd246f7..85c64c1 100644
>> --- a/doc/examples/hello-static-lib/Makefile
>> +++ b/doc/examples/hello-static-lib/Makefile
>> @@ -13,16 +13,16 @@
>>  # a program with tracepoint provider probes compiled as static libraries.
>>
>>  CC = gcc
>> -CFLAGS += -I.
>> +LOCAL_CPPFLAGS += -I.
>>  LIBS = -ldl -llttng-ust      # On Linux
>>  #LIBS = -lc -llttng-ust      # On BSD
>>
>>  # Only necessary when building from the source tree and lttng-ust is not
>>  # installed
>>  ifdef BUILD_EXAMPLES_FROM_TREE
>> -CFLAGS += -I../../../include/
>> +LOCAL_CPPFLAGS += -I../../../include/
>>  LIBLTTNG_UST_PATH = ../../../liblttng-ust/.libs/
>> -LDFLAGS += -L$(LIBLTTNG_UST_PATH) -Wl,-rpath='$$ORIGIN/$(LIBLTTNG_UST_PATH)'
>> +override LDFLAGS += -L$(LIBLTTNG_UST_PATH) -Wl,-rpath='$$ORIGIN/$(LIBLTTNG_UST_PATH)'
>>
>>  # Third-party Makefiles have to define these targets to integrate with an
>>  # automake project
>> @@ -37,13 +37,13 @@ endif
>>  all: hello
>>
>>  lttng-ust-provider-hello.o: tp.c ust_tests_hello.h
>> -     $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
>> +     $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) -c -o $@ $<
>>
>>  lttng-ust-provider-hello.a: lttng-ust-provider-hello.o
>>       ar -rc $@ $^
>>
>>  hello.o: hello.c
>> -     $(CC) $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
>> +     $(CC) $(CPPFLAGS) $(LOCAL_CPPFLAGS) $(CFLAGS) -c -o $@ $<
>>
>>  hello: hello.o lttng-ust-provider-hello.a
>>       $(CC) -o $@ $(LDFLAGS) $^ $(LIBS)
>> --
>> 1.8.2.3
>>
>>
>> _______________________________________________
>> lttng-dev mailing list
>> lttng-dev at lists.lttng.org
>> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com



-- 
Jérémie Galarneau
EfficiOS Inc.
http://www.efficios.com



More information about the lttng-dev mailing list