Makefile revision 1.40
1#	$OpenBSD: Makefile,v 1.40 1998/09/07 00:47:11 niklas Exp $
2
3#
4# For more information on building in tricky environments, please see
5# the list of possible environment variables described in
6# /usr/share/mk/bsd.README.
7# 
8# Building recommendations:
9# 
10# 1) If at all possible, put this source tree in /usr/src.  If /usr/src
11# must be a symbolic link, setenv BSDSRCDIR to point to the real location.
12#
13# 2) It is also recommended that you compile with objects outside the
14# source tree. To do this, ensure /usr/obj exists or points to some
15# area of disk of sufficient size.  Then do "cd /usr/src; make obj".
16# This will make a symbolic link called "obj" in each directory, as
17# well as populate the /usr/obj properly with directories for the
18# objects.
19#
20# 3) If you are reasonably sure that things will compile OK, use the
21# "make build" target supplied here. Good luck.
22#
23# 4) If you want to setup a cross-build environment, there is a "cross-tools"
24# target available which upon completion of "make TARGET=<target> cross-tools" 
25# (where <target> is one of the names in the /sys/arch directory) will produce
26# a set of compilation tools along with the includes in the /usr/cross/<target>
27# directory.
28#
29
30.include <bsd.own.mk>	# for NOMAN, if it's there.
31
32SUBDIR+= lib include bin libexec sbin usr.bin usr.sbin share games
33SUBDIR+= gnu
34
35SUBDIR+= sys lkm
36
37.if (${KERBEROS} == "yes")
38SUBDIR+= kerberosIV
39.endif
40
41.if   make(clean) || make(cleandir) || make(obj)
42SUBDIR+= distrib
43.endif
44
45.if exists(regress)
46.ifmake !(install)
47SUBDIR+= regress
48.endif
49
50regression-tests:
51	@echo Running regression tests...
52	@(cd ${.CURDIR}/regress && ${MAKE} regress)
53.endif
54
55includes:
56	(cd ${.CURDIR}/include; ${MAKE} includes)	
57
58beforeinstall:
59.ifndef DESTDIR
60	(cd ${.CURDIR}/etc && ${MAKE} DESTDIR=/ distrib-dirs)
61.else
62	(cd ${.CURDIR}/etc && ${MAKE} distrib-dirs)
63.endif
64	(cd ${.CURDIR}/include; ${MAKE} includes)
65
66afterinstall:
67.ifndef NOMAN
68	(cd ${.CURDIR}/share/man && ${MAKE} makedb)
69.endif
70
71build:
72.ifdef GLOBAL_AUTOCONF_CACHE
73	rm -f ${GLOBAL_AUTOCONF_CACHE}
74.endif
75	(cd ${.CURDIR}/share/mk && ${SUDO} ${MAKE} install)
76	(cd ${.CURDIR}/include; ${SUDO} ${MAKE} includes)
77	${MAKE} cleandir
78	(cd ${.CURDIR}/lib && ${MAKE} depend && ${MAKE} && \
79	    ${SUDO} ${MAKE} install)
80	(cd ${.CURDIR}/gnu/lib && ${MAKE} depend && ${MAKE} && \
81	    ${SUDO} ${MAKE} install)
82.if (${MACHINE_ARCH} == "mips")
83	ldconfig
84.endif
85.if (${KERBEROS} == "yes")
86	(cd ${.CURDIR}/kerberosIV && ${MAKE} build)
87.endif
88.if (${MACHINE_ARCH} == "mips")
89	ldconfig
90.endif
91	${MAKE} depend && ${MAKE} && ${SUDO} ${MAKE} install
92
93.if !defined(TARGET)
94cross-tools:
95	echo "TARGET must be set"; exit 1
96.else
97cross-tools:	cross-helpers cross-includes cross-binutils cross-gcc cross-lib
98
99CROSSDIR=	${DESTDIR}/usr/cross/${TARGET}
100CROSSENV=	AR=${CROSSDIR}/usr/bin/ar AS=${CROSSDIR}/usr/bin/as \
101		CC=${CROSSDIR}/usr/bin/cc CPP=${CROSSDIR}/usr/bin/cpp \
102		LD=${CROSSDIR}/usr/bin/ld NM=${CROSSDIR}/usr/bin/nm \
103		RANLIB=${CROSSDIR}/usr/bin/ranlib \
104		SIZE=${CROSSDIR}/usr/bin/size STRIP=${CROSSDIR}/usr/bin/strip \
105		HOSTCC=cc
106
107cross-helpers:
108	-mkdir -p ${CROSSDIR}/usr/include
109	echo _MACHINE_ARCH | \
110	    cat ${.CURDIR}/sys/arch/${TARGET}/include/param.h - | \
111	    ${CPP} -E -I${.CURDIR}/sys/arch | \
112	    sed -n '$$p' >${CROSSDIR}/TARGET_ARCH
113	eval `grep '^osr=' sys/conf/newvers.sh`; \
114	   sed "s/\$$/-unknown-openbsd$$osr/" ${CROSSDIR}/TARGET_ARCH > \
115	   ${CROSSDIR}/TARGET_CANON
116
117cross-includes:
118	-mkdir -p ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/include
119	${MAKE} MACHINE=${TARGET} MACHINE_ARCH=`cat ${CROSSDIR}/TARGET_ARCH` \
120	    DESTDIR=${CROSSDIR} includes
121	ln -sf ${CROSSDIR}/usr/include \
122	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/include
123
124.if ${TARGET} == "powerpc" || ${TARGET} == "alpha" || ${TARGET} == "arc" || \
125    ${TARGET} == "pmax" || ${TARGET} == "wgrisc" || ${TARGET} == "hppa"
126cross-binutils: cross-binutils-new
127.else
128cross-binutils: cross-binutils-old
129.endif
130
131cross-binutils-new:
132	-mkdir -p ${CROSSDIR}/usr/obj
133	-mkdir -p ${CROSSDIR}/usr/bin
134	export BSDSRCDIR=`pwd`; \
135	    (cd ${.CURDIR}/gnu/usr.bin/binutils; \
136	    BSDOBJDIR=${CROSSDIR}/usr/obj \
137	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
138	    ${MAKE} -f Makefile.bsd-wrapper obj); \
139	    (cd ${CROSSDIR}/usr/obj/gnu/usr.bin/binutils; \
140	    /bin/sh ${BSDSRCDIR}/gnu/usr.bin/binutils/configure \
141	    --prefix ${CROSSDIR}/usr \
142	    --target `cat ${CROSSDIR}/TARGET_CANON` && \
143	    ${MAKE} CFLAGS=${CFLAGS} && ${MAKE} DESTDIR=${CROSSDIR} install)
144	${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m 755 \
145	    ${.CURDIR}/usr.bin/lorder/lorder.sh.gnm \
146	    ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-lorder
147	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-as \
148	    ${CROSSDIR}/usr/bin/as
149	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-ar \
150	    ${CROSSDIR}/usr/bin/ar
151	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-ld \
152	    ${CROSSDIR}/usr/bin/ld
153	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-strip \
154	    ${CROSSDIR}/usr/bin/strip
155	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-size \
156	    ${CROSSDIR}/usr/bin/size
157	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-ranlib \
158	    ${CROSSDIR}/usr/bin/ranlib
159	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-nm \
160	    ${CROSSDIR}/usr/bin/nm
161	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-strings \
162	    ${CROSSDIR}/usr/bin/strings
163	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-lorder \
164	    ${CROSSDIR}/usr/bin/lorder
165	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-objcopy \
166	    ${CROSSDIR}/usr/bin/objcopy
167	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-objdump \
168	    ${CROSSDIR}/usr/bin/objdump
169	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-gdb \
170	    ${CROSSDIR}/usr/bin/gdb
171
172cross-binutils-old: cross-gas cross-ar cross-ld cross-strip cross-size \
173	cross-ranlib cross-nm
174
175cross-gas:
176	-mkdir -p ${CROSSDIR}/usr/obj
177	-mkdir -p ${CROSSDIR}/usr/bin
178	-mkdir -p ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/bin
179	(cd ${.CURDIR}/gnu/usr.bin/gas; \
180	    BSDOBJDIR=${CROSSDIR}/usr/obj \
181	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
182	    ${MAKE} obj; \
183	    TARGET_MACHINE_ARCH=${TARGET} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
184	    ${MAKE}; \
185	    TARGET_MACHINE_ARCH=${TARGET} \
186	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
187	    ${MAKE} NOMAN= install)
188	ln -sf ${CROSSDIR}/usr/bin/as \
189	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/bin/as
190
191cross-ld:
192	-mkdir -p ${CROSSDIR}/usr/obj
193	-mkdir -p ${CROSSDIR}/usr/bin
194	(cd ${.CURDIR}/gnu/usr.bin/ld; \
195	    BSDOBJDIR=${CROSSDIR}/usr/obj \
196	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
197	    ${MAKE} obj; \
198	    TARGET_MACHINE_ARCH=${TARGET} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
199	    ${MAKE} NOMAN=; \
200	    TARGET_MACHINE_ARCH=${TARGET} \
201	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
202	    ${MAKE} NOMAN= install)
203	ln -sf ${CROSSDIR}/usr/bin/ld \
204	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/bin/ld
205
206cross-ar:
207	-mkdir -p ${CROSSDIR}/usr/obj
208	-mkdir -p ${CROSSDIR}/usr/bin
209	(cd ${.CURDIR}/usr.bin/ar; \
210	    BSDOBJDIR=${CROSSDIR}/usr/obj \
211	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
212	    ${MAKE} obj; \
213	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} ${MAKE} NOMAN=; \
214	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
215	    ${MAKE} NOMAN= install)
216	ln -sf ${CROSSDIR}/usr/bin/ar \
217	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/bin/ar
218
219cross-ranlib:
220	-mkdir -p ${CROSSDIR}/usr/obj
221	-mkdir -p ${CROSSDIR}/usr/bin
222	(cd ${.CURDIR}/usr.bin/ranlib; \
223	    BSDOBJDIR=${CROSSDIR}/usr/obj \
224	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
225	    ${MAKE} obj; \
226	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} ${MAKE} NOMAN=; \
227	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
228	    ${MAKE} NOMAN= install)
229	ln -sf ${CROSSDIR}/usr/bin/ranlib \
230	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/bin/ranlib
231
232cross-strip:
233	-mkdir -p ${CROSSDIR}/usr/obj
234	-mkdir -p ${CROSSDIR}/usr/bin
235	(cd ${.CURDIR}/usr.bin/strip; \
236	    BSDOBJDIR=${CROSSDIR}/usr/obj \
237	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
238	    ${MAKE} obj; \
239	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
240	    ${MAKE} TARGET_MACHINE_ARCH=${TARGET} NOMAN=; \
241	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
242	    ${MAKE} TARGET_MACHINE_ARCH=${TARGET} NOMAN= install)
243	ln -sf ${CROSSDIR}/usr/bin/strip \
244	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/bin/strip
245
246cross-size:
247	-mkdir -p ${CROSSDIR}/usr/obj
248	-mkdir -p ${CROSSDIR}/usr/bin
249	(cd ${.CURDIR}/usr.bin/size; \
250	    BSDOBJDIR=${CROSSDIR}/usr/obj \
251	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
252	    ${MAKE} obj; \
253	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
254	    ${MAKE} TARGET_MACHINE_ARCH=${TARGET} NOMAN=; \
255	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
256	    ${MAKE} NOMAN= install)
257	ln -sf ${CROSSDIR}/usr/bin/size \
258	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/bin/size
259
260cross-nm:
261	-mkdir -p ${CROSSDIR}/usr/obj
262	-mkdir -p ${CROSSDIR}/usr/bin
263	(cd ${.CURDIR}/usr.bin/nm; \
264	    BSDOBJDIR=${CROSSDIR}/usr/obj \
265	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
266	    ${MAKE} obj; \
267	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
268	    ${MAKE} TARGET_MACHINE_ARCH=${TARGET} NOMAN=; \
269	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
270	    ${MAKE} NOMAN= install)
271	ln -sf ${CROSSDIR}/usr/bin/nm \
272	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/bin/nm
273
274cross-gcc:
275	-mkdir -p ${CROSSDIR}/usr/obj
276	-mkdir -p ${CROSSDIR}/usr/bin
277	cd ${.CURDIR}/gnu/usr.bin/gcc; \
278	    BSDOBJDIR=${CROSSDIR}/usr/obj BSDSRCDIR=${.CURDIR} \
279	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
280	    ${MAKE} -f Makefile.bsd-wrapper obj
281	(cd ${CROSSDIR}/usr/obj/gnu/usr.bin/gcc; \
282	    /bin/sh ${.CURDIR}/gnu/usr.bin/gcc/configure \
283	    --prefix ${CROSSDIR}/usr \
284	    --target `cat ${CROSSDIR}/TARGET_CANON` && \
285	    ${MAKE} BISON=yacc LANGUAGES=c LDFLAGS=${LDSTATIC} \
286	    build_infodir=. \
287	    GCC_FOR_TARGET="./xgcc -B./ -I${CROSSDIR}/usr/include" && \
288	    ${MAKE} BISON=yacc LANGUAGES=c LDFLAGS=${LDSTATIC} \
289	    GCC_FOR_TARGET="./xgcc -B./ -I${CROSSDIR}/usr/include" \
290	    build_infodir=. INSTALL_MAN= INSTALL_HEADERS_DIR= install)
291	ln -sf ${CROSSDIR}/usr/bin/`cat ${CROSSDIR}/TARGET_CANON`-gcc \
292	    ${CROSSDIR}/usr/bin/cc
293	CPP=`${CROSSDIR}/usr/bin/cc -print-libgcc-file-name | \
294	    sed 's/libgcc\.a/cpp/'`; \
295	    sed -e 's#/usr/libexec/cpp#'$$CPP'#' \
296	    -e 's#/usr/include#${CROSSDIR}/usr/include#' \
297	    ${.CURDIR}/usr.bin/cpp/cpp.sh > ${CROSSDIR}/usr/bin/cpp
298	chmod ${BINMODE} ${CROSSDIR}/usr/bin/cpp
299	chown ${BINOWN}.${BINGRP} ${CROSSDIR}/usr/bin/cpp
300
301cross-lib:
302	-mkdir -p ${CROSSDIR}/usr/obj
303	-mkdir -p ${CROSSDIR}/usr/lib
304	-mkdir -p ${CROSSDIR}/var/db
305	MACHINE=${TARGET} MACHINE_ARCH=`cat ${CROSSDIR}/TARGET_ARCH`; \
306	export MACHINE MACHINE_ARCH; \
307	(cd ${.CURDIR}/lib; \
308	    BSDOBJDIR=${CROSSDIR}/usr/obj \
309	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
310	    ${MAKE} obj; \
311	    for lib in csu libc; do \
312		(cd $$lib; \
313		    ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
314		    ${MAKE} NOMAN=; \
315		    ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
316		    DESTDIR=${CROSSDIR} ${MAKE} NOMAN= install); \
317	    done; \
318	    ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} ${MAKE} NOMAN=; \
319	    ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
320	    DESTDIR=${CROSSDIR} SKIPDIR=libocurses/PSD.doc \
321	    ${MAKE} NOMAN= install)
322	ln -sf ${CROSSDIR}/usr/lib \
323	    ${CROSSDIR}/usr/`cat ${CROSSDIR}/TARGET_CANON`/lib
324
325.endif
326
327.include <bsd.subdir.mk>
328