xref: /freebsd/libexec/rtld-elf/Makefile (revision f6a3b357e9be4c6423c85eff9a847163a0d307c8)
1# $FreeBSD$
2
3# Use the following command to build local debug version of dynamic
4# linker:
5# make DEBUG_FLAGS=-g WITHOUT_TESTS=yes all
6
7.include <src.opts.mk>
8PACKAGE=	clibs
9MK_PIE=		no # Always position independent using local rules
10MK_SSP=		no
11
12CONFS=		libmap.conf
13PROG?=		ld-elf.so.1
14.if (${PROG:M*ld-elf32*} != "")
15TAGS+=		lib32
16.endif
17SRCS= \
18	rtld_start.S \
19	reloc.c \
20	rtld.c \
21	rtld_lock.c \
22	rtld_malloc.c \
23	rtld_printf.c \
24	map_object.c \
25	xmalloc.c \
26	debug.c \
27	libmap.c
28MAN=		rtld.1
29CSTD?=		gnu99
30CFLAGS+=	-Wall -DFREEBSD_ELF -DIN_RTLD -ffreestanding
31CFLAGS+=	-I${SRCTOP}/lib/csu/common
32.if exists(${.CURDIR}/${MACHINE_ARCH})
33RTLD_ARCH=	${MACHINE_ARCH}
34.else
35RTLD_ARCH=	${MACHINE_CPUARCH}
36.endif
37CFLAGS+=	-I${.CURDIR}/${RTLD_ARCH} -I${.CURDIR}
38.if ${MACHINE_ARCH} == "powerpc64"
39LDFLAGS+=	-nostdlib -e _rtld_start
40.else
41LDFLAGS+=	-nostdlib -e .rtld_start
42.endif
43
44NO_WCAST_ALIGN=	yes
45WARNS?=		6
46INSTALLFLAGS=	-C -b
47PRECIOUSPROG=
48BINDIR=		/libexec
49SYMLINKS=	../..${BINDIR}/${PROG} ${LIBEXECDIR}/${PROG}
50MLINKS=		rtld.1 ld-elf.so.1.1 \
51		rtld.1 ld.so.1
52
53.if ${MACHINE_CPUARCH} == "sparc64"
54CFLAGS+=	-fPIC
55.else
56CFLAGS+=	-fpic
57.endif
58CFLAGS+=	-DPIC $(DEBUG)
59.if ${MACHINE_CPUARCH} == "amd64" || ${MACHINE_CPUARCH} == "i386"
60CFLAGS+=	-fvisibility=hidden
61.endif
62.if ${MACHINE_CPUARCH} == "mips"
63CFLAGS.reloc.c+=-fno-jump-tables
64.endif
65LDFLAGS+=	-shared -Wl,-Bsymbolic -Wl,-z,defs
66# Pull in the dependencies that we use from libc
67.include "rtld-libc/Makefile.inc"
68.if ${MK_TOOLCHAIN} == "no"
69LDFLAGS+=	-L${LIBCDIR}
70.endif
71
72.if ${MACHINE_CPUARCH} == "arm"
73# Some of the required math functions (div & mod) are implemented in
74# libcompiler_rt on ARM. The library also needs to be placed first to be
75# correctly linked. As some of the functions are used before we have
76# shared libraries.
77LIBADD+=	compiler_rt
78.endif
79
80
81
82.if ${MK_SYMVER} == "yes"
83VERSION_DEF=	${LIBCSRCDIR}/Versions.def
84SYMBOL_MAPS=	${.CURDIR}/Symbol.map
85VERSION_MAP=	Version.map
86LDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
87
88.if exists(${.CURDIR}/${RTLD_ARCH}/Symbol.map)
89SYMBOL_MAPS+=	${.CURDIR}/${RTLD_ARCH}/Symbol.map
90.endif
91.endif
92
93.sinclude "${.CURDIR}/${RTLD_ARCH}/Makefile.inc"
94
95# Since moving rtld-elf to /libexec, we need to create a symlink.
96# Fixup the existing binary that's there so we can symlink over it.
97beforeinstall:
98.if exists(${DESTDIR}/usr/libexec/${PROG}) && ${MK_STAGING} == "no"
99	-chflags -h noschg ${DESTDIR}/usr/libexec/${PROG}
100.endif
101
102.PATH: ${.CURDIR}/${RTLD_ARCH}
103
104HAS_TESTS=
105SUBDIR.${MK_TESTS}+= tests
106
107.include <bsd.prog.mk>
108${PROG_FULL}:	${VERSION_MAP}
109.include <bsd.symver.mk>
110
111.if ${COMPILER_TYPE} == "gcc"
112# GCC warns about redeclarations even though they have __exported
113# and are therefore not identical to the ones from the system headers.
114CFLAGS+=	-Wno-redundant-decls
115.if ${COMPILER_VERSION} < 40300
116# Silence -Wshadow false positives in ancient GCC
117CFLAGS+=	-Wno-shadow
118.endif
119.endif
120