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