File:  [NetBSD Developer Wiki] / wikisrc / Attic / bsd_make.mdwn
Revision 1.2: download - view: text, annotated - select for diffs
Wed Jul 3 15:35:10 2013 UTC (7 years, 4 months ago) by wiki
Branches: MAIN
CVS tags: HEAD
web commit by erh: code blocks within lists need to be double indented to work

    1: **Contents**
    2: 
    3: [[!toc levels=2]]
    4: 
    5: # Miscellaneous
    6: 
    7: * Whitespacing is significant in Make:
    8: *   All commands must be indented one tab.
    9: *   Spaces are not the same as tabs.
   10: *   Targets are not indented. 
   11: * ../Makefile.inc is automatically included if you include any bsd.*.mk, but never ../../Makefile.inc or ./Makefile.inc, unless you include these explicitly of course.
   12: * 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.
   13: * 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.
   14: * Installing neatly to a user-customisable path can be done most cleanly like this: 
   15: 
   16:         PREFIX?=        /usr/local
   17:         BINDIR=         ${PREFIX}/bin
   18:         LIBDIR=         ${PREFIX}/lib
   19:         MANDIR=         ${PREFIX}/man
   20:         FILESDIR=       ${PREFIX}/share/misc
   21: 
   22: 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.
   23: 
   24: * Switch manpage generation/installation on and off with MKMAN, by setting it to "yes" or "no".
   25: 
   26: # Make include files (types of projects)
   27: ## bsd.prog.mk (programs)
   28: 
   29: 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:
   30: 
   31:     PROG=foo
   32:     SRCS=foo.c
   33:     MAN=
   34:     .include <bsd.prog.mk>
   35: 
   36: ## bsd.lib.mk (libraries)
   37: 
   38: Does not create shared libraries unless you define SHLIB_MAJOR variable:
   39: 
   40:     LIB=this
   41:     SHLIB_MAJOR=1
   42:     SHLIB_MINOR=0
   43:     .include <bsd.lib.mk>
   44: 
   45: You may define SHLIB_TINY variable too.
   46: 
   47: Alternatively, you may define variables in "shlib_version" file:
   48: 
   49:     major=0
   50:     minor=1
   51: 
   52: where the 0 and 1 are replaced by the appropriate version numbers, of course.
   53: 
   54: ## bsd.man.mk (manpage stuff)
   55: 
   56: 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:
   57: 
   58:     MLINKS = real_foo.3 foo.3  real_foo.3 other_foo.3
   59: 
   60: Here, real_foo.3 is a real file, the rest are all links that will be created in the installation path.
   61: 
   62: * Manpages must have an extension to identify their category, or installation will fail.*
   63: 
   64: # Special constructs
   65: 
   66: 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
   67: 
   68:     .if make(targname)
   69:     blah
   70:     .endif
   71: 
   72: where targname is the target you're checking for.
   73: 
   74: When you check the contents of a variable, if it does not exist (it hasn't been defined), you will get 'strange' errors:
   75: 
   76:     .if ${VAR} == "yes"
   77:     blah
   78:     .endif
   79: 
   80: will get you:
   81: 
   82:     make: "/home/foo/src/libfoo" line 7: Malformed conditional (${VAR} == "yes")
   83:     make: "/home/foo/src/libfoo" line 7: Need an operator
   84:     make: "/home/foo/src/libfoo" line 9: if-less endif
   85:     make: "/home/foo/src/libfoo" line 9: Need an operator
   86:     make: Fatal errors encountered -- cannot continue
   87: 
   88: 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:
   89: 
   90:     .if "${VAR}" == "yes"
   91:     blah
   92:     .endif
   93: 
   94: (The first example evaluates to .if == "yes" while the second to something slightly different: .if "" == "yes")
   95: 
   96: # See also
   97: 
   98:     [[make]]
   99:     [[Basic Unix programming]]

CVSweb for NetBSD wikisrc <wikimaster@NetBSD.org> software: FreeBSD-CVSweb