1#	$NetBSD: Makefile,v 1.14 2009/05/03 17:33:29 tsutsui Exp $
2
3PROG=	xxboot
4NOMAN=	# defined
5SRCS=	start.S main.c readufs.c readufs_ffs.c readufs_lfs.c milli_tiny.S
6
7.PATH:	${.CURDIR}/../common
8
9CPPFLAGS+=	-mpa-risc-1-0 -I${.CURDIR}/../../../.. -I. -D_STANDALONE
10# configuration for readufs module
11CPPFLAGS+=	-DUSE_LFS -DUSE_FFS -DUSE_UFS1 -DUSE_UFS2
12# IODC can handle only 2GB, so this is enough
13CPPFLAGS+=	-D__daddr_t=int32_t
14# ANSI C feature prevents from being relocatable
15#CPPFLAGS+=	-traditional	# would be best
16CPPFLAGS+=	-Dconst=
17COPTS+=		-funsigned-char	-mdisable-fpregs
18
19.include <bsd.own.mk>
20
21LINKS=	${BINDIR}/${PROG} ${BINDIR}/sdboot
22
23BINDIR=		/usr/mdec
24STRIPFLAG=
25BINMODE=	444
26
27# standalone program
28LIBCRTBEGIN=
29LIBCRT0=
30LIBCRTEND=
31LIBC=
32
33S=		${.CURDIR}/../../../..
34
35${PROG}: iplsum ${OBJS}
36	${_MKTARGET_LINK}
37	${LD} -Ttext 0 -Tdata 0 -e '$$START$$' -N -o $@1 $(OBJS)
38	${LD} -Ttext 0x100 -Tdata 0x23456780 -e '$$START$$' -N -o $@2 $(OBJS)
39	${SIZE} $@1
40	${OBJCOPY} -O binary -j .data $@1 $@1.bin
41	${OBJCOPY} -O binary -j .data $@2 $@2.bin
42	cmp $@1.bin $@2.bin	# should be same
43	${OBJCOPY} -O binary -j .text $@1 $@2.bin
44	test ! -s $@2.bin	# text section must be empty
45	${_MKMSG} " iplsum " ${.TARGET}
46	./iplsum $@1.bin $@
47
48iplsum: iplsum.c
49	${_MKTARGET_LINK}
50	${HOST_CC} -o $@ ${.CURDIR}/iplsum.c
51
52CLEANFILES+=	${PROG}1 ${PROG}2 ${PROG}1.bin ${PROG}2.bin ${PROG}.bin iplsum
53CLEANFILES+=	${SRCS:M*.c:S/.c$/.o.S/}
54
55.include <bsd.prog.mk>
56.include <bsd.klinks.mk>
57
58# override default rules
59
60# Place code to data section.
61.S.o:
62	${_MKTARGET_COMPILE}
63	${TOOL_SED} -e 's/\.code/.data/' \
64	-e 's/\.bss/.section .bss,"aw",@nobits/' \
65	-e 's/\.allow$$/.level	1.0/' -e 's/\.allow/.level/' \
66	 ${.IMPSRC} | ${AS} -o ${.TARGET}
67
68# Place code to data section, and make sure all address calculations
69# are relative to $global$.
70.c.o:
71	${_MKTARGET_COMPILE}
72	${CC} ${CFLAGS} ${CPPFLAGS} -o $@.S -S ${.IMPSRC}
73	grep -i 'ldil' $@.S | egrep -v "ldil L'-?[0-9]*," > /dev/null 2>&1; \
74		if [ $$? = 0 ]; then \
75			echo 'found non-relocatable code' >&2 && exit 1; \
76		fi
77	${TOOL_SED} -e 's/\.text/.data/' $@.S | ${AS} -o ${.TARGET}
78