bsd.lib.mk revision 162210
1#	from: @(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
2# $FreeBSD: head/share/mk/bsd.lib.mk 162210 2006-09-11 05:35:57Z imp $
3#
4
5.include <bsd.init.mk>
6
7# Set up the variables controlling shared libraries.  After this section,
8# SHLIB_NAME will be defined only if we are to create a shared library.
9# SHLIB_LINK will be defined only if we are to create a link to it.
10# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
11.if defined(NO_PIC)
12.undef SHLIB_NAME
13.undef INSTALL_PIC_ARCHIVE
14.else
15.if !defined(SHLIB) && defined(LIB)
16SHLIB=		${LIB}
17.endif
18.if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR)
19SHLIB_NAME=	lib${SHLIB}.so.${SHLIB_MAJOR}
20.endif
21.if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*)
22SHLIB_LINK?=	${SHLIB_NAME:R}
23.endif
24SONAME?=	${SHLIB_NAME}
25.endif
26
27.if defined(CRUNCH_CFLAGS)
28CFLAGS+=	${CRUNCH_CFLAGS}
29.endif
30
31.if ${MK_ASSERT_DEBUG} == "no"
32CFLAGS+= -DNDEBUG
33.endif
34
35.if defined(DEBUG_FLAGS)
36CFLAGS+= ${DEBUG_FLAGS}
37.endif
38
39.if !defined(DEBUG_FLAGS)
40STRIP?=	-s
41.endif
42
43.include <bsd.libnames.mk>
44
45# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
46# .So used for PIC object files
47.SUFFIXES:
48.SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln
49
50.if !defined(PICFLAG)
51.if ${MACHINE_ARCH} == "sparc64"
52PICFLAG=-fPIC
53.else
54PICFLAG=-fpic
55.endif
56.endif
57
58.if ${CC} == "icc"
59PO_FLAG=-p
60.else
61PO_FLAG=-pg
62.endif
63
64.c.po:
65	${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
66
67.c.So:
68	${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
69
70.cc.po .C.po .cpp.po .cxx.po:
71	${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
72
73.cc.So .C.So .cpp.So .cxx.So:
74	${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
75
76.f.po:
77	${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
78
79.f.So:
80	${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
81
82.m.po:
83	${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
84
85.m.So:
86	${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
87
88.s.po .s.So:
89	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
90
91.asm.po:
92	${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
93
94.asm.So:
95	${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
96	    -c ${.IMPSRC} -o ${.TARGET}
97
98.S.po:
99	${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
100
101.S.So:
102	${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
103
104all: objwarn
105
106# Generate the version map given the version definitions
107# and symbol maps.
108.if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
109# Find the awk script that generates the version map.
110VERSION_GEN?=	version_gen.awk
111VERSION_MAP?=	Version.map
112
113# Compute the make's -m path.
114_mpath=
115_oarg=
116.for _arg in ${.MAKEFLAGS}
117.if ${_oarg} == "-m"
118_mpath+= ${_arg}
119.endif
120_oarg=  ${_arg}
121.endfor
122_mpath+= /usr/share/mk
123
124# Look up ${VERSION_GEN} in ${_mpath}.
125_vgen=
126.for path in ${_mpath}
127.if empty(_vgen)
128.if exists(${path}/${VERSION_GEN})
129_vgen=  ${path}/${VERSION_GEN}
130.endif
131.endif
132.endfor
133
134${VERSION_MAP}: ${VERSION_DEF} ${_vgen} ${SYMBOL_MAPS}
135	awk -v vfile=${VERSION_DEF} -f ${_vgen} ${SYMBOL_MAPS} \
136	    > ${.TARGET}
137.endif	# !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
138
139# Allow librararies to specify their own version map or have it
140# automatically generated (see above).
141.if !empty(VERSION_MAP)
142${SHLIB_NAME}:	${VERSION_MAP}
143LDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
144.endif
145
146.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
147OBJS+=		${SRCS:N*.h:R:S/$/.o/}
148.endif
149
150.if defined(LIB) && !empty(LIB)
151_LIBS=		lib${LIB}.a
152
153lib${LIB}.a: ${OBJS} ${STATICOBJS}
154	@${ECHO} building static ${LIB} library
155	@rm -f ${.TARGET}
156	@${AR} cq ${.TARGET} `env NM=${NM} lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
157	${RANLIB} ${.TARGET}
158.endif
159
160.if !defined(INTERNALLIB)
161
162.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
163_LIBS+=		lib${LIB}_p.a
164POBJS+=		${OBJS:.o=.po} ${STATICOBJS:.o=.po}
165
166lib${LIB}_p.a: ${POBJS}
167	@${ECHO} building profiled ${LIB} library
168	@rm -f ${.TARGET}
169	@${AR} cq ${.TARGET} `env NM=${NM} lorder ${POBJS} | tsort -q` ${ARADD}
170	${RANLIB} ${.TARGET}
171.endif
172
173.if defined(SHLIB_NAME) || \
174    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
175SOBJS+=		${OBJS:.o=.So}
176.endif
177
178.if defined(SHLIB_NAME)
179_LIBS+=		${SHLIB_NAME}
180
181${SHLIB_NAME}: ${SOBJS}
182	@${ECHO} building shared library ${SHLIB_NAME}
183	@rm -f ${.TARGET} ${SHLIB_LINK}
184.if defined(SHLIB_LINK)
185	@ln -fs ${.TARGET} ${SHLIB_LINK}
186.endif
187	@${CC} ${LDFLAGS} -shared -Wl,-x \
188	    -o ${.TARGET} -Wl,-soname,${SONAME} \
189	    `env NM=${NM} lorder ${SOBJS} | tsort -q` ${LDADD}
190.endif
191
192.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
193_LIBS+=		lib${LIB}_pic.a
194
195lib${LIB}_pic.a: ${SOBJS}
196	@${ECHO} building special pic ${LIB} library
197	@rm -f ${.TARGET}
198	@${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
199	${RANLIB} ${.TARGET}
200.endif
201
202.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
203LINTLIB=	llib-l${LIB}.ln
204_LIBS+=		${LINTLIB}
205LINTOBJS+=	${SRCS:M*.c:.c=.ln}
206
207${LINTLIB}: ${LINTOBJS}
208	@${ECHO} building lint library ${.TARGET}
209	@rm -f ${.TARGET}
210	${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
211.endif
212
213.endif # !defined(INTERNALLIB)
214
215all: ${_LIBS}
216
217.if ${MK_MAN} != "no"
218all: _manpages
219.endif
220
221_EXTRADEPEND:
222	@TMP=_depend$$$$; \
223	sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
224	    > $$TMP; \
225	mv $$TMP ${DEPENDFILE}
226.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
227.if defined(DPADD) && !empty(DPADD)
228	echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
229.endif
230.endif
231
232.if !target(install)
233
234.if defined(PRECIOUSLIB)
235.if !defined(NO_FSCHG)
236SHLINSTALLFLAGS+= -fschg
237.endif
238SHLINSTALLFLAGS+= -S
239.endif
240
241_INSTALLFLAGS:=	${INSTALLFLAGS}
242.for ie in ${INSTALLFLAGS_EDIT}
243_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
244.endfor
245_SHLINSTALLFLAGS:=	${SHLINSTALLFLAGS}
246.for ie in ${INSTALLFLAGS_EDIT}
247_SHLINSTALLFLAGS:=	${_SHLINSTALLFLAGS${ie}}
248.endfor
249
250.if !defined(INTERNALLIB)
251realinstall: _libinstall
252.ORDER: beforeinstall _libinstall
253_libinstall:
254.if defined(LIB) && !empty(LIB) && !defined(NO_INSTALLLIB)
255	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
256	    ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
257.endif
258.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
259	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
260	    ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
261.endif
262.if defined(SHLIB_NAME)
263	${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
264	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
265	    ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
266.if defined(SHLIB_LINK)
267.if ${SHLIBDIR} == ${LIBDIR}
268	ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
269.else
270	ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \
271	    ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
272.if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME})
273	-chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
274	rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
275.endif
276.endif
277.endif
278.endif
279.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
280	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
281	    ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
282.endif
283.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
284	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
285	    ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
286.endif
287.endif # !defined(INTERNALLIB)
288
289.include <bsd.nls.mk>
290.include <bsd.files.mk>
291.include <bsd.incs.mk>
292.include <bsd.links.mk>
293
294.if ${MK_MAN} != "no"
295realinstall: _maninstall
296.ORDER: beforeinstall _maninstall
297.endif
298
299.endif
300
301.if !target(lint)
302lint: ${SRCS:M*.c}
303	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
304.endif
305
306.if ${MK_MAN} != "no"
307.include <bsd.man.mk>
308.endif
309
310.include <bsd.dep.mk>
311
312.if !exists(${.OBJDIR}/${DEPENDFILE})
313.if defined(LIB) && !empty(LIB)
314${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
315.for _S in ${SRCS:N*.[hly]}
316${_S:R}.po: ${_S}
317.endfor
318.endif
319.if defined(SHLIB_NAME) || \
320    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
321${SOBJS}: ${SRCS:M*.h}
322.for _S in ${SRCS:N*.[hly]}
323${_S:R}.So: ${_S}
324.endfor
325.endif
326.endif
327
328.if !target(clean)
329clean:
330.if defined(CLEANFILES) && !empty(CLEANFILES)
331	rm -f ${CLEANFILES}
332.endif
333.if defined(LIB) && !empty(LIB)
334	rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
335.endif
336.if !defined(INTERNALLIB)
337.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
338	rm -f ${POBJS} ${POBJS:S/$/.tmp/}
339.endif
340.if defined(SHLIB_NAME) || \
341    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
342	rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
343.endif
344.if defined(SHLIB_NAME)
345.if defined(SHLIB_LINK)
346	rm -f ${SHLIB_LINK}
347.endif
348.if defined(LIB) && !empty(LIB)
349	rm -f lib${LIB}.so.* lib${LIB}.so
350.endif
351.endif
352.if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
353	rm -f ${LINTOBJS}
354.endif
355.endif # !defined(INTERNALLIB)
356.if defined(_LIBS) && !empty(_LIBS)
357	rm -f ${_LIBS}
358.endif
359.if defined(CLEANDIRS) && !empty(CLEANDIRS)
360	rm -rf ${CLEANDIRS}
361.endif
362.if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
363	rm -f ${VERSION_MAP}
364.endif
365.endif
366
367.include <bsd.obj.mk>
368
369.include <bsd.sys.mk>
370