File:  [NetBSD Developer Wiki] / wikisrc / Attic / bsd_make.mdwn
Revision 1.4: download - view: text, annotated - select for diffs
Wed Jul 3 15:51:43 2013 UTC (8 years ago) by wiki
Branches: MAIN
CVS tags: HEAD
web commit by erh: add links


[[!toc levels=2]]

# Miscellaneous

* Whitespacing is significant in Make:
*   All commands must be indented one tab.
*   Spaces are not the same as tabs.
*   Targets are not indented. 
* ../ is automatically included if you include any bsd.*.mk, but never ../../ or ./, unless you include these explicitly of course.
* You can include files optionally with .-include "filename". You won't get an error if the file doesn't exist. .sinclude is an alias for .-include.
* always list non-file targets in a .PHONY:-line. If there ever will be a file of the same name as your phony targets, make would otherwise immediately stop claiming that 'foo is up to date'. Also, if someone updates modification and creation times with make -t, the 'file' won't get created.
* Installing neatly to a user-customisable path can be done most cleanly like this: 

        PREFIX?=        /usr/local
        BINDIR=         ${PREFIX}/bin
        LIBDIR=         ${PREFIX}/lib
        MANDIR=         ${PREFIX}/man
        FILESDIR=       ${PREFIX}/share/misc

Added advantage is that this will work out-of-the-box on pkgsrc and FreeBSD's ports, since these define PREFIX to be their installation paths.

* Switch manpage generation/installation on and off with MKMAN, by setting it to "yes" or "no".

# Make include files (types of projects)
## (programs)

Expects a manpage of the name ${PROG}.1, if MAN is not defined. Initialise MAN to an empty value if you do not have a manpage:

    .include <>

## (libraries)

Does not create shared libraries unless you define SHLIB_MAJOR variable:

    .include <>

You may define SHLIB_TINY variable too.

Alternatively, you may define variables in "shlib_version" file:


where the 0 and 1 are replaced by the appropriate version numbers, of course.

## (manpage stuff)

You can automatically have BSD Make create symlinks to your base manpages by defining MLINKS as a list of manpage.1 linkname.1 tuples separated by spaces. Example:

    MLINKS = real_foo.3 foo.3  real_foo.3 other_foo.3

Here, real_foo.3 is a real file, the rest are all links that will be created in the installation path.

* Manpages must have an extension to identify their category, or installation will fail.*

# Special constructs

Special constructs (.if, .for, .include etc) must have their dot flush left aligned. The word after the dot may be indented, however. You can check the current target being built by make with

    .if make(targname)

where targname is the target you're checking for.

When you check the contents of a variable, if it does not exist (it hasn't been defined), you will get 'strange' errors:

    .if ${VAR} == "yes"

will get you:

    make: "/home/foo/src/libfoo" line 7: Malformed conditional (${VAR} == "yes")
    make: "/home/foo/src/libfoo" line 7: Need an operator
    make: "/home/foo/src/libfoo" line 9: if-less endif
    make: "/home/foo/src/libfoo" line 9: Need an operator
    make: Fatal errors encountered -- cannot continue

This kind of error is quite subtle since it might never occur on your system because you happen to always have the variable defined. To fix this, enclose the tested variable in quotes:

    .if "${VAR}" == "yes"

(The first example evaluates to .if == "yes" while the second to something slightly different: .if "" == "yes")

# See also

* [[examples/Basic Unix programming]]
* [[]]
* [[]]
* [[]]
* [[]]

CVSweb for NetBSD wikisrc <> software: FreeBSD-CVSweb