xref: /netbsd/sys/arch/i386/stand/Makefile.booters (revision 6550d01e)
1#	$NetBSD: Makefile.booters,v 1.82 2011/01/22 19:19:18 joerg Exp $
2
3.include <bsd.own.mk>
4
5STRIPFLAG=
6BINMODE=444
7
8LIBCRT0=	# nothing
9LIBCRTBEGIN=	# nothing
10LIBCRTEND=	# nothing
11LIBC=		# nothing
12
13# Make sure we override any optimization options specified by the
14# user.
15.if defined(HAVE_GCC)
16.if ${MACHINE_ARCH} == "x86_64"
17CPUFLAGS= -m32
18.else
19.if ${HAVE_GCC} == 3
20CPUFLAGS=  -mcpu=i386
21.else
22CPUFLAGS=  -march=i386 -mtune=i386
23.endif
24.endif
25.endif
26COPTS=	-Os -ffreestanding
27
28I386_STAND_DIR?= $S/arch/i386/stand
29
30.PATH: ${I386_STAND_DIR}/lib
31
32ROMSTART= start_rom.o
33GENPROMDIR= ${I386_STAND_DIR}/genprom
34GENPROMOBJDIR!= cd ${GENPROMDIR} && ${PRINTOBJDIR}
35GENPROM= ${GENPROMOBJDIR}/genprom
36
37.PATH: ${I386_STAND_DIR}/lib/crt/dos
38DOSSTART= start_dos.o doscommain.o
39
40.PATH: ${I386_STAND_DIR}/lib/crt/pxe
41PXESTART= start_pxe.o
42
43CPPFLAGS+= -nostdinc -I${.OBJDIR} -I$S -I${I386_STAND_DIR}/lib -I$S/lib/libsa
44CPPFLAGS+= -D_STANDALONE
45LDFLAGS+=  -nostdlib
46
47# XXX
48.if ${MACHINE_ARCH} == "x86_64"
49CPPFLAGS+=-m32
50LDFLAGS+=-Wl,-m,elf_i386
51LIBKERN_ARCH=i386
52KERNMISCMAKEFLAGS="LIBKERN_ARCH=i386"
53.endif
54
55CLEANFILES+= ${STARTFILE} vers.c ${BASE}.list
56SRCS+=	vers.c
57
58CLEANFILES+= machine x86
59
60.if !make(obj) && !make(clean) && !make(cleandir)
61.BEGIN:
62	-rm -f machine && ln -s $S/arch/i386/include machine
63	-rm -f x86 && ln -s $S/arch/x86/include x86
64.ifdef LIBOBJ
65	-rm -f lib && ln -s ${LIBOBJ}/lib lib
66	mkdir -p ${LIBOBJ}/lib
67.endif
68.endif
69
70### find out what to use for libkern
71KERN_AS=	library
72.include "${S}/lib/libkern/Makefile.inc"
73LIBKERN=	${KERNLIB}
74
75### find out what to use for libz
76Z_AS=		library
77.include "${S}/lib/libz/Makefile.inc"
78LIBZ=		${ZLIB}
79
80### find out what to use for libsa
81SA_AS=		library
82SAMISCMAKEFLAGS+="SA_USE_LOADFILE=yes"
83.include "${S}/lib/libsa/Makefile.inc"
84LIBSA=		${SALIB}
85
86### find out what to use for libi386
87I386DIR= ${I386_STAND_DIR}/lib
88.include "${I386DIR}/Makefile.inc"
89LIBI386=		${I386LIB}
90
91cleandir distclean: .WAIT cleanlibdir
92
93cleanlibdir:
94	-rm -rf lib
95
96LDFLAGS+=-Wl,-M -Wl,-e,start 	# -N does not work properly.
97
98LIBLIST=${LIBI386} ${LIBSA} ${LIBZ} ${LIBSA} ${LIBKERN} ${LIBI386} ${LIBSA}
99
100vers.c: ${VERSIONFILE} ${SOURCES} ${S}/conf/newvers_stand.sh
101	${HOST_SH} ${S}/conf/newvers_stand.sh ${VERSIONFILE} x86 ${NEWVERSWHAT}
102
103CLEANFILES+= ${BASE}.sym
104${BASE}.sym: ${STARTFILE} ${OBJS} ${LIBSA} ${LIBZ} ${LIBKERN} ${LIBI386}
105	${_MKTARGET_LINK}
106	${CC} -o ${BASE}.sym ${LDFLAGS} -Wl,-Ttext,${RELOC} \
107	    ${STARTFILE} ${OBJS} ${LIBLIST} >${BASE}.list
108
109CLEANFILES+= ${BASE}.rom ${BASE}.rom.tmp
110${BASE}.rom: ${STARTFILE} ${OBJS} ${LIBSA} ${LIBZ} ${LIBKERN} ${LIBI386}
111	${_MKTARGET_LINK}
112	${CC} -o ${BASE}.sym ${LDFLAGS} -Wl,-Ttext,${RELOC} \
113	    ${STARTFILE} ${OBJS} ${LIBLIST} >${BASE}.list
114	${OBJCOPY} -O binary ${BASE}.sym ${BASE}.rom.tmp
115	${GENPROM} ${ROM_SIZE} < ${BASE}.rom.tmp > ${BASE}.rom || \
116	    rm -f ${BASE}.rom
117	rm -f ${BASE}.rom.tmp
118
119CLEANFILES+= ${BASE}.com
120${BASE}.com: ${STARTFILE} ${OBJS} ${LIBSA} ${LIBZ} ${LIBKERN} ${LIBI386}
121	${_MKTARGET_LINK}
122	${CC} -o ${BASE}.sym ${LDFLAGS} -Wl,-Ttext,${RELOC} \
123	    ${STARTFILE} ${OBJS} ${LIBLIST} >${BASE}.list
124	${OBJCOPY} -O binary ${BASE}.sym ${BASE}.com
125
126CLEANFILES+= ${BASE}.bin
127${BASE}.bin: ${STARTFILE} ${OBJS} ${LIBSA} ${LIBZ} ${LIBKERN} ${LIBI386}
128	${_MKTARGET_LINK}
129	${CC} -o ${BASE}.sym ${LDFLAGS} -Wl,-Ttext,${RELOC} \
130	    ${STARTFILE} ${OBJS} ${LIBLIST} > ${BASE}.list
131	${OBJCOPY} -O binary ${BASE}.sym ${BASE}.bin
132
133.include <bsd.prog.mk>
134