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