atom feed5 messages in org.freebsd.freebsd-questionsports makefile stuff (bsd.lib.mk)
FromSent OnAttachments
Jim StapletonFeb 6, 2008 7:49 am 
Jim StapletonFeb 6, 2008 12:20 pm 
MelFeb 7, 2008 12:53 pm 
Jim StapletonFeb 8, 2008 5:51 am 
Jim StapletonFeb 8, 2008 6:39 am 
Subject:ports makefile stuff (bsd.lib.mk)
From:Mel (fbsd@rachie.is-a-geek.net)
Date:Feb 7, 2008 12:53:52 pm
List:org.freebsd.freebsd-questions

Hi,

first of all, /usr/share/mk/bsd.lib.mk is part of the FreeBSD system make files, not just the ports. So if you change something there, you will almost certainly break your buildworld and buildkernel.

On Wednesday 06 February 2008 16:49:46 Jim Stapleton wrote:

1) Initially, this library will actually build several sublibraries. To keep my code neat, each library has it's own source directory.

So you set SUBDIR.

However, I also want to make cross linking easier and less prone to "oops, I forgot to add the library's directory to the lib path list" issues, so under the source directory I made an 'objs' directory, where I was manually putting the output. Is there a way to simply have the final output files sent to that directory?

Not sure exactly what you want to do, so I'll just explain the "right" way: The system make, will always look for ${.CURDIR}/../Makefile.inc and include that if it's present. This allows you to centralize common CFLAGS/LDADD/LDFLAGS variables in one file, providing your source tree isn't deeper then 2 levels (otherwise, simply do .include "${.CURDIR}/../../Makefile.inc" before .include <bsd.lib.mk>)

Objects are put in OBJDIR. If you have not set MAKEOBJDIRPREFIX in the environment, this will default to ${.CURDIR} and give you a warning.

Providing the right libraries to compile /your/ program is /your/ responsibility. Here's an example:

./Makefile.inc: ====================================== .ifdef USING_LIBFOO LDFLAGS+=-L${.OBJDIR}/../libfoo CFLAGS+=-I${.CURDIR}/../include LDADD+=-lfoo .endif

./progfoo/Makefile: ====================================== SRCS=main.c foo.c PROG=progfoo USING_LIBFOO=yes

.include <bsd.prog.mk>

Now the only problem you have, is making sure libfoo is built before progfoo, so: ./Makefile: ====================================== SUBDIR=libfoo progfoo

.include <bsd.subdir.mk>