xref: /minix/share/mk/bsd.lib.mk (revision ebfedea0)
1#	$NetBSD: bsd.lib.mk,v 1.342 2013/10/18 16:06:52 christos Exp $
2#	@(#)bsd.lib.mk	8.3 (Berkeley) 4/22/94
3
4.include <bsd.init.mk>
5.include <bsd.shlib.mk>
6.include <bsd.gcc.mk>
7# Pull in <bsd.sys.mk> here so we can override its .c.o rule
8.include <bsd.sys.mk>
9
10LIBISMODULE?=	no
11LIBISPRIVATE?=	no
12LIBISCXX?=	no
13
14.if ${LIBISMODULE} != "no"
15_LIB_PREFIX?=	# empty
16MKDEBUGLIB:=	no
17MKLINT:=	no
18MKPICINSTALL:=	no
19MKPROFILE:=	no
20MKSTATICLIB:=	no
21.else
22_LIB_PREFIX?=	lib
23.endif
24
25.if ${LIBISPRIVATE} != "no"
26MKDEBUGLIB:=	no
27MKLINT:=	no
28MKPICINSTALL:=	no
29. if defined(NOSTATICLIB) && ${MKPICLIB} != "no"
30MKSTATICLIB:=	no
31. else
32MKPIC:=		no
33. endif
34MKPROFILE:=	no
35.endif
36
37##### Basic targets
38.PHONY:		checkver libinstall
39realinstall:	checkver libinstall
40
41##### LIB specific flags.
42# XXX: This is needed for programs that link with .a libraries
43# Perhaps a more correct solution is to always generate _pic.a
44# files or always have a shared library.
45.if defined(MKPIE) && (${MKPIE} != "no")
46CFLAGS+=        ${PIE_CFLAGS}
47AFLAGS+=        ${PIE_AFLAGS}
48.endif
49
50##### Libraries that this may depend upon.
51.if defined(LIBDPLIBS) && ${MKPIC} != "no"				# {
52.for _lib _dir in ${LIBDPLIBS}
53.if !defined(LIBDO.${_lib})
54LIBDO.${_lib}!=	cd "${_dir}" && ${PRINTOBJDIR}
55.MAKEOVERRIDES+=LIBDO.${_lib}
56.endif
57.if ${LIBDO.${_lib}} == "_external"
58LDADD+=		-l${_lib}
59.else
60LDADD+=		-L${LIBDO.${_lib}} -l${_lib}
61DPADD+=		${LIBDO.${_lib}}/lib${_lib}.so	# Don't use _LIB_PREFIX
62.endif
63.endfor
64.endif									# }
65
66##### Build and install rules
67MKDEP_SUFFIXES?=	.o .po .pico .go .ln
68
69.if !defined(SHLIB_MAJOR) && exists(${SHLIB_VERSION_FILE})		# {
70SHLIB_MAJOR != . ${SHLIB_VERSION_FILE} ; echo $$major
71SHLIB_MINOR != . ${SHLIB_VERSION_FILE} ; echo $$minor
72SHLIB_TEENY != . ${SHLIB_VERSION_FILE} ; echo $$teeny
73
74DPADD+=	${SHLIB_VERSION_FILE}
75
76# Check for higher installed library versions.
77.if !defined(NOCHECKVER) && !defined(NOCHECKVER_${LIB}) && \
78	exists(${NETBSDSRCDIR}/lib/checkver)
79checkver:
80	@(cd "${.CURDIR}" && \
81	    HOST_SH=${HOST_SH:Q} AWK=${TOOL_AWK:Q} \
82	    ${HOST_SH} ${NETBSDSRCDIR}/lib/checkver -v ${SHLIB_VERSION_FILE} \
83		    -d ${_DEST.OBJ} ${LIB})
84.endif
85.endif									# }
86
87.if !target(checkver)
88checkver:
89.endif
90
91print-shlib-major:
92.if defined(SHLIB_MAJOR) && ${MKPIC} != "no"
93	@echo ${SHLIB_MAJOR}
94.else
95	@false
96.endif
97
98print-shlib-minor:
99.if defined(SHLIB_MINOR) && ${MKPIC} != "no"
100	@echo ${SHLIB_MINOR}
101.else
102	@false
103.endif
104
105print-shlib-teeny:
106.if defined(SHLIB_TEENY) && ${MKPIC} != "no"
107	@echo ${SHLIB_TEENY}
108.else
109	@false
110.endif
111
112.if defined(SHLIB_MAJOR) && !empty(SHLIB_MAJOR)				# {
113.if defined(SHLIB_MINOR) && !empty(SHLIB_MINOR)
114.if defined(SHLIB_TEENY) && !empty(SHLIB_TEENY)
115SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}.${SHLIB_TEENY}
116.else
117SHLIB_FULLVERSION=${SHLIB_MAJOR}.${SHLIB_MINOR}
118.endif
119.else
120SHLIB_FULLVERSION=${SHLIB_MAJOR}
121.endif
122.endif									# }
123
124# add additional suffixes not exported.
125# .po is used for profiling object files.
126# .pico is used for PIC object files.
127.SUFFIXES: .out .a .ln .pico .po .go .o .s .S .c .cc .cpp .cxx .C .m .F .f .r .y .l .cl .p .h
128.SUFFIXES: .sh .m4 .m
129
130
131# Set PICFLAGS to cc flags for producing position-independent code,
132# if not already set.
133
134# Data-driven table using make variables to control how shared libraries
135# are built for different platforms and object formats.
136# SHLIB_MAJOR, SHLIB_MINOR, SHLIB_TEENY: Major, minor, and teeny version
137#			numbers of shared library
138# SHLIB_SOVERSION:	version number to be compiled into a shared library
139#			via -soname. Usualy ${SHLIB_MAJOR} on ELF.
140#			NetBSD/pmax used to use ${SHLIB_MAJOR}[.${SHLIB_MINOR}
141#			[.${SHLIB_TEENY}]]
142# SHLIB_SHFLAGS:	Flags to tell ${LD} to emit shared library.
143#			with ELF, also set shared-lib version for ld.so.
144# SHLIB_LDSTARTFILE:	support .o file, call C++ file-level constructors
145# SHLIB_LDENDFILE:	support .o file, call C++ file-level destructors
146
147PICFLAGS ?= -fPIC
148
149.if ${MKPICLIB} != "no"
150CSHLIBFLAGS+= ${PICFLAGS}
151.endif
152
153.if defined(CSHLIBFLAGS) && !empty(CSHLIBFLAGS)
154MKSHLIBOBJS= yes
155.else
156MKSHLIBOBJS= no
157.endif
158
159.if (defined(MKDEBUG) && (${MKDEBUG} != "no")) || \
160    (defined(CFLAGS) && !empty(CFLAGS:M*-g*))
161# We only add -g to the shared library objects
162# because we don't currently split .a archives.
163CSHLIBFLAGS+=	-g
164.if ${LIBISPRIVATE} == "yes"
165CFLAGS+=	-g
166.endif
167.endif
168
169# Platform-independent linker flags for ELF shared libraries
170SHLIB_SOVERSION=	${SHLIB_MAJOR}
171SHLIB_SHFLAGS=		-Wl,-soname,${_LIB}.so.${SHLIB_SOVERSION}
172SHLIB_SHFLAGS+=		-Wl,--warn-shared-textrel
173.if !defined(SHLIB_MKMAP) || ${SHLIB_MKMAP} != "no"
174SHLIB_SHFLAGS+=		-Wl,-Map=${_LIB}.so.${SHLIB_SOVERSION}.map
175.endif
176CLEANFILES+=		${_LIB}.so.${SHLIB_SOVERSION}.map
177SHLIB_LDSTARTFILE?=	${_GCC_CRTI} ${_GCC_CRTBEGINS}
178SHLIB_LDENDFILE?=	${_GCC_CRTENDS} ${_GCC_CRTN}
179
180CFLAGS+=	${COPTS}
181OBJCFLAGS+=	${OBJCOPTS}
182AFLAGS+=	${COPTS}
183FFLAGS+=	${FOPTS}
184
185.if defined(CTFCONVERT)
186.if defined(CFLAGS) && !empty(CFLAGS:M*-g*)
187CTFFLAGS+=	-g
188.endif
189.endif
190
191LIBSTRIPAOBJS=	yes
192.if !defined(CFLAGS) || empty(CFLAGS:M*-g*)
193LIBSTRIPCOBJS=	yes
194.endif
195.if !defined(OBJCFLAGS) || empty(OBJCFLAGS:M*-g*)
196LIBSTRIPOBJCOBJS=	yes
197.endif
198.if !defined(FFLAGS) || empty(FFLAGS:M*-g*)
199LIBSTRIPFOBJS=	yes
200.endif
201.if !defined(CSHLIBFLAGS) || empty(CSHLIBFLAGS:M*-g*)
202LIBSTRIPSHLIBOBJS=	yes
203.endif
204
205.if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
206SHLIB_SHFLAGS+= -L ${DESTDIR}/usr/lib
207SHLIB_SHFLAGS+= -Wl,-plugin=${GOLD_PLUGIN} \
208		-Wl,-plugin-opt=-disable-opt
209
210SECTIONIFYPASS?=${NETBSDSRCDIR}/minix/llvm/bin/sectionify.so
211
212.S.bc: ${.TARGET:.bc=.o}
213	rm -f ${.TARGET}
214	ln ${.TARGET:.bc=.o} ${.TARGET}
215.c.bc:
216	${_MKTARGET_COMPILE}
217	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET} -flto
218	if [ -n '${SECTIONIFY.${.IMPSRC:T}}' ]; then \
219		${OPT} -load ${SECTIONIFYPASS} -sectionify ${SECTIONIFY.${.IMPSRC:T}} -o ${.TARGET}.tmp ${.TARGET} && mv -f ${.TARGET}.tmp ${.TARGET}; \
220	fi
221
222.cc.bc .cxx.bc .cpp.bc:
223	${_MKTARGET_COMPILE}
224	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET} -flto
225.endif # defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
226.c.o:
227	${_MKTARGET_COMPILE}
228	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
229.if defined(CTFCONVERT)
230	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
231.endif
232.if defined(LIBSTRIPCOBJS)
233	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
234.endif
235
236.c.po:
237	${_MKTARGET_COMPILE}
238	${COMPILE.c} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
239.if defined(CTFCONVERT)
240	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
241.endif
242.if defined(LIBSTRIPCOBJS)
243	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
244.endif
245
246.c.go:
247	${_MKTARGET_COMPILE}
248	${COMPILE.c} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
249
250.c.pico:
251	${_MKTARGET_COMPILE}
252	${COMPILE.c} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
253.if defined(LIBSTRIPSHLIBOBJS)
254	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
255.endif
256
257.cc.o .cpp.o .cxx.o .C.o:
258	${_MKTARGET_COMPILE}
259	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
260.if defined(LIBSTRIPCOBJS)
261	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
262.endif
263
264.cc.po .cpp.po .cxx.po .C.po:
265	${_MKTARGET_COMPILE}
266	${COMPILE.cc} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -pg ${.IMPSRC} -o ${.TARGET}
267.if defined(LIBSTRIPCOBJS)
268	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
269.endif
270
271.cc.go .cpp.go .cxx.go .C.go:
272	${_MKTARGET_COMPILE}
273	${COMPILE.cc} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} -g ${.IMPSRC} -o ${.TARGET}
274
275.cc.pico .cpp.pico .cxx.pico .C.pico:
276	${_MKTARGET_COMPILE}
277	${COMPILE.cc} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${CSHLIBFLAGS} ${.IMPSRC} -o ${.TARGET}
278.if defined(LIBSTRIPSHLIBOBJS)
279	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
280.endif
281
282.f.o:
283	${_MKTARGET_COMPILE}
284	${COMPILE.f} ${.IMPSRC} -o ${.TARGET}
285.if defined(CTFCONVERT)
286	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
287.endif
288.if defined(LIBSTRIPFOBJS)
289	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
290.endif
291
292.f.po:
293	${_MKTARGET_COMPILE}
294	${COMPILE.f} ${PROFFLAGS} -pg ${.IMPSRC} -o ${.TARGET}
295.if defined(CTFCONVERT)
296	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
297.endif
298.if defined(LIBSTRIPFOBJS)
299	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
300.endif
301
302.f.go:
303	${_MKTARGET_COMPILE}
304	${COMPILE.f} ${DEBUGFLAGS} -g ${.IMPSRC} -o ${.TARGET}
305
306.f.pico:
307	${_MKTARGET_COMPILE}
308	${COMPILE.f} ${PICFLAGS} ${.IMPSRC} -o ${.TARGET}
309.if defined(LIBSTRIPFOBJS)
310	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
311.endif
312
313.f.ln:
314	${_MKTARGET_COMPILE}
315	@echo Skipping lint for Fortran libraries.
316
317.m.o:
318	${_MKTARGET_COMPILE}
319	${COMPILE.m} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
320.if defined(CTFCONVERT)
321	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
322.endif
323.if defined(LIBSTRIPOBJCOBJS)
324	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
325.endif
326
327.m.po:
328	${_MKTARGET_COMPILE}
329	${COMPILE.m} ${PROFFLAGS} -pg ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
330.if defined(CTFCONVERT)
331	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
332.endif
333.if defined(LIBSTRIPOBJCOBJS)
334	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
335.endif
336
337.m.go:
338	${_MKTARGET_COMPILE}
339	${COMPILE.m} ${DEBUGFLAGS} -g ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
340.if defined(LIBSTRIPOBJCOBJS)
341	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
342.endif
343
344.m.pico:
345	${_MKTARGET_COMPILE}
346	${COMPILE.m} ${CSHLIBFLAGS} ${OBJCOPTS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
347.if defined(LIBSTRIPOBJCOBJS)
348	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
349.endif
350
351.s.o:
352	${_MKTARGET_COMPILE}
353	${COMPILE.s} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
354.if defined(CTFCONVERT)
355	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
356.endif
357.if defined(LIBSTRIPAOBJS)
358	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
359.endif
360
361.S.o:
362	${_MKTARGET_COMPILE}
363	${COMPILE.S} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
364.if defined(CTFCONVERT)
365	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
366.endif
367.if defined(LIBSTRIPAOBJS)
368	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
369.endif
370
371.s.po:
372	${_MKTARGET_COMPILE}
373	${COMPILE.s} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
374.if defined(CTFCONVERT)
375	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
376.endif
377.if defined(LIBSTRIPAOBJS)
378	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
379.endif
380
381.S.po:
382	${_MKTARGET_COMPILE}
383	${COMPILE.S} ${PROFFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
384.if defined(CTFCONVERT)
385	${CTFCONVERT} ${CTFFLAGS} ${.TARGET}
386.endif
387.if defined(LIBSTRIPAOBJS)
388	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
389.endif
390
391.s.go:
392	${_MKTARGET_COMPILE}
393	${COMPILE.s} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
394
395.S.go:
396	${_MKTARGET_COMPILE}
397	${COMPILE.S} ${DEBUGFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
398
399.s.pico:
400	${_MKTARGET_COMPILE}
401	${COMPILE.s} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
402.if defined(LIBSTRIPAOBJS)
403	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
404.endif
405
406.S.pico:
407	${_MKTARGET_COMPILE}
408	${COMPILE.S} ${PICFLAGS} ${COPTS.${.IMPSRC:T}} ${CPUFLAGS.${.IMPSRC:T}} ${CPPFLAGS.${.IMPSRC:T}} ${.IMPSRC} -o ${.TARGET}
409.if defined(LIBSTRIPAOBJS)
410	${OBJCOPY} ${OBJCOPYLIBFLAGS} ${.TARGET}
411.endif
412
413# Declare a few variables to make our life easier later.
414_LIB:=${_LIB_PREFIX}${LIB}
415_LIB.a:=${_LIB}.a
416_LIB_p.a:=${_LIB}_p.a
417_LIB_g.a:=${_LIB}_g.a
418_LIB_pic.a:=${_LIB}_pic.a
419_LIB.ln:=llib-l${LIB}.ln
420.if defined(__MINIX) && ${USE_BITCODE:Uno} == "yes"
421_LIB_bc.a:=${_LIB}_bc.a
422.endif # defined(__MINIX)
423
424.if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
425_LIB.so:=${_LIB}.so
426_LIB.so.major:=${_LIB}.so.${SHLIB_MAJOR}
427_LIB.so.full:=${_LIB}.so.${SHLIB_FULLVERSION}
428.if ${MKDEBUG} != "no"
429_LIB.so.debug:=${_LIB.so.full}.debug
430.endif
431.endif
432
433_DEST.LIB:=${DESTDIR}${LIBDIR}
434_DEST.OBJ:=${DESTDIR}${_LIBSODIR}
435_DEST.LINT:=${DESTDIR}${LINTLIBDIR}
436_DEST.DEBUG:=${DESTDIR}${DEBUGDIR}${LIBDIR}
437_DEST.ODEBUG:=${DESTDIR}${DEBUGDIR}${_LIBSODIR}
438
439.if defined(LIB)							# {
440.if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
441	|| ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
442_LIBS=${_LIB.a}
443.else
444_LIBS=
445.endif
446
447.if ${LIBISPRIVATE} != "no" \
448   && (defined(USE_COMBINE) && ${USE_COMBINE} == "yes" \
449   && !defined(NOCOMBINE))						# {
450.for f in ${SRCS:N*.h:N*.sh:C/\.[yl]$/.c/g}
451COMBINEFLAGS.${LIB}.$f := ${CPPFLAGS.$f:D1} ${CPUFLAGS.$f:D2} ${COPTS.$f:D3} ${OBJCOPTS.$f:D4} ${CXXFLAGS.$f:D5}
452.if empty(COMBINEFLAGS.${LIB}.${f}) && !defined(NOCOMBINE.$f)
453COMBINESRCS+=	${f}
454NODPSRCS+=	${f}
455.else
456OBJS+=  	${f:R:S/$/.o/}
457.endif
458.endfor
459
460.if !empty(COMBINESRCS)
461OBJS+=		${_LIB}_combine.o
462${_LIB}_combine.o: ${COMBINESRCS}
463	${_MKTARGET_COMPILE}
464	${COMPILE.c} -MD --combine ${.ALLSRC} -o ${.TARGET}
465.if defined(LIBSTRIPOBJS)
466	${OBJCOPY} -x ${.TARGET}
467.endif
468
469CLEANFILES+=	${_LIB}_combine.d
470
471.if exists("${_LIB}_combine.d")
472.include "${_LIB}_combine.d"
473.endif
474.endif   # empty(XSRCS.${LIB})
475.else							# } {
476OBJS+=${SRCS:N*.h:N*.sh:R:S/$/.o/g}
477.endif							# }
478
479STOBJS+=${OBJS}
480
481LOBJS+=${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
482
483.if ${LIBISPRIVATE} != "no"
484# No installation is required
485libinstall::
486.endif
487
488.if ${MKDEBUGLIB} != "no"
489_LIBS+=${_LIB_g.a}
490GOBJS+=${OBJS:.o=.go}
491DEBUGFLAGS?=-DDEBUG
492.endif
493
494.if ${MKPROFILE} != "no"
495_LIBS+=${_LIB_p.a}
496POBJS+=${OBJS:.o=.po}
497PROFFLAGS?=-DGPROF -DPROF
498.endif
499
500.if ${MKPIC} != "no"							# {
501.if ${MKPICLIB} == "no"
502.if ${MKSHLIBOBJS} != "no"
503# make _pic.a, which isn't really pic,
504# since it's needed for making shared lib.
505# but don't install it.
506SOLIB=${_LIB_pic.a}
507SOBJS+=${OBJS:.o=.pico}
508.else
509SOLIB=${_LIB.a}
510.endif
511.else
512SOLIB=${_LIB_pic.a}
513_LIBS+=${SOLIB}
514SOBJS+=${OBJS:.o=.pico}
515.endif
516.if defined(SHLIB_FULLVERSION)
517_LIBS+=${_LIB.so.full}
518.endif
519.endif									# }
520
521.if ${MKLINT} != "no" && !empty(LOBJS)
522_LIBS+=${_LIB.ln}
523.endif
524
525ALLOBJS=
526.if (${MKPIC} == "no" || (defined(LDSTATIC) && ${LDSTATIC} != "") \
527	|| ${MKLINKLIB} != "no") && ${MKSTATICLIB} != "no"
528ALLOBJS+=${STOBJS}
529.endif
530ALLOBJS+=${POBJS} ${SOBJS}
531.if ${MKLINT} != "no" && !empty(LOBJS)
532ALLOBJS+=${LOBJS}
533.endif
534.else	# !defined(LIB)							# } {
535LOBJS=
536SOBJS=
537.endif	# !defined(LIB)							# }
538
539_YLSRCS=	${SRCS:M*.[ly]:C/\..$/.c/} ${YHEADER:D${SRCS:M*.y:.y=.h}}
540
541.if ${USE_BITCODE:Uno} == "yes"
542_LIBS+=${_LIB_bc.a}
543.endif # ${USE_BITCODE:Uno} == "yes"
544
545.NOPATH: ${ALLOBJS} ${_LIBS} ${_YLSRCS}
546
547realall: ${SRCS} ${ALLOBJS:O} ${_LIBS} ${_LIB.so.debug}
548
549MKARZERO?=no
550
551.if ${MKARZERO} == "yes"
552_ARFL=crsD
553_ARRANFL=sD
554_INSTRANLIB=
555.else
556_ARFL=crs
557_ARRANFL=s
558.if ${USE_BITCODE:Uno} == "yes"
559_INSTRANLIB=${empty(PRESERVE):?-a "${AR} --plugin ${GOLD_PLUGIN} -s":}
560.else
561_INSTRANLIB=${empty(PRESERVE):?-a "${RANLIB} -t":}
562.endif # ${USE_BITCODE:Uno} == "yes"
563.endif
564
565# If you change this, please consider reflecting the change in
566# the override in sys/rump/Makefile.rump.
567.if !target(__archivebuild)
568__archivebuild: .USE
569	${_MKTARGET_BUILD}
570	rm -f ${.TARGET}
571	${AR} ${_ARFL} ${.TARGET} `NM=${NM} ${LORDER} ${.ALLSRC:M*o} | ${TSORT}`
572.endif
573
574.if !target(__archiveinstall)
575__archiveinstall: .USE
576	${_MKTARGET_INSTALL}
577	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
578	    ${_INSTRANLIB} ${.ALLSRC} ${.TARGET}
579.endif
580
581__archivesymlinkpic: .USE
582	${_MKTARGET_INSTALL}
583	${INSTALL_SYMLINK} ${.ALLSRC} ${.TARGET}
584
585DPSRCS+=	${_YLSRCS}
586CLEANFILES+=	${_YLSRCS}
587
588${STOBJS} ${POBJS} ${GOBJS} ${SOBJS} ${LOBJS}: ${DPSRCS}
589
590.if ${USE_BITCODE:Uno} == "yes"
591
592.if !target(__archivebuildbc)
593__archivebuildbc: .USE
594	${_MKTARGET_BUILD}
595	rm -f ${.TARGET}
596	${AR} ${_ARFL} --plugin ${GOLD_PLUGIN} ${.TARGET} ${.ALLSRC:M*bc}
597.endif
598
599# LSC: Ignore libunwind in the bitcode archive, otherwise final linking chokes
600#      on libunwind hidden assembly symbols.
601BCOBJS+=${OBJS:Nlibunwind.*:.o=.bc}
602ALLOBJS+=${BCOBJS}
603${_LIB_bc.a}:: ${BCOBJS} __archivebuildbc
604
605.endif # ${USE_BITCODE:Uno} == "yes"
606
607${_LIB.a}:: ${STOBJS} __archivebuild
608
609${_LIB_p.a}:: ${POBJS} __archivebuild
610
611${_LIB_pic.a}:: ${SOBJS} __archivebuild
612
613${_LIB_g.a}:: ${GOBJS} __archivebuild
614
615
616_LIBLDOPTS=
617.if ${SHLIBDIR} != "/usr/lib"
618_LIBLDOPTS+=	-Wl,-rpath,${SHLIBDIR} \
619		-L=${SHLIBDIR}
620.elif ${SHLIBINSTALLDIR} != "/usr/lib"
621_LIBLDOPTS+=	-Wl,-rpath-link,${DESTDIR}${SHLIBINSTALLDIR} \
622		-L=${SHLIBINSTALLDIR}
623.endif
624
625# gcc -shared now adds -lc automatically. For libraries other than libc and
626# libgcc* we add as a dependency the installed shared libc. For libc and
627# libgcc* we avoid adding libc as a dependency by using -nostdlib. Note that
628# -Xl,-nostdlib is not enough because we want to tell the compiler-driver not
629# to add standard libraries, not the linker.
630.if !defined(LIB)
631.if !empty(LIBC_SO)
632DPLIBC ?= ${DESTDIR}${LIBC_SO}
633.endif
634.else
635.if ${LIB} != "c" && ${LIB:Mgcc*} == "" \
636    && ${LIB} != "sys" && ${LIB} != "minc" && ${LIB} != "mthread" # Minix-specific libs
637.if !empty(LIBC_SO)
638DPLIBC ?= ${DESTDIR}${LIBC_SO}
639.endif
640.else
641LDLIBC ?= -nodefaultlibs
642.if ${HAVE_LIBGCC} == "yes" && (${LIB} == "c" || ${LIB} == "minc")
643.if !defined(__MINIX)
644LDADD+= -lgcc
645.else
646LDADD+= ${${ACTIVE_CC} == "gcc":? -lgcc:}
647.if ${MACHINE_ARCH} == "earm"
648LDADD+= ${${ACTIVE_CC} == "gcc":? -lgcc_eh:}
649.endif # ${MACHINE_ARCH} == "earm"
650.endif # !defined(__MINIX)
651.endif
652.endif
653.endif
654
655.if ${LIBISCXX} != "no"
656LIBCC:=	${CXX}
657. if ${MKLIBCXX} == "yes"
658LIBDPLIBS+=     c++	${.CURDIR}/../../../../../external/bsd/libc++/lib
659. elif defined(HAVE_GCC) && ${HAVE_GCC} == 4
660LIBDPLIBS+=     stdc++	${.CURDIR}/../../../../../gnu/lib/libstdc++-v3_4
661. else
662LIBDPLIBS+=     stdc++	${.CURDIR}/../../../../../external/gpl3/gcc/lib/libstdc++-v3
663. endif
664.else
665LIBCC:=	${CC}
666.endif
667
668_LDADD.${_LIB}=	${LDADD} ${LDADD.${_LIB}}
669_LDFLAGS.${_LIB}=	${LDFLAGS} ${LDFLAGS.${_LIB}}
670
671${_LIB.so.full}: ${SOLIB} ${DPADD} ${DPLIBC} \
672    ${SHLIB_LDSTARTFILE} ${SHLIB_LDENDFILE}
673	${_MKTARGET_BUILD}
674	rm -f ${.TARGET}
675	${LIBCC} ${LDLIBC} -Wl,-x -shared ${SHLIB_SHFLAGS} \
676	    ${_LDFLAGS.${_LIB}} -o ${.TARGET} ${_LIBLDOPTS} \
677	    -Wl,--whole-archive ${SOLIB} \
678	    -Wl,--no-whole-archive ${_LDADD.${_LIB}}
679#  We don't use INSTALL_SYMLINK here because this is just
680#  happening inside the build directory/objdir. XXX Why does
681#  this spend so much effort on libraries that aren't live??? XXX
682.if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
683    "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
684	${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so.major}.tmp
685	mv -f ${_LIB.so.major}.tmp ${_LIB.so.major}
686.endif
687	${HOST_LN} -sf ${_LIB.so.full} ${_LIB.so}.tmp
688	mv -f ${_LIB.so}.tmp ${_LIB.so}
689.if ${MKSTRIPIDENT} != "no"
690	${OBJCOPY} -R .ident ${.TARGET}
691.endif
692
693.if defined(_LIB.so.debug)
694${_LIB.so.debug}: ${_LIB.so.full}
695	${_MKTARGET_CREATE}
696	(  ${OBJCOPY} --only-keep-debug ${_LIB.so.full} ${_LIB.so.debug} \
697	&& ${OBJCOPY} --strip-debug -p -R .gnu_debuglink \
698		--add-gnu-debuglink=${_LIB.so.debug} ${_LIB.so.full} \
699	) || (rm -f ${.TARGET}; false)
700.endif
701
702.if !empty(LOBJS)							# {
703LLIBS?=		-lc
704${_LIB.ln}: ${LOBJS}
705	${_MKTARGET_COMPILE}
706	rm -f ${.TARGET}
707.if defined(DESTDIR)
708	${LINT} -C${LIB} ${.ALLSRC} -L${DESTDIR}/usr/libdata ${LLIBS}
709.else
710	${LINT} -C${LIB} ${.ALLSRC} ${LLIBS}
711.endif
712.endif									# }
713
714lint: ${LOBJS}
715.if defined(LOBJS) && !empty(LOBJS)
716	${LINT} ${LINTFLAGS} ${LOBJS}
717.endif
718
719
720# If the number of entries in CLEANFILES is too large, then the
721# commands in bsd.clean.mk encounter errors like "exec(/bin/sh)
722# failed (Argument list too long)".  Avoid that by splitting the
723# files to clean into several lists using different variable names.
724# __cleanuse is an internal target in bsd.clean.mk; the way we
725# use it here mimics the way it's used by the clean target in
726# bsd.clean.mk.
727#
728clean: libclean1 libclean2 libclean3 libclean4 libclean5
729libclean1: .PHONY .MADE __cleanuse LIBCLEANFILES1
730libclean2: .PHONY .MADE __cleanuse LIBCLEANFILES2
731libclean3: .PHONY .MADE __cleanuse LIBCLEANFILES3
732libclean4: .PHONY .MADE __cleanuse LIBCLEANFILES4
733libclean5: .PHONY .MADE __cleanuse LIBCLEANFILES5
734.if defined(__MINIX)
735# MINIX: core conflicts with core/ in lib/liblwip
736CLEANFILES+= a.out [Ee]rrs mklog *.core
737.else
738CLEANFILES+= a.out [Ee]rrs mklog core *.core
739.endif # defined(__MINIX)
740LIBCLEANFILES1+= ${_LIB.a}   ${STOBJS} ${STOBJS:=.tmp}
741LIBCLEANFILES2+= ${_LIB_p.a} ${POBJS}  ${POBJS:=.tmp}
742LIBCLEANFILES3+= ${_LIB_g.a} ${GOBJS}  ${GOBJS:=.tmp}
743LIBCLEANFILES4+= ${_LIB_pic.a}
744.if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
745LIBCLEANFILES4+= ${_LIB.so}.* ${_LIB.so} ${_LIB.so.debug}
746.endif
747LIBCLEANFILES4+= ${SOBJS} ${SOBJS:=.tmp}
748LIBCLEANFILES5+= ${_LIB.ln} ${LOBJS}
749
750.if defined(__MINIX)
751clean: libclean6
752libclean6: .PHONY .MADE __cleanuse LIBCLEANFILES6
753LIBCLEANFILES6+= ${_LIB_bc.a} ${BCOBJS} ${BCOBJS:=.tmp}
754.endif
755
756.if !target(libinstall)							# {
757# Make sure it gets defined, in case MKPIC==no && MKLINKLIB==no
758libinstall::
759
760.if ${USE_BITCODE:Uno} == "yes"
761libinstall:: ${_DEST.LIB}/bc/${_LIB.a}
762.PRECIOUS: ${_DEST.LIB}/bc/${_LIB.a}
763
764.if ${MKUPDATE} == "no"
765.if !defined(BUILD) && !make(all) && !make(${_LIB_bc.a})
766${_DEST.LIB}/bc/${_LIB.a}! .MADE
767.endif
768${_DEST.LIB}/bc/${_LIB.a}! ${_LIB_bc.a} __archiveinstall
769.else
770.if !defined(BUILD) && !make(all) && !make(${_LIB_bc.a})
771${_DEST.LIB}/bc/${_LIB.a}: .MADE
772.endif
773${_DEST.LIB}/bc/${_LIB.a}: ${_LIB_bc.a} __archiveinstall
774.endif
775.endif # ${USE_BITCODE:Uno} == "yes"
776
777.if ${MKLINKLIB} != "no" && ${MKSTATICLIB} != "no"
778libinstall:: ${_DEST.LIB}/${_LIB.a}
779.PRECIOUS: ${_DEST.LIB}/${_LIB.a}
780
781.if ${MKUPDATE} == "no"
782.if !defined(BUILD) && !make(all) && !make(${_LIB.a})
783${_DEST.LIB}/${_LIB.a}! .MADE
784.endif
785${_DEST.LIB}/${_LIB.a}! ${_LIB.a} __archiveinstall
786.else
787.if !defined(BUILD) && !make(all) && !make(${_LIB.a})
788${_DEST.LIB}/${_LIB.a}: .MADE
789.endif
790${_DEST.LIB}/${_LIB.a}: ${_LIB.a} __archiveinstall
791.endif
792.endif
793
794.if ${MKPROFILE} != "no"
795libinstall:: ${_DEST.LIB}/${_LIB_p.a}
796.PRECIOUS: ${_DEST.LIB}/${_LIB_p.a}
797
798.if ${MKUPDATE} == "no"
799.if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
800${_DEST.LIB}/${_LIB_p.a}! .MADE
801.endif
802${_DEST.LIB}/${_LIB_p.a}! ${_LIB_p.a} __archiveinstall
803.else
804.if !defined(BUILD) && !make(all) && !make(${_LIB_p.a})
805${_DEST.LIB}/${_LIB_p.a}: .MADE
806.endif
807${_DEST.LIB}/${_LIB_p.a}: ${_LIB_p.a} __archiveinstall
808.endif
809.endif
810
811.if ${MKDEBUGLIB} != "no"
812libinstall:: ${_DEST.LIB}/${_LIB_g.a}
813.PRECIOUS: ${_DEST.LIB}/${_LIB_g.a}
814
815.if ${MKUPDATE} == "no"
816.if !defined(BUILD) && !make(all) && !make(${_LIB_g.a})
817${_DEST.LIB}/${_LIB_g.a}! .MADE
818.endif
819${_DEST.LIB}/${_LIB_g.a}! ${_LIB_g.a} __archiveinstall
820.else
821.if !defined(BUILD) && !make(all) && !make(${LIB_g.a})
822${_DEST.LIB}/${_LIB_g.a}: .MADE
823.endif
824${_DEST.LIB}/${_LIB_g.a}: ${_LIB_g.a} __archiveinstall
825.endif
826.endif
827
828.if ${MKPIC} != "no" && ${MKPICINSTALL} != "no"
829libinstall:: ${_DEST.LIB}/${_LIB_pic.a}
830.PRECIOUS: ${_DEST.LIB}/${_LIB_pic.a}
831
832.if ${MKUPDATE} == "no"
833.if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
834${_DEST.LIB}/${_LIB_pic.a}! .MADE
835.endif
836.if ${MKPICLIB} == "no"
837${_DEST.LIB}/${_LIB_pic.a}! ${_LIB.a} __archivesymlinkpic
838.else
839${_DEST.LIB}/${_LIB_pic.a}! ${_LIB_pic.a} __archiveinstall
840.endif
841.else
842.if !defined(BUILD) && !make(all) && !make(${_LIB_pic.a})
843${_DEST.LIB}/${_LIB_pic.a}: .MADE
844.endif
845.if ${MKPICLIB} == "no"
846${_DEST.LIB}/${_LIB_pic.a}: ${_LIB.a} __archivesymlinkpic
847.else
848${_DEST.LIB}/${_LIB_pic.a}: ${_LIB_pic.a} __archiveinstall
849.endif
850.endif
851.endif
852
853.if ${MKPIC} != "no" && defined(SHLIB_FULLVERSION)
854
855libinstall:: ${_DEST.OBJ}/${_LIB.so.full}
856.PRECIOUS: ${_DEST.OBJ}/${_LIB.so.full}
857
858.if ${MKUPDATE} == "no"
859.if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
860${_DEST.OBJ}/${_LIB.so.full}! .MADE
861.endif
862${_DEST.OBJ}/${_LIB.so.full}! ${_LIB.so.full}
863.else
864.if !defined(BUILD) && !make(all) && !make(${_LIB.so.full})
865${_DEST.OBJ}/${_LIB.so.full}: .MADE
866.endif
867${_DEST.OBJ}/${_LIB.so.full}: ${_LIB.so.full}
868.endif
869	${_MKTARGET_INSTALL}
870	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
871	    ${.ALLSRC} ${.TARGET}
872.if ${_LIBSODIR} != ${LIBDIR}
873	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
874	    ${_DEST.LIB}/${_LIB.so.full}
875.endif
876.if defined(SHLIB_FULLVERSION) && defined(SHLIB_MAJOR) && \
877    "${SHLIB_FULLVERSION}" != "${SHLIB_MAJOR}"
878	${INSTALL_SYMLINK} ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so.major}
879.if ${_LIBSODIR} != ${LIBDIR}
880	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
881	    ${_DEST.LIB}/${_LIB.so.major}
882.endif
883.endif
884.if ${MKLINKLIB} != "no"
885	${INSTALL_SYMLINK}  ${_LIB.so.full} ${_DEST.OBJ}/${_LIB.so}
886.if ${_LIBSODIR} != ${LIBDIR}
887	${INSTALL_SYMLINK} -l r ${_DEST.OBJ}/${_LIB.so.full} \
888	    ${_DEST.LIB}/${_LIB.so}
889.endif
890.endif
891.endif
892
893.if defined(_LIB.so.debug)
894libinstall:: ${_DEST.DEBUG}/${_LIB.so.debug}
895.PRECIOUS: ${_DEST.DEBUG}/${_LIB.so.debug}
896
897${_DEST.DEBUG}/${_LIB.so.debug}: ${_LIB.so.debug}
898	${_MKTARGET_INSTALL}
899	${INSTALL_FILE} -o ${DEBUGOWN} -g ${DEBUGGRP} -m ${DEBUGMODE} \
900	    ${.ALLSRC} ${.TARGET}
901.if ${_LIBSODIR} != ${LIBDIR}
902	${INSTALL_SYMLINK} -l r ${_DEST.DEBUG}/${_LIB.so.debug} \
903	    ${_DEST.ODEBUG}/${_LIB.so.debug}
904.endif
905.endif
906
907.if ${MKLINT} != "no" && !empty(LOBJS)
908libinstall:: ${_DEST.LINT}/${_LIB.ln}
909.PRECIOUS: ${_DEST.LINT}/${_LIB.ln}
910
911.if ${MKUPDATE} == "no"
912.if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
913${_DEST.LINT}/${_LIB.ln}! .MADE
914.endif
915${_DEST.LINT}/${_LIB.ln}! ${_LIB.ln}
916.else
917.if !defined(BUILD) && !make(all) && !make(${_LIB.ln})
918${_DEST.LINT}/${_LIB.ln}: .MADE
919.endif
920${_DEST.LINT}/${_LIB.ln}: ${_LIB.ln}
921.endif
922	${_MKTARGET_INSTALL}
923	${INSTALL_FILE} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
924		${.ALLSRC} ${_DEST.LINT}
925.endif
926.endif	# !target(libinstall)						# }
927
928##### Pull in related .mk logic
929LINKSOWN?= ${LIBOWN}
930LINKSGRP?= ${LIBGRP}
931LINKSMODE?= ${LIBMODE}
932.include <bsd.man.mk>
933.include <bsd.nls.mk>
934.include <bsd.files.mk>
935.include <bsd.inc.mk>
936.include <bsd.links.mk>
937.include <bsd.dep.mk>
938.include <bsd.clang-analyze.mk>
939.include <bsd.clean.mk>
940
941${TARGETS}:	# ensure existence
942