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