update Mon Nov 2 18:37:00 PST 2009
[pkgsrc.git] / mk / bsd.pkg.mk
1 #       $NetBSD: bsd.pkg.mk,v 1.1960 2009/11/03 02:14:32 joerg Exp $
2 #
3 # This file is in the public domain.
4 #
5 # Please see the pkgsrc/doc/guide manual for details on the
6 # variables used in this make file template.
7 #
8 # Default sequence for "all" is:
9 #
10 #    bootstrap-depends
11 #    fetch
12 #    checksum
13 #    depends
14 #    tools
15 #    extract
16 #    patch
17 #    wrapper
18 #    configure
19 #    build
20 #
21
22 .include "misc/common.mk"
23
24 ############################################################################
25 # Transform package Makefile variables and set defaults
26 # This is the early set used directly or indirectly in
27 # the phase variables.
28 ############################################################################
29
30 ##### PKGBASE, PKGNAME[_NOREV], PKGVERSION
31
32 PKGBASE?=               ${PKGNAME:C/-[^-]*$//}
33 PKGVERSION?=            ${PKGNAME:C/^.*-//}
34 PKGVERSION?=            ${PKGNAME:C/^.*-//}
35 .if defined(PKGREVISION) && !empty(PKGREVISION) && (${PKGREVISION} != "0")
36 .  if defined(PKGNAME)
37 PKGNAME_NOREV:=         ${PKGNAME}
38 PKGNAME:=               ${PKGNAME}nb${PKGREVISION}
39 .  else
40 PKGNAME?=               ${DISTNAME}nb${PKGREVISION}
41 PKGNAME_NOREV=          ${DISTNAME}
42 .  endif
43 .else
44 PKGNAME?=               ${DISTNAME}
45 PKGNAME_NOREV=          ${PKGNAME}
46 .endif
47 PKGVERSION_NOREV=       ${PKGNAME_NOREV:C/^.*-//}
48
49 # Fail-safe in the case of circular dependencies
50 .if defined(_PKGSRC_DEPS) && defined(PKGNAME) && !empty(_PKGSRC_DEPS:M${PKGNAME})
51 PKG_FAIL_REASON+=       "Circular dependency detected"
52 .endif
53
54 ####
55
56 ############################################################################
57 # Allow various phases to define the default variables
58 ############################################################################
59 .if defined(EMUL_PLATFORMS) && !empty(EMUL_PLATFORMS)
60 .  include "emulator/emulator.mk"
61 .endif
62
63 .include "features/features.mk"
64
65 .include "flavor/bsd.flavor-vars.mk"
66 .include "check/bsd.check-vars.mk"
67 .include "depends/bsd.depends-vars.mk"
68 .include "fetch/bsd.fetch-vars.mk"
69 .include "checksum/bsd.checksum-vars.mk"
70 .include "extract/bsd.extract-vars.mk"
71 .include "patch/bsd.patch-vars.mk"
72 .include "configure/bsd.configure-vars.mk"
73 .include "build/bsd.build-vars.mk"
74 .include "install/bsd.install-vars.mk"
75
76 .include "bsd.pkg.error.mk"
77
78 .include "bsd.hacks.mk"
79
80 ############################################################################
81 # Transform package Makefile variables and set defaults
82 ############################################################################
83
84 MKCRYPTO?=              YES     # build crypto packages by default
85
86 ##### Others
87
88 BUILD_DEPENDS?=         # empty
89 COMMENT?=               (no description)
90 DEPENDS?=               # empty
91 DESCR_SRC?=             ${PKGDIR}/DESCR
92 INTERACTIVE_STAGE?=     none
93 .if defined(OWNER)
94 MAINTAINER=${OWNER}
95 .else
96 MAINTAINER?=            pkgsrc-users@NetBSD.org
97 .endif
98 PKGWILDCARD?=           ${PKGBASE}-[0-9]*
99 SVR4_PKGNAME?=          ${PKGNAME}
100 WRKSRC?=                ${WRKDIR}/${DISTNAME}
101
102 # Override for SU_CMD user check
103 _SU_ROOT_USER?=         ${ROOT_USER}
104 REAL_ROOT_USER?=        ${ROOT_USER}
105 REAL_ROOT_GROUP?=       ${ROOT_GROUP}
106
107 .if (defined(INSTALL_UNSTRIPPED) && !empty(INSTALL_UNSTRIPPED:M[yY][eE][sS])) || defined(DEBUG_FLAGS)
108 _INSTALL_UNSTRIPPED=    # set (flag used by platform/*.mk)
109 .endif
110
111 ##### Transform USE_* into dependencies
112
113 .include "bsd.pkg.use.mk"
114
115 ############################################################################
116 # Sanity checks
117 ############################################################################
118
119 .if defined(BUILDLINK_DEPTH) || defined(BUILDLINK_PACKAGES) || \
120     defined(BUILDLINK_DEPENDS) || defined(BUILDLINK_ORDER)
121 PKG_FAIL_REASON+=       "Out-dated buildlink3.mk detected, please update"
122 .endif
123
124 # PKG_INSTALLATION_TYPE can only be one of two values: "pkgviews" or
125 # "overwrite".
126 .if (${PKG_INSTALLATION_TYPE} != "pkgviews") && \
127     (${PKG_INSTALLATION_TYPE} != "overwrite")
128 PKG_FAIL_REASON+=       "PKG_INSTALLATION_TYPE must be \`\`pkgviews'' or \`\`overwrite''."
129 .endif
130
131 .if empty(PKG_INSTALLATION_TYPES:M${PKG_INSTALLATION_TYPE})
132 PKG_FAIL_REASON+=       "This package doesn't support PKG_INSTALLATION_TYPE=${PKG_INSTALLATION_TYPE}."
133 .endif
134
135 .if defined(ALL_TARGET)
136 PKG_FAIL_REASON+='ALL_TARGET is deprecated and must be replaced with BUILD_TARGET.'
137 .endif
138
139 .if defined(NO_WRKSUBDIR)
140 PKG_FAIL_REASON+='NO_WRKSUBDIR has been deprecated - please replace it with an explicit'
141 PKG_FAIL_REASON+='assignment of WRKSRC= $${WRKDIR}'
142 .endif # NO_WRKSUBDIR
143
144 # We need to make sure the buildlink-x11 package is not installed since it
145 # breaks builds that use imake.
146 .if defined(USE_IMAKE)
147 .  if exists(${LOCALBASE}/lib/X11/config/buildlinkX11.def) || \
148       exists(${X11BASE}/lib/X11/config/buildlinkX11.def)
149 PKG_FAIL_REASON+= "${PKGNAME} uses imake, but the buildlink-x11 package was found." \
150          "    Please deinstall it (pkg_delete buildlink-x11)."
151 .  endif
152 .endif  # USE_IMAKE
153
154 .if !defined(CATEGORIES) || !defined(DISTNAME)
155 PKG_FAIL_REASON+='CATEGORIES and DISTNAME are mandatory.'
156 .endif
157
158 .if defined(PKG_PATH)
159 PKG_FAIL_REASON+='Please unset PKG_PATH before doing pkgsrc work!'
160 .endif
161
162 .if defined(MASTER_SITE_SUBDIR)
163 PKG_FAIL_REASON+='MASTER_SITE_SUBDIR is deprecated and must be replaced with MASTER_SITES.'
164 .endif
165
166 .if defined(PATCH_SITE_SUBDIR)
167 PKG_FAIL_REASON+='PATCH_SITE_SUBDIR is deprecated and must be replaced with PATCH_SITES.'
168 .endif
169
170 .if defined(ONLY_FOR_ARCHS) || defined(NOT_FOR_ARCHS) \
171         || defined(ONLY_FOR_OPSYS) || defined(NOT_FOR_OPSYS)
172 PKG_FAIL_REASON+='ONLY/NOT_FOR_ARCHS/OPSYS are deprecated and must be replaced with ONLY/NOT_FOR_PLATFORM.'
173 .endif
174
175 # Allow variables to be set on a per-OS basis
176 OPSYSVARS+=     CFLAGS CXXFLAGS CPPFLAGS LDFLAGS LIBS
177 .for _var_ in ${OPSYSVARS:O}
178 .  if defined(${_var_}.${OPSYS})
179 ${_var_}+=      ${${_var_}.${OPSYS}}
180 .  elif defined(${_var_}.*)
181 ${_var_}+=      ${${_var_}.*}
182 .  endif
183 .endfor
184
185 CPPFLAGS+=      ${CPP_PRECOMP_FLAGS}
186
187 ALL_ENV+=       CC=${CC:Q}
188 ALL_ENV+=       CFLAGS=${CFLAGS:M*:Q}
189 ALL_ENV+=       CPPFLAGS=${CPPFLAGS:M*:Q}
190 ALL_ENV+=       CXX=${CXX:Q}
191 ALL_ENV+=       CXXFLAGS=${CXXFLAGS:M*:Q}
192 ALL_ENV+=       COMPILER_RPATH_FLAG=${COMPILER_RPATH_FLAG:Q}
193 ALL_ENV+=       F77=${FC:Q}
194 ALL_ENV+=       FC=${FC:Q}
195 ALL_ENV+=       FFLAGS=${FFLAGS:M*:Q}
196 ALL_ENV+=       LANG=C
197 ALL_ENV+=       LC_COLLATE=C
198 ALL_ENV+=       LC_CTYPE=C
199 ALL_ENV+=       LC_MESSAGES=C
200 ALL_ENV+=       LC_MONETARY=C
201 ALL_ENV+=       LC_NUMERIC=C
202 ALL_ENV+=       LC_TIME=C
203 ALL_ENV+=       LDFLAGS=${LDFLAGS:M*:Q}
204 ALL_ENV+=       LINKER_RPATH_FLAG=${LINKER_RPATH_FLAG:Q}
205 ALL_ENV+=       PATH=${PATH:Q}:${LOCALBASE}/bin:${X11BASE}/bin
206 ALL_ENV+=       PREFIX=${PREFIX}
207
208 # This variable can be added to MAKE_ENV to ease installation of packages
209 # that use BSD-style Makefiles.
210 BSD_MAKE_ENV=   BINOWN=${BINOWN} BINGRP=${BINGRP}
211 BSD_MAKE_ENV+=  GAMEOWN=${GAMEOWN} GAMEGRP=${GAMEGRP}
212 BSD_MAKE_ENV+=  MANOWN=${MANOWN} MANGRP=${MANGRP}
213 BSD_MAKE_ENV+=  SHAREOWN=${SHAREOWN} SHAREGRP=${SHAREGRP}
214 BSD_MAKE_ENV+=  DOCOWN=${DOCOWN} DOCGRP=${DOCGRP}
215 BSD_MAKE_ENV+=  BINMODE=${BINMODE} NONBINMODE=${NONBINMODE}
216 BSD_MAKE_ENV+=  BINDIR=${PREFIX}/bin
217 BSD_MAKE_ENV+=  INCSDIR=${PREFIX}/include
218 BSD_MAKE_ENV+=  LIBDIR=${PREFIX}/lib
219 BSD_MAKE_ENV+=  MANDIR=${PREFIX}/${PKGMANDIR}
220 BSD_MAKE_ENV+=  STRIPFLAG=${_STRIPFLAG_INSTALL:Q}
221 BSD_MAKE_ENV+=  MKHTML=no
222
223 _BUILD_DEFS=            ${BUILD_DEFS}
224 _BUILD_DEFS+=           LOCALBASE
225 _BUILD_DEFS+=           PKGINFODIR
226 _BUILD_DEFS+=           PKGMANDIR
227 _BUILD_DEFS+=           _USE_DESTDIR
228
229 # Store the result in the +BUILD_INFO file so we can query for the build
230 # options using "pkg_info -Q PKG_OPTIONS <pkg>".
231 #
232 .if defined(PKG_SUPPORTED_OPTIONS) && defined(PKG_OPTIONS)
233 _BUILD_DEFS+=            PKG_OPTIONS
234 .endif
235
236 .if empty(DEPOT_SUBDIR)
237 PKG_FAIL_REASON+=       "DEPOT_SUBDIR may not be empty."
238 .endif
239
240 # ZERO_FILESIZE_P exits with a successful return code if the given file
241 #       has zero length.
242 # NONZERO_FILESIZE_P exits with a successful return code if the given file
243 #       has nonzero length.
244 #
245 _ZERO_FILESIZE_P=       ${AWK} 'END { exit (NR > 0) ? 1 : 0; }'
246 _NONZERO_FILESIZE_P=    ${AWK} 'END { exit (NR > 0) ? 0 : 1; }'
247
248 # Automatically increase process limit where necessary for building.
249 _ULIMIT_CMD=            ${UNLIMIT_RESOURCES:@_lim_@${ULIMIT_CMD_${_lim_}};@}
250
251 _NULL_COOKIE=           ${WRKDIR}/.null
252
253 # Miscellaneous overridable commands:
254 SHCOMMENT?=             ${ECHO_MSG} >/dev/null '***'
255
256 LIBABISUFFIX?=
257
258 TOUCH_FLAGS?=           -f
259
260 # A few aliases for *-install targets
261 INSTALL=                ${TOOLS_INSTALL}        # XXX override sys.mk
262 INSTALL_PROGRAM?=       \
263         ${INSTALL} ${COPY} ${_STRIPFLAG_INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}
264 INSTALL_GAME?=          \
265         ${INSTALL} ${COPY} ${_STRIPFLAG_INSTALL} -o ${GAMEOWN} -g ${GAMEGRP} -m ${GAMEMODE}
266 INSTALL_SCRIPT?=        \
267         ${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}
268 INSTALL_LIB?=           \
269         ${INSTALL} ${COPY} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE}
270 INSTALL_DATA?=          \
271         ${INSTALL} ${COPY} -o ${SHAREOWN} -g ${SHAREGRP} -m ${SHAREMODE}
272 INSTALL_GAME_DATA?=     \
273         ${INSTALL} ${COPY} -o ${GAMEOWN} -g ${GAMEGRP} -m ${GAMEDATAMODE}
274 INSTALL_MAN?=           \
275         ${INSTALL} ${COPY} -o ${MANOWN} -g ${MANGRP} -m ${MANMODE}
276 INSTALL_PROGRAM_DIR?=   \
277         ${INSTALL} -d -o ${BINOWN} -g ${BINGRP} -m ${PKGDIRMODE}
278 INSTALL_GAME_DIR?=              \
279         ${INSTALL} -d -o ${GAMEOWN} -g ${GAMEGRP} -m ${GAMEDIRMODE}
280 INSTALL_SCRIPT_DIR?=    \
281         ${INSTALL_PROGRAM_DIR}
282 INSTALL_LIB_DIR?=       \
283         ${INSTALL_PROGRAM_DIR}
284 INSTALL_DATA_DIR?=      \
285         ${INSTALL} -d -o ${SHAREOWN} -g ${SHAREGRP} -m ${PKGDIRMODE}
286 INSTALL_MAN_DIR?=       \
287         ${INSTALL} -d -o ${MANOWN} -g ${MANGRP} -m ${PKGDIRMODE}
288
289 INSTALL_MACROS= BSD_INSTALL_PROGRAM=${INSTALL_PROGRAM:Q}                \
290                 BSD_INSTALL_SCRIPT=${INSTALL_SCRIPT:Q}                  \
291                 BSD_INSTALL_LIB=${INSTALL_LIB:Q}                        \
292                 BSD_INSTALL_DATA=${INSTALL_DATA:Q}                      \
293                 BSD_INSTALL_MAN=${INSTALL_MAN:Q}                        \
294                 BSD_INSTALL=${INSTALL:Q}                                \
295                 BSD_INSTALL_PROGRAM_DIR=${INSTALL_PROGRAM_DIR:Q}        \
296                 BSD_INSTALL_SCRIPT_DIR=${INSTALL_SCRIPT_DIR:Q}          \
297                 BSD_INSTALL_LIB_DIR=${INSTALL_LIB_DIR:Q}                \
298                 BSD_INSTALL_DATA_DIR=${INSTALL_DATA_DIR:Q}              \
299                 BSD_INSTALL_MAN_DIR=${INSTALL_MAN_DIR:Q}                \
300                 BSD_INSTALL_GAME=${INSTALL_GAME:Q}                      \
301                 BSD_INSTALL_GAME_DATA=${INSTALL_GAME_DATA:Q}            \
302                 BSD_INSTALL_GAME_DIR=${INSTALL_GAME_DIR:Q}
303 MAKE_ENV+=      ${INSTALL_MACROS:M*}
304 SCRIPTS_ENV+=   ${INSTALL_MACROS:M*}
305
306 # If pkgsrc is supposed to ensure that tests are run before installation
307 # of the package, then the build targets should be "build test", otherwise
308 # just "build" suffices.
309 #
310 .if !empty(PKGSRC_RUN_TEST:M[yY][eE][sS])
311 _PKGSRC_BUILD_TARGETS=  build test
312 .else
313 _PKGSRC_BUILD_TARGETS=  build
314 .endif
315
316 # OVERRIDE_DIRDEPTH represents the common directory depth under
317 #       ${WRKSRC} up to which we find the files that need to be
318 #       overridden.  By default, we search two levels down, i.e.,
319 #       */*/file.
320 #
321 OVERRIDE_DIRDEPTH?=     2
322
323 # Handle alternatives
324 #
325 .include "alternatives.mk"
326
327 # Define SMART_MESSAGES in /etc/mk.conf for messages giving the tree
328 # of dependencies for building, and the current target.
329 _PKGSRC_IN?=            ===${SMART_MESSAGES:D> ${.TARGET} [${PKGNAME}${_PKGSRC_DEPS}] ===}
330
331 # Used to print all the '===>' style prompts - override this to turn them off.
332 ECHO_MSG?=              ${ECHO}
333 PHASE_MSG?=             ${ECHO_MSG} ${_PKGSRC_IN:Q}\>
334 STEP_MSG?=              ${ECHO_MSG} "=>"
335 INFO_MSG?=              ${ECHO_MSG} "INFO:"
336 WARNING_MSG?=           ${ECHO_MSG} 1>&2 "WARNING:"
337 ERROR_MSG?=             ${ECHO_MSG} 1>&2 "ERROR:"
338 FAIL_MSG?=              ${FAIL} ${ERROR_MSG}
339
340 WARNING_CAT?=           ${SED} -e "s|^|WARNING: |" 1>&2
341 ERROR_CAT?=             ${SED} -e "s|^|ERROR: |" 1>&2
342
343 # How to do nothing.  Override if you, for some strange reason, would rather
344 # do something.
345 DO_NADA?=               ${TRUE}
346
347 # the FAIL command executes its arguments and then exits with a non-zero
348 # status.
349 FAIL?=                  ${SH} ${PKGSRCDIR}/mk/scripts/fail
350
351 #
352 # Config file related settings - see doc/pkgsrc.txt
353 #
354 PKG_SYSCONFVAR?=        ${PKGBASE}
355 PKG_SYSCONFSUBDIR?=     # empty
356 .if ${PKG_INSTALLATION_TYPE} == "overwrite"
357 PKG_SYSCONFDEPOTBASE=   # empty
358 PKG_SYSCONFBASEDIR=     ${PKG_SYSCONFBASE}
359 .else
360 .  if !empty(PKG_SYSCONFBASE:M${PREFIX}) || \
361       !empty(PKG_SYSCONFBASE:M${PREFIX}/*)
362 PKG_SYSCONFDEPOTBASE=   # empty
363 PKG_SYSCONFBASEDIR=     ${PKG_SYSCONFBASE}
364 .  else
365 PKG_SYSCONFDEPOTBASE=   ${PKG_SYSCONFBASE}/${DEPOT_SUBDIR}
366 PKG_SYSCONFBASEDIR=     ${PKG_SYSCONFDEPOTBASE}/${PKGNAME}
367 .  endif
368 .endif
369 .if empty(PKG_SYSCONFSUBDIR)
370 DFLT_PKG_SYSCONFDIR:=   ${PKG_SYSCONFBASEDIR}
371 .else
372 DFLT_PKG_SYSCONFDIR:=   ${PKG_SYSCONFBASEDIR}/${PKG_SYSCONFSUBDIR}
373 .endif
374 PKG_SYSCONFDIR=         ${DFLT_PKG_SYSCONFDIR}
375 .if defined(PKG_SYSCONFDIR.${PKG_SYSCONFVAR})
376 PKG_SYSCONFDIR=         ${PKG_SYSCONFDIR.${PKG_SYSCONFVAR}}
377 PKG_SYSCONFBASEDIR=     ${PKG_SYSCONFDIR.${PKG_SYSCONFVAR}}
378 PKG_SYSCONFDEPOTBASE=   # empty
379 .endif
380 PKG_SYSCONFDIR_PERMS?=  ${REAL_ROOT_USER} ${REAL_ROOT_GROUP} 755
381
382 ALL_ENV+=               PKG_SYSCONFDIR=${PKG_SYSCONFDIR:Q}
383 _BUILD_DEFS+=           PKG_SYSCONFBASEDIR PKG_SYSCONFDIR
384
385 # These are all of the tools use by pkgsrc Makefiles.  This should
386 # eventually be split up into lists of tools required by different
387 # phases of a pkgsrc build.
388 #
389 USE_TOOLS+=                                                             \
390         [ awk basename cat chgrp chmod chown cmp cp cut dirname echo    \
391         egrep env false file find grep head hostname id install ln ls   \
392         mkdir mv printf pwd rm rmdir sed sh sort                        \
393         tail test touch tr true wc xargs
394
395 # bsd.wrapper.mk
396 USE_TOOLS+=     expr
397
398 # bsd.bulk-pkg.mk uses certain tools
399 .if defined(BATCH)
400 USE_TOOLS+=     tee tsort
401 .endif
402
403 # INSTALL/DEINSTALL script framework
404 .include "pkginstall/bsd.pkginstall.mk"
405
406 # Locking
407 .include "internal/locking.mk"
408
409 # Tools
410 .include "tools/bsd.tools.mk"
411
412 # Barrier
413 .include "bsd.pkg.barrier.mk"
414
415 # Unprivileged builds
416 .include "unprivileged.mk"
417
418 # If NO_BUILD is defined, default to not needing a compiler.
419 .if defined(NO_BUILD)
420 USE_LANGUAGES?=         # empty
421 .endif
422
423 # Get the proper dependencies and set the PATH to use the compiler
424 # named in PKGSRC_COMPILER.
425 #
426 .include "compiler.mk"
427
428 #Fake up a home directory
429 WRAPPER_TARGETS+=       fake-home
430 FAKEHOMEDIR=            ${WRKDIR}/.home
431 ALL_ENV+=               HOME=${FAKEHOMEDIR}
432 .PHONY: fake-home
433 fake-home: ${FAKEHOMEDIR}
434 ${FAKEHOMEDIR}:
435         ${RUN} ${MKDIR} ${.TARGET}
436
437 .include "wrapper/bsd.wrapper.mk"
438
439 .if defined(ABI_DEPENDS) || defined(BUILD_ABI_DEPENDS)
440 .  if !empty(USE_ABI_DEPENDS:M[yY][eE][sS])
441 DEPENDS+=               ${ABI_DEPENDS}
442 BUILD_DEPENDS+=         ${BUILD_ABI_DEPENDS}
443 .  else
444 _BUILD_DEFS+=           USE_ABI_DEPENDS
445 .  endif
446 .endif
447
448 # Find out the PREFIX of dependencies where the PREFIX is needed at build time.
449 .if defined(EVAL_PREFIX)
450 FIND_PREFIX:=   ${EVAL_PREFIX}
451 .  include "find-prefix.mk"
452 .endif
453
454 .if !defined(_PATH_ORIG)
455 _PATH_ORIG:=            ${PATH}
456 MAKEFLAGS+=             _PATH_ORIG=${_PATH_ORIG:Q}
457 .endif
458
459 .if !empty(PREPEND_PATH:M*)
460 # This is very Special.  Because PREPEND_PATH is set with += in reverse order,
461 # this command reverses the order again (since bootstrap bmake doesn't
462 # yet support the :[-1..1] construct).
463 _PATH_CMD= \
464         path=${_PATH_ORIG:Q};                                           \
465         for i in ${PREPEND_PATH}; do path="$$i:$$path"; done;           \
466         ${ECHO} "$$path"
467 PATH=   ${_PATH_CMD:sh} # DOES NOT use :=, to defer evaluation
468 .endif
469
470 ################################################################
471 # Many ways to disable a package.
472 #
473 # Ignore packages that can't be resold if building for a CDROM.
474 #
475 # Don't build a package if it's restricted and we don't want to
476 # get into that.
477 #
478 # Don't build any package that utilizes strong cryptography, for
479 # when the law of the land forbids it.
480 #
481 # Don't attempt to build packages against X if we don't have X.
482 #
483 # Don't build a package if it's broken.
484 ################################################################
485 .if ${X11_TYPE} == "xorg"
486 PKG_FAIL_REASON+=       "Support for X11_TYPE=xorg was removed."
487 PKG_FAIL_REASON+=       "Please switch to X11_TYPE=modular."
488 X11_TYPE:=              native
489 X11BASE:=               /usr
490 .endif
491
492 .if !defined(NO_SKIP)
493 .  if (defined(NO_BIN_ON_CDROM) && defined(FOR_CDROM))
494 PKG_FAIL_REASON+= "${PKGNAME} may not be placed in binary form on a CDROM:" \
495          "    "${NO_BIN_ON_CDROM:Q}
496 .  endif
497 .  if (defined(NO_SRC_ON_CDROM) && defined(FOR_CDROM))
498 PKG_FAIL_REASON+= "${PKGNAME} may not be placed in source form on a CDROM:" \
499          "    "${NO_SRC_ON_CDROM:Q}
500 .  endif
501 .  if (defined(RESTRICTED) && defined(NO_RESTRICTED))
502 PKG_FAIL_REASON+= "${PKGNAME} is restricted:" \
503          "    "${RESTRICTED:Q}
504 .  endif
505 .  if !(${MKCRYPTO} == "YES" || ${MKCRYPTO} == yes)
506 .    if defined(CRYPTO)
507 PKG_FAIL_REASON+= "${PKGNAME} may not be built, because it utilizes strong cryptography"
508 .    endif
509 .  endif
510 .  if defined(USE_X11) && (${X11_TYPE} == "native") && !exists(${X11BASE})
511 PKG_FAIL_REASON+= "${PKGNAME} uses X11, but ${X11BASE} not found"
512 .  endif
513 .  if defined(BROKEN)
514 PKG_FAIL_REASON+= "${PKGNAME} is marked as broken:" ${BROKEN:Q}
515 .  endif
516
517 .include "license.mk"
518
519 # Define __PLATFORM_OK only if the OS matches the pkg's allowed list.
520 .  if defined(ONLY_FOR_PLATFORM) && !empty(ONLY_FOR_PLATFORM)
521 .    for __tmp__ in ${ONLY_FOR_PLATFORM}
522 .      if ${MACHINE_PLATFORM:M${__tmp__}} != ""
523 __PLATFORM_OK?= yes
524 .      endif    # MACHINE_PLATFORM
525 .    endfor     # __tmp__
526 .  else # !ONLY_FOR_PLATFORM
527 __PLATFORM_OK?= yes
528 .  endif        # ONLY_FOR_PLATFORM
529 .  for __tmp__ in ${NOT_FOR_PLATFORM}
530 .    if ${MACHINE_PLATFORM:M${__tmp__}} != ""
531 .      undef __PLATFORM_OK
532 .    endif      # MACHINE_PLATFORM
533 .  endfor       # __tmp__
534 .  if !defined(__PLATFORM_OK)
535 PKG_FAIL_REASON+= "${PKGNAME} is not available for ${MACHINE_PLATFORM}"
536 .  endif        # !__PLATFORM_OK
537 .endif
538
539 # Add these defs to the ones dumped into +BUILD_DEFS
540 _BUILD_DEFS+=   PKGPATH
541 _BUILD_DEFS+=   OPSYS OS_VERSION MACHINE_ARCH MACHINE_GNU_ARCH
542 _BUILD_DEFS+=   ABI
543 _BUILD_DEFS+=   CPPFLAGS CFLAGS FFLAGS LDFLAGS
544 _BUILD_DEFS+=   OBJECT_FMT LICENSE RESTRICTED
545 _BUILD_DEFS+=   NO_SRC_ON_FTP NO_SRC_ON_CDROM
546 _BUILD_DEFS+=   NO_BIN_ON_FTP NO_BIN_ON_CDROM
547
548 .if defined(OSVERSION_SPECIFIC)
549 _BUILD_DEFS+=   OSVERSION_SPECIFIC
550 .endif # OSVERSION_SPECIFIC
551
552 .PHONY: all
553 .if !target(all)
554 all: ${_PKGSRC_BUILD_TARGETS}
555 .endif
556
557 .PHONY: makedirs
558 makedirs: ${WRKDIR}
559
560 ${WRKDIR}:
561 .if !defined(KEEP_WRKDIR)
562 .  if ${WRKDIR_LOCKTYPE} != "none"
563         ${RUN} ${TEST} -f ${_WRKDIR_LOCKFILE} || ${RM} -fr ${WRKDIR}
564 .  endif
565 .endif
566         ${RUN} ${MKDIR} ${WRKDIR:H}
567         ${RUN} umask 077 && ${MKDIR} ${WRKDIR}
568
569 # Create a symlink from ${WRKDIR} to the package directory if
570 # CREATE_WRKDIR_SYMLINK is "yes".
571 #
572 CREATE_WRKDIR_SYMLINK?= no
573
574 .if defined(WRKOBJDIR) && !empty(CREATE_WRKDIR_SYMLINK:M[Yy][Ee][Ss])
575 makedirs: ${.CURDIR}/${WRKDIR_BASENAME}
576 ${.CURDIR}/${WRKDIR_BASENAME}:
577 .  if ${WRKDIR_LOCKTYPE} != "none"
578         ${RUN} ${TEST} -f ${_WRKDIR_LOCKFILE} || ${RM} -f ${.TARGET}
579 .  endif
580         ${RUN} \
581         if ${LN} -s ${WRKDIR} ${.TARGET} 2>/dev/null; then              \
582                 ${ECHO_MSG} "${.TARGET:T} -> ${WRKDIR}";                \
583         fi
584 .endif
585
586 .include "flavor/bsd.flavor.mk"
587
588 .include "depends/bsd.depends.mk"
589 .include "check/bsd.check.mk"
590 .include "fetch/bsd.fetch.mk"
591 .include "checksum/bsd.checksum.mk"
592 .include "extract/bsd.extract.mk"
593 .include "patch/bsd.patch.mk"
594 .include "configure/bsd.configure.mk"
595 .include "build/bsd.build.mk"
596 .include "install/bsd.install.mk"
597 .include "package/bsd.package.mk"
598
599 .include "bsd.pkg.clean.mk"
600 .include "bsd.pkg.update.mk"
601
602 # su-target is a macro target that does just-in-time su-to-root before
603 # reinvoking the make process as root.  It acquires root privileges and
604 # invokes a new make process with the target named "su-${.TARGET}".
605 #
606 # MAKEFLAGS.su-${.TARGET}
607 #       The additional flags that are passed to the make process.
608 #
609
610 # XXX: Shouldn't the $${PATH} be ${PATH} here? This may be related to
611 # PR 34470.
612 _ROOT_CMD=      cd ${.CURDIR} &&                                        \
613                 ${SETENV} ${PKGSRC_MAKE_ENV}                            \
614                         PATH="$${PATH}:"${SU_CMD_PATH_APPEND:Q}         \
615                 ${MAKE} ${MAKEFLAGS} _PKGSRC_BARRIER=yes                \
616                         PKG_DEBUG_LEVEL=${PKG_DEBUG_LEVEL:Q}            \
617                         su-${.TARGET} ${MAKEFLAGS.su-${.TARGET}}
618
619 .PHONY: su-target
620 su-target: .USE
621         ${RUN} \
622         case ${PRE_CMD.su-${.TARGET}:Q}"" in                            \
623         "")     ;;                                                      \
624         *)      ${PRE_CMD.su-${.TARGET}} ;;                             \
625         esac;                                                           \
626         if ${TEST} `${ID} -u` = `${ID} -u ${_SU_ROOT_USER}`; then       \
627                 ${_ROOT_CMD};                                           \
628         else                                                            \
629                 case ${PRE_ROOT_CMD:Q}"" in                             \
630                 ${TRUE:Q}"")    ;;                                      \
631                 *) ${WARNING_MSG} "Running: "${PRE_ROOT_CMD:Q} ;;       \
632                 esac;                                                   \
633                 ${PRE_ROOT_CMD};                                        \
634                 ${STEP_MSG} "Becoming \`\`${_SU_ROOT_USER}'' to make su-${.TARGET} (`${ECHO} ${SU_CMD} | ${AWK} '{ print $$1 }'`)"; \
635                 ${SU_CMD} ${_ROOT_CMD:Q};                               \
636                 ${STEP_MSG} "Dropping \`\`${_SU_ROOT_USER}'' privileges.";      \
637         fi
638
639 ################################################################
640 # Some more targets supplied for users' convenience
641 ################################################################
642
643 # Run pkglint:
644 .PHONY: lint
645 lint:
646         ${RUN} ${LOCALBASE}/bin/pkglint
647
648 # List of flags to pass to pkg_add(1) for bin-install:
649
650 BIN_INSTALL_FLAGS?=     # -v
651 .if ${PKG_INSTALLATION_TYPE} == "pkgviews"
652 PKG_ARGS_ADD=           -W ${LOCALBASE} -w ${DEFAULT_VIEW}
653 .endif
654 _BIN_INSTALL_FLAGS=     ${BIN_INSTALL_FLAGS}
655 .if defined(_AUTOMATIC) && !empty(_AUTOMATIC:M[Yy][Ee][Ss])
656 _BIN_INSTALL_FLAGS+=    -A
657 .endif
658 _BIN_INSTALL_FLAGS+=    ${PKG_ARGS_ADD}
659
660 _SHORT_UNAME_R= ${:!${UNAME} -r!:C@\.([0-9]*)[_.].*@.\1@} # n.n[_.]anything => n.n
661
662 .include "install/bin-install.mk"
663
664 .PHONY: show-pkgtools-version
665 .if !target(show-pkgtools-version)
666 show-pkgtools-version:
667         @${ECHO} ${PKGTOOLS_VERSION}
668 .endif
669
670 # convenience target, to display make variables from command line
671 # i.e. "make show-var VARNAME=var", will print var's value
672 #
673 # See also:
674 #       show-vars, show-subdir-var
675 #
676 .PHONY: show-var
677 show-var:
678         @${ECHO} ${${VARNAME}:Q}
679
680 # enhanced version of target above, to display multiple variables
681 .PHONY: show-vars
682 show-vars:
683 .for VARNAME in ${VARNAMES}
684         @${ECHO} ${${VARNAME}:Q}
685 .endfor
686
687 # displays multiple variables as shell expressions
688 # VARS is space separated list of VARNAME:shellvarname
689 .PHONY: show-vars-eval
690 show-vars-eval:
691 .for var in ${VARS}
692         @${ECHO} ${var:C/^.*://}="${${var:C/:.*$//}:Q}"
693 .endfor
694
695 LICENSE_FILE?=          ${PKGSRCDIR}/licenses/${LICENSE}
696
697 .if !target(show-license)
698 show-license show-licence: .PHONY
699         @license=${LICENSE:Q};                                          \
700         license_file=${LICENSE_FILE:Q};                                 \
701         pager=${PAGER:Q};                                               \
702         case "$$pager" in "") pager=${CAT:Q};; esac;                    \
703         case "$$license" in "") exit 0;; esac;                          \
704         if ${TEST} -f "$$license_file"; then                            \
705                 $$pager "$$license_file";                               \
706         else                                                            \
707                 ${ECHO} "Generic $$license information not available";  \
708                 ${ECHO} "See the package description (pkg_info -d ${PKGNAME}) for more information."; \
709         fi
710 .endif
711
712 # This target is defined in bsd.options.mk for packages that use
713 # the options framework.
714 .if !target(show-options)
715 .PHONY: show-options
716 show-options:
717         @${ECHO} This package does not use the options framework.
718 .endif
719
720 # Depend is generally meaningless for arbitrary packages, but if someone wants
721 # one they can override this.  This is just to catch people who've gotten into
722 # the habit of typing `${MAKE} depend all install' as a matter of course.
723 #
724 .PHONY: depend
725 .if !target(depend)
726 depend:
727 .endif
728
729 # Same goes for tags
730 .PHONY: tags
731 .if !target(tags)
732 tags:
733 .endif
734
735 .include "plist/bsd.plist.mk"
736
737 .include "bsd.utils.mk"
738
739 .include "subst.mk"
740
741 #
742 # For bulk build targets (bulk-install, bulk-package), the
743 # BATCH variable must be set in /etc/mk.conf:
744 #
745 .if defined(BATCH)
746 .  include "bulk/bsd.bulk-pkg.mk"
747 .endif
748
749 # README generation code.
750 .include "bsd.pkg.readme.mk"
751
752 # Create a PKG_ERROR_HANDLER shell command for each class listed in
753 # PKG_ERROR_CLASSES.  The error handler is meant to be invoked within
754 # a make target.
755 #
756 .for _class_ in ${PKG_ERROR_CLASSES}
757 PKG_ERROR_HANDLER.${_class_}?=  {                                       \
758                 ec=$$?;                                                 \
759                 for str in ${PKG_ERROR_MSG.${_class_}}; do              \
760                         ${PHASE_MSG} "$$str";                           \
761                 done;                                                   \
762                 exit $$ec;                                              \
763         }
764 .endfor
765
766 # Cache variables listed in MAKEVARS in a phase-specific "makevars.mk"
767 # file.  These variables are effectively passed to sub-make processes
768 # that are invoked on the same Makefile.
769 #
770 .for _phase_ in ${_ALL_PHASES}
771 ${_MAKEVARS_MK.${_phase_}}: ${WRKDIR}
772         ${RUN}${RM} -f ${.TARGET}.tmp
773 .  for _var_ in ${MAKEVARS:O:u}
774 .    if defined(${_var_})
775         ${RUN}                                  \
776         ${ECHO} ${_var_}"=      "${${_var_}:Q} >> ${.TARGET}.tmp
777 .    endif
778 .  endfor
779         ${RUN}                                  \
780         if ${TEST} -f ${.TARGET}.tmp; then                              \
781                 ( ${ECHO} ".if !defined(_MAKEVARS_MK)";                 \
782                   ${ECHO} "_MAKEVARS_MK=        defined";               \
783                   ${ECHO} "";                                           \
784                   ${CAT} ${.TARGET}.tmp;                                \
785                   ${ECHO} "";                                           \
786                   ${ECHO} ".endif # _MAKEVARS_MK";                      \
787                 ) > ${.TARGET};                                         \
788                 ${RM} -f ${.TARGET}.tmp;                                \
789         fi
790         ${RUN}${TOUCH} ${TOUCH_FLAGS} ${.TARGET}
791 .endfor
792
793 .if make(pbulk-index) || make(pbulk-index-item) || make(pbulk-save-wrkdir)
794 .include "pbulk/pbulk-index.mk"
795 .endif
796
797 .if defined(PKG_DEVELOPER)
798 .  include "misc/developer.mk"
799 .endif
800 .include "misc/show.mk"
801 .if make(debug)
802 .  include "bsd.pkg.debug.mk"
803 .endif
804 .include "misc/warnings.mk"
805 .if make(import)
806 .include "misc/import.mk"
807 .endif
808 .include "misc/can-be-built-here.mk"