xref: /dragonfly/share/mk/bsd.lib.mk (revision d4ef6694)
1#	from: @(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
2# $FreeBSD: src/share/mk/bsd.lib.mk,v 1.91.2.15 2002/08/07 16:31:50 ru Exp $
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(NOPIC)
12.undef SHLIB_NAME
13.undef INSTALL_PIC_ARCHIVE
14.else
15.if !defined(SHLIB_NAME) && defined(LIB) && defined(SHLIB_MAJOR)
16SHLIB_NAME=	lib${LIB}.so.${SHLIB_MAJOR}
17.endif
18.if defined(SHLIB_NAME) && ${SHLIB_NAME:M*.so.*}
19SHLIB_LINK?=	${SHLIB_NAME:R}
20.endif
21SONAME?=	${SHLIB_NAME}
22.endif
23
24.if defined(DEBUG_FLAGS)
25CFLAGS+= ${DEBUG_FLAGS}
26.endif
27
28.if !defined(DEBUG_FLAGS)
29STRIP?=	-s
30.endif
31
32.include <bsd.libnames.mk>
33
34TARGET_LIBDIR?=		${LIBDIR}
35TARGET_DEBUGLIBDIR?=	${DEBUGLIBDIR}
36TARGET_PROFLIBDIR?=	${PROFLIBDIR}
37TARGET_SHLIBDIR?=	${SHLIBDIR}
38
39# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
40# .So used for PIC object files
41.SUFFIXES:
42.SUFFIXES: .out .o .po .So .S .s .c .cc .cpp .cxx .m .C .f .y .l
43
44.if !defined(PICFLAG)
45PICFLAG=-fpic
46.endif
47
48PO_FLAG=-pg
49PO_CFLAGS=${CFLAGS:N-ffunction-sections}
50PO_CXXFLAGS=${CXXFLAGS:N-ffunction-sections}
51
52.c.o:
53	${CC} ${_${.IMPSRC:T}_FLAGS} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
54
55.c.po:
56	${CC} ${_${.IMPSRC:T}_FLAGS} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
57
58.c.So:
59	${CC} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
60
61.cc.o .C.o .cpp.o .cxx.o:
62	${CXX} ${_${.IMPSRC:T}_FLAGS} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
63
64.cc.po .C.po .cpp.po .cxx.po:
65	${CXX} ${_${.IMPSRC:T}_FLAGS} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
66
67.cc.So .C.So .cpp.So .cxx.So:
68	${CXX} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
69
70.f.o:
71	${FC} ${_${.IMPSRC:T}_FLAGS} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
72
73.f.po:
74	${FC} ${_${.IMPSRC:T}_FLAGS} ${PO_FLAG} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
75
76.f.So:
77	${FC} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
78
79.m.o:
80	${OBJC} ${_${.IMPSRC:T}_FLAGS} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
81
82.m.po:
83	${OBJC} ${_${.IMPSRC:T}_FLAGS} ${OBJCFLAGS} ${PO_FLAG} -c ${.IMPSRC} -o ${.TARGET}
84
85.m.So:
86	${OBJC} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
87
88.s.o:
89	${CC} ${_${.IMPSRC:T}_FLAGS} -x assembler-with-cpp ${CFLAGS} -c \
90	    ${.IMPSRC} -o ${.TARGET}
91
92.s.po:
93	${CC} ${_${.IMPSRC:T}_FLAGS} -x assembler-with-cpp -DPROF ${CFLAGS} -c \
94	    ${.IMPSRC} -o ${.TARGET}
95
96.s.So:
97	${CC} ${_${.IMPSRC:T}_FLAGS} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
98	    -c ${.IMPSRC} -o ${.TARGET}
99
100.S.o:
101	${CC} ${_${.IMPSRC:T}_FLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
102
103.S.po:
104	${CC} ${_${.IMPSRC:T}_FLAGS} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
105
106.S.So:
107	${CC} ${_${.IMPSRC:T}_FLAGS} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} \
108	    -o ${.TARGET}
109
110all: objwarn
111
112.include <bsd.symver.mk>
113
114# Allow libraries to specify their own version map or have it
115# automatically generated (see bsd.symver.mk above).
116.if !defined(NO_SYMVER) && !empty(VERSION_MAP)
117${SHLIB_NAME}:	${VERSION_MAP}
118LDFLAGS+=	-Wl,--version-script=${VERSION_MAP}
119.endif
120
121.include <bsd.patch.mk>
122
123.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
124OBJS+=  ${SRCS:N*.h:N*.patch:R:S/$/.o/g}
125.endif
126
127.if defined(LIB) && !empty(LIB)
128_LIBS=		lib${LIB}.a
129
130lib${LIB}.a: ${OBJS} ${STATICOBJS}
131	@${ECHO} building static ${LIB} library
132	rm -f ${.TARGET}
133	${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
134	${RANLIB} ${.TARGET}
135.endif
136
137.if !defined(INTERNALLIB) && !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
138_LIBS+=		lib${LIB}_p.a
139POBJS+=		${OBJS:.o=.po} ${STATICOBJS:.o=.po}
140
141lib${LIB}_p.a: ${POBJS}
142	@${ECHO} building profiled ${LIB} library
143	rm -f ${.TARGET}
144	${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
145	${RANLIB} ${.TARGET}
146.endif
147
148.if !defined(INTERNALLIB) && defined(SHLIB_NAME) || \
149    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
150SOBJS+=		${OBJS:.o=.So}
151.endif
152
153.if !defined(INTERNALLIB) && defined(SHLIB_NAME)
154_LIBS+=		${SHLIB_NAME}
155
156${SHLIB_NAME}: ${SOBJS}
157	@${ECHO} building shared library ${SHLIB_NAME}
158	rm -f ${.TARGET} ${SHLIB_LINK}
159.if defined(SHLIB_LINK)
160	${LN} -fs ${.TARGET} ${SHLIB_LINK}
161.endif
162	${CC_LINK} ${LDFLAGS} -shared -Wl,-x \
163	    -o ${.TARGET} -Wl,-soname,${SONAME} \
164	    `lorder ${SOBJS} | tsort -q` ${LDADD}
165.endif
166
167.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
168_LIBS+=		lib${LIB}_pic.a
169
170lib${LIB}_pic.a: ${SOBJS}
171	@${ECHO} building special pic ${LIB} library
172	rm -f ${.TARGET}
173	${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
174	${RANLIB} ${.TARGET}
175.endif
176
177all: ${_LIBS}
178
179.if !defined(NOMAN)
180all: _manpages
181.endif
182
183_EXTRADEPEND:
184	@TMP=_depend$$$$; \
185	sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
186	    > $$TMP; \
187	mv $$TMP ${DEPENDFILE}
188.if !defined(NOEXTRADEPEND) && defined(SHLIB_NAME)
189.if defined(DPADD) && !empty(DPADD)
190	echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
191.endif
192.endif
193
194.if !target(install)
195
196.if defined(PRECIOUSLIB) && !defined(NOFSCHG)
197SHLINSTALLFLAGS+= -fschg
198.endif
199
200_INSTALLFLAGS:=	${INSTALLFLAGS}
201.for ie in ${INSTALLFLAGS_EDIT}
202_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
203.endfor
204_SHLINSTALLFLAGS:=	${SHLINSTALLFLAGS}
205.for ie in ${INSTALLFLAGS_EDIT}
206_SHLINSTALLFLAGS:=	${_SHLINSTALLFLAGS${ie}}
207.endfor
208
209.if !defined(INTERNALLIB)
210realinstall: _libinstall
211.ORDER: beforeinstall _libinstall
212_libinstall:
213.if defined(LIB) && !empty(LIB) && !defined(NOINSTALLLIB)
214	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
215	    ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${TARGET_LIBDIR}
216.endif
217.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
218	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
219	    ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${TARGET_PROFLIBDIR}/lib${LIB}.a
220.endif
221.if defined(SHLIB_NAME)
222	${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
223	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
224	    ${SHLIB_NAME} ${DESTDIR}${TARGET_SHLIBDIR}
225.if defined(SHLIB_LINK)
226.if ${SHLIBDIR} == ${LIBDIR}
227	${LN} -fs ${SHLIB_NAME} ${DESTDIR}${TARGET_SHLIBDIR}/${SHLIB_LINK}
228.else
229	${LN} -fs ${_SHLIBDIRPREFIX}${TARGET_SHLIBDIR}/${SHLIB_NAME} \
230	    ${DESTDIR}${TARGET_LIBDIR}/${SHLIB_LINK}
231.endif
232.endif
233.endif
234.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
235	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
236	    ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${TARGET_LIBDIR}
237.endif
238.endif # !defined(INTERNALLIB)
239
240.include <bsd.nls.mk>
241.include <bsd.files.mk>
242.include <bsd.incs.mk>
243.include <bsd.links.mk>
244
245.if !defined(NOMAN)
246realinstall: _maninstall
247.ORDER: beforeinstall _maninstall
248.endif
249
250.endif
251
252.if !defined(NOMAN)
253.include <bsd.man.mk>
254.endif
255
256.include <bsd.dep.mk>
257
258.if !exists(${.OBJDIR}/${DEPENDFILE})
259.if defined(LIB) && !empty(LIB)
260${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
261.endif
262.if defined(SHLIB_NAME) || \
263    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
264${SOBJS}: ${SRCS:M*.h}
265.endif
266.endif
267
268.if !target(clean)
269clean:
270.if defined(CLEANFILES) && !empty(CLEANFILES)
271	rm -f ${CLEANFILES}
272.endif
273.if defined(LIB) && !empty(LIB)
274	rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
275.endif
276.if defined(SHLIB_NAME) || \
277    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
278	rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
279.endif
280.if !defined(INTERNALLIB)
281.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
282	rm -f ${POBJS} ${POBJS:S/$/.tmp/}
283.endif
284.if defined(SHLIB_NAME)
285.if defined(SHLIB_LINK)
286	rm -f ${SHLIB_LINK}
287.endif
288.if defined(LIB) && !empty(LIB)
289	rm -f lib${LIB}.so.* lib${LIB}.so
290.endif
291.endif
292.endif # !defined(INTERNALLIB)
293.if defined(_LIBS) && !empty(_LIBS)
294	rm -f ${_LIBS}
295.endif
296.if defined(CLEANDIRS) && !empty(CLEANDIRS)
297	rm -rf ${CLEANDIRS}
298.endif
299.endif
300
301.include <bsd.obj.mk>
302
303.include <bsd.sys.mk>
304
305