.\"
.\" Copyright (c) 2007-2014 Hypertriton, Inc.
.\" All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS'' AND ANY EXPRESS OR
.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
.\" IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
.\"
.Dd July 18, 2007
.Dt BUILD.LIB.MK 5
.Os
.ds vT BSDBuild Reference
.ds oS BSDBuild 1.0
.Sh NAME
.Nm build.lib.mk
.Nd bsdbuild - compilation of libraries
.Sh SYNOPSIS
.Fd .include
.Sh DESCRIPTION
The
.Nm
module compiles static and/or shared libraries from a set of source files.
For shared libraries, it uses a bundled copy of GNU libtool.
The module provides built-in support for sources in the following languages:
.Bl -bullet -compact
.It
C (*.c)
.It
C++ (*.cc or *.cpp)
.It
Objective C (*.m)
.It
Assembler (*.asm)
.It
Lex (*.l)
.It
Yacc (*.y)
.El
.Sh TARGETS
.Bl -tag -width "deinstall-lib "
.It Ar lib${LIB}.a
Compile the source files into a static library.
.It Ar lib${LIB}.la
Compile the source files into static and shared libraries using libtool
(libtool comes bundled with BSDBuild).
.It Ar clean-lib
Clean up object and library files.
.It Ar cleandir-lib
Clean up for packaging.
.It Ar install-lib
Install library files to the target installation directory
(see
.Xr csoft.common.mk 5 ) .
.It Ar deinstall-lib
Uninstall libraries from the installation directory.
.El
.Sh VARIABLES
.Bl -tag -width "LIBTOOLOPS_SHARED "
.It Ev LIB
Name of target library.
Platform-specific transforms will be applied to the name.
.It Ev LIBDIR
Target installation directory for libraries
(usually set by configure).
.It Ev LIB_INSTALL
If set to Yes, the
.Ar install
target will install the library files, otherwise it will be a no-op.
Defaults to No.
.It Ev LIB_SHARED
If set to Yes, a shared library will be built.
Default is No.
.It Ev LIB_MODULE
If set to Yes, a
.Xr dlopen 3
compatible module will be built.
Default is No.
.It Ev LIB_GUID
A Global Unique Identifier (GUID) for the library.
Exact interpretation is platform-specific.
.It Ev LIB_MAJOR
Major version number for shared libraries.
.It Ev LIB_MINOR
Minor version number for shared libraries.
.It Ev LIB_REVISION
Revision number for shared libraries.
.It Ev LIBS
Specify other libraries to link against this library.
Bare filename arguments are interpreted as archive files ("foo.a" or "foo.la").
Arguments of the form "-L/path/to/dir" and "-lfoo" specify shared libraries.
.It Ev USE_LIBTOOL
If set to Yes, use
.Xr libtool 1
to build the libraries.
If set to No, generate the library using the traditional method involving
.Xr ar 1 ,
.Xr ranlib 1 ,
and
.Ar -fPIC .
.It Ev LIBTOOL
Path to GNU
.Xr libtool 1 .
This is usually set by the configure script.
BSDBuild-generated configure scripts will select BSDBuild's bundled copy
of libtool by default (recommended), but an alternate libtool may be specified
using --with-libtool=PATH.
.It Ev LIBTOOLOPTS
Specify general libtool arguments (passed before --mode).
Defaults to "--quiet".
.It Ev LIBTOOLOPTS_SHARED
Specify extra libtool arguments for linking of shared libraries.
.It Ev LIBTOOLOPTS_STATIC
Specify extra libtool arguments for linking of static libraries.
.It Ev CC
Compiler for C, C++ and Objective C sources.
Defaults to the CC environment variable, or "cc".
.It Ev CFLAGS
Compiler flags for C sources.
Defaults to the CFLAGS environment variable.
.It Ev CXXFLAGS
Compiler flags for C++ sources.
Defaults to the CXXFLAGS environment variable.
.It Ev OBJCFLAGS
Compiler flags for Objective C sources.
Defaults to
.Sq ${CFLAGS} .
.It Ev CPPFLAGS
Compiler preprocessor flags, for sources in all languages featuring
a C preprocessor.
.It Ev ASM
Compiler for assembler sources.
Defaults to
.Sq nasm .
.It Ev ASMFLAGS
Compiler flags for assembler.
Defaults to
.Sq -g -w-orphan-labels .
.It Ev LEX
Path to the
.Xr lex 1
lexical analyzer generator.
.It Ev YACC
Path to the
.Xr yacc 1
parser generator.
.It Ev LFLAGS
Options for
.Xr lex 1 ,
defaults to
.Sq .
.It Ev YFLAGS
Options for
.Xr yacc 1 ,
defaults to
.Sq -d .
.It Ev LIBL
Libraries to use for Lex lexers.
Defaults to
.Sq -ll .
.It Ev WINDRES
(Specific to the win32 platform)
Path to the
.Xr windres 1
utility, which generates windows resource files.
.It Ev WINRES
(Specific to the win32 platform)
Resource file to use with
.Xr windres 1 .
.It Ev DATAFILES
List of data files to install into
.Dv ${DATADIR} .
The files must have been generated from the build process (i.e., if using a
separate build with --srcdir, the specified files must exist in the build
directory).
.It Ev DATAFILES_SRC
Files to install into
.Dv ${DATADIR} .
This variable is handled similarly to
.Ev DATAFILES ,
except that the specified files must exist in the source directory.
.It Ev INCLDIR
Library header files will be installed into this directory.
See
.Xr build.common.mk 5 .
.It Ev INCL
List of library header files.
.It Ev CONFDIR
System-wide configuration files will be installed into this directory.
It is usually set relative to
.Sq ${SYSCONFDIR} ,
for example
.Sq ${SYSCONFDIR}/MyLibrary .
.It Ev CONF
List of configuration files to install into
.Dv ${CONFDIR}.
Note that the
.Ar install
target will not override existing configuration files, instead it will
output a
.Dq The following configuration files have been preserved
message.
.It Ev CONF_OVERWRITE
Overwrite any existing configuration file on installation.
Default is "No".
.El
.Sh SEE ALSO
.Xr build.common.mk 5 ,
.Xr build.prog.mk 5
.Sh HISTORY
.Nm
first appeared in BSDBuild 1.0.
.Pp
BSDBuild is based on the 4.4BSD build system.