xref: /freebsd/lib/libc/Makefile (revision 7899f917b1c0ea178f1d2be0cfb452086d079d23)
1PACKAGE=	clibs
2SHLIBDIR?= /lib
3
4.include <src.opts.mk>
5
6LIBC_SRCTOP?= ${.CURDIR}
7LIBSYS_SRCTOP?=	${.CURDIR:H}/libsys
8
9# Pick the current architecture directory for libc. In general, this is named
10# MACHINE_CPUARCH, but some ABIs are different enough to require their own libc,
11# so allow a directory named MACHINE_ARCH to override this (though treat
12# powerpc64le and powerpc64 the same).
13# Note: This is copied to msun/Makefile
14M=${MACHINE_ARCH:S/powerpc64le/powerpc64/}
15.if exists(${LIBC_SRCTOP}/${M})
16LIBC_ARCH=${M}
17.else
18LIBC_ARCH=${MACHINE_CPUARCH}
19.endif
20
21CFLAGS+=-D_FORTIFY_SOURCE_read=_read
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}
43CFLAGS+=-I${LIBSYS_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# Use a more efficient TLS model for libc since we can reasonably assume that
58# it will be loaded during program startup.
59CFLAGS+= -ftls-model=initial-exec
60
61#
62# Link with static libcompiler_rt.a.
63#
64LDFLAGS+= -nodefaultlibs
65LIBADD+=	compiler_rt
66LIBADD+=	sys
67.if defined(COMPAT_libcompat)
68# XXX: work around gcc -m32 + bfd ld path issue for DT_NEEDED symbols.
69# https://sourceware.org/bugzilla/show_bug.cgi?id=31395
70LDFLAGS+=	-Wl,--rpath=/usr/lib${COMPAT_libcompat}
71.endif
72
73LDFLAGS+=-Wl,--auxiliary,libsys.so.7
74
75.if ${MK_SSP} != "no" && \
76    (${LIBC_ARCH} == "i386" || ${LIBC_ARCH:Mpowerpc*} != "")
77LIBADD+=	ssp_nonshared
78.endif
79
80# Extras that live in either libc.a or libc_nonshared.a
81LIBC_NONSHARED_SRCS=
82
83RTLD_ELF_DIR=${SRCTOP}/libexec/rtld-elf
84.if exists(${RTLD_ELF_DIR}/${MACHINE_ARCH:S/powerpc64le/powerpc64/})
85RTLD_ARCH=	${MACHINE_ARCH:S/powerpc64le/powerpc64/}
86.else
87RTLD_ARCH=	${MACHINE_CPUARCH}
88.endif
89RTLD_HDRS= -I${RTLD_ELF_DIR}/${RTLD_ARCH} -I${RTLD_ELF_DIR}
90
91# Define (empty) variables so that make doesn't give substitution
92# errors if the included makefiles don't change these:
93MDSRCS=
94MISRCS=
95MDASM=
96MIASM=
97NOASM=
98
99.include "${LIBC_SRCTOP}/${LIBC_ARCH}/Makefile.inc"
100.include "${LIBC_SRCTOP}/csu/Makefile.inc"
101.include "${LIBC_SRCTOP}/db/Makefile.inc"
102.include "${LIBC_SRCTOP}/compat-43/Makefile.inc"
103.include "${LIBC_SRCTOP}/gdtoa/Makefile.inc"
104.include "${LIBC_SRCTOP}/gen/Makefile.inc"
105.include "${LIBC_SRCTOP}/gmon/Makefile.inc"
106.if ${MK_ICONV} != "no"
107.include "${LIBC_SRCTOP}/iconv/Makefile.inc"
108.endif
109.include "${LIBC_SRCTOP}/inet/Makefile.inc"
110.include "${LIBC_SRCTOP}/isc/Makefile.inc"
111.include "${LIBC_SRCTOP}/locale/Makefile.inc"
112.include "${LIBC_SRCTOP}/md/Makefile.inc"
113.include "${LIBC_SRCTOP}/nameser/Makefile.inc"
114.include "${LIBC_SRCTOP}/net/Makefile.inc"
115.include "${LIBC_SRCTOP}/nls/Makefile.inc"
116.include "${LIBC_SRCTOP}/posix1e/Makefile.inc"
117.if ${MACHINE_ABI:Mlong32}
118.include "${LIBC_SRCTOP}/quad/Makefile.inc"
119.endif
120.include "${LIBC_SRCTOP}/regex/Makefile.inc"
121.include "${LIBC_SRCTOP}/resolv/Makefile.inc"
122.include "${LIBC_SRCTOP}/stdio/Makefile.inc"
123.include "${LIBC_SRCTOP}/stdlib/Makefile.inc"
124.include "${LIBC_SRCTOP}/stdtime/Makefile.inc"
125.include "${LIBC_SRCTOP}/string/Makefile.inc"
126.include "${LIBC_SRCTOP}/sys/Makefile.inc"
127.include "${LIBC_SRCTOP}/secure/Makefile.inc"
128.include "${LIBC_SRCTOP}/rpc/Makefile.inc"
129.include "${LIBC_SRCTOP}/uuid/Makefile.inc"
130.include "${LIBC_SRCTOP}/xdr/Makefile.inc"
131.if (${LIBC_ARCH} == "arm" && (defined(CPUTYPE) && ${CPUTYPE:M*soft*}))
132.include "${LIBC_SRCTOP}/softfloat/Makefile.inc"
133.endif
134.if ${LIBC_ARCH} == "i386" || ${LIBC_ARCH} == "amd64"
135.include "${LIBC_SRCTOP}/x86/gen/Makefile.inc"
136.endif
137.if ${MK_NIS} != "no"
138CFLAGS+= -DYP
139.include "${LIBC_SRCTOP}/yp/Makefile.inc"
140.endif
141.include "${LIBC_SRCTOP}/capability/Makefile.inc"
142.if ${MK_HESIOD} != "no"
143CFLAGS+= -DHESIOD
144.endif
145.if ${MK_FP_LIBC} == "no"
146CFLAGS+= -DNO_FLOATING_POINT
147.endif
148.if ${MK_NS_CACHING} != "no"
149CFLAGS+= -DNS_CACHING
150.endif
151.if defined(_FREEFALL_CONFIG)
152CFLAGS+=-D_FREEFALL_CONFIG
153.endif
154
155STATICOBJS+=${LIBC_NONSHARED_SRCS:S/.c$/.o/}
156
157VERSION_DEF=${LIBC_SRCTOP}/Versions.def
158SYMBOL_MAPS=${SYM_MAPS}
159
160# If there are no machine dependent sources, append all the
161# machine-independent sources:
162.if empty(MDSRCS) || ${MK_MACHDEP_OPTIMIZATIONS} == no
163SRCS+=	${MISRCS}
164.else
165# Append machine-dependent sources, then append machine-independent sources
166# for which there is no machine-dependent variant.
167SRCS+=	${MDSRCS}
168.for _src in ${MISRCS}
169.if ${MDSRCS:R:M${_src:R}} == ""
170SRCS+=	${_src}
171.endif
172.endfor
173.endif
174
175KQSRCS=	adddi3.c anddi3.c ashldi3.c ashrdi3.c cmpdi2.c divdi3.c iordi3.c \
176	lshldi3.c lshrdi3.c moddi3.c muldi3.c negdi2.c notdi2.c qdivrem.c \
177	subdi3.c ucmpdi2.c udivdi3.c umoddi3.c xordi3.c
178KSRCS=	bcmp.c ffs.c ffsl.c fls.c flsl.c mcount.c strcat.c strchr.c \
179	strcmp.c strcpy.c strlen.c strncpy.c strrchr.c
180
181libkern: libkern.gen libkern.${LIBC_ARCH}
182
183libkern.gen: ${KQSRCS} ${KSRCS}
184	${CP} ${LIBC_SRCTOP}/quad/quad.h ${.ALLSRC} ${DESTDIR}/sys/libkern
185
186libkern.${LIBC_ARCH}:: ${KMSRCS}
187.if defined(KMSRCS) && !empty(KMSRCS)
188	${CP} ${.ALLSRC} ${DESTDIR}/sys/libkern/${LIBC_ARCH}
189.endif
190
191HAS_TESTS=
192SUBDIR.${MK_TESTS}+= tests
193
194.include <bsd.lib.mk>
195
196.if (${LIBC_ARCH} == amd64 || ${LIBC_ARCH} == i386) && \
197    ${.TARGETS:Mall} == all && \
198    defined(LINKER_FEATURES) && ${LINKER_FEATURES:Mifunc} == ""
199.error ${LIBC_ARCH} libc requires linker ifunc support
200.endif
201
202.if !defined(_SKIP_BUILD)
203# We need libutil.h, get it directly to avoid
204# recording a build dependency
205CFLAGS+= -I${SRCTOP}/lib/libutil
206# Same issue with libm
207MSUN_ARCH_SUBDIR != ${MAKE} -B -C ${SRCTOP}/lib/msun -V ARCH_SUBDIR
208# unfortunately msun/src contains both private and public headers
209CFLAGS+= -I${SRCTOP}/lib/msun/${MSUN_ARCH_SUBDIR}
210.if ${MACHINE_CPUARCH} == "i386" || ${MACHINE_CPUARCH} == "amd64"
211CFLAGS+= -I${SRCTOP}/lib/msun/x86
212.endif
213CFLAGS+= -I${SRCTOP}/lib/msun/src
214# and we do not want to record a dependency on msun
215.if ${.MAKE.LEVEL} > 0
216GENDIRDEPS_FILTER+= N${RELDIR:H}/msun
217.endif
218.endif
219
220# Disable warnings in contributed sources.
221CWARNFLAGS:=	${.IMPSRC:Ngdtoa_*.c:C/^.+$/${CWARNFLAGS}/:C/^$/-w/}
222# Disable stack protection for SSP symbols.
223SSP_CFLAGS:=	${.IMPSRC:N*/stack_protector.c:C/^.+$/${SSP_CFLAGS}/}
224# Generate stack unwinding tables for cancellation points
225CANCELPOINTS_CFLAGS:=	${.IMPSRC:Mcancelpoints_*:C/^.+$/${CANCELPOINTS_CFLAGS}/:C/^$//}
226