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