From owner-freebsd-questions@FreeBSD.ORG Sat Feb 12 08:37:11 2011 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 1E199106564A for ; Sat, 12 Feb 2011 08:37:11 +0000 (UTC) (envelope-from keramida@ceid.upatras.gr) Received: from igloo.linux.gr (igloo.linux.gr [62.1.205.36]) by mx1.freebsd.org (Postfix) with ESMTP id A74788FC17 for ; Sat, 12 Feb 2011 08:37:10 +0000 (UTC) X-Spam-Status: No X-Hellug-MailScanner-From: keramida@ceid.upatras.gr X-Hellug-MailScanner-SpamCheck: not spam, SpamAssassin (not cached, score=-2.9, required 5, autolearn=not spam, ALL_TRUSTED -1.00, BAYES_00 -1.90) X-Hellug-MailScanner: Found to be clean X-Hellug-MailScanner-ID: p1C8aroM003469 Received: from gkeramidas-glaptop.linux.gr (207.47.25.82.static.nextweb.net [207.47.25.82]) (authenticated bits=0) by igloo.linux.gr (8.14.3/8.14.3/Debian-9.4) with ESMTP id p1C8aroM003469 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NOT); Sat, 12 Feb 2011 10:37:00 +0200 From: Giorgos Keramidas To: Vikash Badal References: <9B425C841283E0418B1825D40CBCFA615B422306F9@ZABRYSVISEXMBX1.af.didata.local> <201102102359.p1ANxEcA044340@mail.r-bonomi.com> <9B425C841283E0418B1825D40CBCFA615B42230B05@ZABRYSVISEXMBX1.af.didata.local> Date: Sat, 12 Feb 2011 00:36:52 -0800 Message-ID: User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.50 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain Cc: freebsd-questions@freebsd.org, Robert Bonomi Subject: Re: switching from gnu make to bsd make X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 12 Feb 2011 08:37:11 -0000 On Fri, 11 Feb 2011 10:26:13 +0200, Vikash Badal wrote: > Make all produces the follow output: > > make all > cc -o bin/nntpd -lpthread -lmysqlclient_r -Wall -g -Iinclude > -I/usr/local/include -I/usr/local/include/mysql -L/usr/local/lib > -L/usr/local/lib/mysql obj/log.o obj/cleanup.o obj/config.o > obj/leecherpool.o obj/mytime.o obj/nntp.o obj/upstream.o obj/mysleep.o > obj/sqlpool.o obj/sql.o obj/signalhandler.o obj/daemon.o obj/list.o > obj/tcpserver.o obj/tmpfiles.o obj/listenpool.o obj/workers.o > obj/nntpd.o > cc: obj/log.o: No such file or directory > cc: obj/cleanup.o: No such file or directory > cc: obj/config.o: No such file or directory > cc: obj/leecherpool.o: No such file or directory > cc: obj/mytime.o: No such file or directory > cc: obj/nntp.o: No such file or directory > cc: obj/upstream.o: No such file or directory > cc: obj/mysleep.o: No such file or directory > cc: obj/sqlpool.o: No such file or directory > cc: obj/sql.o: No such file or directory > cc: obj/signalhandler.o: No such file or directory > cc: obj/daemon.o: No such file or directory > cc: obj/list.o: No such file or directory > cc: obj/tcpserver.o: No such file or directory > cc: obj/tmpfiles.o: No such file or directory > cc: obj/listenpool.o: No such file or directory > cc: obj/workers.o: No such file or directory > cc: obj/nntpd.o: No such file or directory > *** Error code 1 > > With gmake : > $(OBJDIR)/%.o:${SRCDIR}/%.c > ${CC} -c ${CFLAGS} ${INCDIR} ${LIBDIR} $< -o $@ > > This creates all the .o files I need Does gmake also create the `obj/' directory automagically? I kind of doubt that, unless the gmake folks have started doing all sorts of magic behind-your-back stuff. You have no makefile rule to create `obj/' and no dependency of all the object files to the object directory. > How do I do this with bsd make ? The canonical way of writing a program that depends on object files that _may_ live in another object directory is to use the existing makefile macros from `/usr/share/mk/bsd.*.mk'. This means you will have to re-organize your Makefile a bit though. Instead of all the hand-crafted rules you are now trying to debug, which are nice but will take ages to 'get the job done', you should probably use a Makefile like this: PROG= nntpd SRCS= cleanup.c \ config.c \ leecherpool.c \ list.c \ listenpool.c \ log.c \ mysleep.c \ mytime.c \ nntpd.c \ signalhandler.c \ sql.c \ tcpserver.c \ upstream.c \ workers.c MYSQLPREFIX?= /usr/local MYSQLINCDIR?= ${MYSQLPREFIX}/include MYSQLLIBDIR?= ${MYSQLPREFIX}/lib CFLAGS+= -I${.CURDIR}/include \ -I/usr/local/include \ -I${MYSQLINCDIR} LDFLAGS+= -L/usr/local/lib \ -L${MYSQLLIBDIR} LDADD+= -lmysqlclient_r -lpthread .include By using the `bsd.prog.mk' rules, you can now type stuff like this: 1. # Build everything, putting object files in the current directory. make all 2. # Build and install everything, but use debugging CFLAGS and inhibit # the final 'strip' step of 'make install' by setting DEBUG_FLAGS. make CFLAGS='' DEBUG_FLAGS='-O0 -ggdb' all install 3. # Clean everything. make clean 4. # Build everything, but instead of installing in /usr/{bin,sbin} # install in a chroot under `/tmp/chroot', with the binaries # auto-mapped to `/tmp/chroot/usr/{bin,sbin}'. env DESTDIR='/tmp/chroot' make install 5. # Set up a special 'object tree' under /tmp/obj, to keep the sources # clean from generated files. mkdir /tmp/obj # Point the bsd.*.mk glue to the new object tree. export MAKEOBJDIRPREFIX=/tmp/obj # Create a 'mirror' of the source tree under `/tmp/obj', so that # e.g. the object code for `/home/keramida/src/foo' will be saved at # `/tmp/obj/home/keramida/tmp/foo'. make obj # Try to build `.depend' files with source/header -> object file # dependencies. make depend # Biuld everything, saving object code in /tmp/obj make all # Clean up /tmp/obj. Then clean up current directory too. make cleandir make cleandir The bsd.prog.mk rules will take care of creating the object directory paths; they will take care of generating the appropriate rules to build with the sources in one place and the object files in another directory; the macros will let you built multiple snapshots of the same source tree in different places, e.g. one for 'release' builds and one for 'debug' builds with different CFLAGS, etc. Another important point is that if you _do_ the legwork of converting the makefile rules from gmake to BSD make, you will have tons of examples of how to do things by looking at the makefiles of FreeBSD itself. All our makefiles use bsd.prog.mk, bsd.lib.mk, and the rest of the bsd.*.mk macros from `/usr/share/mk'.