Add files from parent branch HEAD:
[pkgsrc.git] / mk / bsd.pkg.subdir.mk
1 #       $NetBSD: bsd.pkg.subdir.mk,v 1.54 2003/09/06 11:28:13 cjep Exp $
2 #       Derived from: FreeBSD Id: bsd.port.subdir.mk,v 1.19 1997/03/09 23:10:56 wosch Exp 
3 #       from: @(#)bsd.subdir.mk 5.9 (Berkeley) 2/1/91
4 #
5 # The include file <bsd.pkg.subdir.mk> contains the default targets
6 # for building ports subdirectories. 
7 #
8 #
9 # +++ variables +++
10 #
11 # OPSYS         Get the operating system type [`uname -s`]
12 #
13 # SUBDIR        A list of subdirectories that should be built as well.
14 #               Each of the targets will execute the same target in the
15 #               subdirectories.
16 #
17 #
18 # +++ targets +++
19 #
20 #       README.html:
21 #               Creating README.html for package.
22 #
23 #       afterinstall, all, beforeinstall, build, checksum, clean,
24 #       configure, deinstall, depend, describe, extract, fetch, fetch-list, 
25 #       install, package, readmes, realinstall, reinstall, tags,
26 #       mirror-distfiles, bulk-install, bulk-package, ${PKG_MISC_TARGETS}
27 #
28
29 # Pull in stuff from mk.conf - need to check two places as this may be
30 # called from pkgsrc or from pkgsrc/category.
31 .if exists(${.CURDIR}/mk/bsd.prefs.mk)
32 .include "${.CURDIR}/mk/bsd.prefs.mk"
33 .else
34 .if exists(${.CURDIR}/../mk/bsd.prefs.mk)
35 .include "${.CURDIR}/../mk/bsd.prefs.mk"
36 .endif  # exists(${.CURDIR}/../mk/bsd.prefs.mk)
37 .endif  # exists(${.CURDIR}/mk/bsd.prefs.mk)
38
39
40 .MAIN: all
41
42 AWK?=           /usr/bin/awk
43 CAT?=           /bin/cat
44 BASENAME?=      /usr/bin/basename
45 ECHO?=          echo
46 ECHO_MSG?=      ${ECHO}
47 MV?=            /bin/mv
48 RM?=            /bin/rm
49 SED?=           /usr/bin/sed
50 SORT?=          /usr/bin/sort
51
52 _SUBDIRUSE: .USE
53         @for entry in "" ${SUBDIR}; do \
54                 if [ "X$$entry" = "X" ]; then continue; fi; \
55                 OK=""; \
56                 for dud in "" ${DUDS}; do \
57                         if [ "X$$dud" = "X" ]; then continue; fi; \
58                         if [ $${dud} = $${entry} ]; then \
59                                 OK="false"; \
60                                 ${ECHO_MSG} "===> ${_THISDIR_}$${entry} skipped"; \
61                         fi; \
62                 done; \
63                 if [ -d ${.CURDIR}/$${entry}.${MACHINE} ]; then \
64                         edir=$${entry}.${MACHINE}; \
65                 elif [ -d ${.CURDIR}/$${entry} ]; then \
66                         edir=$${entry}; \
67                 else \
68                         OK="false"; \
69                         ${ECHO_MSG} "===> ${_THISDIR_}$${entry} non-existent"; \
70                 fi; \
71                 if [ "$$OK" = "" ]; then \
72                         cd ${.CURDIR}/$${edir}; \
73                         ${ECHO_MSG} "===> ${_THISDIR_}$${edir}"; \
74                         ${MAKE} ${MAKEFLAGS} "_THISDIR_=${_THISDIR_}$${edir}/" \
75                             ${.TARGET:realinstall=install} || true; \
76                 fi; \
77         done
78
79 ${SUBDIR}::
80         @if [ -d ${.TARGET}.${MACHINE} ]; then \
81                 cd ${.CURDIR}/${.TARGET}.${MACHINE}; \
82         else \
83                 cd ${.CURDIR}/${.TARGET}; \
84         fi; \
85         ${MAKE} ${MAKEFLAGS} all
86
87 .for __target in all fetch package extract configure build clean \
88                 cleandir distclean depend describe reinstall tags checksum \
89                 makepatchsum mirror-distfiles deinstall show-downlevel \
90                 show-pkgsrc-dir show-var show-vars bulk-install bulk-package \
91                 fetch-list-one-pkg fetch-list-recursive \
92                 update clean-update \
93                 lint \
94                 ${PKG_MISC_TARGETS}
95 .if !target(__target)
96 ${__target}: _SUBDIRUSE
97 .endif
98 .endfor
99
100 .if !target(install)
101 .if !target(beforeinstall)
102 beforeinstall:
103 .endif
104 .if !target(afterinstall)
105 afterinstall:
106 .endif
107 install: afterinstall
108 afterinstall: realinstall
109 realinstall: beforeinstall _SUBDIRUSE
110 .endif
111
112 .if !target(readmes)
113 readmes: readme _SUBDIRUSE
114 .endif
115
116 .if !target(readme)
117 readme:
118         @${MAKE} ${MAKEFLAGS} README.html _README_TYPE_FLAG=--ftp _README_TYPE=$@
119 .endif
120
121 .if !target(cdrom-readme)
122 cdrom-readme:
123         @${MAKE} ${MAKEFLAGS} README.html _README_TYPE_FLAG=--cdrom README_TYPE=$@
124 .endif
125
126 .if defined(PKGSRCTOP)
127 README= templates/README.top
128 .else
129 README= ../templates/README.category
130 .endif
131
132 HTMLIFY=        ${SED} -e 's/&/\&amp;/g' -e 's/>/\&gt;/g' -e 's/</\&lt;/g'
133
134 .if !target(README.html)
135 .PHONY: README.html
136 README.html: .PRECIOUS
137         @> $@.tmp
138 .for entry in ${SUBDIR}
139 .if defined(PKGSRCTOP)
140         @${ECHO} '<TR><TD VALIGN=TOP><a href="'${entry}/README.html'">'"`${ECHO} ${entry} | ${HTMLIFY}`"'</a>: <TD>' >> $@.tmp
141         @${ECHO} `cd ${entry} && ${MAKE} ${MAKEFLAGS} show-comment | ${HTMLIFY}` >> $@.tmp
142 .else
143         @${ECHO} '<TR><TD VALIGN=TOP><a href="'${entry}/README.html'">'"`cd ${entry}; ${MAKE} ${MAKEFLAGS} make-readme-html-help`" >> $@.tmp
144 .endif
145 .endfor
146         @${SORT} -t '>' +3 -4 $@.tmp > $@.tmp2
147         @${AWK} '{ ++n } END { print n }' < $@.tmp2 > $@.tmp4
148 .if exists(${.CURDIR}/DESCR)
149         @${HTMLIFY} ${.CURDIR}/DESCR > $@.tmp3
150 .else
151         @> $@.tmp3
152 .endif
153         @${CAT} ${README} | \
154                 ${SED} -e 's/%%CATEGORY%%/'"`${BASENAME} ${.CURDIR}`"'/g' \
155                         -e '/%%NUMITEMS%%/r$@.tmp4' \
156                         -e '/%%NUMITEMS%%/d' \
157                         -e '/%%DESCR%%/r$@.tmp3' \
158                         -e '/%%DESCR%%/d' \
159                         -e '/%%SUBDIR%%/r$@.tmp2' \
160                         -e '/%%SUBDIR%%/d' \
161                 > $@.tmp5
162         @if [ ! -f $@ ]; then ${TOUCH} $@ ; fi
163         @if ${CMP} -s $@.tmp5 $@ ; then \
164                 ${RM} $@.tmp5 ; \
165         else \
166                 ${ECHO_MSG} "===>  Creating README.html for ${_THISDIR_}${.CURDIR:T}" ; \
167                 ${MV} $@.tmp5 $@ ; \
168         fi
169         @${RM} -f $@.tmp $@.tmp2 $@.tmp3 $@.tmp4
170 .for subdir in ${SUBDIR}
171         @cd ${subdir} && ${MAKE} ${MAKEFLAGS} "_THISDIR_=${_THISDIR_}${.CURDIR:T}/" ${_README_TYPE}
172 .endfor
173 .endif
174
175 show-comment:
176         @if [ "${COMMENT}" ]; then                                      \
177                 ${ECHO} "${COMMENT:Q}";                                 \
178         elif [ -f COMMENT ] ; then                                      \
179                 ${CAT} COMMENT;                                         \
180         else                                                            \
181                 ${ECHO} '(no description)';                             \
182         fi
183
184 .if !target(show-distfiles)
185 show-distfiles:
186         @for entry in ${SUBDIR}; do                                     \
187                 if [ -d ${.CURDIR}/$${entry}.${MACHINE} ]; then         \
188                         edir=$${entry}.${MACHINE};                      \
189                 elif [ -d ${.CURDIR}/$${entry} ]; then                  \
190                         edir=$${entry};                                 \
191                 else                                                    \
192                         OK="false";                                     \
193                         ${ECHO_MSG} "===> ${_THISDIR_}$${entry} non-existent"; \
194                 fi;                                                     \
195                 if [ "$$OK" = "" ]; then                                \
196                         cd ${.CURDIR}/$${edir} && ${MAKE} ${MAKEFLAGS} show-distfiles; \
197                 fi;                                                     \
198         done
199 .endif
200
201
202 # Print out a script to fetch all needed files (no checksumming).
203 #
204 # When invoked at the top or category level, this target needs to be
205 # handled specially, to elide the "===>" messages that would otherwise
206 # ruin the script.
207 #
208 .if !target(fetch-list)
209 .PHONY: fetch-list
210
211 fetch-list:
212         @${ECHO} '#!/bin/sh'
213         @${ECHO} '#'
214         @${ECHO} '# This is an auto-generated script, the result of running'
215         @${ECHO} '# `make fetch-list'"'"' in directory "'"`${PWD_CMD}`"'"'
216         @${ECHO} '# on host "'"`${UNAME} -n`"'" on "'"`date`"'".'
217         @${ECHO} '#'
218 .if defined(PKGSRCTOP) && !defined(SPECIFIC_PKGS)
219 #       Recursing over dependencies would be pointless, in this case.
220         @${MAKE} ${MAKEFLAGS} fetch-list-one-pkg                \
221         | ${AWK} '                                              \
222         function do_block () {                                  \
223                 if (FoundSomething) {                           \
224                         for (line = 0; line < c; line++)        \
225                                 print block[line];              \
226                         FoundSomething = 0                      \
227                         }                                       \
228                 c = 0                                           \
229                 }                                               \
230         /^[^#=]/ { FoundSomething = 1 }                         \
231         /^unsorted/ { gsub(/[[:space:]]+/, " \\\n\t") }         \
232         /^echo/ { gsub(/;[[:space:]]+/, "\n") }                 \
233         !/^=/ { block[c++] = $$0 }                              \
234         /^=/ { do_block() }                                     \
235         END { do_block() }                                      \
236         '
237 .else
238         @${MAKE} ${MAKEFLAGS} fetch-list-recursive              \
239         | ${SED} '/^=/d'
240 .endif
241 .endif # !target(fetch-list)