xref: /freebsd/libexec/rtld-elf/Makefile (revision 7d536dc855c85c15bf45f033d108a61b1f3cecc3)
1# $FreeBSD$
2
3# Use the following command to build local debug version of dynamic
4# linker:
5# make DEBUG_FLAGS=-g DEBUG=-DDEBUG MK_TESTS=no all
6
7.include <src.opts.mk>
8PACKAGE=	clibs
9MK_SSP=		no
10
11PROG?=		ld-elf.so.1
12.if (${PROG:M*ld-elf32*} != "")
13TAGS+=		lib32
14.endif
15SRCS=		rtld_start.S \
16		reloc.c rtld.c rtld_lock.c rtld_printf.c map_object.c \
17		malloc.c xmalloc.c debug.c libmap.c
18MAN=		rtld.1
19CSTD?=		gnu99
20CFLAGS+=	-Wall -DFREEBSD_ELF -DIN_RTLD -ffreestanding
21CFLAGS+=	-I${SRCTOP}/lib/csu/common
22.if exists(${.CURDIR}/${MACHINE_ARCH})
23RTLD_ARCH=	${MACHINE_ARCH}
24.else
25RTLD_ARCH=	${MACHINE_CPUARCH}
26.endif
27CFLAGS+=	-I${.CURDIR}/${RTLD_ARCH} -I${.CURDIR}
28.if ${MACHINE_ARCH} == "powerpc64"
29LDFLAGS+=	-nostdlib -e _rtld_start
30.else
31LDFLAGS+=	-nostdlib -e .rtld_start
32.endif
33WARNS?=		2
34INSTALLFLAGS=	-C -b
35PRECIOUSPROG=
36BINDIR=		/libexec
37SYMLINKS=	${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG}
38MLINKS=		rtld.1 ld-elf.so.1.1 \
39		rtld.1 ld.so.1
40
41.if ${MACHINE_CPUARCH} == "sparc64"
42CFLAGS+=	-fPIC
43.else
44CFLAGS+=	-fpic
45.endif
46CFLAGS+=	-DPIC $(DEBUG)
47.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
48CFLAGS+=	-fvisibility=hidden
49.endif
50LDFLAGS+=	-shared -Wl,-Bsymbolic
51LIBADD=		c_pic
52
53.if ${MACHINE_CPUARCH} == "arm"
54# Some of the required math functions (div & mod) are implemented in
55# libcompiler_rt on ARM. The library also needs to be placed first to be
56# correctly linked. As some of the functions are used before we have
57# shared libraries.
58LIBADD+=	compiler_rt
59.endif
60
61
62
63.if ${MK_SYMVER} == "yes"
64VERSION_DEF=	${LIBCSRCDIR}/Versions.def
65SYMBOL_MAPS=	${.CURDIR}/Symbol.map
66VERSION_MAP=	Version.map
67LDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
68
69${PROG}:	${VERSION_MAP}
70
71.if exists(${.CURDIR}/${RTLD_ARCH}/Symbol.map)
72SYMBOL_MAPS+=	${.CURDIR}/${RTLD_ARCH}/Symbol.map
73.endif
74.endif
75
76.sinclude "${.CURDIR}/${RTLD_ARCH}/Makefile.inc"
77
78# Since moving rtld-elf to /libexec, we need to create a symlink.
79# Fixup the existing binary that's there so we can symlink over it.
80beforeinstall:
81.if exists(${DESTDIR}/usr/libexec/${PROG}) && ${MK_STAGING} == "no"
82	-chflags -h noschg ${DESTDIR}/usr/libexec/${PROG}
83.endif
84
85.PATH: ${.CURDIR}/${RTLD_ARCH}
86
87.if ${MK_TESTS} != "no"
88SUBDIR+=	tests
89.endif
90
91.include <bsd.prog.mk>
92.include <bsd.symver.mk>
93