xref: /freebsd/lib/libc/Makefile (revision 96294c22f7e54a48df44c86a4ee5848e71ac4470)
1c389411cSGlen BarberPACKAGE=	clibs
218b2ee82SBaptiste DaroussinSHLIBDIR?= /lib
3fcaa4668SRuslan Ermilov
4c6063d0dSWarner Losh.include <src.opts.mk>
5e1fe3dbaSRuslan Ermilov
68876613dSMarcel MoolenaarLIBC_SRCTOP?= ${.CURDIR}
78269e767SBrooks DavisLIBSYS_SRCTOP?=	${.CURDIR:H}/libsys
88876613dSMarcel Moolenaar
9b19d8afeSWarner Losh# Pick the current architecture directory for libc. In general, this is named
10b19d8afeSWarner Losh# MACHINE_CPUARCH, but some ABIs are different enough to require their own libc,
11b19d8afeSWarner Losh# so allow a directory named MACHINE_ARCH to override this (though treat
12b19d8afeSWarner Losh# powerpc64le and powerpc64 the same).
13da8238d6SBrooks Davis# Note: This is copied to msun/Makefile
14b19d8afeSWarner LoshM=${MACHINE_ARCH:S/powerpc64le/powerpc64/}
15b19d8afeSWarner Losh.if exists(${LIBC_SRCTOP}/${M})
16b19d8afeSWarner LoshLIBC_ARCH=${M}
172c0959aeSWarner Losh.else
18bff351d7SWarner LoshLIBC_ARCH=${MACHINE_CPUARCH}
192c0959aeSWarner Losh.endif
202c0959aeSWarner Losh
21e5551250SKyle EvansCFLAGS+=-D_FORTIFY_SOURCE_read=_read
22e5551250SKyle Evans
23ecaaecd7SDavid E. O'Brien# All library objects contain FreeBSD revision strings by default; they may be
2458f0484fSRodney W. Grimes# excluded as a space-saving measure.  To produce a library that does
2554a5fb6cSDavid E. O'Brien# not contain these strings, add -DSTRIP_FBSDID (see <sys/cdefs.h>) to CFLAGS
26e481bf77SBruce Evans# below.  Note: there are no IDs for syscall stubs whose sources are generated.
2741b9df16SJohn Baldwin# To include legacy CSRG SCCS ID strings, remove -DNO__SCCSID from CFLAGS.
2841b9df16SJohn Baldwin# To include RCS ID strings from other BSD projects, remove -DNO__RCSID from CFLAGS.
2941b9df16SJohn BaldwinCFLAGS+=-DNO__SCCSID -DNO__RCSID
3041b9df16SJohn Baldwin
3158f0484fSRodney W. GrimesLIB=c
32794063c0SHajimu UMEMOTOSHLIB_MAJOR= 7
330f611708SEd Maste.if ${MK_SSP} != "no" && \
34884ba431SPiotr Kubaj    (${LIBC_ARCH} == "i386" || ${LIBC_ARCH:Mpowerpc*} != "")
3554f82841SJeremie Le HenSHLIB_LDSCRIPT=libc.ldscript
3632797df5SRuslan Bukin.else
3732797df5SRuslan BukinSHLIB_LDSCRIPT=libc_nossp.ldscript
3832797df5SRuslan Bukin.endif
39f051a5b3SColin PercivalSHLIB_LDSCRIPT_LINKS=libxnet.so
408e1b0bc6SJacques VidrineWARNS?=	2
41d0fd0203SEnji CooperCFLAGS+=-I${LIBC_SRCTOP}/include -I${SRCTOP}/include
428876613dSMarcel MoolenaarCFLAGS+=-I${LIBC_SRCTOP}/${LIBC_ARCH}
438269e767SBrooks DavisCFLAGS+=-I${LIBSYS_SRCTOP}/${LIBC_ARCH}
44c7e52324SGleb Kurtsou.if ${MK_NLS} != "no"
45fe73c506SGabor KovesdanCFLAGS+=-DNLS
46c7e52324SGleb Kurtsou.endif
4758f0484fSRodney W. GrimesCLEANFILES+=tags
48a35d8893SRuslan ErmilovINSTALL_PIC_ARCHIVE=
49db08bfceSKonstantin BelousovBUILD_NOSSP_PIC_ARCHIVE=
50a35d8893SRuslan ErmilovPRECIOUSLIB=
5158f0484fSRodney W. Grimes
52f4213b90SDavid Xu.ifndef NO_THREAD_STACK_UNWIND
53f4213b90SDavid XuCANCELPOINTS_CFLAGS=-fexceptions
54f4213b90SDavid XuCFLAGS+=${CANCELPOINTS_CFLAGS}
55f4213b90SDavid Xu.endif
56f4213b90SDavid Xu
579c97062bSMark Johnston# Use a more efficient TLS model for libc since we can reasonably assume that
589c97062bSMark Johnston# it will be loaded during program startup.
599c97062bSMark JohnstonCFLAGS+= -ftls-model=initial-exec
609c97062bSMark Johnston
61e20b1658SAlexander Kabaev#
6237656b87SEd Schouten# Link with static libcompiler_rt.a.
63e20b1658SAlexander Kabaev#
640212104bSAlexander KabaevLDFLAGS+= -nodefaultlibs
656b129086SBaptiste DaroussinLIBADD+=	compiler_rt
6699ea6757SBrooks DavisLIBADD+=	sys
67eb90239dSBrooks Davis.if defined(COMPAT_libcompat)
68eb90239dSBrooks Davis# XXX: work around gcc -m32 + bfd ld path issue for DT_NEEDED symbols.
69eb90239dSBrooks Davis# https://sourceware.org/bugzilla/show_bug.cgi?id=31395
70eb90239dSBrooks DavisLDFLAGS+=	-Wl,--rpath=/usr/lib${COMPAT_libcompat}
71eb90239dSBrooks Davis.endif
720d4f7723SBrooks Davis
7357ddfad8SBrooks DavisLDFLAGS+=-Wl,--auxiliary,libsys.so.7
7446ad3707SMarcel Moolenaar
750f611708SEd Maste.if ${MK_SSP} != "no" && \
76884ba431SPiotr Kubaj    (${LIBC_ARCH} == "i386" || ${LIBC_ARCH:Mpowerpc*} != "")
776b129086SBaptiste DaroussinLIBADD+=	ssp_nonshared
7846ad3707SMarcel Moolenaar.endif
79e20b1658SAlexander Kabaev
80db2af393SPeter Wemm# Extras that live in either libc.a or libc_nonshared.a
81db2af393SPeter WemmLIBC_NONSHARED_SRCS=
82db2af393SPeter Wemm
837f7489ebSKonstantin BelousovRTLD_ELF_DIR=${SRCTOP}/libexec/rtld-elf
847f7489ebSKonstantin Belousov.if exists(${RTLD_ELF_DIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
857f7489ebSKonstantin BelousovRTLD_ARCH=	${MACHINE_ARCH:S/powerpc64le/powerpc64/}
867f7489ebSKonstantin Belousov.else
877f7489ebSKonstantin BelousovRTLD_ARCH=	${MACHINE_CPUARCH}
887f7489ebSKonstantin Belousov.endif
897f7489ebSKonstantin BelousovRTLD_HDRS= -I${RTLD_ELF_DIR}/${RTLD_ARCH} -I${RTLD_ELF_DIR}
907f7489ebSKonstantin Belousov
91c51d717fSRuslan Ermilov# Define (empty) variables so that make doesn't give substitution
92c51d717fSRuslan Ermilov# errors if the included makefiles don't change these:
93c51d717fSRuslan ErmilovMDSRCS=
94c51d717fSRuslan ErmilovMISRCS=
95c51d717fSRuslan ErmilovMDASM=
96c51d717fSRuslan ErmilovMIASM=
97c51d717fSRuslan ErmilovNOASM=
98c51d717fSRuslan Ermilov
998876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/${LIBC_ARCH}/Makefile.inc"
10051015e6dSKonstantin Belousov.include "${LIBC_SRCTOP}/csu/Makefile.inc"
1018876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/db/Makefile.inc"
1028876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/compat-43/Makefile.inc"
1038876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/gdtoa/Makefile.inc"
1048876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/gen/Makefile.inc"
1058876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/gmon/Makefile.inc"
106ad30f8e7SGabor Kovesdan.if ${MK_ICONV} != "no"
1078876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/iconv/Makefile.inc"
108ad30f8e7SGabor Kovesdan.endif
1098876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/inet/Makefile.inc"
1108876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/isc/Makefile.inc"
1118876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/locale/Makefile.inc"
1128876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/nameser/Makefile.inc"
1138876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/net/Makefile.inc"
1148876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/nls/Makefile.inc"
1158876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/posix1e/Makefile.inc"
116c3fb59edSBrooks Davis.if ${MACHINE_ABI:Mlong32}
1178876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/quad/Makefile.inc"
118c51d717fSRuslan Ermilov.endif
1198876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/regex/Makefile.inc"
1208876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/resolv/Makefile.inc"
121*6296500aSRobert Clausecker.include "${LIBC_SRCTOP}/stdbit/Makefile.inc"
1228876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/stdio/Makefile.inc"
1238876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/stdlib/Makefile.inc"
1248876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/stdtime/Makefile.inc"
1258876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/string/Makefile.inc"
126d7847a8dSBrooks Davis.include "${LIBC_SRCTOP}/sys/Makefile.inc"
127fe0d386cSPedro F. Giffuni.include "${LIBC_SRCTOP}/secure/Makefile.inc"
1288876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/rpc/Makefile.inc"
1298876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/uuid/Makefile.inc"
1308876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/xdr/Makefile.inc"
13147e888f8SJohn Baldwin.if (${LIBC_ARCH} == "arm" && (defined(CPUTYPE) && ${CPUTYPE:M*soft*}))
1328876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/softfloat/Makefile.inc"
1332357939bSOlivier Houchard.endif
13416808549SKonstantin Belousov.if ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "amd64"
135071bca67SKonstantin Belousov.include "${LIBC_SRCTOP}/x86/gen/Makefile.inc"
13616808549SKonstantin Belousov.endif
137e1fe3dbaSRuslan Ermilov.if ${MK_NIS} != "no"
138c51d717fSRuslan ErmilovCFLAGS+= -DYP
1398876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/yp/Makefile.inc"
140c51d717fSRuslan Ermilov.endif
1418876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/capability/Makefile.inc"
142e1fe3dbaSRuslan Ermilov.if ${MK_HESIOD} != "no"
143c51d717fSRuslan ErmilovCFLAGS+= -DHESIOD
144c51d717fSRuslan Ermilov.endif
14506a99fe3SHajimu UMEMOTO.if ${MK_NS_CACHING} != "no"
14606a99fe3SHajimu UMEMOTOCFLAGS+= -DNS_CACHING
14706a99fe3SHajimu UMEMOTO.endif
1483dd425f7SSimon L. B. Nielsen.if defined(_FREEFALL_CONFIG)
1493dd425f7SSimon L. B. NielsenCFLAGS+=-D_FREEFALL_CONFIG
1503dd425f7SSimon L. B. Nielsen.endif
151c51d717fSRuslan Ermilov
152db2af393SPeter WemmSTATICOBJS+=${LIBC_NONSHARED_SRCS:S/.c$/.o/}
153db2af393SPeter Wemm
1548876613dSMarcel MoolenaarVERSION_DEF=${LIBC_SRCTOP}/Versions.def
15596e022f7SDaniel EischenSYMBOL_MAPS=${SYM_MAPS}
15696e022f7SDaniel Eischen
157c51d717fSRuslan Ermilov# If there are no machine dependent sources, append all the
158c51d717fSRuslan Ermilov# machine-independent sources:
15920adba8bSGleb Popov.if empty(MDSRCS) || ${MK_MACHDEP_OPTIMIZATIONS} == no
160c51d717fSRuslan ErmilovSRCS+=	${MISRCS}
161c51d717fSRuslan Ermilov.else
162c51d717fSRuslan Ermilov# Append machine-dependent sources, then append machine-independent sources
163c51d717fSRuslan Ermilov# for which there is no machine-dependent variant.
164c51d717fSRuslan ErmilovSRCS+=	${MDSRCS}
165c51d717fSRuslan Ermilov.for _src in ${MISRCS}
166c51d717fSRuslan Ermilov.if ${MDSRCS:R:M${_src:R}} == ""
167c51d717fSRuslan ErmilovSRCS+=	${_src}
168c51d717fSRuslan Ermilov.endif
169c51d717fSRuslan Ermilov.endfor
170c51d717fSRuslan Ermilov.endif
17158f0484fSRodney W. Grimes
17258f0484fSRodney W. GrimesKQSRCS=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
17358f0484fSRodney W. Grimes	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
17458f0484fSRodney W. Grimes	subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
17546632c18SEd SchoutenKSRCS=	bcmp.c ffs.c ffsl.c fls.c flsl.c mcount.c strcat.c strchr.c \
17646632c18SEd Schouten	strcmp.c strcpy.c strlen.c strncpy.c strrchr.c
17758f0484fSRodney W. Grimes
1782c0959aeSWarner Loshlibkern: libkern.gen libkern.${LIBC_ARCH}
17958f0484fSRodney W. Grimes
18058f0484fSRodney W. Grimeslibkern.gen: ${KQSRCS} ${KSRCS}
1817a37b5fcSWill Andrews	${CP} ${LIBC_SRCTOP}/quad/quad.h ${.ALLSRC} ${DESTDIR}/sys/libkern
18258f0484fSRodney W. Grimes
1832c0959aeSWarner Loshlibkern.${LIBC_ARCH}:: ${KMSRCS}
18458f0484fSRodney W. Grimes.if defined(KMSRCS) && !empty(KMSRCS)
1857a37b5fcSWill Andrews	${CP} ${.ALLSRC} ${DESTDIR}/sys/libkern/${LIBC_ARCH}
18658f0484fSRodney W. Grimes.endif
18758f0484fSRodney W. Grimes
188d511b20aSEnji CooperHAS_TESTS=
1894b330699SEnji CooperSUBDIR.${MK_TESTS}+= tests
1902f121787SEnji Cooper
19158f0484fSRodney W. Grimes.include <bsd.lib.mk>
192042a0b7eSRuslan Ermilov
1937750ad47SMarcel Moolenaar.if !defined(_SKIP_BUILD)
1947750ad47SMarcel Moolenaar# We need libutil.h, get it directly to avoid
1957750ad47SMarcel Moolenaar# recording a build dependency
196dfdb6cf4SBryan DreweryCFLAGS+= -I${SRCTOP}/lib/libutil
1977750ad47SMarcel Moolenaar# Same issue with libm
198dfdb6cf4SBryan DreweryMSUN_ARCH_SUBDIR != ${MAKE} -B -C ${SRCTOP}/lib/msun -V ARCH_SUBDIR
1997750ad47SMarcel Moolenaar# unfortunately msun/src contains both private and public headers
200dfdb6cf4SBryan DreweryCFLAGS+= -I${SRCTOP}/lib/msun/${MSUN_ARCH_SUBDIR}
201aab5fee0SSimon J. Gerraty.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
202dfdb6cf4SBryan DreweryCFLAGS+= -I${SRCTOP}/lib/msun/x86
203aab5fee0SSimon J. Gerraty.endif
204dfdb6cf4SBryan DreweryCFLAGS+= -I${SRCTOP}/lib/msun/src
205aab5fee0SSimon J. Gerraty# and we do not want to record a dependency on msun
206aab5fee0SSimon J. Gerraty.if ${.MAKE.LEVEL} > 0
207aab5fee0SSimon J. GerratyGENDIRDEPS_FILTER+= N${RELDIR:H}/msun
208aab5fee0SSimon J. Gerraty.endif
2097750ad47SMarcel Moolenaar.endif
2107750ad47SMarcel Moolenaar
211042a0b7eSRuslan Ermilov# Disable warnings in contributed sources.
212271e7c59SRui PauloCWARNFLAGS:=	${.IMPSRC:Ngdtoa_*.c:C/^.+$/${CWARNFLAGS}/:C/^$/-w/}
213042df2e2SRuslan Ermilov# Disable stack protection for SSP symbols.
214e7a629c8SKyle EvansSSP_CFLAGS:=	${.IMPSRC:N*/libc_stack_protector.c:C/^.+$/${SSP_CFLAGS}/}
215f4213b90SDavid Xu# Generate stack unwinding tables for cancellation points
216f4213b90SDavid XuCANCELPOINTS_CFLAGS:=	${.IMPSRC:Mcancelpoints_*:C/^.+$/${CANCELPOINTS_CFLAGS}/:C/^$//}
217