Makefile revision 147090
1178825Sdfr#$FreeBSD: head/rescue/rescue/Makefile 147090 2005-06-07 04:51:24Z brooks $
2178825Sdfr#	@(#)Makefile	8.1 (Berkeley) 6/2/93
3178825Sdfr
4178825SdfrPROG=	rescue
5233294SstasBINDIR?=/rescue
6233294Sstas
7178825Sdfr# Shell scripts need #! line to be edited from /bin/sh to /rescue/sh
8178825SdfrSCRIPTS= nextboot_FIXED
9178825SdfrSCRIPTSNAME_nextboot_FIXED= nextboot.sh
10178825Sdfrnextboot_FIXED: ../../sbin/reboot/nextboot.sh
11178825Sdfr	sed '1s/\/bin\//\/rescue\//' ${.ALLSRC} > ${.TARGET}
12178825SdfrCLEANFILES+= nextboot_FIXED
13178825Sdfr
14178825SdfrSCRIPTS+= dhclient_FIXED
15178825SdfrSCRIPTSNAME_dhclient_FIXED= dhclient-script
16178825Sdfrdhclient_FIXED: ../../sbin/dhclient/dhclient-script
17178825Sdfr	sed '1s/\/bin\//\/rescue\//' ${.ALLSRC} > ${.TARGET}
18178825SdfrCLEANFILES+= dhclient_FIXED
19178825Sdfr
20178825Sdfr#################################################################
21178825Sdfr#
22178825Sdfr# General notes:
23178825Sdfr#
24178825Sdfr# A number of Make variables are used to generate the crunchgen config file.
25178825Sdfr#
26178825Sdfr#  CRUNCH_SRCDIRS: lists directories to search for included programs
27178825Sdfr#  CRUNCH_PROGS:  lists programs to be included
28178825Sdfr#  CRUNCH_LIBS:  libraries to link with
29178825Sdfr#  CRUNCH_BUILDOPTS: generic build options to be added to every program
30178825Sdfr#
31178825Sdfr# Special options can be specified for individual programs
32178825Sdfr#  CRUNCH_SRCDIR_$(P): base source directory for program $(P)
33178825Sdfr#  CRUNCH_BUILDOPTS_$(P): additional build options for $(P)
34178825Sdfr#  CRUNCH_ALIAS_$(P): additional names to be used for $(P)
35178825Sdfr#
36178825Sdfr# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
37178825Sdfr# will be used to generate a hard link to the resulting binary.
38178825Sdfr# Specific links can be suppressed by setting
39178825Sdfr# CRUNCH_SUPPRESS_LINK_$(NAME) to 1.
40178825Sdfr#
41178825Sdfr
42178825Sdfr# Define Makefile variable RESCUE
43178825SdfrCRUNCH_BUILDOPTS+= -DRESCUE
44178825Sdfr# Define compile-time RESCUE symbol when compiling components
45178825SdfrCRUNCH_BUILDOPTS+= CRUNCH_CFLAGS=-DRESCUE
46178825Sdfr
47233294Sstas# An experiment that failed: try overriding bsd.lib.mk and bsd.prog.mk
48178825Sdfr# rather than incorporating rescue-specific logic into standard files.
49178825Sdfr#MAKEFLAGS= -m ${.CURDIR} ${.MAKEFLAGS}
50233294Sstas
51178825Sdfr# Hackery:  'librescue' exists merely as a tool for appropriately
52178825Sdfr# recompiling specific library entries.  We _know_ they're needed, and
53178825Sdfr# regular archive searching creates ugly library ordering problems.
54178825Sdfr# Easiest fix: tell the linker to include them into the executable
55178825Sdfr# first, so they are guaranteed to override the regular lib entries.
56178825Sdfr# Note that if 'librescue' hasn't been compiled, we'll just get the
57178825Sdfr# regular lib entries from libc and friends.
58178825SdfrCRUNCH_LIBS+= ${.OBJDIR}/../librescue/*.o
59178825Sdfr
60178825Sdfr###################################################################
61178825Sdfr# Programs from stock /bin
62178825Sdfr#
63233294Sstas# WARNING: Changing this list may require adjusting
64233294Sstas# /usr/include/paths.h as well!  You were warned!
65178825Sdfr#
66178825SdfrCRUNCH_SRCDIRS+= bin
67178825SdfrCRUNCH_PROGS_bin= cat chflags chio chmod cp date dd df echo 	\
68178825Sdfr	 ed expr getfacl hostname kenv kill ln ls mkdir mv pax ps pwd 	\
69178825Sdfr	 realpath rm rmdir setfacl sh stty sync test
70178825SdfrCRUNCH_LIBS+= -lcrypt -ledit -lkvm -ll -lm -ltermcap -lutil
71233294Sstas.if !defined(NO_CRYPT) && !defined(NO_OPENSSL)
72233294SstasCRUNCH_LIBS+= -lcrypto
73233294Sstas.endif
74178825Sdfr
75233294Sstas# Additional options for specific programs
76233294SstasCRUNCH_ALIAS_test= [
77233294SstasCRUNCH_ALIAS_sh= -sh
78178825Sdfr# The -sh alias shouldn't appear in /rescue as a hard link
79233294SstasCRUNCH_SUPPRESS_LINK_-sh= 1
80233294SstasCRUNCH_ALIAS_ln= link
81233294SstasCRUNCH_ALIAS_rm= unlink
82178825SdfrCRUNCH_ALIAS_ed= red
83233294Sstas
84233294Sstas.if !defined(NO_RCMDS)
85178825SdfrCRUNCH_PROGS_bin+= rcp
86178825Sdfr.endif
87233294Sstas
88233294Sstas.if !defined(NO_TCSH)
89233294SstasCRUNCH_PROGS_bin+= csh
90233294SstasCRUNCH_ALIAS_csh= -csh tcsh -tcsh
91233294SstasCRUNCH_SUPPRESS_LINK_-csh= 1
92178825SdfrCRUNCH_SUPPRESS_LINK_-tcsh= 1
93178825Sdfr.endif
94233294Sstas
95178825Sdfr###################################################################
96178825Sdfr# Programs from standard /sbin
97178825Sdfr#
98178825Sdfr# WARNING: Changing this list may require adjusting
99233294Sstas# /usr/include/paths.h as well!  You were warned!
100178825Sdfr#
101178825Sdfr# Note that mdmfs have their own private 'pathnames.h'
102178825Sdfr# headers in addition to the standard 'paths.h' header.
103233294Sstas#
104178825SdfrCRUNCH_SRCDIRS+= sbin
105233294SstasCRUNCH_PROGS_sbin= atacontrol badsect bsdlabel		\
106233294Sstas	camcontrol ccdconfig clri devfs dmesg dump			\
107233294Sstas	dumpfs dumpon fsck fsck_ffs fsck_msdosfs fsdb		\
108178825Sdfr	fsirand gbde ifconfig init 				\
109178825Sdfr	kldconfig kldload kldstat kldunload ldconfig 			\
110178825Sdfr	md5 mdconfig mdmfs mknod mount mount_cd9660 mount_ext2fs	\
111178825Sdfr	mount_msdosfs mount_nfs mount_ntfs mount_nullfs			\
112178825Sdfr	mount_std mount_udf mount_umapfs mount_unionfs newfs		\
113178825Sdfr	newfs_msdos nos-tun ping reboot			\
114178825Sdfr	restore rcorder route routed rtquery rtsol savecore 		\
115178825Sdfr	slattach spppcontrol startslip swapon sysctl tunefs umount 
116178825Sdfr
117178825Sdfr.if !defined(NO_ATM)
118178825SdfrCRUNCH_PROGS_sbin+= atm atmconfig fore_dnld ilmid
119178825SdfrCRUNCH_LIBS+= -latm
120178825Sdfr.endif
121178825Sdfr
122178825Sdfr.if !defined(NO_INET6)
123178825SdfrCRUNCH_PROGS_sbin+= ping6
124178825Sdfr.endif
125178825Sdfr
126178825Sdfr.if !defined(NO_IPFILTER)
127178825SdfrCRUNCH_PROGS_sbin+= ipf
128178825Sdfr.endif
129178825Sdfr
130178825Sdfr# crunchgen does not like C++ programs; this should be fixed someday
131178825Sdfr# CRUNCH_PROGS+= devd
132178825Sdfr
133178825SdfrCRUNCH_LIBS+= -lalias -lbsdxml -lcam -lcurses -ldevstat -lipsec -lipx \
134178825Sdfr	-lgeom -lkiconv -lmd -lreadline -lsbuf -lufs -lz 
135178825Sdfr
136178825Sdfr.if ${MACHINE_ARCH} == "i386"
137178825SdfrCRUNCH_PROGS_sbin+= sconfig fdisk
138178825SdfrCRUNCH_ALIAS_bsdlabel= disklabel
139178825Sdfr#CRUNCH_PROGS+= mount_nwfs mount_smbfs
140178825Sdfr#CRUNCH_LIBS+= -lncp -lsmb
141178825Sdfr.endif
142178825Sdfr
143233294Sstas.if ${MACHINE} == "pc98"
144233294SstasCRUNCH_SRCDIR_fdisk= $(.CURDIR)/../../sbin/fdisk_pc98
145233294Sstas.endif
146178825Sdfr
147233294Sstas.if ${MACHINE_ARCH} == "ia64"
148233294SstasCRUNCH_PROGS_sbin+= mca gpt fdisk
149233294Sstas.endif
150178825Sdfr
151178825Sdfr.if ${MACHINE_ARCH} == "sparc64"
152178825SdfrCRUNCH_PROGS_sbin+= sunlabel
153178825Sdfr.endif
154178825Sdfr
155178825Sdfr.if ${MACHINE_ARCH} == "alpha"
156178825SdfrCRUNCH_ALIAS_bsdlabel= disklabel
157178825Sdfr.endif
158178825Sdfr
159178825Sdfr.if ${MACHINE_ARCH} == "amd64"
160178825SdfrCRUNCH_PROGS_sbin+= fdisk
161178825SdfrCRUNCH_ALIAS_bsdlabel= disklabel
162178825Sdfr.endif
163178825Sdfr
164178825SdfrCRUNCH_SRCDIR_atm= $(.CURDIR)/../../sbin/atm/atm
165178825SdfrCRUNCH_SRCDIR_atmconfig= $(.CURDIR)/../../sbin/atm/atmconfig
166178825SdfrCRUNCH_SRCDIR_fore_dnld= $(.CURDIR)/../../sbin/atm/fore_dnld
167178825SdfrCRUNCH_SRCDIR_ilmid= $(.CURDIR)/../../sbin/atm/ilmid
168178825SdfrCRUNCH_SRCDIR_rtquery= $(.CURDIR)/../../sbin/routed/rtquery
169178825SdfrCRUNCH_SRCDIR_ipf= $(.CURDIR)/../../sbin/ipf/ipf
170178825SdfrCRUNCH_ALIAS_reboot= fastboot halt fasthalt
171178825SdfrCRUNCH_ALIAS_restore= rrestore
172178825SdfrCRUNCH_ALIAS_dump= rdump
173178825SdfrCRUNCH_ALIAS_fsck_ffs= fsck_4.2bsd fsck_ufs
174178825SdfrCRUNCH_ALIAS_mount_std= mount_devfs mount_fdescfs mount_linprocfs mount_procfs
175178825Sdfr
176178825Sdfr# dhclient has historically been troublesome...
177178825SdfrCRUNCH_PROGS_sbin+= dhclient
178178825SdfrCRUNCH_BUILDOPTS_dhclient= -DRELEASE_CRUNCH -Dlint
179178825Sdfr
180178825Sdfr##################################################################
181178825Sdfr# Programs from stock /usr/bin
182178825Sdfr# 
183178825SdfrCRUNCH_SRCDIRS+= usr.bin
184178825SdfrCRUNCH_SRCDIRS+= gnu/usr.bin
185178825Sdfr
186178825SdfrCRUNCH_PROGS_gnu/usr.bin+= gzip
187178825SdfrCRUNCH_ALIAS_gzip= gunzip gzcat zcat
188178825Sdfr
189178825SdfrCRUNCH_PROGS_usr.bin+= bzip2
190178825SdfrCRUNCH_ALIAS_bzip2= bunzip2 bzcat
191178825SdfrCRUNCH_LIBS+= -lbz2
192178825Sdfr
193178825SdfrCRUNCH_PROGS_usr.bin+= tar
194178825SdfrCRUNCH_LIBS+= -larchive
195178825Sdfr
196178825SdfrCRUNCH_PROGS_usr.bin+= vi
197178825SdfrCRUNCH_ALIAS_vi= ex
198178825Sdfr
199178825SdfrCRUNCH_PROGS_usr.bin+= id
200178825SdfrCRUNCH_ALIAS_id= groups whoami
201178825Sdfr
202178825Sdfr##################################################################
203178825Sdfr# Programs from stock /usr/sbin
204178825Sdfr# 
205178825SdfrCRUNCH_SRCDIRS+= usr.sbin
206178825Sdfr
207178825SdfrCRUNCH_PROGS_usr.sbin+= chroot
208178825Sdfr
209178825Sdfr##################################################################
210178825Sdfr#  The following is pretty nearly a generic crunchgen-handling makefile
211178825Sdfr#
212178825Sdfr
213178825SdfrCONF=	$(PROG).conf
214178825SdfrOUTMK=	$(PROG).mk
215178825SdfrOUTC=   $(PROG).c
216178825SdfrOUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
217178825SdfrCRUNCHOBJS= ${.OBJDIR}
218178825Sdfr.if defined(MAKEOBJDIRPREFIX)
219178825SdfrCANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
220178825Sdfr.else
221178825SdfrCANONICALOBJDIR:= /usr/obj${.CURDIR}
222178825Sdfr.endif
223178825Sdfr
224178825SdfrNO_MAN=
225178825SdfrCLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
226178825Sdfr
227178825Sdfr# Program names and their aliases contribute hardlinks to 'rescue' executable,
228178825Sdfr# except for those that get suppressed.
229178825Sdfr.for D in $(CRUNCH_SRCDIRS)
230178825Sdfr.for P in $(CRUNCH_PROGS_$(D))
231178825Sdfr.ifdef CRUNCH_SRCDIR_${P}
232178825Sdfr$(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile
233178825Sdfr.else
234178825Sdfr$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
235178825Sdfr.endif
236178825Sdfr.ifndef CRUNCH_SUPPRESS_LINK_${P}
237178825SdfrLINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
238178825Sdfr.endif
239178825Sdfr.for A in $(CRUNCH_ALIAS_$(P))
240178825Sdfr.ifndef CRUNCH_SUPPRESS_LINK_${A}
241178825SdfrLINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
242178825Sdfr.endif
243178825Sdfr.endfor
244178825Sdfr.endfor
245178825Sdfr.endfor
246178825Sdfr
247178825Sdfrall: $(PROG)
248233294Sstasexe: $(PROG)
249178825Sdfr
250178825Sdfr$(CONF): Makefile
251178825Sdfr	echo \# Auto-generated, do not edit >$(.TARGET)
252178825Sdfr.ifdef CRUNCH_BUILDOPTS
253178825Sdfr	echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
254178825Sdfr.endif
255178825Sdfr.ifdef CRUNCH_LIBS
256178825Sdfr	echo libs $(CRUNCH_LIBS) >>$(.TARGET)
257178825Sdfr.endif
258233294Sstas.for D in $(CRUNCH_SRCDIRS)
259178825Sdfr.for P in $(CRUNCH_PROGS_$(D))
260178825Sdfr	echo progs $(P) >>$(.TARGET)
261178825Sdfr.ifdef CRUNCH_SRCDIR_${P}
262178825Sdfr	echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
263178825Sdfr.else
264178825Sdfr	echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
265178825Sdfr.endif
266178825Sdfr.ifdef CRUNCH_BUILDOPTS_${P}
267178825Sdfr	echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
268178825Sdfr	    $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
269178825Sdfr.else
270178825Sdfr	echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
271178825Sdfr.endif
272233294Sstas.for A in $(CRUNCH_ALIAS_$(P))
273178825Sdfr	echo ln $(P) $(A) >>$(.TARGET)
274178825Sdfr.endfor
275178825Sdfr.endfor
276178825Sdfr.endfor
277178825Sdfr
278178825Sdfr# XXX Make sure we don't pass -P to crunchgen(1).
279178825Sdfr.MAKEFLAGS:= ${.MAKEFLAGS:N-P}
280178825Sdfr.ORDER: $(OUTPUTS) objs
281178825Sdfr$(OUTPUTS): $(CONF)
282178825Sdfr	MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
283178825Sdfr	    -c $(OUTC) $(CONF)
284178825Sdfr
285233294Sstas$(PROG): $(OUTPUTS) objs
286178825Sdfr	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
287178825Sdfr
288178825Sdfrobjs: $(OUTMK)
289178825Sdfr	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
290178825Sdfr
291178825Sdfr# <sigh> Someone should replace the bin/csh and bin/sh build-tools with
292178825Sdfr# shell scripts so we can remove this nonsense.
293178825Sdfrbuild-tools:
294178825Sdfr.for _tool in bin/csh bin/sh 
295178825Sdfr	cd $(.CURDIR)/../../${_tool}; \
296233294Sstas	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
297178825Sdfr	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
298178825Sdfr.endfor
299178825Sdfr
300178825Sdfr# Use a separate build tree to hold files compiled for this crunchgen binary
301178825Sdfr# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
302178825Sdfr# get that to cooperate with bsd.prog.mk.  Besides, many of the standard
303178825Sdfr# targets should NOT be propagated into the components.
304178825Sdfrcleandepend cleandir obj objlink:
305178825Sdfr.for D in $(CRUNCH_SRCDIRS)
306178825Sdfr.for P in $(CRUNCH_PROGS_$(D))
307178825Sdfr.ifdef CRUNCH_SRCDIR_${P}
308178825Sdfr	cd ${CRUNCH_SRCDIR_$(P)} && \
309178825Sdfr	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
310178825Sdfr	    DIRPRFX=${DIRPRFX}${P}/ ${.TARGET}
311178825Sdfr.else
312178825Sdfr	cd $(.CURDIR)/../../${D}/${P} && \
313178825Sdfr	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
314178825Sdfr	    DIRPRFX=${DIRPRFX}${P}/ ${.TARGET}
315178825Sdfr.endif
316178825Sdfr.endfor
317178825Sdfr.endfor
318178825Sdfr
319178825Sdfrclean:
320178825Sdfr	rm -f ${CLEANFILES}
321178825Sdfr	if [ -e ${.OBJDIR}/$(OUTMK) ]; then				\
322233294Sstas		MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean;	\
323178825Sdfr	fi
324178825Sdfr.for D in $(CRUNCH_SRCDIRS)
325178825Sdfr.for P in $(CRUNCH_PROGS_$(D))
326178825Sdfr.ifdef CRUNCH_SRCDIR_${P}
327178825Sdfr	cd ${CRUNCH_SRCDIR_$(P)} && \
328178825Sdfr	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
329178825Sdfr	    DIRPRFX=${DIRPRFX}${P}/ ${.TARGET}
330178825Sdfr.else
331178825Sdfr	cd $(.CURDIR)/../../${D}/${P} && \
332178825Sdfr	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
333233294Sstas	    DIRPRFX=${DIRPRFX}${P}/ ${.TARGET}
334178825Sdfr.endif
335178825Sdfr.endfor
336178825Sdfr.endfor
337178825Sdfr
338178825Sdfr.include <bsd.prog.mk>
339178825Sdfr