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