?

Log in

No account? Create an account
memcached autoconf/automake help - brad's life [entries|archive|friends|userinfo]
Brad Fitzpatrick

[ website | bradfitz.com ]
[ userinfo | livejournal userinfo ]
[ archive | journal archive ]

memcached autoconf/automake help [Sep. 5th, 2006|03:55 pm]
Brad Fitzpatrick
[Tags|, ]

I don't want this to turn into an "Autotools sucks!" thread. I just want help....

Requirements:
  • I want "make test" to run against a binary that has assert() enabled (AM_CFLAGS not containing "-DNDEBUG").
  • I want users to have a choice to run a binary with asserts on or off. CPU vs. paranoia trade-off. Whether this is building two binaries and installing them both on the system, or letting them choose with --without-asserts or --with-asserts, I don't care.
What's the best way to do this?
Are there best practices regarding similar things? (testing with asserts on, regardless of their ultimate choice)

Here's my current Makefile.am:
bin_PROGRAMS = memcached memcached_SOURCES = memcached.c slabs.c items.c memcached.h assoc.c memcached_LDADD = @LIBOBJS@ SUBDIRS = doc DIST_DIRS = scripts EXTRA_DIST = doc scripts TODO t test: memcached prove t # Uncomment the following to save some CPU (by disabling assertions) #AM_CFLAGS=-DNDEBUG dist-hook: rm -rf $(distdir)/doc/.svn/ rm -rf $(distdir)/scripts/.svn/ rm -rf $(distdir)/t/.svn/ rm -rf $(distdir)/t/lib/.svn/
Suggestions?
LinkReply

Comments:
[User Picture]From: robbat2
2006-09-05 11:39 pm (UTC)
You should build two binaries.
The debug build should compile object files named %.debug.o, which get linked to provide your debug binary, it uses -DNDEBUG.
The production build should compile object files named %.production.o, which provide your production binary, and uses -DNDEBUG.


It's mainly an exercise in Makefiles. You might want to use the autoconf to choose which binary is installed however. I would suggest not installing both.
(Reply) (Thread)
[User Picture]From: brad
2006-09-05 11:51 pm (UTC)
I understand all that in theory, but I don't know autotools nor Makefiles-as-they-should-be-written. I can write my own Makefiles, but not portable Makefiles. For instance, adding a rule:

memcached-notdebug: memcached.c items.c ......
gcc -DNDEBUG ....

Isn't good, because I imagine I want $(CC) or $(COMPILE) or whatever.

Or I don't know how to do portable per-target $(AM_CFLAGS)?

I don't even know what I need to know.
(Reply) (Parent) (Thread)
[User Picture]From: robbat2
2006-09-06 12:25 am (UTC)
give me a moment, and i'll grab your current SVN head and shoot a patch your way.

the greatest failure of Make, and autotools, is their documentation.
(Reply) (Parent) (Thread)
[User Picture]From: stechert
2006-09-06 12:29 am (UTC)

per target

AM_CFLAGS=-I../include

bin_PROGRAMS=foo bar

foo_CFLAGS = -DNDEBUG
foo_SOURCES = foo.c

bar_SOURCES = bar.c


...


stechert@kirin:~/Scratch/test [1105] $ autoreconf -fvi
autoreconf: Entering directory `.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force
autoreconf: configure.ac: tracing
autoreconf: configure.ac: not using Libtool
autoreconf: running: /opt/local/bin/autoconf --force
autoreconf: running: /opt/local/bin/autoheader --force
autoreconf: running: automake --add-missing --copy --force-missing
configure.ac: installing `./install-sh'
configure.ac: installing `./missing'
configure.ac:5: installing `./config.guess'
configure.ac:5: installing `./config.sub'
Makefile.am: installing `./compile'
Makefile.am: installing `./depcomp'
autoreconf: Leaving directory `.'



stechert@kirin:~/Scratch/test [1106] $ ./configure
checking build system type... i686-apple-darwin8.7.1
checking host system type... i686-apple-darwin8.7.1
checking target system type... i686-apple-darwin8.7.1
checking for a BSD-compatible install... /opt/local/bin/ginstall -c
checking whether build environment is sane... yes
checking for gawk... gawk
checking whether make sets $(MAKE)... yes
checking for g++... g++
checking for C++ compiler default output file name... a.out
checking whether the C++ compiler works... yes
checking whether we are cross compiling... no
checking for suffix of executables...
checking for suffix of object files... o
checking whether we are using the GNU C++ compiler... yes
checking whether g++ accepts -g... yes
checking for style of include used by make... GNU
checking dependency style of g++... gcc3
checking for gcc... gcc
checking whether we are using the GNU C compiler... yes
checking whether gcc accepts -g... yes
checking for gcc option to accept ANSI C... none needed
checking dependency style of gcc... gcc3
configure: creating ./config.status
config.status: creating Makefile
config.status: creating config.h
config.status: executing depfiles commands




stechert@kirin:~/Scratch/test [1107] $ ls
Makefile autom4te.cache config.h config.sub foo.c
Makefile.am bar.c config.h.in configure install-sh
Makefile.in compile config.log configure.ac missing
aclocal.m4 config.guess config.status depcomp stamp-h1
stechert@kirin:~/Scratch/test [1108] $ make
make all-am
if gcc -DHAVE_CONFIG_H -I. -I. -I. -DNDEBUG -g -O2 -MT foo-foo.o -MD -MP -MF ".deps/foo-foo.Tpo" -c -o foo-foo.o `test -f 'foo.c' || echo './'`foo.c; \
then mv -f ".deps/foo-foo.Tpo" ".deps/foo-foo.Po"; else rm -f ".deps/foo-foo.Tpo"; exit 1; fi
gcc -I../include -g -O2 -o foo foo-foo.o
if gcc -DHAVE_CONFIG_H -I. -I. -I. -I../include -g -O2 -MT bar.o -MD -MP -MF ".deps/bar.Tpo" -c -o bar.o bar.c; \
then mv -f ".deps/bar.Tpo" ".deps/bar.Po"; else rm -f ".deps/bar.Tpo"; exit 1; fi
gcc -I../include -g -O2 -o bar bar.o
(Reply) (Parent) (Thread)
[User Picture]From: robbat2
2006-09-06 01:39 am (UTC)
see your email.

duplicated here for everybody else:
Index: Makefile.am
===================================================================
--- Makefile.am (revision 374)
+++ Makefile.am (working copy)
@@ -1,12 +1,17 @@
-bin_PROGRAMS = memcached
+bin_PROGRAMS = memcached memcached-debug

-memcached_SOURCES = memcached.c slabs.c items.c memcached.h assoc.c
+memcached_SOURCES = memcached.c slabs.c items.c assoc.c
+memcached_debug_SOURCES = $(memcached_SOURCES)
+memcached_CPPFLAGS = -DNDEBUG
memcached_LDADD = @LIBOBJS@
+memcached_debug_LDADD = $(memcached_LDADD)

SUBDIRS = doc
DIST_DIRS = scripts
EXTRA_DIST = doc scripts TODO t

+memcached.c: memcached.h
+
test: memcached
prove t

(Reply) (Parent) (Thread)
[User Picture]From: brad
2006-09-06 07:52 am (UTC)
Wonderful, thanks!
(Reply) (Parent) (Thread)