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