xref: /freebsd/libexec/rtld-elf/Makefile (revision d3d381b2b194b4d24853e92eecef55f262688d1a)
1# $FreeBSD$
2
3# Use the following command to build local debug version of dynamic
4# linker:
5# make DEBUG_FLAGS=-g DEBUG=-DDEBUG WITHOUT_TESTS=yes 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
50.if ${MACHINE_CPUARCH} == "mips"
51CFLAGS.reloc.c+=-fno-jump-tables
52.endif
53LDFLAGS+=	-shared -Wl,-Bsymbolic -Wl,-z,defs
54LIBADD=		c_nossp_pic
55.if ${MK_TOOLCHAIN} == "no"
56LDFLAGS+=	-L${LIBCDIR}
57.endif
58
59.if ${MACHINE_CPUARCH} == "arm"
60# Some of the required math functions (div & mod) are implemented in
61# libcompiler_rt on ARM. The library also needs to be placed first to be
62# correctly linked. As some of the functions are used before we have
63# shared libraries.
64LIBADD+=	compiler_rt
65.endif
66
67
68
69.if ${MK_SYMVER} == "yes"
70VERSION_DEF=	${LIBCSRCDIR}/Versions.def
71SYMBOL_MAPS=	${.CURDIR}/Symbol.map
72VERSION_MAP=	Version.map
73LDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
74
75.if exists(${.CURDIR}/${RTLD_ARCH}/Symbol.map)
76SYMBOL_MAPS+=	${.CURDIR}/${RTLD_ARCH}/Symbol.map
77.endif
78.endif
79
80.sinclude "${.CURDIR}/${RTLD_ARCH}/Makefile.inc"
81
82# Since moving rtld-elf to /libexec, we need to create a symlink.
83# Fixup the existing binary that's there so we can symlink over it.
84beforeinstall:
85.if exists(${DESTDIR}/usr/libexec/${PROG}) && ${MK_STAGING} == "no"
86	-chflags -h noschg ${DESTDIR}/usr/libexec/${PROG}
87.endif
88
89.PATH: ${.CURDIR}/${RTLD_ARCH}
90
91HAS_TESTS=
92SUBDIR.${MK_TESTS}+= tests
93
94.include <bsd.prog.mk>
95${PROG_FULL}:	${VERSION_MAP}
96.include <bsd.symver.mk>
97