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