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