Makefile revision 120519
1#$FreeBSD: head/rescue/rescue/Makefile 120519 2003-09-27 17:27:02Z markm $
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 echo 	\
68	 ed expr getfacl hostname kenv kill ln ls mkdir mv pax ps pwd 	\
69	 realpath rm rmdir setfacl sh stty sync test
70CRUNCH_LIBS+= -lcrypt -ledit -lkvm -ll -lm -ltermcap -lutil
71.if !defined(NOCRYPT) && !defined(NO_OPENSSL)
72CRUNCH_LIBS+= -lcrypto
73.endif
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###################################################################
96# Programs from standard /sbin
97#
98# WARNING: Changing this list may require adjusting
99# /usr/include/paths.h as well!  You were warned!
100#
101# Note that mdmfs have their own private 'pathnames.h'
102# headers in addition to the standard 'paths.h' header.
103#
104CRUNCH_SRCDIRS+= sbin
105CRUNCH_PROGS_sbin= atacontrol badsect bsdlabel		\
106	camcontrol ccdconfig clri devfs dmesg dump			\
107	dumpfs dumpon fore_dnld fsck fsck_ffs fsck_msdosfs fsdb		\
108	fsirand gbde ifconfig init 				\
109	kldconfig kldload kldstat kldunload ldconfig 			\
110	md5 mdconfig mdmfs mknod mount mount_cd9660 mount_ext2fs	\
111	mount_msdosfs mount_nfs mount_ntfs mount_nullfs			\
112	mount_std mount_udf mount_umapfs mount_unionfs newfs		\
113	newfs_msdos nos-tun ping raidctl reboot			\
114	restore rcorder route routed rtquery rtsol savecore 		\
115	slattach spppcontrol startslip swapon sysctl tunefs umount 
116
117.if !defined(NOATM)
118CRUNCH_PROGS_sbin+= atm atmconfig ilmid
119CRUNCH_LIBS+= -latm
120.endif
121
122.if !defined(NOINET6)
123CRUNCH_PROGS_sbin+= ping6
124.endif
125
126.if !defined(NO_VINUM)
127CRUNCH_PROGS_sbin+= vinum
128.endif
129
130.if !defined(NO_IPFILTER)
131CRUNCH_PROGS_sbin+= ipf ipfs ipfstat ipmon ipnat
132.endif
133
134# crunchgen does not like C++ programs; this should be fixed someday
135# CRUNCH_PROGS+= devd
136
137CRUNCH_LIBS+= -lalias -lbsdxml -lcam -lcurses -ldevstat -lipsec -lipx \
138	-lgeom -lkiconv -lmd -lreadline -lsbuf -lufs -lz 
139
140.if ${MACHINE_ARCH} == "i386"
141CRUNCH_PROGS_sbin+= cxconfig fdisk
142CRUNCH_ALIAS_bsdlabel= disklabel
143#CRUNCH_PROGS+= mount_nwfs mount_smbfs
144#CRUNCH_LIBS+= -lncp -lsmb
145.endif
146
147.if ${MACHINE} == "pc98"
148CRUNCH_SRCDIR_fdisk= $(.CURDIR)/../../sbin/fdisk_pc98
149.endif
150
151.if ${MACHINE_ARCH} == "ia64"
152CRUNCH_PROGS_sbin+= mca gpt fdisk
153.endif
154
155.if ${MACHINE_ARCH} == "sparc64"
156CRUNCH_PROGS_sbin+= sunlabel
157.endif
158
159.if ${MACHINE_ARCH} == "alpha"
160CRUNCH_ALIAS_bsdlabel= disklabel
161.endif
162
163.if ${MACHINE_ARCH} == "amd64"
164CRUNCH_PROGS_sbin+= fdisk
165CRUNCH_ALIAS_bsdlabel= disklabel
166.endif
167
168CRUNCH_SRCDIR_atm= $(.CURDIR)/../../sbin/atm/atm
169CRUNCH_SRCDIR_atmconfig= $(.CURDIR)/../../sbin/atm/atmconfig
170CRUNCH_SRCDIR_fore_dnld= $(.CURDIR)/../../sbin/atm/fore_dnld
171CRUNCH_SRCDIR_ilmid= $(.CURDIR)/../../sbin/atm/ilmid
172CRUNCH_SRCDIR_rtquery= $(.CURDIR)/../../sbin/routed/rtquery
173CRUNCH_ALIAS_reboot= fastboot halt fasthalt
174CRUNCH_ALIAS_restore= rrestore
175CRUNCH_ALIAS_dump= rdump
176CRUNCH_ALIAS_fsck_ffs= fsck_4.2bsd fsck_ufs
177CRUNCH_ALIAS_mount_std= mount_devfs mount_fdescfs mount_linprocfs mount_procfs
178
179# dhclient has historically been troublesome...
180CRUNCH_PROGS_sbin+= dhclient
181CRUNCH_BUILDOPTS_dhclient= -DRELEASE_CRUNCH -Dlint
182
183##################################################################
184# Programs from stock /usr/bin
185# 
186CRUNCH_SRCDIRS+= usr.bin
187CRUNCH_SRCDIRS+= gnu/usr.bin
188
189CRUNCH_PROGS_gnu/usr.bin+= gzip
190CRUNCH_ALIAS_gzip= gunzip gzcat zcat
191
192CRUNCH_PROGS_usr.bin+= bzip2
193CRUNCH_ALIAS_bzip2= bunzip2 bzcat
194CRUNCH_LIBS+= -lbz2
195
196CRUNCH_PROGS_gnu/usr.bin+= tar
197CRUNCH_PROGS_usr.bin+= vi
198CRUNCH_ALIAS_vi= ex
199
200##################################################################
201#  The following is pretty nearly a generic crunchgen-handling makefile
202#
203
204CONF=	$(PROG).conf
205OUTMK=	$(PROG).mk
206OUTC=   $(PROG).c
207OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
208CRUNCHOBJS= ${.OBJDIR}
209.if defined(MAKEOBJDIRPREFIX)
210CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
211.else
212CANONICALOBJDIR:= /usr/obj${.CURDIR}
213.endif
214
215NOMAN=	true
216CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
217
218# Program names and their aliases contribute hardlinks to 'rescue' executable,
219# except for those that get suppressed.
220.for D in $(CRUNCH_SRCDIRS)
221.for P in $(CRUNCH_PROGS_$(D))
222.ifndef CRUNCH_SUPPRESS_LINK_${P}
223LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
224.endif
225.for A in $(CRUNCH_ALIAS_$(P))
226.ifndef CRUNCH_SUPPRESS_LINK_${A}
227LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
228.endif
229.endfor
230.endfor
231.endfor
232
233all: $(PROG)
234exe: $(PROG)
235
236$(CONF): Makefile
237	echo \# Auto-generated, do not edit >$(.TARGET)
238.for D in $(CRUNCH_SRCDIRS)
239	echo srcdirs $(.CURDIR)/../../$(D) >>$(.TARGET)
240.endfor
241.ifdef CRUNCH_BUILDOPTS
242	echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
243.endif
244.ifdef CRUNCH_LIBS
245	echo libs $(CRUNCH_LIBS) >>$(.TARGET)
246.endif
247.for D in $(CRUNCH_SRCDIRS)
248.for P in $(CRUNCH_PROGS_$(D))
249	echo progs $(P) >>$(.TARGET)
250.ifdef CRUNCH_SRCDIR_${P}
251	echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
252.endif
253.ifdef CRUNCH_BUILDOPTS_${P}
254	echo special $(P) buildopts $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
255.endif
256.for A in $(CRUNCH_ALIAS_$(P))
257	echo ln $(P) $(A) >>$(.TARGET)
258.endfor
259.endfor
260.endfor
261
262
263.ORDER: $(OUTPUTS) objs
264$(OUTPUTS): $(CONF)
265	MAKEFLAGS= MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -q -m $(OUTMK) \
266	    -c $(OUTC) $(CONF)
267
268$(PROG): $(OUTPUTS) objs
269	MAKEOBJDIRPREFIX=${CRUNCHOBJS} make -f $(OUTMK) 
270
271objs: $(OUTMK)
272	MAKEOBJDIRPREFIX=${CRUNCHOBJS} make -f $(OUTMK) objs
273
274# <sigh> Someone should replace the bin/csh and bin/sh build-tools with
275# shell scripts so we can remove this nonsense.
276build-tools:
277.for _tool in bin/csh bin/sh 
278	cd $(.CURDIR)/../../${_tool}; \
279	MAKEOBJDIRPREFIX=${CRUNCHOBJS} make DIRPRFX=rescue/${_tool} build-tools
280.endfor
281
282# Use a separate build tree to hold files compiled for this crunchgen binary
283# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
284# get that to cooperate with bsd.prog.mk.  Besides, many of the standard
285# targets should NOT be propagated into the components.
286cleandepend cleandir obj objlink:
287.for D in $(CRUNCH_SRCDIRS)
288.for P in $(CRUNCH_PROGS_$(D))
289.ifdef CRUNCH_SRCDIR_${P}
290	cd ${CRUNCH_SRCDIR_$(P)} && \
291	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} make ${.TARGET}
292.else
293	cd $(.CURDIR)/../../${D}/${P} && \
294	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} make ${.TARGET}
295.endif
296.endfor
297.endfor
298
299clean:
300	rm -f ${CLEANFILES}
301	if [ -e ${.OBJDIR}/$(OUTMK) ]; then				\
302		MAKEOBJDIRPREFIX=${CRUNCHOBJS} make -f $(OUTMK) clean;	\
303	fi
304.for D in $(CRUNCH_SRCDIRS)
305.for P in $(CRUNCH_PROGS_$(D))
306.ifdef CRUNCH_SRCDIR_${P}
307	cd ${CRUNCH_SRCDIR_$(P)} && \
308	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} make ${.TARGET}
309.else
310	cd $(.CURDIR)/../../${D}/${P} && \
311	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} make ${.TARGET}
312.endif
313.endfor
314.endfor
315
316.include <bsd.prog.mk>
317