Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 7 Feb 2008 21:54:05 +0100
From:      Mel <fbsd.questions@rachie.is-a-geek.net>
To:        freebsd-questions@freebsd.org
Cc:        Jim Stapleton <stapleton.41@gmail.com>
Subject:   Re: ports makefile stuff (bsd.lib.mk)
Message-ID:  <200802072154.06464.fbsd.questions@rachie.is-a-geek.net>
In-Reply-To: <80f4f2b20802060749p60c9d0ddw83b1ecbbed19db47@mail.gmail.com>
References:  <80f4f2b20802060749p60c9d0ddw83b1ecbbed19db47@mail.gmail.com>

next in thread | previous in thread | raw e-mail | index | archive | help
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>


-- 
Mel



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200802072154.06464.fbsd.questions>