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