summaryrefslogtreecommitdiff
path: root/Makefile.cross
blob: 95b3982a2d89f3f6e84b27994757590f30b5536e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# $OpenBSD: Makefile.cross,v 1.17 2006/05/09 21:17:11 miod Exp $

cross-tools:	cross-includes cross-binutils cross-gcc cross-lib
cross-distrib:	cross-tools cross-bin cross-etc-root-var

# Have to compute TARGET_ARCH directly in the Makefile, for .if tests involving
# this variable to work.
.if	(${TARGET} == "cats" || ${TARGET} == "zaurus")
TARGET_ARCH=	arm
.elif	(${TARGET} == "hp300" || ${TARGET} == "mac68k" || \
	 ${TARGET} == "mvme68k")
TARGET_ARCH=	m68k
.elif	(${TARGET} == "aviion" || ${TARGET} == "luna88k" || \
	 ${TARGET} == "mvme88k")
TARGET_ARCH=	m88k
.elif	(${TARGET} == "sgi")
TARGET_ARCH=	mips64
.elif	(${TARGET} == "macppc" || ${TARGET} == "mvmeppc")
TARGET_ARCH=	powerpc
.else
TARGET_ARCH=	${TARGET}
.endif

CROSSCPPFLAGS?=	-nostdinc -I${CROSSDIR}/usr/include
CROSSLDFLAGS?=	-nostdlib -L${CROSSDIR}/usr/lib -static
CROSSCFLAGS?=	${CROSSCPPFLAGS}
CROSSCXXFLAGS?=	${CROSSCPPFLAGS}
LDSTATIC?=	-static

CROSSDIR=	${DESTDIR}/usr/cross/${TARGET}
CROSSENV=	AR=${CROSSDIR}/usr/bin/ar AS=${CROSSDIR}/usr/bin/as \
		CC=${CROSSDIR}/usr/bin/cc CPP=${CROSSDIR}/usr/bin/cpp \
		CXX=${CROSSDIR}/usr/bin/c++ \
		LD=${CROSSDIR}/usr/bin/ld \
		LORDER=/usr/bin/lorder RANLIB=${CROSSDIR}/usr/bin/ranlib \
		STRIP=${CROSSDIR}/usr/bin/strip \
		HOSTCC=\"${CC}\" HOSTCXX=\"${CXX}\" NOMAN= DESTDIR=${CROSSDIR} \
		HOSTCFLAGS=\"${CFLAGS}\" HOSTCXXFLAGS=\"${CXXFLAGS}\" \
		HOSTLDFLAGS=\"${LDFLAGS}\" \
		CFLAGS=\"${CROSSCFLAGS}\" CPPFLAGS=\"${CROSSCPPFLAGS}\" \
		CXXFLAGS=\"${CROSSCXXFLAGS}\" \
		LDFLAGS=\"${CROSSLDFLAGS}\"
CROSSPATH=	${PATH}:${CROSSDIR}/usr/bin
CROSSLANGS?=	c c++

TARGET_CANON=`cat ${CROSSDIR}/TARGET_CANON`

CROSSDIRS=	${CROSSDIR}/.dirs_done
CROSSOBJ=	${CROSSDIR}/usr/obj/.obj_done
CROSSINCLUDES=	${CROSSDIR}/usr/include/.includes_done
CROSSBINUTILS=	${CROSSDIR}/usr/bin/.binutils_done
CROSSGCC=	${CROSSDIR}/usr/bin/.gcc_done
NO_CROSS=	isakmpd tn3270 less sudo openssl libkeynote libssl \
		keynote sectok ssh

# no libcrypto.... these won't build
NO_CROSS+=	dc login_krb5 login_krb5-or-pwd passwd ppp tcpdump telnet
# need host setup for ydr
NO_CROSS+=afs
# explicit cross-compile
NO_CROSS+=bind

cross-dirs:	${CROSSDIRS}
cross-obj:	${CROSSOBJ}
cross-includes:	${CROSSINCLUDES}
cross-binutils:	${CROSSBINUTILS}
cross-gcc:	${CROSSGCC}

cross-env:
	@echo ${CROSSENV} MACHINE=${TARGET} \
	    MACHINE_ARCH=`cat ${CROSSDIR}/TARGET_ARCH`

${CROSSDIRS}:
	@-mkdir -p ${CROSSDIR}
	@echo ${TARGET_ARCH} > ${CROSSDIR}/TARGET_ARCH
	@echo TARGET_ARCH is `cat ${CROSSDIR}/TARGET_ARCH`
	@eval `grep '^osr=' sys/conf/newvers.sh`; \
	   sed "s/\$$/-unknown-openbsd$$osr/" ${CROSSDIR}/TARGET_ARCH > \
	   ${CROSSDIR}/TARGET_CANON
	@-mkdir -p ${CROSSDIR}
	@-mkdir -p ${CROSSDIR}/usr/${TARGET_CANON}
	@ln -sf ${CROSSDIR}/usr/include \
	    ${CROSSDIR}/usr/${TARGET_CANON}/include
	@ln -sf ${CROSSDIR}/usr/lib \
	    ${CROSSDIR}/usr/${TARGET_CANON}/lib
	@-mkdir -p ${CROSSDIR}/usr/${TARGET_CANON}/bin
	@(cd ${.CURDIR}/etc && DESTDIR=${CROSSDIR} ${MAKE} distrib-dirs)
	@touch ${CROSSDIRS}

${CROSSOBJ}:	${CROSSDIRS}
	@-mkdir -p ${CROSSDIR}/usr/obj
	@(cd ${.CURDIR} && \
	    BSDOBJDIR=${CROSSDIR}/usr/obj \
	    MACHINE=${TARGET} \
	    MACHINE_ARCH=${TARGET_ARCH} \
	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} obj)
	@touch ${CROSSOBJ}

${CROSSINCLUDES}:	${CROSSOBJ}
	@-mkdir -p ${CROSSDIR}/usr/include
	@(cd ${.CURDIR}/include && \
	    MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    TARGET_ARCH=${TARGET_ARCH} \
	    ${MAKE} prereq && \
	    MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    TARGET_ARCH=${TARGET_ARCH} \
	    ${MAKE} DESTDIR=${CROSSDIR} includes)
	@touch ${CROSSINCLUDES}

.if (${TARGET_ARCH} == "m68k" || ${TARGET_ARCH} == "m88k" || \
     ${TARGET_ARCH} == "vax")
BINUTILS=	ar as ld nm ranlib objcopy objdump strings strip
NEW_BINUTILS?=	No
.else
BINUTILS=	ar as gasp ld nm objcopy objdump ranlib readelf size \
		strings strip
NEW_BINUTILS?=	Yes
.endif

${CROSSBINUTILS}:	${CROSSINCLUDES}
	(cd ${.CURDIR}/gnu/usr.bin/binutils; \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    USING_NEW_BINUTILS=${NEW_BINUTILS} \
	    TARGET_ARCH=${TARGET_ARCH} \
	    ${MAKE} -f Makefile.bsd-wrapper depend && \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    USING_NEW_BINUTILS=${NEW_BINUTILS} \
	    TARGET_ARCH=${TARGET_ARCH} \
	    ${MAKE} -f Makefile.bsd-wrapper all && \
	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    USING_NEW_BINUTILS=${NEW_BINUTILS} \
	    ${MAKE} -f Makefile.bsd-wrapper install)
.if ${NEW_BINUTILS:L} != "yes"
	(cd ${.CURDIR}/gnu/usr.bin/gas; \
	    TARGET_MACHINE_ARCH=${TARGET_ARCH} \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} ${MAKE} depend all; \
	    TARGET_MACHINE_ARCH=${TARGET_ARCH} \
	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} NOMAN= install)
	ln -sf ${CROSSDIR}/usr/bin/as \
	    ${CROSSDIR}/usr/${TARGET_CANON}/bin/as
	(cd ${.CURDIR}/gnu/usr.bin/ld; \
	    TARGET_MACHINE_ARCH=${TARGET_ARCH} \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} NOPIC= NOMAN= depend all; \
	    TARGET_MACHINE_ARCH=${TARGET_ARCH} \
	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} NOPIC= NOMAN= install)
	ln -sf ${CROSSDIR}/usr/bin/ld \
	    ${CROSSDIR}/usr/${TARGET_CANON}/bin/ld
	(cd ${.CURDIR}/usr.bin/ar; \
	    ELF_TOOLCHAIN=no \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} ${MAKE} NOMAN= depend all; \
	    ELF_TOOLCHAIN=no \
	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} NOMAN= install)
	ln -sf ${CROSSDIR}/usr/bin/ar \
	    ${CROSSDIR}/usr/${TARGET_CANON}/bin/ar
	(cd ${.CURDIR}/usr.bin/ranlib; \
	    ELF_TOOLCHAIN=no \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} ${MAKE} NOMAN= depend all; \
	    ELF_TOOLCHAIN=no \
	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} NOMAN= install)
	ln -sf ${CROSSDIR}/usr/bin/ranlib \
	    ${CROSSDIR}/usr/${TARGET_CANON}/bin/ranlib
	(cd ${.CURDIR}/usr.bin/strip; \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} TARGET_MACHINE_ARCH=${TARGET_ARCH} \
	    NOMAN= depend all; \
	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} TARGET_MACHINE_ARCH=${TARGET_ARCH} \
	    NOMAN= install)
	ln -sf ${CROSSDIR}/usr/bin/strip \
	    ${CROSSDIR}/usr/${TARGET_CANON}/bin/strip
.endif
	@for cmd in ${BINUTILS}; do \
	 if [ ! -e ${CROSSDIR}/usr/bin/$$cmd -a \
	 -e ${CROSSDIR}/usr/bin/${TARGET_CANON}-$$cmd ]; then \
	    ln -sf ${TARGET_CANON}-$$cmd ${CROSSDIR}/usr/bin/$$cmd ;\
	 elif [ -e ${CROSSDIR}/usr/bin/$$cmd -a \
	 ! -e ${CROSSDIR}/usr/bin/${TARGET_CANON}-$$cmd ]; then \
	    ln -sf $$cmd ${CROSSDIR}/usr/bin/${TARGET_CANON}-$$cmd; \
	 fi ;\
	 if [ -e ${CROSSDIR}/usr/bin/$$cmd -a \
	 ! -e ${CROSSDIR}/usr/${TARGET_CANON}/bin/$$cmd ]; then \
	    ln -sf ${CROSSDIR}/usr/bin/$$cmd \
	        ${CROSSDIR}/usr/${TARGET_CANON}/bin/$$cmd; \
	 fi ;\
	done
	@touch ${CROSSBINUTILS}

# bsd.own.mk can't do it for us
.if ${TARGET_ARCH} == "alpha" || \
    ${TARGET_ARCH} == "m68k" || ${TARGET_ARCH} == "m88k" || \
    ${TARGET_ARCH} == "sparc" || ${TARGET_ARCH} == "vax"
TARGET_USE_GCC3=No
.else
TARGET_USE_GCC3=Yes
.endif

${CROSSGCC}:		${CROSSBINUTILS}
.if ${TARGET_USE_GCC3:L} == "yes"
	(cd ${.CURDIR}/gnu/usr.bin/gcc; \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    TARGET_ARCH=${TARGET_ARCH} CROSSDIR=${CROSSDIR} \
	    ${MAKE} -f Makefile.bsd-wrapper depend && \
	    MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    TARGET_ARCH=${TARGET_ARCH} CROSSDIR=${CROSSDIR} \
	    ${MAKE} -f Makefile.bsd-wrapper all && \
	    DESTDIR=${CROSSDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    ${MAKE} -f Makefile.bsd-wrapper install)
	ln -sf ${TARGET_CANON}-g++ ${CROSSDIR}/usr/bin/c++
	ln -sf ${CROSSDIR}/usr/libexec/cpp \
	    ${CROSSDIR}/usr/bin/cpp
.else
	(cd ${CROSSDIR}/usr/obj/gnu/egcs/gcc; \
	    /bin/sh ${.CURDIR}/gnu/egcs/gcc/configure \
	    --with-gnu-as --with-gnu-ld --prefix ${CROSSDIR}/usr \
	    --target ${TARGET_CANON} \
	    --enable-languages="c,c++" --enable-cpp --disable-nls \
	    --with-gxx-include-dir=${CROSSDIR}/usr/include/g++ && \
	    PATH=${CROSSPATH} ${MAKE} BISON=yacc LANGUAGES="${CROSSLANGS}" \
	    CFLAGS="${CFLAGS} -I${.CURDIR}/gnu/lib/libiberty/include" \
	    LIBIBERTY_INCLUDES=${.CURDIR}/gnu/lib/libiberty/include \
	    DEMANGLER_PROG= DEMANGLE_H= LDFLAGS="${LDSTATIC}" build_infodir=. \
	    GCC_FOR_TARGET="./xgcc -B./ -I${CROSSDIR}/usr/include" && \
	    ${MAKE} BISON=yacc LANGUAGES="${CROSSLANGS}" LDFLAGS="${LDSTATIC}" \
	    GCC_FOR_TARGET="./xgcc -B./ -I${CROSSDIR}/usr/include" \
	    CFLAGS="${CFLAGS} -I${.CURDIR}/gnu/lib/libiberty/include" \
	    LIBIBERTY_INCLUDES=${.CURDIR}/gnu/lib/libiberty/include \
	    build_infodir=. INSTALL_MAN= INSTALL_HEADERS_DIR= install)
	ln -sf ${TARGET_CANON}-gcc ${CROSSDIR}/usr/bin/cc
	ln -sf ${TARGET_CANON}-g++ ${CROSSDIR}/usr/bin/c++
	${INSTALL} -c -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
	    ${CROSSDIR}/usr/obj/gnu/egcs/gcc/cpp \
	    ${CROSSDIR}/usr/libexec/cpp
	sed -e 's#/usr/libexec/cpp#${CROSSDIR}/usr/libexec/cpp#' \
	    -e 's#/usr/include#${CROSSDIR}/usr/include#' \
	    -e 's/@dollaropt@/-$$/' \
	    ${.CURDIR}/usr.bin/cpp/cpp.sh > ${CROSSDIR}/usr/bin/cpp
	chmod ${BINMODE} ${CROSSDIR}/usr/bin/cpp
	chown ${BINOWN}:${BINGRP} ${CROSSDIR}/usr/bin/cpp
.endif
	@touch ${CROSSGCC}

# XXX MAKEOBJDIR maybe should be obj.${TARGET} here, revisit later
cross-lib:	${CROSSGCC}
	MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}; \
	export MACHINE MACHINE_ARCH; \
	(cd ${.CURDIR}/lib; \
	    for lib in csu libc; do \
	    (cd $$lib; \
	        eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
		    ${MAKE} WANTLINT=no depend all install); \
	    done; \
	    eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	        SKIPDIR=\"${NO_CROSS} libocurses/PSD.doc\" \
	        ${MAKE} WANTLINT=no depend all install)

cross-bin:	${CROSSOBJ}
	MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH}; \
	export MACHINE MACHINE_ARCH; \
	for i in libexec bin sbin usr.bin usr.sbin; do \
	(cd ${.CURDIR}/$$i; \
	    eval ${CROSSENV} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	        SKIPDIR=\"${BINUTILS} ${NO_CROSS}\" \
	        ${MAKE} depend all install); \
	done

cross-etc-root-var:	${CROSSOBJ}
	(cd ${.CURDIR}/etc && \
	    MACHINE=${TARGET} MACHINE_ARCH=${TARGET_ARCH} \
	    DESTDIR=${CROSSDIR} ${MAKE} distribution-etc-root-var)

cross-depend:
	@(cd ${.CURDIR} && \
	    BSDOBJDIR=${CROSSDIR}/usr/obj \
	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    SKIPDIR="${NO_CROSS}" \
	    ${MAKE} depend)

cross-clean:
	@(cd ${.CURDIR} && \
	    BSDOBJDIR=${CROSSDIR}/usr/obj \
	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    SKIPDIR="${NO_CROSS}" \
	    ${MAKE} clean)

cross-cleandir:
	@(cd ${.CURDIR} && \
	    BSDOBJDIR=${CROSSDIR}/usr/obj \
	    BSDSRCDIR=${.CURDIR} MAKEOBJDIR=obj.${MACHINE}.${TARGET} \
	    SKIPDIR="${NO_CROSS}" \
	    ${MAKE} cleandir)