Home | History | Annotate | Line # | Download | only in ld.elf_so
Makefile revision 1.136.6.2
      1  1.136.6.2    martin #	$NetBSD: Makefile,v 1.136.6.2 2023/08/09 16:16:40 martin Exp $
      2       1.90        ad #
      3       1.90        ad # NOTE: when changing ld.so, ensure that ldd still compiles.
      4       1.90        ad #
      5       1.88     lukem 
      6       1.89  christos WARNS?=4
      7        1.5       cjs 
      8      1.117      matt LDELFSO_MACHINE_ARCH?= ${MACHINE_ARCH}
      9      1.117      matt 
     10       1.92       mrg # This needs to be before bsd.init.mk
     11       1.92       mrg .if defined(BSD_MK_COMPAT_FILE)
     12       1.92       mrg .include <${BSD_MK_COMPAT_FILE}>
     13       1.92       mrg .endif
     14       1.92       mrg 
     15       1.86  christos # We are not building this with PIE
     16       1.86  christos PIE_CFLAGS=
     17       1.86  christos PIE_LDFLAGS=
     18       1.97       mrg .include <bsd.init.mk>			# for MKPIC definition
     19      1.114     joerg .include <bsd.shlib.mk>			# for SHLINKINSTALLDIR definition
     20       1.11  jonathan 
     21       1.87       mrg .if defined(LDELFSO_MACHINE_CPU) && !empty(LDELFSO_MACHINE_CPU) && \
     22       1.87       mrg     exists(${.CURDIR}/arch/${LDELFSO_MACHINE_CPU})
     23       1.87       mrg ARCHSUBDIR=	${LDELFSO_MACHINE_CPU}
     24       1.87       mrg .else
     25       1.67     skrll ARCHSUBDIR=	${MACHINE_CPU}
     26       1.87       mrg .endif
     27       1.67     skrll M=		${.CURDIR}/arch/${ARCHSUBDIR}
     28       1.23  jonathan 
     29      1.127      matt .if ((${MACHINE_CPU} == "aarch64") ||					\
     30      1.127      matt      (${LDELFSO_MACHINE_ARCH} == "alpha") ||				\
     31       1.75    simonb      (${MACHINE_CPU} == "arm") ||					\
     32      1.121      matt      (${LDELFSO_MACHINE_ARCH} == "coldfire") ||				\
     33      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "hppa") ||				\
     34      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "i386") ||				\
     35      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "m68k") ||				\
     36       1.75    simonb      (${MACHINE_CPU} == "mips") ||					\
     37      1.128      matt      (${MACHINE_CPU} == "or1k") ||					\
     38      1.126      matt      (${MACHINE_CPU} == "powerpc") ||					\
     39      1.129      matt      (${MACHINE_CPU} == "riscv") ||					\
     40       1.75    simonb      (${MACHINE_CPU} == "sh3") ||					\
     41      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "sparc") ||				\
     42      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "sparc64") ||				\
     43      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "x86_64") ||				\
     44      1.117      matt      (${LDELFSO_MACHINE_ARCH} == "vax")) &&				\
     45       1.97       mrg     ${MKPIC} != "no"
     46       1.29   thorpej 
     47      1.106     joerg LDFLAGS+=	${${ACTIVE_CC} == "clang":? -Wl,-Bsymbolic : -symbolic} \
     48      1.106     joerg 		-shared -nostartfiles -nodefaultlibs
     49       1.74     skrll LDFLAGS+=	-Wl,-static
     50      1.102      matt LDFLAGS+=	-Wl,--warn-shared-textrel
     51      1.126      matt LDFLAGS+=	-Wl,-Map=${.TARGET}.map
     52      1.102      matt 
     53      1.112      matt COPTS+=		-fvisibility=hidden
     54       1.66       uwe 
     55        1.8     lukem # Adds SRCS, CPPFLAGS, LDFLAGS, etc.  Must go first so MD startup source
     56        1.1       cgd # is first.
     57       1.23  jonathan .if exists($M/Makefile.inc)
     58       1.23  jonathan .include "$M/Makefile.inc"
     59        1.3       cgd .endif
     60        1.1       cgd 
     61       1.93       mrg # Support compat ld.elf_so.
     62       1.91       mrg .if defined(MLIBDIR)
     63       1.93       mrg PROG=		ld.elf_so-${MLIBDIR}
     64       1.93       mrg CPPFLAGS+=	-DRTLD_ARCH_SUBDIR=\"${MLIBDIR}\"
     65      1.134  christos .	if ${MLIBDIR} == "o32"
     66      1.134  christos .	endif
     67       1.87       mrg .else
     68       1.93       mrg PROG=		ld.elf_so
     69       1.93       mrg .endif
     70       1.93       mrg 
     71       1.51     lukem CLIBOBJ!=	cd ${NETBSDSRCDIR}/lib/libc && ${PRINTOBJDIR}
     72       1.44        tv 
     73  1.136.6.2    martin SRCS+=		debug.c
     74  1.136.6.2    martin SRCS+=		diagassert.c
     75  1.136.6.2    martin SRCS+=		expand.c
     76  1.136.6.2    martin SRCS+=		hash.c
     77  1.136.6.2    martin SRCS+=		headers.c
     78  1.136.6.2    martin SRCS+=		load.c
     79  1.136.6.2    martin SRCS+=		map_object.c
     80  1.136.6.2    martin SRCS+=		paths.c
     81  1.136.6.2    martin SRCS+=		reloc.c
     82  1.136.6.2    martin SRCS+=		rtld.c
     83  1.136.6.2    martin SRCS+=		search.c
     84  1.136.6.2    martin SRCS+=		symbol.c
     85  1.136.6.2    martin SRCS+=		symver.c
     86  1.136.6.2    martin SRCS+=		tls.c
     87  1.136.6.2    martin SRCS+=		xmalloc.c
     88  1.136.6.2    martin SRCS+=		xprintf.c
     89       1.40   thorpej 
     90       1.85  christos .if ${USE_FORT} == "yes"
     91       1.84        ad .PATH.c: ${NETBSDSRCDIR}/lib/libc/misc
     92       1.80  christos SRCS+=		stack_protector.c
     93       1.85  christos .endif
     94       1.83     skrll 
     95       1.83     skrll .PATH.c: ${NETBSDSRCDIR}/lib/libc/stdlib
     96       1.83     skrll SRCS+=		exit.c
     97       1.80  christos 
     98      1.101     joerg errlist_concat.h: ${NETBSDSRCDIR}/lib/libc/gen/errlist.awk ${NETBSDSRCDIR}/sys/sys/errno.h
     99      1.101     joerg 	${TOOL_AWK} -v concat=1 -f ${.ALLSRC} > ${.TARGET}.tmp && \
    100      1.101     joerg 	mv -f ${.TARGET}.tmp ${.TARGET}
    101      1.101     joerg 
    102      1.101     joerg xprintf.c: errlist_concat.h
    103      1.101     joerg 
    104      1.126      matt CLEANFILES+=	errlist_concat.h ${PROG}.map
    105      1.101     joerg 
    106      1.114     joerg BINDIR=		${SHLINKINSTALLDIR}
    107      1.114     joerg 
    108       1.67     skrll CPPFLAGS+=	-DLIBDIR=\"${LIBDIR}\" -D_PATH_RTLD=\"${BINDIR}/${PROG}\"
    109      1.130  christos CPPFLAGS+=	-I${.CURDIR} -I. -D_KERNTYPES
    110       1.67     skrll CPPFLAGS+=	-DRTLD_LOADER
    111      1.133  christos CPPFLAGS+=	-DGNU_RELRO
    112       1.67     skrll CPPFLAGS+=	-D_RTLD_SOURCE
    113       1.71    martin #CPPFLAGS+=	-DDEBUG
    114       1.67     skrll #CPPFLAGS+=	-DRTLD_DEBUG
    115       1.67     skrll #CPPFLAGS+=	-DRTLD_DEBUG_RELOC
    116      1.117      matt .if !empty(LDELFSO_MACHINE_ARCH:Mearm*)
    117      1.116      matt CPPFLAGS+=	-I${NETBSDSRCDIR}/lib/libexecinfo
    118      1.116      matt .endif
    119       1.67     skrll #DBG=		-g
    120      1.122     joerg COPTS+=		-O3
    121      1.122     joerg 
    122      1.123      matt .if ${MACHINE_CPU} != "m68k" && ${MACHINE_CPU} != "sh3" && ${MACHINE_ARCH} != "vax"
    123      1.122     joerg COPTS+=		-fomit-frame-pointer
    124      1.122     joerg .endif
    125       1.43     lukem 
    126      1.117      matt .if ${LDELFSO_MACHINE_ARCH} == "i386" || ${LDELFSO_MACHINE_ARCH} == "x86_64"
    127      1.112      matt COPTS+=		-mno-3dnow -mno-mmx -mno-sse -mno-sse2 -mno-sse3
    128      1.105     joerg .endif
    129      1.105     joerg 
    130      1.114     joerg 
    131      1.114     joerg .if ${SHLIBDIR} != ${LIBDIR}
    132      1.114     joerg CPPFLAGS+=	-DRTLD_DEFAULT_LIBRARY_PATH=\"${SHLIBDIR}:${LIBDIR}\"
    133      1.114     joerg .endif
    134      1.114     joerg 
    135       1.96     skrll # rtld.c and symbol.c use alloca, so disable SSP warnings.
    136       1.96     skrll COPTS.rtld.c+=	-Wno-stack-protector
    137       1.96     skrll COPTS.symbol.c+=-Wno-stack-protector
    138       1.96     skrll 
    139      1.136  christos LDADD+=		-Wl,--version-script=${.CURDIR}/symbols.map
    140       1.77      matt LDADD+=		-L${CLIBOBJ} -L${DESTDIR}${LIBDIR}
    141       1.77      matt .if ${MKPICLIB} != "no"
    142       1.77      matt LDADD+=		-lc_pic
    143       1.68     enami .if ${MKPICINSTALL} != "no"
    144       1.67     skrll DPADD+=		${LIBC_PIC}
    145       1.60       uwe .endif
    146       1.67     skrll DPADD+=		${CLIBOBJ}/libc_pic.a
    147       1.77      matt .else
    148       1.77      matt LDADD+=		-lc
    149       1.77      matt DPADD+=		${CLIBOBJ}/libc.a
    150       1.77      matt .endif
    151        1.1       cgd 
    152      1.135  christos .if ${MACHINE_CPU} == "hppa" || ${MACHINE_CPU} == "sh3"
    153      1.107  christos # for $$divU, $$remU etc. (millicode)
    154      1.110       mrg LDADD+=		-lgcc
    155      1.110       mrg DPADD+=		${LIBGCC}
    156      1.107  christos .endif
    157      1.107  christos 
    158        1.4   thorpej STRIPFLAG=
    159        1.1       cgd 
    160       1.23  jonathan .PATH: $M
    161        1.1       cgd 
    162      1.115  christos 
    163       1.36  christos ${PROG}: ${OBJS} ${DPADD}
    164       1.64     lukem 	${_MKMSG_LINK} ${PROG}
    165       1.72     lukem 	${CC} ${LDFLAGS} -o ${PROG} ${OBJS} ${LDADD}
    166      1.115  christos .if ${MKDEBUG} != "no"
    167      1.115  christos 	(  ${OBJCOPY} --only-keep-debug ${.TARGET} ${.TARGET}.debug \
    168      1.115  christos 	   && ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
    169      1.115  christos 	   --add-gnu-debuglink=${.TARGET}.debug ${.TARGET} \
    170      1.115  christos 	) || (rm -f ${.TARGET}.debug; false)
    171      1.115  christos 
    172      1.115  christos _PROGDEBUG.${PROG} := ${PROG}.debug
    173      1.115  christos .endif
    174      1.115  christos 
    175       1.35  christos 
    176      1.114     joerg .if ${SHLINKINSTALLDIR} != "/usr/libexec"
    177      1.114     joerg SYMLINKS+=	${SHLINKINSTALLDIR}/${PROG} /usr/libexec/${PROG}
    178      1.119  christos .if ${MKDEBUG} != "no"
    179      1.120     skrll SYMLINKS+=	${DEBUGDIR}${BINDIR}/${PROG}.debug \
    180      1.120     skrll 		${DEBUGDIR}/usr${BINDIR}/${PROG}.debug
    181      1.119  christos .endif
    182        1.7       mrg .endif
    183        1.1       cgd 
    184        1.1       cgd .include <bsd.prog.mk>
    185       1.45     skrll .else
    186       1.45     skrll 
    187       1.68     enami MAN=		ld.elf_so.1
    188       1.45     skrll 
    189       1.45     skrll .include <bsd.man.mk>
    190       1.45     skrll .endif
    191