xref: /openbsd/libexec/ld.so/Makefile (revision 264ca280)
1#	$OpenBSD: Makefile,v 1.62 2016/07/04 21:15:06 guenther Exp $
2
3SUBDIR=ldconfig ldd
4MAN=	ld.so.1
5
6.include <bsd.own.mk>
7
8.if defined(NOPIC)
9NOPROG=
10.else
11PROG=	ld.so
12BINMODE=444
13
14VERSION_SCRIPT=	${.CURDIR}/Symbols.map
15ELF_LDFLAGS+=--version-script=${VERSION_SCRIPT}
16
17VPATH=${.CURDIR}/../../lib/libc/string
18
19SRCS=	ldasm.S boot.c loader.c resolve.c dlfcn.c dl_printf.c rtld_machine.c
20SRCS+=	path.c util.c sod.c strsep.c strtol.c dir.c library_subr.c
21SRCS+=	dl_realpath.c dl_uname.c dl_dirname.c strlcat.c strlen.c trace.c
22SRCS+=	malloc.c reallocarray.c tib.c
23
24.if (${MACHINE_ARCH} == "i386")
25SRCS+=	library_mquery.c
26.else
27SRCS+=	library.c
28.endif
29
30.include "${.CURDIR}/${MACHINE_CPU}/Makefile.inc"
31.PATH:	${.CURDIR}/${MACHINE_CPU}
32
33DEBUG?=	-g
34CFLAGS += -Wall -Werror
35CFLAGS += -I${.CURDIR} -I${.CURDIR}/${MACHINE_CPU} \
36	-D'DEF_WEAK(x)=asm("")' -D'DEF_STRONG(x)=asm("")' \
37	-Dstrsep=_dl_strsep -Dstrlcat=_dl_strlcat -Dstrlen=_dl_strlen
38CDIAGFLAGS=
39INSTALL_STRIP=
40
41ELF_LDFLAGS+=--shared -Bsymbolic --no-undefined
42
43test_prog=	test-$(PROG)
44CLEANFILES+=	test-$(PROG)
45candidate=	$(PROG).test
46CLEANFILES+=	${candidate}
47
48$(test_prog):
49	printf '#include <stdio.h>\nint main(int argc, char **argv){ printf("%%s: ", argv[0]); printf("%%s!\\n", argv[1] ? argv[1] : "foo"); }\n' | \
50	$(CC) -x c - -Wl,-dynamic-linker,${.OBJDIR}/$(candidate) -o $@
51
52$(PROG): $(test_prog) ${VERSION_SCRIPT}
53	$(LD) -x -e _dl_start $(ELF_LDFLAGS) -o $(candidate) $(OBJS) $(LDADD)
54.ifndef CROSSDIR
55	ulimit -c 0; [ "`${.OBJDIR}/$(test_prog) ok`" = "${.OBJDIR}/$(test_prog): ok!" ]
56.endif
57	cp $(candidate) $@
58.endif
59
60.include <bsd.prog.mk>
61
62boot.o: boot.c
63	${COMPILE.c} -fno-stack-protector ${.IMPSRC}
64