recognize and execute dynamically linked executables
[minix3.git] / libexec / ld.elf_so / Makefile
blob179d9a9a63440fe88ac2f3c28254b074e2a50408
1 # $NetBSD: Makefile,v 1.102 2011/01/16 02:36:05 matt Exp $
3 # NOTE: when changing ld.so, ensure that ldd still compiles.
6 WARNS?=4
8 # This needs to be before bsd.init.mk
9 .if defined(BSD_MK_COMPAT_FILE)
10 .include <${BSD_MK_COMPAT_FILE}>
11 .endif
13 # We are not building this with PIE
14 PIE_CFLAGS=
15 PIE_LDFLAGS=
16 .include <bsd.init.mk> # for MKPIC definition
17 .include <bsd.shlib.mk> # for SHLINKINSTALLDIR definition
19 .if defined(LDELFSO_MACHINE_CPU) && !empty(LDELFSO_MACHINE_CPU) && \
20 exists(${.CURDIR}/arch/${LDELFSO_MACHINE_CPU})
21 ARCHSUBDIR= ${LDELFSO_MACHINE_CPU}
22 .else
23 ARCHSUBDIR= ${MACHINE_CPU}
24 .endif
25 M= ${.CURDIR}/arch/${ARCHSUBDIR}
27 .if ((${MACHINE_ARCH} == "alpha") || \
28 (${MACHINE_CPU} == "arm") || \
29 (${MACHINE_ARCH} == "hppa") || \
30 (${MACHINE_ARCH} == "i386") || \
31 (${MACHINE_ARCH} == "m68k") || \
32 (${MACHINE_CPU} == "mips") || \
33 (${MACHINE_ARCH} == "powerpc") || \
34 (${MACHINE_CPU} == "sh3") || \
35 (${MACHINE_ARCH} == "sparc") || \
36 (${MACHINE_ARCH} == "sparc64") || \
37 (${MACHINE_ARCH} == "x86_64") || \
38 (${MACHINE_ARCH} == "vax")) && \
39 ${MKPIC} != "no"
41 .if ${CC} == "gcc"
42 LDFLAGS+= -shared -symbolic -nostartfiles
43 .else
44 LDFLAGS+= -shared -Wl,-Bsymbolic -nostartfiles
45 .endif
46 LDFLAGS+= -Wl,-static
47 LDFLAGS+= -Wl,--warn-shared-textrel
49 CFLAGS+= -fvisibility=hidden
51 # Adds SRCS, CPPFLAGS, LDFLAGS, etc. Must go first so MD startup source
52 # is first.
53 .if exists($M/Makefile.inc)
54 .include "$M/Makefile.inc"
55 .endif
57 # Support compat ld.elf_so.
58 .if defined(MLIBDIR)
59 PROG= ld.elf_so-${MLIBDIR}
60 CPPFLAGS+= -DRTLD_ARCH_SUBDIR=\"${MLIBDIR}\"
61 .else
62 PROG= ld.elf_so
63 .endif
65 CLIBOBJ!= cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
67 SRCS+= rtld.c reloc.c symbol.c xmalloc.c xprintf.c debug.c \
68 map_object.c load.c search.c headers.c paths.c expand.c
70 .if ${USE_FORT} == "yes"
71 .PATH.c: ${NETBSDSRCDIR}/lib/libc/misc
72 SRCS+= stack_protector.c
73 .endif
75 .PATH.c: ${NETBSDSRCDIR}/lib/libc/stdlib
76 SRCS+= exit.c
78 errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h
79 ${TOOL_AWK} -v concat=1 -f ${.ALLSRC} > ${.TARGET}.tmp && \
80 mv -f ${.TARGET}.tmp ${.TARGET}
82 xprintf.c: errlist_concat.h
84 CLEANFILES+= errlist_concat.h
86 BINDIR= ${SHLINKINSTALLDIR}
88 CPPFLAGS+= -DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
89 CPPFLAGS+= -I${.CURDIR} -I.
90 CPPFLAGS+= -DRTLD_LOADER
91 CPPFLAGS+= -D_RTLD_SOURCE
92 CPPFLAGS+= -DCOMBRELOC
93 #CPPFLAGS+= -DDEBUG
94 #CPPFLAGS+= -DRTLD_DEBUG
95 #CPPFLAGS+= -DRTLD_DEBUG_RELOC
96 #DBG= -g
97 DBG= -O3 -fomit-frame-pointer
99 .if ${SHLIBDIR} != ${LIBDIR}
100 CPPFLAGS+= -DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
101 .endif
103 # rtld.c and symbol.c use alloca, so disable SSP warnings.
104 COPTS.rtld.c+= -Wno-stack-protector
105 COPTS.symbol.c+=-Wno-stack-protector
107 LDADD+= -L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
108 .if ${MKPICLIB} != "no"
109 LDADD+= -lc_pic
110 .if ${MKPICINSTALL} != "no"
111 DPADD+= ${LIBC_PIC}
112 .endif
113 DPADD+= ${CLIBOBJ}/libc_pic.a
114 .else
115 LDADD+= -lc
116 DPADD+= ${CLIBOBJ}/libc.a
117 .endif
119 STRIPFLAG=
121 .PATH: $M
123 ${PROG}: ${OBJS} ${DPADD}
124 ${_MKMSG_LINK} ${PROG}
125 ${CC} ${LDFLAGS} -o ${PROG} ${OBJS} ${LDADD}
127 .if ${SHLINKINSTALLDIR} != "/usr/libexec"
128 SYMLINKS+= ${SHLINKINSTALLDIR}/${PROG} /usr/libexec/${PROG}
129 .endif
131 .include <bsd.prog.mk>
132 .else
134 MAN= ld.elf_so.1
136 .include <bsd.man.mk>
137 .endif