On 27 December 2017 at 18:18, Willy Tarreau <w...@1wt.eu> wrote:

> Hi David,
>
> On Wed, Dec 27, 2017 at 01:23:34PM +0000, David CARLIER wrote:
> > diff --git a/contrib/spoa_example/Makefile b/contrib/spoa_example/
> Makefile
> > index c44c2b879..71ba6107a 100644
> > --- a/contrib/spoa_example/Makefile
> > +++ b/contrib/spoa_example/Makefile
> > @@ -2,12 +2,14 @@ DESTDIR =
> >  PREFIX  = /usr/local
> >  BINDIR  = $(PREFIX)/bin
> >
> > -CC = gcc
> > +CC ?= gcc
>
> Please don't use "?=". It will inherit stuff from the environment, leading
> to all sort of surprizes. Instead "=" is easily overriden on the command
> line. Example :
>

True. Here a new patch if you like. Cheers.


>
>   $ CC=foo make
>
> will always use "gcc" when the rule says "CC = gcc" but will use "foo" when
> the rule uses "CC ?= gcc".
>
> But :
>
>   $ make CC=foo
>
> will always use "foo" regardless of how you write your rule. If you
> explicitly
> want to force using "$CC" in your case because you do have such a variable
> in
> your environment that you prefer, you can easily do it this way :
>
>   $ make CC=$CC
>
> While it may not seem obvious for a variable such as CC that it's bad to
> have Make automatically inherit random variables, it becomes much more
> visible when you simply type "env" on your shell after a day of work and
> figure the number of things you've added for a temporary usage that you
> forgot to unset and that you'd never want your makefile to automatically
> use! And it's even worse when you make from a script which may sometimes
> set CFLAGS or stuff like this for certain components.
>
> So it's a good practice to isolate makefiles against accidental use of
> environment variables. Some projects have gone to great lengths doing
> this, e.g. to avoid randomly breaking complex build setups (like CFLAGS
> silently being passed through older versions of gcc+glibc+binutils build
> sessions, randomly breaking toolchain utilities, sometimes requiring to
> build several times in a row just to get rid of the issue).
>
> >  CFLAGS  = -g -O2 -Wall -Werror -pthread
> > -INCS += -I../../ebtree -I./include
> > -LIBS = -lpthread -levent -levent_pthreads
> > +INCS += -I../../ebtree -I./include -I$(PREFIX)/include
> > +LIBS = -lpthread -l$(EVENTLIB) -levent_pthreads -L$(PREFIX)/lib
>
> I'm suspecting we may get into new trouble here due to the fact that
> it becomes impossible to remove this one when not relevant. For example
> on some systems you have to use $PREFIX/lib64. On other systems, no
> single $PREFIX will be valid and you risk to get undesired stuff. Also
> when cross-compiling, $PREFIX will point to your native system instead
> of the one in the toolchain.
>
> What exact build problem did you meet in your environment, and with
> what component ? Maybe we can find another way to deal with it. We
> could also imagine setting a set of FOOLIB and FOOINC variables to
> respectively specify the lib and include directories, properly taking
> care of the lib64 crap.
>
> > diff --git a/contrib/spoa_example/spoa.c b/contrib/spoa_example/spoa.c
> > index d8defd192..760ad9210 100644
> > --- a/contrib/spoa_example/spoa.c
> > +++ b/contrib/spoa_example/spoa.c
> > @@ -53,7 +53,7 @@
> >
> \
> >               gettimeofday(&now, NULL);                               \
> >               fprintf(stderr, "%ld.%06ld [%02d] " fmt "\n",           \
> > -                     now.tv_sec, now.tv_usec, (worker)->id, ##args); \
> > +                     (long int)now.tv_sec, now.tv_usec, (worker)->id,
> ##args);       \
>
> Good catch!
>
> Cheers,
> Willy
>
From 2e76de286db0e4672a9173e52a070e4b61452983 Mon Sep 17 00:00:00 2001
From: David Carlier <devne...@gmail.com>
Date: Wed, 27 Dec 2017 13:19:14 +0000
Subject: [PATCH] BUILD/SMALL: contrib : spoa example

Change to the build to be able to build it in systems
different than Linux.
---
 contrib/spoa_example/Makefile | 8 ++++++--
 contrib/spoa_example/spoa.c   | 2 +-
 2 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/contrib/spoa_example/Makefile b/contrib/spoa_example/Makefile
index c44c2b879..548d280ba 100644
--- a/contrib/spoa_example/Makefile
+++ b/contrib/spoa_example/Makefile
@@ -5,9 +5,13 @@ BINDIR  = $(PREFIX)/bin
 CC = gcc
 LD = $(CC)
 
+EVENTINC = $(PREFIX)/include
+EVENTLIB = $(PREFIX)/lib
+EVENTLIBNM = event
+
 CFLAGS  = -g -O2 -Wall -Werror -pthread
-INCS += -I../../ebtree -I./include
-LIBS = -lpthread -levent -levent_pthreads
+INCS += -I../../ebtree -I./include -I$(EVENTINC)
+LIBS = -lpthread -l$(EVENTLIBNM) -levent_pthreads -L$(EVENTLIB)
 
 OBJS = spoa.o
 
diff --git a/contrib/spoa_example/spoa.c b/contrib/spoa_example/spoa.c
index d8defd192..760ad9210 100644
--- a/contrib/spoa_example/spoa.c
+++ b/contrib/spoa_example/spoa.c
@@ -53,7 +53,7 @@
                                                                         \
 		gettimeofday(&now, NULL);				\
 		fprintf(stderr, "%ld.%06ld [%02d] " fmt "\n",		\
-			now.tv_sec, now.tv_usec, (worker)->id, ##args);	\
+			(long int)now.tv_sec, now.tv_usec, (worker)->id, ##args);	\
 	} while (0)
 
 #define DEBUG(x...)				\
-- 
2.15.1

Reply via email to