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