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