Initial import from FreeBSD RELENG_4:
[dragonfly.git] / sys / boot / i386 / boot2 / Makefile
1 # $FreeBSD: src/sys/boot/i386/boot2/Makefile,v 1.16.2.5 2002/08/07 16:31:53 ru Exp $
2
3 PROG=           boot2
4 NOMAN=
5 STRIP=
6 BINDIR?=        /boot
7 BINMODE=        444
8 CLEANFILES+=    boot1 boot1.out boot1.o \
9                 boot2.ldr boot2.bin boot2.ld boot2.out boot2.o boot2.h \
10                 sio.o
11
12 NM?=            nm
13
14 # A value of 0x80 enables LBA support.
15 B1FLAGS=        0x80
16
17 BOOT_COMCONSOLE_PORT?= 0x3f8
18 BOOT_COMCONSOLE_SPEED?= 9600
19 B2SIOFMT?=      0x3
20
21 .if exists(${.OBJDIR}/../btx)
22 BTX=    ${.OBJDIR}/../btx
23 .else
24 BTX=    ${.CURDIR}/../btx
25 .endif
26
27 ORG1=   0x7c00
28 ORG2=   0x1000
29
30 CFLAGS= -elf -I${.CURDIR}/../btx/lib -I. \
31         -Os -fno-builtin -fforce-addr -fdata-sections \
32         -malign-functions=0 -malign-jumps=0 -malign-loops=0 -mrtd \
33         -mpreferred-stack-boundary=2 \
34         -Wall -Waggregate-return -Wbad-function-cast -Wcast-align \
35         -Wmissing-declarations -Wmissing-prototypes -Wnested-externs \
36         -Wpointer-arith -Wshadow -Wstrict-prototypes -Wwrite-strings
37
38 LDFLAGS=-nostdlib -static -N
39
40 all: boot1 boot2
41
42 boot1: boot1.out
43         objcopy -S -O binary boot1.out ${.TARGET}
44
45 boot1.out: boot1.o
46         ${LD} ${LDFLAGS} -e start -Ttext ${ORG1} -o ${.TARGET} boot1.o
47
48 boot1.o: boot1.s
49         ${AS} ${AFLAGS} --defsym FLAGS=${B1FLAGS} ${.IMPSRC} -o ${.TARGET}
50
51 boot2.h: boot1.out
52         ${NM} -t d ${.ALLSRC} | awk '/([0-9])+ T xread/ \
53                 { x = $$1 - ORG1; printf("#define XREADORG 0x7%x\n", x) }' \
54                 ORG1=`printf "%d" ${ORG1}` > boot2.h
55
56 boot2: boot2.ldr boot2.bin ${BTX}/btx/btx
57         btxld -v -E ${ORG2} -f bin -b ${BTX}/btx/btx -l boot2.ldr \
58                 -o boot2.ld -P 1 boot2.bin
59         @ls -l boot2.ld | awk '{ x = 7680 - $$5; \
60                 print x " bytes available"; if (x < 0) exit 1 }'
61         dd if=boot2.ld of=${.TARGET} obs=7680 conv=osync 2>/dev/null
62
63 boot2.ldr:
64         dd if=/dev/zero of=${.TARGET} bs=512 count=1 2>/dev/null
65
66 boot2.bin: boot2.out
67         objcopy -S -O binary boot2.out ${.TARGET}
68
69 boot2.out: boot2.o sio.o
70         ${LD} ${LDFLAGS} -Ttext ${ORG2} -o ${.TARGET} \
71                 ${BTX}/lib/crt0.o boot2.o sio.o
72
73 boot2.o: boot2.h
74
75 sio.o: sio.s
76         ${AS} ${AFLAGS} --defsym SIOPRT=${BOOT_COMCONSOLE_PORT} \
77                 --defsym SIOFMT=${B2SIOFMT} \
78                 --defsym SIOSPD=${BOOT_COMCONSOLE_SPEED} \
79                 ${.IMPSRC} -o ${.TARGET}
80
81 install:
82         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
83                 boot1 ${DESTDIR}${BINDIR}/boot1
84         ${INSTALL} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
85                 boot2 ${DESTDIR}${BINDIR}/boot2
86
87 .include <bsd.prog.mk>