Don't pass assembler flags to the compiler.
[dragonfly.git] / sys / boot / pc32 / boot2 / Makefile
... / ...
CommitLineData
1# $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.47 2003/06/26 03:51:57 peter Exp $
2# $DragonFly: src/sys/boot/pc32/boot2/Makefile,v 1.18 2008/09/13 11:45:45 corecode Exp $
3
4PROG= boot2
5NOMAN=
6STRIP=
7BINDIR?= /boot
8BINMODE= 444
9CLEANFILES= boot boot1 boot1.out boot1.o \
10 boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
11 boot2.s sio.o
12
13NM?= nm
14NXCFLAGS=
15NXLDFLAGS=
16
17.PATH: ${.CURDIR}/..
18
19# A value of 0x80 enables LBA support.
20B1FLAGS= 0x80
21
22BOOT_COMCONSOLE_PORT?= 0x3f8
23BOOT_COMCONSOLE_SPEED?= 9600
24B2SIOFMT?= 0x3
25
26.if exists(${.OBJDIR}/../btx)
27BTX= ${.OBJDIR}/../btx
28.else
29BTX= ${.CURDIR}/../btx
30.endif
31
32# These origins are taken from bootasm.h.
33#
34REL1 = `${.OBJDIR}/bootasmdef.nx BOOT1_ORIGIN`
35REL1D = `${.OBJDIR}/bootasmdef.nx -d BOOT1_ORIGIN`
36ORG1 = `${.OBJDIR}/bootasmdef.nx MEM_BIOS_LADDR`
37ORG1D = `${.OBJDIR}/bootasmdef.nx -d MEM_BIOS_LADDR`
38
39# WARNING! The ORG2 calculation is the origin of boot2.bin relative to
40# the start of the BTX *USER* address space, not the start of physical
41# memory.
42#
43ORG2= `${.OBJDIR}/bootasmdef.nx BOOT2_VORIGIN`
44
45# Decide Level of UFS support. UFS1_AND_UFS2 doesn't fit.
46
47# BOOT2_UFS?= UFS2_ONLY
48#BOOT2_UFS?= UFS1_AND_UFS2
49BOOT2_UFS?= UFS1_ONLY
50#BOOT2_UFS?= HAMMERFS
51
52# gcc3.x
53# -fno-guess-branch-probability
54# -mno-align-long-strings
55CFLAGS= -elf -ffreestanding -Os -fno-builtin \
56 -fomit-frame-pointer \
57 -std=c99 \
58 -DBOOT2 \
59 -D${BOOT2_UFS} \
60 -I${.CURDIR}/../../common \
61 -I${.CURDIR}/../../../../lib/libstand \
62 -I${.CURDIR}/../btx/lib -I. \
63 -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
64 -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
65 -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings \
66 -D__BOOT2_HACK
67
68# Unfortunately, unit-at-a-time creates issues as yet
69# not tracked down, in boot2, so we have to turn it off. Note that
70# the problem has been narrowed down to the 'boot2' code. The /boot/loader
71# doesn't seem to have a problem.
72#
73CFLAGS+= -fno-unit-at-a-time
74
75# Disable propolice on gcc that supports it
76.if ${CCVER} == "gcc34"
77CFLAGS+= -fno-stack-protector
78.endif
79
80NSECT?= 16
81CFLAGS+= -DNSECT=${NSECT}
82
83LDFLAGS=-nostdlib -static -N --gc-sections
84
85all: boot1 boot2 boot
86
87boot: boot1 boot2
88 cat boot1 boot2 > boot
89
90boot1: boot1.out
91 objcopy -S -O binary boot1.out ${.TARGET}
92
93boot1.out: boot1.o bootasmdef.nx
94 ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
95
96boot1.o: boot1.S
97 ${CC} ${CFLAGS} -DFLAGS=${B1FLAGS} \
98 ${.IMPSRC} -o ${.TARGET} -c
99
100boot2.o: boot2.c ${.CURDIR}/../../common/ufsread.c ${.CURDIR}/../../../../lib/libstand/hammerread.c
101 ${CC} ${CFLAGS} -S -o boot2.s.tmp ${.IMPSRC}
102 sed -e '/align/d' -e '/nop/d' < boot2.s.tmp > boot2.s
103 rm -f boot2.s.tmp
104 ${AS} ${AFLAGS} -o boot2.o boot2.s
105
106boot2.h: boot1.out bootasmdef.nx
107 @echo "NOTE: boot2 using xread from boot1 at ${REL1}"
108 ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
109 { x = $$1 - ORG1; \
110 printf("#define XREADORG %#x\n", REL1 + x) }' \
111 ORG1=${ORG1D} REL1=${REL1D} > boot2.h
112
113boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
114 btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
115 -o boot2.ld -P 1 boot2.bin
116 stat boot2.ld | awk '{ x = (${NSECT} - 1) * 512 - $$8; \
117 print x " bytes available"; if (x < 0) exit 1 }'
118 dd if=boot2.ld of=${.TARGET} obs=$$(( (${NSECT} - 1) * 512)) conv=osync 2>/dev/null
119
120boot2.ldr:
121 dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
122
123boot2.bin: boot2.out
124 objcopy -S -O binary boot2.out ${.TARGET}
125
126boot2.out: boot2.o sio.o
127 ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
128 ${BTX}/lib/crt0.o ${.ALLSRC}
129
130boot2.o: boot2.h
131
132sio.o: sio.S
133 ${CC} -DSIOPRT=${BOOT_COMCONSOLE_PORT} -DSIOFMT=${B2SIOFMT} \
134 -DSIOSPD=${BOOT_COMCONSOLE_SPEED} \
135 ${.IMPSRC} -o ${.TARGET} -c
136
137install:
138 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
139 boot ${DESTDIR}${BINDIR}/boot
140 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
141 boot1 ${DESTDIR}${BINDIR}/boot1
142 ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
143 boot2 ${DESTDIR}${BINDIR}/boot2
144
145.include <bsd.prog.mk>
146
147.if defined(REALLY_AMD64)
148boot2.o: machine
149
150beforedepend ${OBJS}: machine
151
152machine:
153 ${LN} -sf ${.CURDIR}/../../../i386/include machine
154
155CLEANFILES+= machine
156.endif
157
158CLEANFILES+= bootasmdef.nx
159