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