xref: /freebsd/lib/libc/Makefile (revision 20adba8bc1beb125d5e5ed8f12e747ae79ca6a10)
158f0484fSRodney W. Grimes#	@(#)Makefile	8.2 (Berkeley) 2/3/94
27f3dea24SPeter Wemm# $FreeBSD$
3e1fe3dbaSRuslan Ermilov
4c389411cSGlen BarberPACKAGE=	clibs
518b2ee82SBaptiste DaroussinSHLIBDIR?= /lib
6fcaa4668SRuslan Ermilov
7c6063d0dSWarner Losh.include <src.opts.mk>
8e1fe3dbaSRuslan Ermilov
9c0f5aeb0SBryan Drewery# Force building of libc_pic.a
10c0f5aeb0SBryan DreweryMK_TOOLCHAIN=	yes
11c0f5aeb0SBryan Drewery
128876613dSMarcel MoolenaarLIBC_SRCTOP?= ${.CURDIR}
138876613dSMarcel Moolenaar
14f61ce568SNathan Whitehorn# Pick the current architecture directory for libc. In general, this is
15f61ce568SNathan Whitehorn# named MACHINE_CPUARCH, but some ABIs are different enough to require
16f61ce568SNathan Whitehorn# their own libc, so allow a directory named MACHINE_ARCH to override this.
17f61ce568SNathan Whitehorn
1824faccc2SBrandon Bergren.if exists(${LIBC_SRCTOP}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
1924faccc2SBrandon BergrenLIBC_ARCH=${MACHINE_ARCH:S/powerpc64le/powerpc64/}
202c0959aeSWarner Losh.else
21bff351d7SWarner LoshLIBC_ARCH=${MACHINE_CPUARCH}
222c0959aeSWarner Losh.endif
232c0959aeSWarner Losh
24ecaaecd7SDavid E. O'Brien# All library objects contain FreeBSD revision strings by default; they may be
2558f0484fSRodney W. Grimes# excluded as a space-saving measure.  To produce a library that does
2654a5fb6cSDavid E. O'Brien# not contain these strings, add -DSTRIP_FBSDID (see <sys/cdefs.h>) to CFLAGS
27e481bf77SBruce Evans# below.  Note: there are no IDs for syscall stubs whose sources are generated.
2841b9df16SJohn Baldwin# To include legacy CSRG SCCS ID strings, remove -DNO__SCCSID from CFLAGS.
2941b9df16SJohn Baldwin# To include RCS ID strings from other BSD projects, remove -DNO__RCSID from CFLAGS.
3041b9df16SJohn BaldwinCFLAGS+=-DNO__SCCSID -DNO__RCSID
3141b9df16SJohn Baldwin
3258f0484fSRodney W. GrimesLIB=c
33794063c0SHajimu UMEMOTOSHLIB_MAJOR= 7
340f611708SEd Maste.if ${MK_SSP} != "no" && \
35884ba431SPiotr Kubaj    (${LIBC_ARCH} == "i386" || ${LIBC_ARCH:Mpowerpc*} != "")
3654f82841SJeremie Le HenSHLIB_LDSCRIPT=libc.ldscript
3732797df5SRuslan Bukin.else
3832797df5SRuslan BukinSHLIB_LDSCRIPT=libc_nossp.ldscript
3932797df5SRuslan Bukin.endif
40f051a5b3SColin PercivalSHLIB_LDSCRIPT_LINKS=libxnet.so
418e1b0bc6SJacques VidrineWARNS?=	2
42d0fd0203SEnji CooperCFLAGS+=-I${LIBC_SRCTOP}/include -I${SRCTOP}/include
438876613dSMarcel MoolenaarCFLAGS+=-I${LIBC_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 Johnston.if ${LIBC_ARCH} == "aarch64" || ${LIBC_ARCH} == "amd64" || \
60884ba431SPiotr Kubaj    ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "riscv" || \
61884ba431SPiotr Kubaj    ${LIBC_ARCH:Mpowerpc*} != ""
629c97062bSMark JohnstonCFLAGS+= -ftls-model=initial-exec
639c97062bSMark Johnston.endif
649c97062bSMark Johnston
65e20b1658SAlexander Kabaev#
6637656b87SEd Schouten# Link with static libcompiler_rt.a.
67e20b1658SAlexander Kabaev#
680212104bSAlexander KabaevLDFLAGS+= -nodefaultlibs
696b129086SBaptiste DaroussinLIBADD+=	compiler_rt
7046ad3707SMarcel Moolenaar
710f611708SEd Maste.if ${MK_SSP} != "no" && \
72884ba431SPiotr Kubaj    (${LIBC_ARCH} == "i386" || ${LIBC_ARCH:Mpowerpc*} != "")
736b129086SBaptiste DaroussinLIBADD+=	ssp_nonshared
7446ad3707SMarcel Moolenaar.endif
75e20b1658SAlexander Kabaev
76db2af393SPeter Wemm# Extras that live in either libc.a or libc_nonshared.a
77db2af393SPeter WemmLIBC_NONSHARED_SRCS=
78db2af393SPeter Wemm
797f7489ebSKonstantin BelousovRTLD_ELF_DIR=${SRCTOP}/libexec/rtld-elf
807f7489ebSKonstantin Belousov.if exists(${RTLD_ELF_DIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
817f7489ebSKonstantin BelousovRTLD_ARCH=	${MACHINE_ARCH:S/powerpc64le/powerpc64/}
827f7489ebSKonstantin Belousov.else
837f7489ebSKonstantin BelousovRTLD_ARCH=	${MACHINE_CPUARCH}
847f7489ebSKonstantin Belousov.endif
857f7489ebSKonstantin BelousovRTLD_HDRS= -I${RTLD_ELF_DIR}/${RTLD_ARCH} -I${RTLD_ELF_DIR}
867f7489ebSKonstantin Belousov
87c51d717fSRuslan Ermilov# Define (empty) variables so that make doesn't give substitution
88c51d717fSRuslan Ermilov# errors if the included makefiles don't change these:
89c51d717fSRuslan ErmilovMDSRCS=
90c51d717fSRuslan ErmilovMISRCS=
91c51d717fSRuslan ErmilovMDASM=
92c51d717fSRuslan ErmilovMIASM=
93c51d717fSRuslan ErmilovNOASM=
94c51d717fSRuslan Ermilov
958876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/${LIBC_ARCH}/Makefile.inc"
968876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/db/Makefile.inc"
978876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/compat-43/Makefile.inc"
988876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/gdtoa/Makefile.inc"
998876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/gen/Makefile.inc"
1008876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/gmon/Makefile.inc"
101ad30f8e7SGabor Kovesdan.if ${MK_ICONV} != "no"
1028876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/iconv/Makefile.inc"
103ad30f8e7SGabor Kovesdan.endif
1048876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/inet/Makefile.inc"
1058876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/isc/Makefile.inc"
1068876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/locale/Makefile.inc"
1076f79a95bSHajimu UMEMOTO.include "${LIBC_SRCTOP}/md/Makefile.inc"
1088876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/nameser/Makefile.inc"
1098876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/net/Makefile.inc"
1108876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/nls/Makefile.inc"
1118876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/posix1e/Makefile.inc"
112d422e6f9SAndrew Turner.if ${LIBC_ARCH} != "aarch64" && \
113d422e6f9SAndrew Turner    ${LIBC_ARCH} != "amd64" && \
1142c0959aeSWarner Losh    ${LIBC_ARCH} != "powerpc64" && \
1158ff32ab5SWarner Losh    ${LIBC_ARCH} != "riscv"
1168876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/quad/Makefile.inc"
117c51d717fSRuslan Ermilov.endif
1188876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/regex/Makefile.inc"
1198876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/resolv/Makefile.inc"
1208876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/stdio/Makefile.inc"
1218876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/stdlib/Makefile.inc"
1228876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/stdlib/jemalloc/Makefile.inc"
1238876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/stdtime/Makefile.inc"
1248876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/string/Makefile.inc"
1258876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/sys/Makefile.inc"
126fe0d386cSPedro F. Giffuni.include "${LIBC_SRCTOP}/secure/Makefile.inc"
1278876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/rpc/Makefile.inc"
1288876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/uuid/Makefile.inc"
1298876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/xdr/Makefile.inc"
1302c0e9e2aSWarner Losh.if (${LIBC_ARCH} == "arm" && \
1310b972ac9SWarner Losh	(${MACHINE_ARCH:Marmv[67]*} == "" || (defined(CPUTYPE) && ${CPUTYPE:M*soft*}))) || \
1327804dd52SRuslan Bukin    (${LIBC_ARCH} == "riscv" && ${MACHINE_ARCH:Mriscv*sf} != "")
1338876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/softfloat/Makefile.inc"
1342357939bSOlivier Houchard.endif
13516808549SKonstantin Belousov.if ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "amd64"
13616808549SKonstantin Belousov.include "${LIBC_SRCTOP}/x86/sys/Makefile.inc"
137071bca67SKonstantin Belousov.include "${LIBC_SRCTOP}/x86/gen/Makefile.inc"
13816808549SKonstantin Belousov.endif
139e1fe3dbaSRuslan Ermilov.if ${MK_NIS} != "no"
140c51d717fSRuslan ErmilovCFLAGS+= -DYP
1418876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/yp/Makefile.inc"
142c51d717fSRuslan Ermilov.endif
1438876613dSMarcel Moolenaar.include "${LIBC_SRCTOP}/capability/Makefile.inc"
144e1fe3dbaSRuslan Ermilov.if ${MK_HESIOD} != "no"
145c51d717fSRuslan ErmilovCFLAGS+= -DHESIOD
146c51d717fSRuslan Ermilov.endif
147e1fe3dbaSRuslan Ermilov.if ${MK_FP_LIBC} == "no"
148757edc65SDavid SchultzCFLAGS+= -DNO_FLOATING_POINT
149757edc65SDavid Schultz.endif
15006a99fe3SHajimu UMEMOTO.if ${MK_NS_CACHING} != "no"
15106a99fe3SHajimu UMEMOTOCFLAGS+= -DNS_CACHING
15206a99fe3SHajimu UMEMOTO.endif
1533dd425f7SSimon L. B. Nielsen.if defined(_FREEFALL_CONFIG)
1543dd425f7SSimon L. B. NielsenCFLAGS+=-D_FREEFALL_CONFIG
1553dd425f7SSimon L. B. Nielsen.endif
156c51d717fSRuslan Ermilov
157db2af393SPeter WemmSTATICOBJS+=${LIBC_NONSHARED_SRCS:S/.c$/.o/}
158db2af393SPeter Wemm
1598876613dSMarcel MoolenaarVERSION_DEF=${LIBC_SRCTOP}/Versions.def
16096e022f7SDaniel EischenSYMBOL_MAPS=${SYM_MAPS}
16196e022f7SDaniel EischenCFLAGS+= -DSYMBOL_VERSIONING
16296e022f7SDaniel Eischen
163c51d717fSRuslan Ermilov# If there are no machine dependent sources, append all the
164c51d717fSRuslan Ermilov# machine-independent sources:
165*20adba8bSGleb Popov.if empty(MDSRCS) || ${MK_MACHDEP_OPTIMIZATIONS} == no
166c51d717fSRuslan ErmilovSRCS+=	${MISRCS}
167c51d717fSRuslan Ermilov.else
168c51d717fSRuslan Ermilov# Append machine-dependent sources, then append machine-independent sources
169c51d717fSRuslan Ermilov# for which there is no machine-dependent variant.
170c51d717fSRuslan ErmilovSRCS+=	${MDSRCS}
171c51d717fSRuslan Ermilov.for _src in ${MISRCS}
172c51d717fSRuslan Ermilov.if ${MDSRCS:R:M${_src:R}} == ""
173c51d717fSRuslan ErmilovSRCS+=	${_src}
174c51d717fSRuslan Ermilov.endif
175c51d717fSRuslan Ermilov.endfor
176c51d717fSRuslan Ermilov.endif
17758f0484fSRodney W. Grimes
17858f0484fSRodney W. GrimesKQSRCS=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
17958f0484fSRodney W. Grimes	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
18058f0484fSRodney W. Grimes	subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
18146632c18SEd SchoutenKSRCS=	bcmp.c ffs.c ffsl.c fls.c flsl.c mcount.c strcat.c strchr.c \
18246632c18SEd Schouten	strcmp.c strcpy.c strlen.c strncpy.c strrchr.c
18358f0484fSRodney W. Grimes
1842c0959aeSWarner Loshlibkern: libkern.gen libkern.${LIBC_ARCH}
18558f0484fSRodney W. Grimes
18658f0484fSRodney W. Grimeslibkern.gen: ${KQSRCS} ${KSRCS}
1877a37b5fcSWill Andrews	${CP} ${LIBC_SRCTOP}/quad/quad.h ${.ALLSRC} ${DESTDIR}/sys/libkern
18858f0484fSRodney W. Grimes
1892c0959aeSWarner Loshlibkern.${LIBC_ARCH}:: ${KMSRCS}
19058f0484fSRodney W. Grimes.if defined(KMSRCS) && !empty(KMSRCS)
1917a37b5fcSWill Andrews	${CP} ${.ALLSRC} ${DESTDIR}/sys/libkern/${LIBC_ARCH}
19258f0484fSRodney W. Grimes.endif
19358f0484fSRodney W. Grimes
194d511b20aSEnji CooperHAS_TESTS=
1954b330699SEnji CooperSUBDIR.${MK_TESTS}+= tests
1962f121787SEnji Cooper
19758f0484fSRodney W. Grimes.include <bsd.lib.mk>
198042a0b7eSRuslan Ermilov
1992417a95eSEd Maste.if (${LIBC_ARCH} == amd64 || ${LIBC_ARCH} == i386) && \
2002417a95eSEd Maste    ${.TARGETS:Mall} == all && \
2012417a95eSEd Maste    defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mifunc} == ""
202f2be828fSSimon J. Gerraty.error ${LIBC_ARCH} libc requires linker ifunc support
2032417a95eSEd Maste.endif
2042417a95eSEd Maste
2057750ad47SMarcel Moolenaar.if !defined(_SKIP_BUILD)
2067750ad47SMarcel Moolenaar# We need libutil.h, get it directly to avoid
2077750ad47SMarcel Moolenaar# recording a build dependency
208dfdb6cf4SBryan DreweryCFLAGS+= -I${SRCTOP}/lib/libutil
2097750ad47SMarcel Moolenaar# Same issue with libm
210dfdb6cf4SBryan DreweryMSUN_ARCH_SUBDIR != ${MAKE} -B -C ${SRCTOP}/lib/msun -V ARCH_SUBDIR
2117750ad47SMarcel Moolenaar# unfortunately msun/src contains both private and public headers
212dfdb6cf4SBryan DreweryCFLAGS+= -I${SRCTOP}/lib/msun/${MSUN_ARCH_SUBDIR}
213aab5fee0SSimon J. Gerraty.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
214dfdb6cf4SBryan DreweryCFLAGS+= -I${SRCTOP}/lib/msun/x86
215aab5fee0SSimon J. Gerraty.endif
216dfdb6cf4SBryan DreweryCFLAGS+= -I${SRCTOP}/lib/msun/src
217aab5fee0SSimon J. Gerraty# and we do not want to record a dependency on msun
218aab5fee0SSimon J. Gerraty.if ${.MAKE.LEVEL} > 0
219aab5fee0SSimon J. GerratyGENDIRDEPS_FILTER+= N${RELDIR:H}/msun
220aab5fee0SSimon J. Gerraty.endif
2217750ad47SMarcel Moolenaar.endif
2227750ad47SMarcel Moolenaar
223042a0b7eSRuslan Ermilov# Disable warnings in contributed sources.
224271e7c59SRui PauloCWARNFLAGS:=	${.IMPSRC:Ngdtoa_*.c:C/^.+$/${CWARNFLAGS}/:C/^$/-w/}
225042df2e2SRuslan Ermilov# Disable stack protection for SSP symbols.
226042df2e2SRuslan ErmilovSSP_CFLAGS:=	${.IMPSRC:N*/stack_protector.c:C/^.+$/${SSP_CFLAGS}/}
227f4213b90SDavid Xu# Generate stack unwinding tables for cancellation points
228f4213b90SDavid XuCANCELPOINTS_CFLAGS:=	${.IMPSRC:Mcancelpoints_*:C/^.+$/${CANCELPOINTS_CFLAGS}/:C/^$//}
229