xref: /openbsd/lib/csu/Makefile (revision 4cfece93)
1#	$OpenBSD: Makefile,v 1.35 2020/06/27 18:35:07 kettenis Exp $
2
3OBJS=		crt0.o gcrt0.o
4OBJS+=		crtbegin.o crtend.o
5OBJS+=		crtbeginS.o crtendS.o
6OBJS+=		rcrt0.o
7SRCS=		crt0.c crtbegin.c crtbeginS.c crtend.c crtendS.c
8
9CFLAGS+=	-I${.CURDIR}/${MACHINE_CPU}
10CFLAGS+=	-I${.CURDIR}/../../libexec/ld.so
11CFLAGS+=	-I${.CURDIR}/../../libexec/ld.so/${MACHINE_CPU}
12
13# XXX "use -fno-omit-frame-pointer; the reason is almost crazy; pr#287"
14.if ${MACHINE_ARCH} == "amd64" || ${MACHINE_ARCH} == "i386"
15CFLAGS+=	-fno-omit-frame-pointer
16.endif
17
18.ifdef NOPIC
19PICFLAG=
20.elif ${MACHINE_ARCH} == "powerpc" || ${MACHINE_ARCH} == "sparc64"
21# The objects for shared libraries need to work for all possible
22# libraries, so force big PIC where it matters.
23# Arguably m88k should do this too, but maybe there aren't any
24# libraries big enough to need it there?
25PICFLAG=	-fPIC
26.endif
27
28RCFLAGS=-DRCRT0
29# amd64 can access the stack protector before relocation has occurred.
30# Other archs aren't so lucky
31.if ${MACHINE_ARCH} != "amd64"
32RCFLAGS+=-fno-stack-protector
33.endif
34
35# Prevent use of builtins in _dl_boot_bind().
36.if ${MACHINE_CPU} == "mips64" || ${MACHINE_CPU} == "powerpc"
37RCFLAGS+=-fno-builtin
38.endif
39
40.if ${MACHINE_CPU} == "powerpc64"
41RCFLAGS+= -mno-vsx -mno-altivec
42.endif
43
44# Prevent use of jump tables in _dl_boot_bind().
45.if ${MACHINE_CPU} == "mips64" || ${MACHINE_CPU} == "powerpc" || \
46    ${MACHINE_CPU} == "powerpc64"
47RCFLAGS+=-fno-jump-tables
48.endif
49
50DEPS = ${OBJS:.o=.d}
51DFLAGS += -MF ${.TARGET:R}.d
52
53all: ${OBJS}
54
55crt0.o: crt0.c
56	@echo ${COMPILE.c} ${.CURDIR}/crt0.c -o ${.TARGET}
57	@${COMPILE.c} ${DFLAGS} ${.CURDIR}/crt0.c -o ${.TARGET}.o
58	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
59	@rm -f ${.TARGET}.o
60
61gcrt0.o: crt0.c
62	@echo ${COMPILE.c} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}
63	@${COMPILE.c} ${DFLAGS} -DMCRT0 ${.CURDIR}/crt0.c -o ${.TARGET}.o
64	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
65	@rm -f ${.TARGET}.o
66
67rcrt0.o: crt0.c
68	@echo ${COMPILE.c} ${RCFLAGS} ${.CURDIR}/crt0.c -o ${.TARGET}
69	@${COMPILE.c} ${DFLAGS} ${RCFLAGS} ${.CURDIR}/crt0.c -o ${.TARGET}.o
70	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
71	@rm -f ${.TARGET}.o
72
73crtbegin.o: crtbegin.c
74	@echo ${COMPILE.c} ${.CURDIR}/crtbegin.c -o ${.TARGET}
75	@${COMPILE.c} ${DFLAGS} ${.CURDIR}/crtbegin.c -o ${.TARGET}.o
76	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
77	@rm -f ${.TARGET}.o
78
79crtbeginS.o: crtbeginS.c
80	@echo ${COMPILE.c} ${PICFLAG} ${.CURDIR}/crtbeginS.c -o ${.TARGET}
81	@${COMPILE.c} ${DFLAGS} ${PICFLAG} ${.CURDIR}/crtbeginS.c -o ${.TARGET}.o
82	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
83	@rm -f ${.TARGET}.o
84
85crtend.o: crtend.c
86	@echo ${COMPILE.c} ${.CURDIR}/crtend.c -o ${.TARGET}
87	@${COMPILE.c} ${DFLAGS} ${.CURDIR}/crtend.c -o ${.TARGET}.o
88	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
89	@rm -f ${.TARGET}.o
90
91crtendS.o: crtendS.c
92	@echo ${COMPILE.c} ${PICFLAG} ${.CURDIR}/crtendS.c -o ${.TARGET}
93	@${COMPILE.c} ${DFLAGS} ${PICFLAG} ${.CURDIR}/crtendS.c -o ${.TARGET}.o
94	@${LD} -x -r -o ${.TARGET} ${.TARGET}.o
95	@rm -f ${.TARGET}.o
96
97realinstall:
98	${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 ${OBJS} \
99	    ${DESTDIR}/usr/lib
100
101.include <bsd.prog.mk>
102