1# from: @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91 2 3# The include file <bsd.port.subdir.mk> contains the default targets 4# for building mports subdirectories. 5# 6# 7# +++ variables +++ 8# 9# STRIP - The flag passed to the install program to cause the binary 10# to be stripped. This is to be used when building your 11# own install script so that the entire system can be made 12# stripped/not-stripped using a single knob. [-s] 13# 14# OPSYS - Get the operating system type [`uname -s`] 15# 16# SUBDIR - A list of subdirectories that should be built as well. 17# Each of the targets will execute the same target in the 18# subdirectories. 19# 20# 21# +++ targets +++ 22# 23# README.html: 24# Creating README.html for package. 25# 26# afterinstall, all, beforeinstall, build, checksum, clean, 27# clean-for-cdrom, clean-restricted, 28# clean-for-cdrom-list, clean-restricted-list, 29# configure, deinstall, 30# depend, depends, describe, extract, fetch, fetch-list, 31# ignorelist, ignorelist-verbose, 32# install, maintainer, makesum, package, readmes, realinstall, reinstall, 33# tags 34# 35# search: 36# Search for mports using either 'make search key=<keyword>' 37# or 'make search name=<keyword>'. 38 39PORTSDIR?= /usr/mports 40TEMPLATES?= ${PORTSDIR}/Templates 41.if defined(PORTSTOP) 42README= ${TEMPLATES}/README.top 43.else 44README= ${TEMPLATES}/README.category 45.endif 46MOVEDDIR?= ${PORTSDIR} 47MOVEDFILE?= MOVED 48 49# Ensure .CURDIR contains an absolute path without a trailing slash. Failed 50# builds can occur when PORTSDIR is a symbolic link, or with something like 51# make -C /usr/mports/category/port/. 52.CURDIR:= ${.CURDIR:tA} 53 54# Ensure .CURDIR doesn't contain a colon, which breaks makefile targets 55.if ${.CURDIR:S/:/\:/g} != ${.CURDIR} 56.error The current directory path contains ':', this is not supported 57.endif 58 59.include "${PORTSDIR}/Mk/components/commands.mk" 60 61.MAIN: all 62 63.if !defined(DEBUG_FLAGS) 64STRIP?= -s 65.endif 66 67# These are variables that are invariant for the lifetime of a recursive port traversal 68# (index build, etc), so it is more efficient to precompute them here and pass them in 69# to child makes explicitly, instead of recomputing them tens of thousands of times. 70 71.if !defined(NOPRECIOUSMAKEVARS) 72. if !defined(ARCH) 73ARCH!= ${UNAME} -p 74. endif 75_EXPORTED_VARS+= ARCH 76 77. if !defined(OSVERSION) 78. if exists(/usr/include/sys/param.h) 79OSVERSION!= ${AWK} '/^\#define[[:blank:]]__MidnightBSD_version/ {print $$3}' < /usr/include/sys/param.h 80. elif exists(${SRC_BASE}/sys/sys/param.h) 81OSVERSION!=${AWK} '/^\#define[[:blank:]]__MidnightBSD_version/ {print $$3}' < ${SRC_BASE}/sys/sys/param.h 82. else 83OSVERSION!= ${SYSCTL} -n kern.osreldate 84. endif 85. endif 86_EXPORTED_VARS+= OSVERSION 87 88 89. if !defined(_OSRELEASE) 90_OSRELEASE!= ${UNAME} -r 91. endif 92_EXPORTED_VARS+= _OSRELEASE 93. if !defined(OSREL) 94OSREL= ${_OSRELEASE:C/\.[0-9]*$//} 95. endif 96_EXPORTED_VARS+= OSREL 97 98. if !defined(OPSYS) 99OPSYS!= ${UNAME} -s 100. endif 101_EXPORTED_VARS+= OPSYS 102 103. if ${ARCH} == "amd64" 104. if !defined(HAVE_COMPAT_IA32_KERN) 105HAVE_COMPAT_IA32_KERN!= if ${SYSCTL} -n compat.ia32.maxvmem >/dev/null 2>&1; then echo YES; fi; echo 106. if empty(HAVE_COMPAT_IA32_KERN) 107.undef HAVE_COMPAT_IA32_KERN 108. endif 109. endif 110. endif 111_EXPORTED_VARS+= HAVE_COMPAT_IA32_KERN 112 113. if !defined(CONFIGURE_MAX_CMD_LEN) 114CONFIGURE_MAX_CMD_LEN!= ${SYSCTL} -n kern.argmax 115. endif 116_EXPORTED_VARS+= CONFIGURE_MAX_CMD_LEN 117 118. if !defined(_JAVA_VERSION_LIST_REGEXP) 119_JAVA_VERSION_LIST_REGEXP!= ${MAKE} -V _JAVA_VERSION_LIST_REGEXP USE_JAVA=1 -f ${PORTSDIR}/Mk/bsd.mport.mk 120. endif 121_EXPORTED_VARS+= _JAVA_VERSION_LIST_REGEXP 122 123. if !defined(_JAVA_VENDOR_LIST_REGEXP) 124_JAVA_VENDOR_LIST_REGEXP!= ${MAKE} -V _JAVA_VENDOR_LIST_REGEXP USE_JAVA=1 -f ${PORTSDIR}/Mk/bsd.mport.mk 125. endif 126_EXPORTED_VARS+= _JAVA_VENDOR_LIST_REGEXP 127 128. if !defined(_JAVA_OS_LIST_REGEXP) 129_JAVA_OS_LIST_REGEXP!= ${MAKE} -V _JAVA_OS_LIST_REGEXP USE_JAVA=1 -f ${PORTSDIR}/Mk/bsd.mport.mk 130. endif 131_EXPORTED_VARS+= _JAVA_OS_LIST_REGEXP 132 133. if !defined(_JAVA_PORTS_INSTALLED) 134_JAVA_PORTS_INSTALLED!= ${MAKE} -V _JAVA_PORTS_INSTALLED USE_JAVA=1 -f ${PORTSDIR}/Mk/bsd.mport.mk 135. endif 136_EXPORTED_VARS+= _JAVA_PORTS_INSTALLED 137 138UID?= ${.MAKE.UID} 139_EXPORTED_VARS+= UID 140 141.endif 142 143INDEXDIR?= ${PORTSDIR} 144INDEXFILE?= INDEX-${OSVERSION:C/([0-9]).*/\1/} 145 146# local customization of the mports tree 147.sinclude "${.CURDIR}/Makefile.local" 148 149TARGETS+= all 150TARGETS+= build 151TARGETS+= checksum 152TARGETS+= clean 153TARGETS+= clean-for-cdrom 154TARGETS+= clean-for-cdrom-list 155TARGETS+= clean-restricted 156TARGETS+= clean-restricted-list 157TARGETS+= configure 158TARGETS+= deinstall 159TARGETS+= depend 160TARGETS+= depends 161TARGETS+= distclean 162TARGETS+= extract 163TARGETS+= fetch 164TARGETS+= fetch-list 165TARGETS+= ignorelist 166TARGETS+= ignorelist-verbose 167TARGETS+= makesum 168TARGETS+= maintainer 169TARGETS+= package 170TARGETS+= package-recursive 171TARGETS+= realinstall 172TARGETS+= reinstall 173TARGETS+= tags 174TARGETS+= check-license 175 176.for __target in ${TARGETS} 177.if !target(${__target}) 178.if defined(SUBDIR) && !empty(SUBDIR) 179${__target}: ${SUBDIR:S/^/_/:S/$/.${__target}/} 180.else 181${__target}: 182.endif 183.endif 184.endfor 185 186.if defined(SUBDIR) && !empty(SUBDIR) 187 188.for __target in ${TARGETS} checksubdirs describe readmes 189${SUBDIR:S/^/_/:S/$/.${__target}/}: _SUBDIRUSE 190.endfor 191 192_SUBDIRUSE: .USE 193 @OK=""; sub=${.TARGET:S/^_//:R}; \ 194 for dud in $$DUDS; do \ 195 if [ $${dud} = $$sub ]; then \ 196 OK="false"; \ 197 ${ECHO_MSG} "===> ${DIRPRFX}$$sub skipped"; \ 198 fi; \ 199 done; \ 200 if test -d ${.CURDIR}/$${sub}.${MACHINE_ARCH}; then \ 201 edir=$${sub}.${MACHINE_ARCH}; \ 202 elif test -d ${.CURDIR}/$${sub}; then \ 203 edir=$${sub}; \ 204 else \ 205 OK="false"; \ 206 ${ECHO_MSG} "===> ${DIRPRFX}$${sub} non-existent"; \ 207 fi; \ 208 if [ "$$OK" = "" ]; then \ 209 ${ECHO_MSG} "===> ${DIRPRFX}$${edir}"; \ 210 cd ${.CURDIR}/$${edir}; \ 211 ${MAKE} -B ${.TARGET:E:realinstall=install} \ 212 DIRPRFX=${DIRPRFX}$$edir/; \ 213 fi 214 215.for _subdir in ${SUBDIR:S/^/_/} 216${_subdir}:: ${_subdir:S/$/.all/} 217.endfor 218 219.endif 220 221.if !target(install) 222.if !target(beforeinstall) 223beforeinstall: 224.endif 225.if !target(afterinstall) 226afterinstall: 227.endif 228install: afterinstall 229afterinstall: realinstall 230realinstall: beforeinstall ${SUBDIR:S/^/_/:S/$/.realinstall/} 231.endif 232 233IGNOREDIR= Mk Packages Templates Tools Distfiles pkg Keywords 234 235.if !target(checksubdirs) 236.if defined(PORTSTOP) 237checksubdirs: checksubdir ${SUBDIR:S/^/_/:S/$/.checksubdirs/} 238.else 239checksubdirs: checksubdir 240.endif 241.endif 242 243.if !target(checksubdir) 244checksubdir: 245 @for d in *; do \ 246 if [ -d "$$d" ]; then \ 247 found=0; \ 248 for s in ${SUBDIR} ${IGNOREDIR}; do \ 249 if [ "x$$s" = "x$$d" ]; then \ 250 found=1; \ 251 break; \ 252 fi; \ 253 done; \ 254 if [ $$found = 0 ]; then \ 255 ${ECHO_MSG} "Warning: directory $$d not in SUBDIR"; \ 256 fi; \ 257 fi; \ 258 done 259 @for s in ${SUBDIR}; do \ 260 if ! [ -d ${.CURDIR}/$$s ]; then \ 261 ${ECHO_MSG} "Warning: directory $$s in SUBDIR does not exist"; \ 262 fi \ 263 done 264.endif 265 266.if !target(describe) 267.if defined(PORTSTOP) 268# This is a bit convoluted to deal with the fact that make will overlap I/O from child make processes 269# if they write more than 2k: this will corrupt the INDEX file. make -P does not do this, but it adds 270# extraneous output and redirects stderr, so we lose error reporting from child makes. Instead we have 271# to roll our own implementation of make -P and make sure that each child make writes to their own file, 272# which we will combine at the end. This gives substantial performance benefits over doing a make -j1 273 274.if defined(BUILDING_INDEX) 275describe: ${SUBDIR:S/^/describe./} 276 277.for i in ${SUBDIR} 278describe.$i: 279 @cd ${.CURDIR}; ${MAKE} -B ${i:S/^/_/:S/$/.describe/} > ${INDEX_TMPDIR}/${INDEXFILE}.desc.${i} 280.endfor 281.else 282describe: ${SUBDIR:S/^/_/:S/$/.describe/} 283.endif 284.else 285describe: 286 @for sub in ${SUBDIR}; do \ 287 case $$sub in \ 288 /*) pdir=$$sub ;; \ 289 *) pdir=${PORTSDIR}/$$sub ;; \ 290 esac ; \ 291 if ${TEST} -d ${.CURDIR}/$${sub}; then \ 292 ${ECHO_MSG} "===> ${DIRPRFX}$${sub}"; \ 293 cd ${.CURDIR}/$${sub}; \ 294 ${MAKE} -B describe || \ 295 (${ECHO_CMD} "===> ${DIRPRFX}$${sub} failed" >&2; \ 296 exit 1) ;\ 297 else \ 298 ${ECHO_MSG} "===> ${DIRPRFX}$${sub} non-existent"; \ 299 fi; \ 300 done 301.endif 302.endif 303 304# Store last subdir name 305_LAST_DIR = ${SUBDIR:[-1]} 306describe-json: 307 @${ECHO_MSG} "{" 308 @for sub in ${SUBDIR}; do \ 309 if ${TEST} -d ${.CURDIR}/$${sub}; then \ 310 cd ${.CURDIR}/$${sub}; \ 311 ${ECHO_MSG} "\"$${sub}\": " ;\ 312 ${MAKE} -B describe-json || \ 313 (${ECHO_CMD} "===> ${DIRPRFX}$${sub} failed" >&2; \ 314 exit 1) ;\ 315 if [ "$${sub}" != "${_LAST_DIR}" ]; then \ 316 (${ECHO_MSG} ",") ; \ 317 fi; \ 318 else \ 319 ${ECHO_MSG} "===> ${DIRPRFX}$${sub} non-existent"; \ 320 fi; \ 321 done 322 @${ECHO_MSG} "}" 323 324.if !target(readmes) 325.if defined(PORTSTOP) 326readmes: readme ${SUBDIR:S/^/_/:S/$/.readmes/} 327 @${ECHO_MSG} "===> Creating README.html for all mports" 328 @perl ${PORTSDIR}/Tools/make_readmes < ${INDEXDIR}/${INDEXFILE} 329.else 330readmes: readme 331.endif 332.endif 333 334.if !target(readme) 335readme: 336 @${RM} -f README.html 337 @${MAKE} README.html 338.endif 339 340HTMLIFY= ${SED} -e 's/&/\&/g' -e 's/>/\>/g' -e 's/</\</g' 341 342package-name: 343 @${ECHO_CMD} ${.CURDIR} | ${SED} -e 's^.*/^^' 344 345README.html: 346 @${ECHO_CMD} "===> Creating README.html" 347 @> $@.tmp 348.for entry in ${SUBDIR} 349.if exists(${entry}) 350.if defined(PORTSTOP) 351 @${ECHO_CMD} -n '<li><a href="'${entry}/README.html'">'"`${ECHO_CMD} ${entry} | ${HTMLIFY}`"'</a>: ' >> $@.tmp 352.else 353 @${ECHO_CMD} -n '<li><a href="'${entry}/README.html'">'"`cd ${entry}; ${MAKE} package-name | ${HTMLIFY}`</a>: " >> $@.tmp 354.endif 355 @${ECHO_CMD} `cd ${entry}; ${MAKE} -V COMMENT` | ${HTMLIFY} >> $@.tmp 356.endif 357.endfor 358 @${SORT} -t '>' +1 -2 $@.tmp > $@.tmp2 359.if exists(${DESCR}) 360 @${HTMLIFY} ${DESCR} > $@.tmp3 361.else 362 @> $@.tmp3 363.endif 364.if defined(COMMENT) 365 @${ECHO_CMD} "${COMMENT}" | ${HTMLIFY} > $@.tmp4 366.else 367 @> $@.tmp4 368.endif 369 @${CAT} ${README} | \ 370 ${SED} -e 's/%%CATEGORY%%/'"`basename ${.CURDIR}`"'/g' \ 371 -e '/%%COMMENT%%/r$@.tmp4' \ 372 -e '/%%COMMENT%%/d' \ 373 -e '/%%DESCR%%/r$@.tmp3' \ 374 -e '/%%DESCR%%/d' \ 375 -e '/%%SUBDIR%%/r$@.tmp2' \ 376 -e '/%%SUBDIR%%/d' \ 377 > $@ 378 @${RM} -f $@.tmp $@.tmp2 $@.tmp3 $@.tmp4 379 380# Pass in the cached invariant variables to child makes. 381.if !defined(NOPRECIOUSMAKEVARS) 382.for var in ${_EXPORTED_VARS} 383.if empty(.MAKEFLAGS:M${var}=*) && !empty(${var}) 384.MAKEFLAGS: ${var}=${${var}:Q} 385.endif 386.endfor 387.endif 388 389PORTSEARCH_DISPLAY_FIELDS?=name,path,info,maint,index,bdeps,rdeps,www 390PORTSEARCH_KEYLIM?=0 391PORTSEARCH_XKEYLIM?=0 392PORTSEARCH_IGNORECASE?=1 393PORTSEARCH_MOVED?=1 394 395_PORTSEARCH= \ 396 here=${.CURDIR}; \ 397 if [ ! -r ${INDEXDIR}/${INDEXFILE} ] ; then \ 398 ${ECHO_MSG} "The ${.TARGET} target requires ${INDEXFILE}. Please run make index or make fetchindex."; \ 399 else \ 400 cd ${PORTSDIR}; \ 401 if [ -z "$$key" -a -z "$$xkey" -a \ 402 -z "$$name" -a -z "$$xname" -a \ 403 -z "$$path" -a -z "$$xpath" -a \ 404 -z "$$info" -a -z "$$xinfo" -a \ 405 -z "$$maint" -a -z "$$xmaint" -a \ 406 -z "$$cat" -a -z "$$xcat" -a \ 407 -z "$$bdeps" -a -z "$$xbdeps" -a \ 408 -z "$$rdeps" -a -z "$$xrdeps" -a \ 409 -z "$$www" -a -z "$$xwww" ]; \ 410 then \ 411 ${ECHO_MSG} "The ${.TARGET} target requires a keyword parameter or name parameter,"; \ 412 ${ECHO_MSG} "e.g.: \"make ${.TARGET} key=somekeyword\""; \ 413 ${ECHO_MSG} "or \"make ${.TARGET} name=somekeyword\""; \ 414 exit; \ 415 fi; \ 416 ${AWK} -F\| -v there="$$here/" -v top="$$(pwd -P)" \ 417 -v key="$$key" -v xkey="$$xkey" \ 418 -v name="$$name" -v xname="$$xname" \ 419 -v path="$$path" -v xpath="$$xpath" \ 420 -v info="$$info" -v xinfo="$$xinfo" \ 421 -v maint="$$maint" -v xmaint="$$xmaint" \ 422 -v cat="$$cat" -v xcat="$$xcat" \ 423 -v bdeps="$$bdeps" -v xbdeps="$$xbdeps" \ 424 -v rdeps="$$rdeps" -v xrdeps="$$xrdeps" \ 425 -v www="$$www" -v xwww="$$xwww" \ 426 -v icase="$${icase:-${PORTSEARCH_IGNORECASE}}" \ 427 -v keylim="$${keylim:-${PORTSEARCH_KEYLIM}}" \ 428 -v xkeylim="$${xkeylim:-${PORTSEARCH_XKEYLIM}}" \ 429 -v display="$${display:-${PORTSEARCH_DISPLAY_FIELDS}}" \ 430 -v xdisplay="$$xdisplay" \ 431 'BEGIN { \ 432 gsub(/\+/,"\\+",name); \ 433 if (substr(there, 1, length(top)) == top) \ 434 there = "${PORTSDIR}" substr(there, 1 + length(top)); \ 435 therelen = length(there); \ 436 keylen = length(key); keylim = keylim && keylen; \ 437 if (!keylim && keylen) \ 438 parms[0] = (icase ? tolower(key) : key); \ 439 xkeylen = length(xkey); xkeylim = xkeylim && xkeylen; \ 440 if (!xkeylim && xkeylen) \ 441 xparms[0] = (icase ? tolower(xkey) : xkey); \ 442 if (icase) { \ 443 if (length(name)) parms[1] = tolower(name); if (length(xname)) xparms[1] = tolower(xname); \ 444 if (length(path)) parms[2] = tolower(path); if (length(xpath)) xparms[2] = tolower(xpath); \ 445 if (length(info)) parms[4] = tolower(info); if (length(xinfo)) xparms[4] = tolower(xinfo); \ 446 if (length(maint)) parms[6] = tolower(maint); if (length(xmaint)) xparms[6] = tolower(xmaint); \ 447 if (length(cat)) parms[7] = tolower(cat); if (length(xcat)) xparms[7] = tolower(xcat); \ 448 if (length(bdeps)) parms[8] = tolower(bdeps); if (length(xbdeps)) xparms[8] = tolower(xbdeps); \ 449 if (length(rdeps)) parms[9] = tolower(rdeps); if (length(xrdeps)) xparms[9] = tolower(xrdeps); \ 450 if (length(www)) parms[10] = tolower(www); if (length(xwww)) xparms[10] = tolower(xwww); \ 451 } else { \ 452 if (length(name)) parms[1] = name; if (length(xname)) xparms[1] = xname; \ 453 if (length(path)) parms[2] = path; if (length(xpath)) xparms[2] = xpath; \ 454 if (length(info)) parms[4] = info; if (length(xinfo)) xparms[4] = xinfo; \ 455 if (length(maint)) parms[6] = maint; if (length(xmaint)) xparms[6] = xmaint; \ 456 if (length(cat)) parms[7] = cat; if (length(xcat)) xparms[7] = xcat; \ 457 if (length(bdeps)) parms[8] = bdeps; if (length(xbdeps)) xparms[8] = xbdeps; \ 458 if (length(rdeps)) parms[9] = rdeps; if (length(xrdeps)) xparms[9] = xrdeps; \ 459 if (length(www)) parms[10] = www; if (length(xwww)) xparms[10] = xwww; \ 460 } \ 461 fields["name"] = 1; names[1] = "Port"; \ 462 fields["path"] = 2; names[2] = "Path"; \ 463 fields["info"] = 4; names[4] = "Info"; \ 464 fields["maint"] = 6; names[6] = "Maint"; \ 465 fields["cat"] = 7; names[7] = "Index"; \ 466 fields["bdeps"] = 8; names[8] = "B-deps"; \ 467 fields["rdeps"] = 9; names[9] = "R-deps"; \ 468 fields["www"] = 10; names[10] = "WWW"; \ 469 split(display, d, /,[ \t]*/); \ 470 split(xdisplay, xd, /,[ \t]*/); \ 471 for (i in d) { \ 472 toprint = 1; \ 473 for (j in xd) { \ 474 if (d[i] == xd[j] ) { \ 475 toprint=0; \ 476 break; \ 477 }\ 478 } \ 479 if (toprint == 1 ) disp[fields[d[i]]] = 1; \ 480 } \ 481 } \ 482 { \ 483 if (match($$2, "^/usr/mports/[^/]*/[^/]*$$") > 0) \ 484 sub("^/usr/mports", "${PORTSDIR}", $$2); \ 485 if (substr($$2, 1, therelen) != there) \ 486 next; \ 487 for (i in parms) \ 488 if ((icase ? tolower($$i) : $$i) !~ parms[i]) \ 489 next; \ 490 for (i in xparms) \ 491 if ((icase ? tolower($$i) : $$i) ~ xparms[i]) \ 492 next; \ 493 found = 0; \ 494 for (i = 1; i < 11; i++) \ 495 if (i in disp) { \ 496 if (xkeylim && (icase ? tolower($$i) : $$i) ~ xkey) \ 497 next; \ 498 if (!found && keylim && (icase ? tolower($$i) : $$i) ~ key) \ 499 found = 1; \ 500 } \ 501 if (keylim && !found) \ 502 next; \ 503 for (i = 1; i < 11; i++) \ 504 if (i in disp) \ 505 printf("%s:\t%s\n", names[i], $$i); \ 506 print(""); \ 507 }' ${INDEXDIR}/${INDEXFILE}; \ 508 if [ "$$name" -o "$$xname" ] && [ ${PORTSEARCH_MOVED} -gt 0 ]; \ 509 then \ 510 ${AWK} -F\| -v name="$$name" -v xname="$$xname" \ 511 -v icase="$${icase:-${PORTSEARCH_IGNORECASE}}" \ 512 'BEGIN { \ 513 if (icase) { \ 514 if (length(name)) name = tolower(name); if (length(xname)) xname = tolower(xname); \ 515 } \ 516 fields["name"] = 1; names[1] = "Port"; \ 517 fields["destination"] = 2; names[2] = "Moved"; \ 518 fields["date"] = 3; names[3] = "Date"; \ 519 fileds["reason"] = 4; names[4] = "Reason"; \ 520 } \ 521 { \ 522 oldname = $$1; newname = $$2; \ 523 if (oldname ~ /^\#/) next; \ 524 sub(".*\/", "", oldname); newname = sub(".*\/", "", newname); \ 525 if (((icase ? tolower(oldname) : oldname) ~ name) || \ 526 ((icase ? tolower(newname) : newname) ~ name)) { \ 527 for (i = 1; i <= 4; i++) { \ 528 printf("%s:\t%s\n", names[i], $$i); \ 529 } \ 530 print(""); \ 531 } \ 532 }' ${MOVEDDIR}/${MOVEDFILE}; \ 533 fi \ 534 fi 535 536search: 537 @${_PORTSEARCH} 538 539quicksearch: 540 @export display="name,path,info" ; \ 541 ${_PORTSEARCH} 542