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