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