Makefile revision 117693
1#$FreeBSD: head/rescue/rescue/Makefile 117693 2003-07-17 16:44:06Z obrien $
2#	@(#)Makefile	8.1 (Berkeley) 6/2/93
3
4PROG=	rescue
5BINDIR?=/rescue
6
7# Shell scripts need #! line to be edited from /bin/sh to /rescue/sh
8SCRIPTS= nextboot_FIXED
9SCRIPTSNAME_nextboot_FIXED= nextboot.sh
10nextboot_FIXED: ../../sbin/reboot/nextboot.sh
11	sed '1s/\/bin\//\/rescue\//' ${.ALLSRC} > ${.TARGET}
12CLEANFILES+= nextboot_FIXED
13
14SCRIPTS+= dhclient_FIXED
15SCRIPTSNAME_dhclient_FIXED= dhclient-script
16dhclient_FIXED: ../../contrib/isc-dhcp/client/scripts/freebsd
17	sed '1s/\/bin\//\/rescue\//' ${.ALLSRC} > ${.TARGET}
18CLEANFILES+= dhclient_FIXED
19
20#################################################################
21#
22# General notes:
23#
24# A number of Make variables are used to generate the crunchgen config file.
25#
26#  CRUNCH_SRCDIRS: lists directories to search for included programs
27#  CRUNCH_PROGS:  lists programs to be included
28#  CRUNCH_LIBS:  libraries to link with
29#  CRUNCH_BUILDOPTS: generic build options to be added to every program
30#
31# Special options can be specified for individual programs
32#  CRUNCH_SRCDIR_$(P): base source directory for program $(P)
33#  CRUNCH_BUILDOPTS_$(P): additional build options for $(P)
34#  CRUNCH_ALIAS_$(P): additional names to be used for $(P)
35#
36# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
37# will be used to generate a hard link to the resulting binary.
38# Specific links can be suppressed by setting
39# CRUNCH_SUPPRESS_LINK_$(NAME) to 1.
40#
41
42# Define Makefile variable RESCUE
43CRUNCH_BUILDOPTS+= -DRESCUE
44# Define compile-time RESCUE symbol when compiling components
45CRUNCH_BUILDOPTS+= CRUNCH_CFLAGS=-DRESCUE
46
47# An experiment that failed: try overriding bsd.lib.mk and bsd.prog.mk
48# rather than incorporating rescue-specific logic into standard files.
49#MAKEFLAGS= -m ${.CURDIR} ${.MAKEFLAGS}
50
51# Hackery:  'librescue' exists merely as a tool for appropriately
52# recompiling specific library entries.  We _know_ they're needed, and
53# regular archive searching creates ugly library ordering problems.
54# Easiest fix: tell the linker to include them into the executable
55# first, so they are guaranteed to override the regular lib entries.
56# Note that if 'librescue' hasn't been compiled, we'll just get the
57# regular lib entries from libc and friends.
58CRUNCH_LIBS+= ${.OBJDIR}/../librescue/*.o
59
60###################################################################
61# Programs from stock /bin
62#
63# WARNING: Changing this list may require adjusting
64# /usr/include/paths.h as well!  You were warned!
65#
66CRUNCH_SRCDIRS+= bin
67CRUNCH_PROGS_bin= cat chflags chio chmod cp date dd df domainname echo 	\
68	 ed expr getfacl hostname kenv kill ln ls mkdir mv pax ps pwd 	\
69	 realpath rm rmdir setfacl sh sleep stty sync test
70CRUNCH_LIBS+= -lcrypt -lcrypto -ledit -lkvm -ll -lm -ltermcap -lutil
71
72# Additional options for specific programs
73CRUNCH_ALIAS_test= [
74CRUNCH_ALIAS_sh= -sh
75# The -sh alias shouldn't appear in /rescue as a hard link
76CRUNCH_SUPPRESS_LINK_-sh= 1
77CRUNCH_ALIAS_ln= link
78CRUNCH_ALIAS_rm= unlink
79CRUNCH_ALIAS_ed= red
80
81.if !defined(NO_RCMNDS)
82CRUNCH_PROGS_bin+= rcp
83.endif
84
85.if !defined(NO_TCSH)
86CRUNCH_PROGS_bin+= csh
87CRUNCH_ALIAS_csh= -csh tcsh -tcsh
88CRUNCH_SUPPRESS_LINK_-csh= 1
89CRUNCH_SUPPRESS_LINK_-tcsh= 1
90.endif
91
92###################################################################
93# Programs from standard /sbin
94#
95# WARNING: Changing this list may require adjusting
96# /usr/include/paths.h as well!  You were warned!
97#
98# Note that mdmfs and shutdown have their own private 'pathnames.h'
99# headers in addition to the standard 'paths.h' header.
100#
101CRUNCH_SRCDIRS+= sbin
102CRUNCH_PROGS_sbin= atm adjkerntz atacontrol badsect bsdlabel camcontrol \
103	ccdconfig clri comcontrol conscontrol devfs dmesg dump		\
104	dumpfs dumpon fore_dnld fsck fsck_ffs fsck_msdosfs fsdb		\
105	fsirand gbde growfs ifconfig ilmid init ip6fw 			\
106	ipfw kldconfig kldload kldstat kldunload ldconfig 		\
107	md5 mdconfig mdmfs mknod mount mount_cd9660 mount_ext2fs	\
108	mount_msdosfs mount_nfs mount_ntfs mount_nullfs			\
109	mount_std mount_udf mount_umapfs mount_unionfs natd newfs	\
110	newfs_msdos nfsiod nos-tun ping ping6 quotacheck raidctl reboot	\
111	restore rcorder route routed rtquery rtsol savecore shutdown	\
112	slattach spppcontrol startslip swapon sysctl tunefs umount vinum
113
114.if !defined(NO_IPFILTER)
115CRUNCH_PROGS_sbin+= ipf ipfs ipfstat ipmon ipnat
116.endif
117
118# crunchgen does not like C++ programs; this should be fixed someday
119# CRUNCH_PROGS+= devd
120
121CRUNCH_LIBS+= -lalias -latm -lbsdxml -lcam -lcurses -ldevstat -lipsec -lipx \
122	-lgeom -lmd -lreadline -lsbuf -lufs -lz 
123
124.if ${MACHINE_ARCH} == "i386"
125CRUNCH_PROGS_sbin+= cxconfig fdisk
126CRUNCH_ALIAS_bsdlabel= disklabel
127#CRUNCH_PROGS+= mount_nwfs mount_smbfs
128#CRUNCH_LIBS+= -lncp -lsmb
129.endif
130
131.if ${MACHINE} == "pc98"
132CRUNCH_SRCDIR_fdisk= $(.CURDIR)/../../sbin/fdisk_pc98
133.endif
134
135.if ${MACHINE_ARCH} == "ia64"
136CRUNCH_PROGS_sbin+= mca gpt fdisk
137.endif
138
139.if ${MACHINE_ARCH} == "sparc64"
140CRUNCH_PROGS_sbin+= sunlabel
141.endif
142
143.if ${MACHINE_ARCH} == "alpha"
144CRUNCH_ALIAS_bsdlabel= disklabel
145.endif
146
147.if ${MACHINE_ARCH} == "amd64"
148CRUNCH_PROGS_sbin+= fdisk
149CRUNCH_ALIAS_bsdlabel= disklabel
150.endif
151
152CRUNCH_SRCDIR_atm= $(.CURDIR)/../../sbin/atm/atm
153CRUNCH_SRCDIR_fore_dnld= $(.CURDIR)/../../sbin/atm/fore_dnld
154CRUNCH_SRCDIR_ilmid= $(.CURDIR)/../../sbin/atm/ilmid
155CRUNCH_SRCDIR_rtquery= $(.CURDIR)/../../sbin/routed/rtquery
156CRUNCH_ALIAS_reboot= fastboot halt fasthalt
157CRUNCH_ALIAS_restore= rrestore
158CRUNCH_ALIAS_dump= rdump
159CRUNCH_ALIAS_fsck_ffs= fsck_4.2bsd fsck_ufs
160CRUNCH_ALIAS_mount_std= mount_devfs mount_fdescfs mount_linprocfs mount_procfs
161
162# dhclient has historically been troublesome...
163CRUNCH_PROGS_sbin+= dhclient
164CRUNCH_BUILDOPTS_dhclient= -DRELEASE_CRUNCH -Dlint
165
166##################################################################
167# Programs from stock /usr/bin
168# 
169CRUNCH_SRCDIRS+= usr.bin
170CRUNCH_SRCDIRS+= gnu/usr.bin
171
172CRUNCH_PROGS_usr.bin+= wall
173
174CRUNCH_PROGS_gnu/usr.bin+= gzip
175CRUNCH_ALIAS_gzip= gunzip gzcat zcat
176
177CRUNCH_PROGS_usr.bin+= bzip2
178CRUNCH_ALIAS_bzip2= bunzip2 bzcat
179CRUNCH_LIBS+= -lbz2
180
181CRUNCH_PROGS_gnu/usr.bin+= tar
182CRUNCH_PROGS_usr.bin+= vi
183CRUNCH_ALIAS_vi= ex
184
185##################################################################
186#  The following is pretty nearly a generic crunchgen-handling makefile
187#
188
189CONF=	$(PROG).conf
190OUTMK=	$(PROG).mk
191OUTC=   $(PROG).c
192OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
193CRUNCHOBJS= ${.OBJDIR}
194.if defined(MAKEOBJDIRPREFIX)
195CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
196.else
197CANONICALOBJDIR:= /usr/obj${.CURDIR}
198.endif
199
200NOMAN=	true
201CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
202
203# Program names and their aliases contribute hardlinks to 'rescue' executable,
204# except for those that get suppressed.
205.for D in $(CRUNCH_SRCDIRS)
206.for P in $(CRUNCH_PROGS_$(D))
207.ifndef CRUNCH_SUPPRESS_LINK_${P}
208LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
209.endif
210.for A in $(CRUNCH_ALIAS_$(P))
211.ifndef CRUNCH_SUPPRESS_LINK_${A}
212LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
213.endif
214.endfor
215.endfor
216.endfor
217
218all: $(PROG)
219exe: $(PROG)
220
221$(CONF): Makefile
222	echo \# Auto-generated, do not edit >$(.TARGET)
223.for D in $(CRUNCH_SRCDIRS)
224	echo srcdirs $(.CURDIR)/../../$(D) >>$(.TARGET)
225.endfor
226.ifdef CRUNCH_BUILDOPTS
227	echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
228.endif
229.ifdef CRUNCH_LIBS
230	echo libs $(CRUNCH_LIBS) >>$(.TARGET)
231.endif
232.for D in $(CRUNCH_SRCDIRS)
233.for P in $(CRUNCH_PROGS_$(D))
234	echo progs $(P) >>$(.TARGET)
235.ifdef CRUNCH_SRCDIR_${P}
236	echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
237.endif
238.ifdef CRUNCH_BUILDOPTS_${P}
239	echo special $(P) buildopts $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
240.endif
241.for A in $(CRUNCH_ALIAS_$(P))
242	echo ln $(P) $(A) >>$(.TARGET)
243.endfor
244.endfor
245.endfor
246
247
248$(OUTPUTS): $(CONF)
249	MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -q -m $(OUTMK) -c $(OUTC) \
250	    $(CONF)
251
252$(PROG): $(OUTPUTS)
253	MAKEOBJDIRPREFIX=${CRUNCHOBJS} make -f $(OUTMK) 
254
255objs:
256	MAKEOBJDIRPREFIX=${CRUNCHOBJS} make -f $(OUTMK) objs
257
258# <sigh> Someone should replace the bin/csh and bin/sh build-tools with
259# shell scripts so we can remove this nonsense.
260build-tools:
261.for _tool in bin/csh bin/sh 
262	cd $(.CURDIR)/../../${_tool}; \
263	MAKEOBJDIRPREFIX=${CRUNCHOBJS} make DIRPRFX=rescue/${_tool} build-tools
264.endfor
265
266# Use a separate build tree to hold files compiled for this crunchgen binary
267# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
268# get that to cooperate with bsd.prog.mk.  Besides, many of the standard
269# targets should NOT be propagated into the components.
270cleandepend cleandir obj objlink:
271.for D in $(CRUNCH_SRCDIRS)
272.for P in $(CRUNCH_PROGS_$(D))
273.ifdef CRUNCH_SRCDIR_${P}
274	cd ${CRUNCH_SRCDIR_$(P)} && \
275	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} make ${.TARGET}
276.else
277	cd $(.CURDIR)/../../${D}/${P} && \
278	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} make ${.TARGET}
279.endif
280.endfor
281.endfor
282
283clean:
284	rm -f ${CLEANFILES}
285	if [ -e ${.OBJDIR}/$(OUTMK) ]; then				\
286		MAKEOBJDIRPREFIX=${CRUNCHOBJS} make -f $(OUTMK) clean;	\
287	fi
288.for D in $(CRUNCH_SRCDIRS)
289.for P in $(CRUNCH_PROGS_$(D))
290.ifdef CRUNCH_SRCDIR_${P}
291	cd ${CRUNCH_SRCDIR_$(P)} && \
292	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} make ${.TARGET}
293.else
294	cd $(.CURDIR)/../../${D}/${P} && \
295	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} make ${.TARGET}
296.endif
297.endfor
298.endfor
299
300.include <bsd.prog.mk>
301