xref: /freebsd-13-stable/lib/libc/Makefile (revision c364608261d17d2d6aa0ff64085bcf908b8fb5a0)
1#	@(#)Makefile	8.2 (Berkeley) 2/3/94
2
3PACKAGE=	clibs
4SHLIBDIR?= /lib
5
6.include <src.opts.mk>
7
8# Force building of libc_pic.a
9MK_TOOLCHAIN=	yes
10
11LIBC_SRCTOP?= ${.CURDIR}
12
13# Pick the current architecture directory for libc. In general, this is
14# named MACHINE_CPUARCH, but some ABIs are different enough to require
15# their own libc, so allow a directory named MACHINE_ARCH to override this.
16
17.if exists(${LIBC_SRCTOP}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
18LIBC_ARCH=${MACHINE_ARCH:S/powerpc64le/powerpc64/}
19.else
20LIBC_ARCH=${MACHINE_CPUARCH}
21.endif
22
23# All library objects contain FreeBSD revision strings by default; they may be
24# excluded as a space-saving measure.  To produce a library that does
25# not contain these strings, add -DSTRIP_FBSDID (see <sys/cdefs.h>) to CFLAGS
26# below.  Note: there are no IDs for syscall stubs whose sources are generated.
27# To include legacy CSRG SCCS ID strings, remove -DNO__SCCSID from CFLAGS.
28# To include RCS ID strings from other BSD projects, remove -DNO__RCSID from CFLAGS.
29CFLAGS+=-DNO__SCCSID -DNO__RCSID
30
31LIB=c
32SHLIB_MAJOR= 7
33.if ${MK_SSP} != "no" && \
34    (${LIBC_ARCH} == "i386" || ${LIBC_ARCH:Mpowerpc*} != "")
35SHLIB_LDSCRIPT=libc.ldscript
36.else
37SHLIB_LDSCRIPT=libc_nossp.ldscript
38.endif
39SHLIB_LDSCRIPT_LINKS=libxnet.so
40WARNS?=	2
41CFLAGS+=-I${LIBC_SRCTOP}/include -I${SRCTOP}/include
42CFLAGS+=-I${LIBC_SRCTOP}/${LIBC_ARCH}
43.if ${MK_NLS} != "no"
44CFLAGS+=-DNLS
45.endif
46CLEANFILES+=tags
47INSTALL_PIC_ARCHIVE=
48BUILD_NOSSP_PIC_ARCHIVE=
49PRECIOUSLIB=
50
51.ifndef NO_THREAD_STACK_UNWIND
52CANCELPOINTS_CFLAGS=-fexceptions
53CFLAGS+=${CANCELPOINTS_CFLAGS}
54.endif
55
56# Use a more efficient TLS model for libc since we can reasonably assume that
57# it will be loaded during program startup.
58CFLAGS+= -ftls-model=initial-exec
59
60#
61# Link with static libcompiler_rt.a.
62#
63LDFLAGS+= -nodefaultlibs
64LIBADD+=	compiler_rt
65
66.if ${MK_SSP} != "no" && \
67    (${LIBC_ARCH} == "i386" || ${LIBC_ARCH:Mpowerpc*} != "")
68LIBADD+=	ssp_nonshared
69.endif
70
71# Extras that live in either libc.a or libc_nonshared.a
72LIBC_NONSHARED_SRCS=
73
74RTLD_ELF_DIR=${SRCTOP}/libexec/rtld-elf
75.if exists(${RTLD_ELF_DIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
76RTLD_ARCH=	${MACHINE_ARCH:S/powerpc64le/powerpc64/}
77.else
78RTLD_ARCH=	${MACHINE_CPUARCH}
79.endif
80RTLD_HDRS= -I${RTLD_ELF_DIR}/${RTLD_ARCH} -I${RTLD_ELF_DIR}
81
82# Define (empty) variables so that make doesn't give substitution
83# errors if the included makefiles don't change these:
84MDSRCS=
85MISRCS=
86MDASM=
87MIASM=
88NOASM=
89
90.include "${LIBC_SRCTOP}/${LIBC_ARCH}/Makefile.inc"
91.include "${LIBC_SRCTOP}/csu/Makefile.inc"
92.include "${LIBC_SRCTOP}/db/Makefile.inc"
93.include "${LIBC_SRCTOP}/compat-43/Makefile.inc"
94.include "${LIBC_SRCTOP}/gdtoa/Makefile.inc"
95.include "${LIBC_SRCTOP}/gen/Makefile.inc"
96.include "${LIBC_SRCTOP}/gmon/Makefile.inc"
97.if ${MK_ICONV} != "no"
98.include "${LIBC_SRCTOP}/iconv/Makefile.inc"
99.endif
100.include "${LIBC_SRCTOP}/inet/Makefile.inc"
101.include "${LIBC_SRCTOP}/isc/Makefile.inc"
102.include "${LIBC_SRCTOP}/locale/Makefile.inc"
103.include "${LIBC_SRCTOP}/md/Makefile.inc"
104.include "${LIBC_SRCTOP}/nameser/Makefile.inc"
105.include "${LIBC_SRCTOP}/net/Makefile.inc"
106.include "${LIBC_SRCTOP}/nls/Makefile.inc"
107.include "${LIBC_SRCTOP}/posix1e/Makefile.inc"
108.if ${LIBC_ARCH} != "aarch64" && \
109    ${LIBC_ARCH} != "amd64" && \
110    ${LIBC_ARCH} != "powerpc64" && \
111    ${LIBC_ARCH} != "riscv" && \
112    ${MACHINE_ARCH:Mmipsn32*} == "" && \
113    ${MACHINE_ARCH:Mmips64*} == ""
114.include "${LIBC_SRCTOP}/quad/Makefile.inc"
115.endif
116.include "${LIBC_SRCTOP}/regex/Makefile.inc"
117.include "${LIBC_SRCTOP}/resolv/Makefile.inc"
118.include "${LIBC_SRCTOP}/stdio/Makefile.inc"
119.include "${LIBC_SRCTOP}/stdlib/Makefile.inc"
120.include "${LIBC_SRCTOP}/stdlib/jemalloc/Makefile.inc"
121.include "${LIBC_SRCTOP}/stdtime/Makefile.inc"
122.include "${LIBC_SRCTOP}/string/Makefile.inc"
123.include "${LIBC_SRCTOP}/sys/Makefile.inc"
124.include "${LIBC_SRCTOP}/secure/Makefile.inc"
125.include "${LIBC_SRCTOP}/rpc/Makefile.inc"
126.include "${LIBC_SRCTOP}/uuid/Makefile.inc"
127.include "${LIBC_SRCTOP}/xdr/Makefile.inc"
128.if (${LIBC_ARCH} == "arm" && \
129	(${MACHINE_ARCH:Marmv[67]*} == "" || (defined(CPUTYPE) && ${CPUTYPE:M*soft*}))) || \
130    (${LIBC_ARCH} == "mips" && ${MACHINE_ARCH:Mmips*hf} == "") || \
131    (${LIBC_ARCH} == "riscv" && ${MACHINE_ARCH:Mriscv*sf} != "")
132.include "${LIBC_SRCTOP}/softfloat/Makefile.inc"
133.endif
134.if ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "amd64"
135.include "${LIBC_SRCTOP}/x86/sys/Makefile.inc"
136.include "${LIBC_SRCTOP}/x86/gen/Makefile.inc"
137.endif
138.if ${MK_NIS} != "no"
139CFLAGS+= -DYP
140.include "${LIBC_SRCTOP}/yp/Makefile.inc"
141.endif
142.include "${LIBC_SRCTOP}/capability/Makefile.inc"
143.if ${MK_HESIOD} != "no"
144CFLAGS+= -DHESIOD
145.endif
146.if ${MK_FP_LIBC} == "no"
147CFLAGS+= -DNO_FLOATING_POINT
148.endif
149.if ${MK_NS_CACHING} != "no"
150CFLAGS+= -DNS_CACHING
151.endif
152.if defined(_FREEFALL_CONFIG)
153CFLAGS+=-D_FREEFALL_CONFIG
154.endif
155
156STATICOBJS+=${LIBC_NONSHARED_SRCS:S/.c$/.o/}
157
158VERSION_DEF=${LIBC_SRCTOP}/Versions.def
159SYMBOL_MAPS=${SYM_MAPS}
160CFLAGS+= -DSYMBOL_VERSIONING
161
162# If there are no machine dependent sources, append all the
163# machine-independent sources:
164.if empty(MDSRCS) || ${MK_MACHDEP_OPTIMIZATIONS} == no
165SRCS+=	${MISRCS}
166.else
167# Append machine-dependent sources, then append machine-independent sources
168# for which there is no machine-dependent variant.
169SRCS+=	${MDSRCS}
170.for _src in ${MISRCS}
171.if ${MDSRCS:R:M${_src:R}} == ""
172SRCS+=	${_src}
173.endif
174.endfor
175.endif
176
177KQSRCS=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
178	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
179	subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
180KSRCS=	bcmp.c ffs.c ffsl.c fls.c flsl.c mcount.c strcat.c strchr.c \
181	strcmp.c strcpy.c strlen.c strncpy.c strrchr.c
182
183libkern: libkern.gen libkern.${LIBC_ARCH}
184
185libkern.gen: ${KQSRCS} ${KSRCS}
186	${CP} ${LIBC_SRCTOP}/quad/quad.h ${.ALLSRC} ${DESTDIR}/sys/libkern
187
188libkern.${LIBC_ARCH}:: ${KMSRCS}
189.if defined(KMSRCS) && !empty(KMSRCS)
190	${CP} ${.ALLSRC} ${DESTDIR}/sys/libkern/${LIBC_ARCH}
191.endif
192
193HAS_TESTS=
194SUBDIR.${MK_TESTS}+= tests
195
196.include <bsd.lib.mk>
197
198.if (${LIBC_ARCH} == amd64 || ${LIBC_ARCH} == i386) && \
199    ${.TARGETS:Mall} == all && \
200    defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mifunc} == ""
201.error ${LIBC_ARCH} libc requires linker ifunc support
202.endif
203
204.if !defined(_SKIP_BUILD)
205# We need libutil.h, get it directly to avoid
206# recording a build dependency
207CFLAGS+= -I${SRCTOP}/lib/libutil
208# Same issue with libm
209MSUN_ARCH_SUBDIR != ${MAKE} -B -C ${SRCTOP}/lib/msun -V ARCH_SUBDIR
210# unfortunately msun/src contains both private and public headers
211CFLAGS+= -I${SRCTOP}/lib/msun/${MSUN_ARCH_SUBDIR}
212.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
213CFLAGS+= -I${SRCTOP}/lib/msun/x86
214.endif
215CFLAGS+= -I${SRCTOP}/lib/msun/src
216# and we do not want to record a dependency on msun
217.if ${.MAKE.LEVEL} > 0
218GENDIRDEPS_FILTER+= N${RELDIR:H}/msun
219.endif
220.endif
221
222# Disable warnings in contributed sources.
223CWARNFLAGS:=	${.IMPSRC:Ngdtoa_*.c:C/^.+$/${CWARNFLAGS}/:C/^$/-w/}
224# Disable stack protection for SSP symbols.
225SSP_CFLAGS:=	${.IMPSRC:N*/stack_protector.c:C/^.+$/${SSP_CFLAGS}/}
226# Generate stack unwinding tables for cancellation points
227CANCELPOINTS_CFLAGS:=	${.IMPSRC:Mcancelpoints_*:C/^.+$/${CANCELPOINTS_CFLAGS}/:C/^$//}
228