xref: /freebsd/share/mk/bsd.port.subdir.mk (revision 2ad872c5794e4c26fdf6ed219ad3f09ca0d5304a)
1#	from: @(#)bsd.subdir.mk	5.9 (Berkeley) 2/1/91
2#	$Id: bsd.port.subdir.mk,v 1.26 1998/11/08 10:29:53 asami Exp $
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# ECHO_MSG	Used to print all the '===>' style prompts - override this
16#		to turn them off [echo].
17#
18# OPSYS		Get the operating system type [`uname -s`]
19#
20# SUBDIR	A list of subdirectories that should be built as well.
21#		Each of the targets will execute the same target in the
22#		subdirectories.
23#
24#
25# +++ targets +++
26#
27#	README.html:
28#		Creating README.html for package.
29#
30#	afterinstall, all, beforeinstall, build, checksum, clean,
31#	clean-for-cdrom, clean-restricted, configure, deinstall,
32#	depend, depends, describe, extract, fetch, fetch-list, ignorelist,
33#	install, package, package-loop, readmes, realinstall, reinstall, tags
34#
35
36
37.MAIN: all
38
39.if !defined(DEBUG_FLAGS)
40STRIP?=	-s
41.endif
42
43.if !defined(OPSYS)	# XXX !!
44OPSYS!=	uname -s
45.endif
46
47ECHO_MSG?=	echo
48
49_SUBDIRUSE: .USE
50	@for entry in ${SUBDIR}; do \
51		OK=""; \
52		for dud in $$DUDS; do \
53			if [ $${dud} = $${entry} ]; then \
54				OK="false"; \
55				${ECHO_MSG} "===> ${DIRPRFX}$${entry} skipped"; \
56			fi; \
57		done; \
58		if test -d ${.CURDIR}/$${entry}.${MACHINE}; then \
59			edir=$${entry}.${MACHINE}; \
60		elif test -d ${.CURDIR}/$${entry}; then \
61			edir=$${entry}; \
62		else \
63			OK="false"; \
64			${ECHO_MSG} "===> ${DIRPRFX}$${entry} non-existent"; \
65		fi; \
66		if [ "$$OK" = "" ]; then \
67			${ECHO_MSG} "===> ${DIRPRFX}$${edir}"; \
68			cd ${.CURDIR}/$${edir}; \
69			${MAKE} ${.TARGET:realinstall=install} \
70				DIRPRFX=${DIRPRFX}$$edir/; \
71		fi; \
72	done
73
74${SUBDIR}::
75	@if test -d ${.TARGET}.${MACHINE}; then \
76		cd ${.CURDIR}/${.TARGET}.${MACHINE}; \
77	else \
78		cd ${.CURDIR}/${.TARGET}; \
79	fi; \
80	${MAKE} all
81
82.for __target in all fetch fetch-list package package-loop extract configure \
83		 build clean clean-for-cdrom clean-restricted \
84		 deinstall depend depends describe distclean \
85		 reinstall tags checksum \
86		 ignorelist
87.if !target(${__target})
88${__target}: _SUBDIRUSE
89.endif
90.endfor
91
92.if !target(install)
93.if !target(beforeinstall)
94beforeinstall:
95.endif
96.if !target(afterinstall)
97afterinstall:
98.endif
99install: afterinstall
100afterinstall: realinstall
101realinstall: beforeinstall _SUBDIRUSE
102.endif
103
104IGNOREDIR=	CVS distfiles packages pkg templates
105
106.if !target(checksubdirs)
107.if defined(PORTSTOP)
108checksubdirs: checksubdir _SUBDIRUSE
109.else
110checksubdirs: checksubdir
111.endif
112.endif
113
114.if !target(checksubdir)
115checksubdir:
116	@for d in *; do \
117	  if [ -d "$$d" ]; then \
118	    found=0; \
119	    for s in ${SUBDIR} ${IGNOREDIR}; do \
120	      if [ "x$$s" = "x$$d" ]; then \
121	        found=1; \
122	        break; \
123	      fi; \
124	    done; \
125	    if [ $$found = 0 ]; then \
126	      ${ECHO} "Warning: directory $$d not in SUBDIR"; \
127	    fi; \
128	  fi; \
129	done
130.endif
131
132.if !target(readmes)
133readmes: readme _SUBDIRUSE
134.endif
135
136.if !target(readme)
137readme:
138	@rm -f README.html
139	@make README.html
140.endif
141
142.if (${OPSYS} == "NetBSD")
143PORTSDIR ?= /usr/opt
144.else
145PORTSDIR ?= /usr/ports
146.endif
147TEMPLATES ?= ${PORTSDIR}/templates
148.if defined(PORTSTOP)
149README=	${TEMPLATES}/README.top
150.else
151README=	${TEMPLATES}/README.category
152.endif
153
154HTMLIFY=	sed -e 's/&/\&amp;/g' -e 's/>/\&gt;/g' -e 's/</\&lt;/g'
155
156README.html:
157	@echo "===>  Creating README.html"
158	@> $@.tmp
159.for entry in ${SUBDIR}
160.if defined(PORTSTOP)
161	@echo -n '<a href="'${entry}/README.html'">'"`echo ${entry} | ${HTMLIFY}`"'</a>: ' >> $@.tmp
162.else
163	@echo -n '<a href="'${entry}/README.html'">'"`cd ${entry}; make package-name | ${HTMLIFY}`</a>: " >> $@.tmp
164.endif
165.if exists(${entry}/pkg/COMMENT)
166	@${HTMLIFY} ${entry}/pkg/COMMENT >> $@.tmp
167.else
168	@echo "(no description)" >> $@.tmp
169.endif
170.endfor
171	@sort -t '>' +1 -2 $@.tmp > $@.tmp2
172.if exists(${.CURDIR}/pkg/DESCR)
173	@${HTMLIFY} ${.CURDIR}/pkg/DESCR > $@.tmp3
174.else
175	@> $@.tmp3
176.endif
177	@cat ${README} | \
178		sed -e 's/%%CATEGORY%%/'"`basename ${.CURDIR}`"'/g' \
179			-e '/%%DESCR%%/r$@.tmp3' \
180			-e '/%%DESCR%%/d' \
181			-e '/%%SUBDIR%%/r$@.tmp2' \
182			-e '/%%SUBDIR%%/d' \
183		> $@
184	@rm -f $@.tmp $@.tmp2 $@.tmp3
185