xref: /freebsd/lib/libc/Makefile (revision a321cc5dc908a14d42e57e2468923937f18c21fc)
1#	@(#)Makefile	8.2 (Berkeley) 2/3/94
2# $FreeBSD$
3
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})
18LIBC_ARCH=${MACHINE_ARCH}
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 sccsid strings, add -DLIBC_SCCS and -DSYSLIBC_SCCS
28# to CFLAGS below.  -DSYSLIBC_SCCS affects just the system call stubs.
29LIB=c
30SHLIB_MAJOR= 7
31SHLIB_LDSCRIPT=libc.ldscript
32SHLIB_LDSCRIPT_LINKS=libxnet.so
33WARNS?=	2
34CFLAGS+=-I${LIBC_SRCTOP}/include -I${LIBC_SRCTOP}/../../include
35CFLAGS+=-I${LIBC_SRCTOP}/${LIBC_ARCH}
36.if ${MK_NLS} != "no"
37CFLAGS+=-DNLS
38.endif
39CLEANFILES+=tags
40INSTALL_PIC_ARCHIVE=
41PRECIOUSLIB=
42
43.ifndef NO_THREAD_STACK_UNWIND
44CANCELPOINTS_CFLAGS=-fexceptions
45CFLAGS+=${CANCELPOINTS_CFLAGS}
46.endif
47
48#
49# Link with static libcompiler_rt.a.
50#
51LDFLAGS+= -nodefaultlibs
52LIBADD+=	compiler_rt
53
54.if ${MK_SSP} != "no"
55LIBADD+=	ssp_nonshared
56.endif
57
58# Extras that live in either libc.a or libc_nonshared.a
59LIBC_NONSHARED_SRCS=
60
61# Define (empty) variables so that make doesn't give substitution
62# errors if the included makefiles don't change these:
63MDSRCS=
64MISRCS=
65MDASM=
66MIASM=
67NOASM=
68
69.include "${LIBC_SRCTOP}/${LIBC_ARCH}/Makefile.inc"
70.include "${LIBC_SRCTOP}/db/Makefile.inc"
71.include "${LIBC_SRCTOP}/compat-43/Makefile.inc"
72.include "${LIBC_SRCTOP}/gdtoa/Makefile.inc"
73.include "${LIBC_SRCTOP}/gen/Makefile.inc"
74.include "${LIBC_SRCTOP}/gmon/Makefile.inc"
75.if ${MK_ICONV} != "no"
76.include "${LIBC_SRCTOP}/iconv/Makefile.inc"
77.endif
78.include "${LIBC_SRCTOP}/inet/Makefile.inc"
79.include "${LIBC_SRCTOP}/isc/Makefile.inc"
80.include "${LIBC_SRCTOP}/locale/Makefile.inc"
81.include "${LIBC_SRCTOP}/md/Makefile.inc"
82.include "${LIBC_SRCTOP}/nameser/Makefile.inc"
83.include "${LIBC_SRCTOP}/net/Makefile.inc"
84.include "${LIBC_SRCTOP}/nls/Makefile.inc"
85.include "${LIBC_SRCTOP}/posix1e/Makefile.inc"
86.if ${LIBC_ARCH} != "aarch64" && \
87    ${LIBC_ARCH} != "amd64" && \
88    ${LIBC_ARCH} != "powerpc64" && \
89    ${LIBC_ARCH} != "riscv" && \
90    ${LIBC_ARCH} != "sparc64" && \
91    ${MACHINE_ARCH:Mmipsn32*} == "" && \
92    ${MACHINE_ARCH:Mmips64*} == ""
93.include "${LIBC_SRCTOP}/quad/Makefile.inc"
94.endif
95.include "${LIBC_SRCTOP}/regex/Makefile.inc"
96.include "${LIBC_SRCTOP}/resolv/Makefile.inc"
97.include "${LIBC_SRCTOP}/stdio/Makefile.inc"
98.include "${LIBC_SRCTOP}/stdlib/Makefile.inc"
99.include "${LIBC_SRCTOP}/stdlib/jemalloc/Makefile.inc"
100.include "${LIBC_SRCTOP}/stdtime/Makefile.inc"
101.include "${LIBC_SRCTOP}/string/Makefile.inc"
102.include "${LIBC_SRCTOP}/sys/Makefile.inc"
103.include "${LIBC_SRCTOP}/secure/Makefile.inc"
104.include "${LIBC_SRCTOP}/rpc/Makefile.inc"
105.include "${LIBC_SRCTOP}/uuid/Makefile.inc"
106.include "${LIBC_SRCTOP}/xdr/Makefile.inc"
107.if (${LIBC_ARCH} == "arm" && ${MACHINE_ARCH} != "armv6hf") ||\
108     ${LIBC_ARCH} == "mips"
109.include "${LIBC_SRCTOP}/softfloat/Makefile.inc"
110.endif
111.if ${MK_NIS} != "no"
112CFLAGS+= -DYP
113.include "${LIBC_SRCTOP}/yp/Makefile.inc"
114.endif
115.include "${LIBC_SRCTOP}/capability/Makefile.inc"
116.if ${MK_HESIOD} != "no"
117CFLAGS+= -DHESIOD
118.endif
119.if ${MK_FP_LIBC} == "no"
120CFLAGS+= -DNO_FLOATING_POINT
121.endif
122.if ${MK_NS_CACHING} != "no"
123CFLAGS+= -DNS_CACHING
124.endif
125.if defined(_FREEFALL_CONFIG)
126CFLAGS+=-D_FREEFALL_CONFIG
127.endif
128
129STATICOBJS+=${LIBC_NONSHARED_SRCS:S/.c$/.o/}
130
131VERSION_DEF=${LIBC_SRCTOP}/Versions.def
132SYMBOL_MAPS=${SYM_MAPS}
133CFLAGS+= -DSYMBOL_VERSIONING
134
135# If there are no machine dependent sources, append all the
136# machine-independent sources:
137.if empty(MDSRCS)
138SRCS+=	${MISRCS}
139.else
140# Append machine-dependent sources, then append machine-independent sources
141# for which there is no machine-dependent variant.
142SRCS+=	${MDSRCS}
143.for _src in ${MISRCS}
144.if ${MDSRCS:R:M${_src:R}} == ""
145SRCS+=	${_src}
146.endif
147.endfor
148.endif
149
150KQSRCS=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
151	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
152	subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
153KSRCS=	bcmp.c ffs.c ffsl.c fls.c flsl.c mcount.c strcat.c strchr.c \
154	strcmp.c strcpy.c strlen.c strncpy.c strrchr.c
155
156libkern: libkern.gen libkern.${LIBC_ARCH}
157
158libkern.gen: ${KQSRCS} ${KSRCS}
159	${CP} ${LIBC_SRCTOP}/quad/quad.h ${.ALLSRC} ${DESTDIR}/sys/libkern
160
161libkern.${LIBC_ARCH}:: ${KMSRCS}
162.if defined(KMSRCS) && !empty(KMSRCS)
163	${CP} ${.ALLSRC} ${DESTDIR}/sys/libkern/${LIBC_ARCH}
164.endif
165
166.if ${MK_TESTS} != "no"
167SUBDIR+=	tests
168.endif
169
170.include <bsd.lib.mk>
171
172.if !defined(_SKIP_BUILD)
173# We need libutil.h, get it directly to avoid
174# recording a build dependency
175CFLAGS+= -I${SRCTOP}/lib/libutil
176# Same issue with libm
177MSUN_ARCH_SUBDIR != ${MAKE} -B -C ${SRCTOP}/lib/msun -V ARCH_SUBDIR
178# unfortunately msun/src contains both private and public headers
179CFLAGS+= -I${SRCTOP}/lib/msun/${MSUN_ARCH_SUBDIR}
180.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
181CFLAGS+= -I${SRCTOP}/lib/msun/x86
182.endif
183CFLAGS+= -I${SRCTOP}/lib/msun/src
184# and we do not want to record a dependency on msun
185.if ${.MAKE.LEVEL} > 0
186GENDIRDEPS_FILTER+= N${RELDIR:H}/msun
187.endif
188.endif
189
190# Disable warnings in contributed sources.
191CWARNFLAGS:=	${.IMPSRC:Ngdtoa_*.c:C/^.+$/${CWARNFLAGS}/:C/^$/-w/}
192# XXX For now, we don't allow libc to be compiled with
193# -fstack-protector-all because it breaks rtld.  We may want to make a librtld
194# in the future to circumvent this.
195SSP_CFLAGS:=	${SSP_CFLAGS:S/^-fstack-protector-all$/-fstack-protector/}
196# Disable stack protection for SSP symbols.
197SSP_CFLAGS:=	${.IMPSRC:N*/stack_protector.c:C/^.+$/${SSP_CFLAGS}/}
198# Generate stack unwinding tables for cancellation points
199CANCELPOINTS_CFLAGS:=	${.IMPSRC:Mcancelpoints_*:C/^.+$/${CANCELPOINTS_CFLAGS}/:C/^$//}
200