Add files from parent branch HEAD:
[pkgsrc.git] / mk / djbware.mk
1 # $NetBSD: djbware.mk,v 1.21 2008/02/07 21:36:13 rillig Exp $
2 #
3 # Makefile fragment for packages with djb-style build machinery
4 #
5 # Common functions provided:
6 # * a boilerplate RESTRICTED clause
7 # * typical defaults for BUILD_TARGET and INSTALL_TARGET
8 # * typical values for conf-* files
9 # * replace inline definitions of errno with "#include <errno.h>"
10 #
11 # TODO:
12 # * centralize handling of third-party manpages
13 # * centralize MASTER_SITES and SITES_foo
14 # * centralize compiler hack for arm{,32}
15 # * common install script for compatibility with default conf-home pathnames
16 # * PKG_OPTIONS (default):
17 #     djbware-errno-hack (off)
18 #     djbware-pathname-compat (on)
19 #     inet6 (off)
20 #     pam (off)
21 # * set RESTRICTED automatically iff patches or other mods are applied
22 # * be unrestricted by default for bulk builds
23 #
24
25 .if !defined(DJBWARE_MK)
26 DJBWARE_MK=             # defined
27
28 DJB_RESTRICTED?=        YES
29 DJB_MAKE_TARGETS?=      YES
30 DJB_BUILD_TARGETS?=     # empty
31 DJB_INSTALL_TARGETS?=   # empty
32 DJB_SLASHPACKAGE?=      NO
33 .if !empty(DJB_SLASHPACKAGE:M[yY][eE][sS])
34 DJB_CONFIG_DIR?=        ${WRKSRC}/src
35 DJB_BUILD_ARGS?=        # empty
36 .else
37 DJB_CONFIG_DIR?=        ${WRKSRC}
38 .endif
39 DJB_CONFIG_PREFIX?=     ${PREFIX}
40 DJB_CONFIG_HOME?=       conf-home
41 DJB_CONFIG_CMDS?=       ${DO_NADA}
42
43 .if !empty(DJB_RESTRICTED:M[yY][eE][sS])
44 LICENSE=                djb-nonlicense
45
46 RESTRICTED=             modified source and binaries may not be distributed
47 NO_BIN_ON_CDROM=        ${RESTRICTED}
48 NO_BIN_ON_FTP=          ${RESTRICTED}
49 .endif
50
51 .if !empty(DJB_MAKE_TARGETS:M[yY][eE][sS])
52 BUILD_TARGET?=          it ${DJB_BUILD_TARGETS}
53 INSTALL_TARGET?=        setup check ${DJB_INSTALL_TARGETS}
54 .endif
55
56 .if !defined(NO_CONFIGURE) && !target(do-configure)
57 do-configure:
58         ${RUN}cd ${DJB_CONFIG_DIR};             \
59         for i in conf-*; do ${CP} $${i} $${i}.orig_dist; done;          \
60         [ -f ${DJB_CONFIG_HOME} ] && \
61                 ${ECHO} ${DJB_CONFIG_PREFIX} > ${DJB_CONFIG_HOME};      \
62         [ -f conf-cc ] && \
63                 ${ECHO} ${CC:Q} ${CFLAGS:Q} ${CPPFLAGS:Q} > conf-cc;    \
64         [ -f conf-ld ] && \
65                 ${ECHO} ${CC:Q} ${_STRIPFLAG_CC} ${LDFLAGS:Q} > conf-ld;\
66         [ -f conf-bin ] && \
67                 ${ECHO} ${DJB_CONFIG_PREFIX}/bin > conf-bin;            \
68         [ -f conf-man ] && \
69                 ${ECHO} ${DJB_CONFIG_PREFIX}/${PKGMANDIR} > conf-man;   \
70         [ -f conf-qmail ] && \
71                 ${ECHO} ${QMAILDIR} > conf-qmail;                       \
72         [ -f conf-bgincs ] && \
73                 ${ECHO} ${LOCALBASE}/include/bglibs > conf-bgincs;      \
74         [ -f conf-bglibs ] && \
75                 ${ECHO} ${LOCALBASE}/lib/bglibs > conf-bglibs;          \
76         ${DJB_CONFIG_CMDS}
77 .endif
78
79 .if !target(do-build) && !empty(DJB_SLASHPACKAGE:M[yY][eE][sS])
80 do-build:
81         cd ${WRKSRC} && package/compile ${DJB_BUILD_ARGS}
82 .endif
83
84 PKG_SUPPORTED_OPTIONS+= djbware-errno-hack
85 PKG_SUGGESTED_OPTIONS+= djbware-errno-hack
86
87 .include "bsd.fast.prefs.mk"
88
89 .if exists(${PKGDIR}/options.mk)
90 . include "${PKGDIR}/options.mk"
91 .else
92 # Note: This expression is the same as ${PKGBASE}, but the latter is
93 # not defined yet, so we cannot use it here.
94 PKG_OPTIONS_VAR=        PKG_OPTIONS.${PKGNAME:C/-[0-9].*//}
95 .include "bsd.options.mk"
96 .endif
97
98 .if !empty(PKG_OPTIONS:Mdjbware-errno-hack)
99 SUBST_CLASSES+=         djbware
100 SUBST_STAGE.djbware=    do-configure
101 SUBST_FILES.djbware+=   error.h
102 SUBST_SED.djbware=      -e 's|^extern\ int\ errno\;|\#include \<errno.h\>|'
103 SUBST_MESSAGE.djbware=  Correcting definition of errno.
104 .endif
105
106 .endif  # DJBWARE_MK