Skip to content

Commit

Permalink
use CFLAGS, CPPFLAGS and LDFLAGS properly
Browse files Browse the repository at this point in the history
  • Loading branch information
esmil committed Sep 18, 2013
1 parent 28633b6 commit 2d18237
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 16 deletions.
15 changes: 9 additions & 6 deletions Makefile.in
@@ -1,6 +1,9 @@
# @configure_input@
CC = @CC@
CFLAGS ?= @CFLAGS@
CFLAGS += @CPPFLAGS@
CFLAGS = @CFLAGS@
CPPFLAGS = @CPPFLAGS@
CPPFLAGS += @CPPFLAGS_ADD@
LDFLAGS = @LDFLAGS@
SHARED = @SHARED@
LIBS = @LIBS@

Expand Down Expand Up @@ -51,7 +54,7 @@ endif

.PHONY: all strip install clean

all: CFLAGS += -DNDEBUG
all: CPPFLAGS += -DNDEBUG
all: bin/lem lem.pc $(clibs)

debug: bin/lem lem.pc $(clibs)
Expand All @@ -60,7 +63,7 @@ bin/libev.o: CFLAGS += -w
include/lem.h: lua/luaconf.h
bin/lua.o: lua/luaconf.h
bin/lem.o: include/lem.h bin/pool.c
bin/lem.o: CFLAGS += -D'LEM_LDIR="$(lmoddir)/"'
bin/lem.o: CPPFLAGS += -D'LEM_LDIR="$(lmoddir)/"'
lem/io/core.so: include/lem-parsers.h \
lem/io/file.c \
lem/io/stream.c \
Expand All @@ -72,15 +75,15 @@ lem/http/core.so: include/lem-parsers.h

%.o: %.c
$E ' CC $@'
$Q$(CC) $(CFLAGS) -c $< -o $@
$Q$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@

bin/lem: $(objects)
$E ' LD $@'
$Q$(CC) $^ -o $@ -rdynamic $(LDFLAGS) $(LIBS)

%.so: %.c include/lem.h
$E ' CCLD $@'
$Q$(CC) $(CFLAGS) -fPIC -nostartfiles $(SHARED) $< -o $@ $(LDFLAGS)
$Q$(CC) $(CFLAGS) $(CPPFLAGS) -fPIC -nostartfiles $(SHARED) $< -o $@ $(LDFLAGS)

lua/luaconf.h: lua/luaconf.h.in
$E ' SED > $@'
Expand Down
16 changes: 11 additions & 5 deletions configure
Expand Up @@ -659,6 +659,7 @@ pkgconfigdir
cmoddir
lmoddir
SHARED
CPPFLAGS_ADD
objects
headers
target_alias
Expand Down Expand Up @@ -2155,9 +2156,14 @@ headers='lem.h lem-parsers.h'

objects='bin/lem.o'

CPPFLAGS_ADD='-Iinclude'

SHARED='-shared'

CPPFLAGS='-Iinclude'

if test "x$CFLAGS" = 'x'; then :
CFLAGS='-O2 -g -Wall -Wextra'
fi


# Check whether --with-lua was given.
Expand Down Expand Up @@ -3751,7 +3757,7 @@ fi
# Configure libev
objects="bin/libev.o $objects"
headers="ev-config.h ev.h $headers"
CPPFLAGS="$CPPFLAGS -Ilibev"
CPPFLAGS_ADD="$CPPFLAGS_ADD -Ilibev"

# Configure Lua
ac_ext=c
Expand Down Expand Up @@ -5235,7 +5241,7 @@ fi

objects="bin/lua.o $objects"
headers="luaconf.h lua.h lauxlib.h $headers"
CPPFLAGS="$CPPFLAGS -Ilua"
CPPFLAGS_ADD="$CPPFLAGS_ADD -Ilua"
Lua_CFLAGS=''
Lua_LIBS=''
ac_cv_func_luaL_traceback=yes
Expand All @@ -5247,7 +5253,7 @@ fi
fi
fi

CPPFLAGS="$CPPFLAGS $Lua_CFLAGS"
CPPFLAGS_ADD="$CPPFLAGS_ADD $Lua_CFLAGS"
LIBS="$Lua_LIBS $LIBS"
if test "x$lmoddir" = 'x'; then :
lmoddir="`$PKG_CONFIG --variable=INSTALL_LMOD $with_lua`"
Expand All @@ -5265,7 +5271,7 @@ fi

ac_fn_c_check_func "$LINENO" "luaL_traceback" "ac_cv_func_luaL_traceback"
if test "x$ac_cv_func_luaL_traceback" = xyes; then :
CPPFLAGS="$CPPFLAGS -DHAVE_TRACEBACK"
CPPFLAGS_ADD="$CPPFLAGS_ADD -DHAVE_TRACEBACK"
fi


Expand Down
12 changes: 7 additions & 5 deletions configure.ac
Expand Up @@ -7,8 +7,10 @@ AC_CONFIG_HEADERS([libev/ev-config.h:ev-config.h.in])

AC_SUBST([headers], ['lem.h lem-parsers.h'])
AC_SUBST([objects], ['bin/lem.o'])
AC_SUBST([CPPFLAGS_ADD], ['-Iinclude'])
AC_SUBST([SHARED], ['-shared'])
CPPFLAGS='-Iinclude'

AS_IF([test "x$CFLAGS" = 'x'], CFLAGS='-O2 -g -Wall -Wextra')

AC_ARG_WITH([lua],
[AS_HELP_STRING([--with-lua],
Expand Down Expand Up @@ -51,7 +53,7 @@ AC_SEARCH_LIBS([pthread_create], [pthread])
# Configure libev
objects="bin/libev.o $objects"
headers="ev-config.h ev.h $headers"
CPPFLAGS="$CPPFLAGS -Ilibev"
CPPFLAGS_ADD="$CPPFLAGS_ADD -Ilibev"

# Configure Lua
AS_CASE(["x$with_lua"],
Expand All @@ -76,14 +78,14 @@ AS_IF([test "x$with_lua" = 'xbuiltin'],
[AC_SEARCH_LIBS([dlopen], [dl])]
[objects="bin/lua.o $objects"]
[headers="luaconf.h lua.h lauxlib.h $headers"]
[CPPFLAGS="$CPPFLAGS -Ilua"]
[CPPFLAGS_ADD="$CPPFLAGS_ADD -Ilua"]
[Lua_CFLAGS='']
[Lua_LIBS='']
[ac_cv_func_luaL_traceback=yes]
[AS_IF([test "x$lmoddir" = 'x'], [lmoddir="\${datarootdir}/lua/$builtin_lua_version"])]
[AS_IF([test "x$cmoddir" = 'x'], [cmoddir="\${libdir}/lua/$builtin_lua_version"])])

CPPFLAGS="$CPPFLAGS $Lua_CFLAGS"
CPPFLAGS_ADD="$CPPFLAGS_ADD $Lua_CFLAGS"
LIBS="$Lua_LIBS $LIBS"
AS_IF([test "x$lmoddir" = 'x'], [lmoddir="`$PKG_CONFIG --variable=INSTALL_LMOD $with_lua`"])
AS_IF([test "x$cmoddir" = 'x'], [cmoddir="`$PKG_CONFIG --variable=INSTALL_CMOD $with_lua`"])
Expand All @@ -93,7 +95,7 @@ AS_IF([test "x$lmoddir" = 'x'],
AS_IF([test "x$cmoddir" = 'x'],
[AC_MSG_ERROR([unable to deduce Lua C module directory, please use --with-cmoddir=path])])

AC_CHECK_FUNC([luaL_traceback], [CPPFLAGS="$CPPFLAGS -DHAVE_TRACEBACK"])
AC_CHECK_FUNC([luaL_traceback], [CPPFLAGS_ADD="$CPPFLAGS_ADD -DHAVE_TRACEBACK"])

# Checks for header files.
AC_CHECK_HEADERS([stddef.h stdlib.h string.h unistd.h sys/time.h time.h pthread.h])
Expand Down

0 comments on commit 2d18237

Please sign in to comment.