bsd.lib.mk revision 126890
1184610Salfred#	from: @(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
2184610Salfred# $FreeBSD: head/share/mk/bsd.lib.mk 126890 2004-03-12 21:36:12Z trhodes $
3184610Salfred#
4184610Salfred
5184610Salfred.include <bsd.init.mk>
6184610Salfred
7184610Salfred# Set up the variables controlling shared libraries.  After this section,
8189002Sed# SHLIB_NAME will be defined only if we are to create a shared library.
9184610Salfred# SHLIB_LINK will be defined only if we are to create a link to it.
10184610Salfred# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
11184610Salfred.if defined(NOPIC)
12184610Salfred.undef SHLIB_NAME
13184610Salfred.undef INSTALL_PIC_ARCHIVE
14184610Salfred.else
15184610Salfred.if !defined(SHLIB_NAME) && defined(LIB) && defined(SHLIB_MAJOR)
16184610SalfredSHLIB_NAME=	lib${LIB}.so.${SHLIB_MAJOR}
17184610Salfred.endif
18184610Salfred.if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*)
19184610SalfredSHLIB_LINK?=	${SHLIB_NAME:R}
20184610Salfred.endif
21184610SalfredSONAME?=	${SHLIB_NAME}
22184610Salfred.endif
23184610Salfred
24184610Salfred.if defined(CRUNCH_CFLAGS)
25184610SalfredCFLAGS+=	${CRUNCH_CFLAGS}
26184610Salfred.endif
27184610Salfred
28184610Salfred.if defined(DEBUG_FLAGS)
29184610SalfredCFLAGS+= ${DEBUG_FLAGS}
30184610Salfred.endif
31191746Sthompsa
32191746Sthompsa.if !defined(DEBUG_FLAGS)
33191746SthompsaSTRIP?=	-s
34191746Sthompsa.endif
35191746Sthompsa
36191746Sthompsa.include <bsd.libnames.mk>
37191746Sthompsa
38191746Sthompsa# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
39191746Sthompsa# .So used for PIC object files
40191746Sthompsa.SUFFIXES:
41191746Sthompsa.SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln
42191746Sthompsa
43191746Sthompsa.if !defined(PICFLAG)
44191746Sthompsa.if ${MACHINE_ARCH} == "sparc64"
45184610SalfredPICFLAG=-fPIC
46191746Sthompsa.else
47191746SthompsaPICFLAG=-fpic
48191746Sthompsa.endif
49191746Sthompsa.endif
50191746Sthompsa
51191746Sthompsa.if ${CC} == "icc"
52191746SthompsaPO_FLAG=-p
53191746Sthompsa.else
54191746SthompsaPO_FLAG=-pg
55191746Sthompsa.endif
56191746Sthompsa
57191746Sthompsa.c.o:
58191746Sthompsa	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
59191746Sthompsa
60191746Sthompsa.c.po:
61191746Sthompsa	${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
62191746Sthompsa
63191746Sthompsa.c.So:
64191746Sthompsa	${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
65191746Sthompsa
66191746Sthompsa.cc.po .C.po .cpp.po .cxx.po:
67191746Sthompsa	${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
68191746Sthompsa
69206358Srpaulo.cc.So .C.So .cpp.So .cxx.So:
70191746Sthompsa	${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
71191746Sthompsa
72194677Sthompsa.f.po:
73191746Sthompsa	${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 
74184610Salfred
75194677Sthompsa.f.So:
76194677Sthompsa	${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
77191746Sthompsa
78188942Sthompsa.m.po:
79188942Sthompsa	${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
80184610Salfred
81207077Sthompsa.m.So:
82184610Salfred	${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
83184610Salfred
84192502Sthompsa.s.po .s.So:
85192502Sthompsa	${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
86184610Salfred
87184610Salfred.asm.po:
88184610Salfred	${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
89188417Sthompsa
90188417Sthompsa.asm.So:
91188417Sthompsa	${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
92184610Salfred	    -c ${.IMPSRC} -o ${.TARGET}
93188417Sthompsa
94223486Shselasky.S.po:
95201028Sthompsa	${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
96201028Sthompsa
97201028Sthompsa.S.So:
98201028Sthompsa	${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
99201028Sthompsa
100201028Sthompsaall: objwarn
101201028Sthompsa
102201028Sthompsa.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
103201028SthompsaOBJS+=		${SRCS:N*.h:R:S/$/.o/}
104201028Sthompsa.endif
105201028Sthompsa
106201028Sthompsa.if defined(LIB) && !empty(LIB)
107201028Sthompsa_LIBS=		lib${LIB}.a
108201028Sthompsa
109201028Sthompsalib${LIB}.a: ${OBJS} ${STATICOBJS}
110201028Sthompsa	@${ECHO} building static ${LIB} library
111201028Sthompsa	@rm -f ${.TARGET}
112201028Sthompsa	@${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
113201028Sthompsa	${RANLIB} ${.TARGET}
114201028Sthompsa.endif
115201028Sthompsa
116201028Sthompsa.if !defined(INTERNALLIB)
117201028Sthompsa
118201028Sthompsa.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
119201028Sthompsa_LIBS+=		lib${LIB}_p.a
120201028SthompsaPOBJS+=		${OBJS:.o=.po} ${STATICOBJS:.o=.po}
121201028Sthompsa
122201028Sthompsalib${LIB}_p.a: ${POBJS}
123201028Sthompsa	@${ECHO} building profiled ${LIB} library
124201028Sthompsa	@rm -f ${.TARGET}
125201028Sthompsa	@${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
126188417Sthompsa	${RANLIB} ${.TARGET}
127184610Salfred.endif
128193045Sthompsa
129193045Sthompsa.if defined(SHLIB_NAME) || \
130184610Salfred    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
131193045SthompsaSOBJS+=		${OBJS:.o=.So}
132192984Sthompsa.endif
133185948Sthompsa
134234753Sdim.if defined(SHLIB_NAME)
135234753Sdim_LIBS+=		${SHLIB_NAME}
136234753Sdim
137188417Sthompsa${SHLIB_NAME}: ${SOBJS}
138188417Sthompsa	@${ECHO} building shared library ${SHLIB_NAME}
139188419Sthompsa	@rm -f ${.TARGET} ${SHLIB_LINK}
140188419Sthompsa.if defined(SHLIB_LINK)
141188417Sthompsa	@ln -fs ${.TARGET} ${SHLIB_LINK}
142188417Sthompsa.endif
143188417Sthompsa	@${CC} ${LDFLAGS} -shared -Wl,-x \
144188417Sthompsa	    -o ${.TARGET} -Wl,-soname,${SONAME} \
145188417Sthompsa	    `lorder ${SOBJS} | tsort -q` ${LDADD}
146188417Sthompsa.endif
147188417Sthompsa
148188417Sthompsa.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
149188417Sthompsa_LIBS+=		lib${LIB}_pic.a
150188417Sthompsa
151188417Sthompsalib${LIB}_pic.a: ${SOBJS}
152188417Sthompsa	@${ECHO} building special pic ${LIB} library
153188417Sthompsa	@rm -f ${.TARGET}
154188417Sthompsa	@${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
155188417Sthompsa	${RANLIB} ${.TARGET}
156188417Sthompsa.endif
157188417Sthompsa
158188417Sthompsa.if defined(WANT_LINT) && !defined(NOLINT) && defined(LIB) && !empty(LIB)
159188417SthompsaLINTLIB=	llib-l${LIB}.ln
160188417Sthompsa_LIBS+=		${LINTLIB}
161188417SthompsaLINTOBJS+=	${SRCS:M*.c:.c=.ln}
162188417Sthompsa
163188417Sthompsa${LINTLIB}: ${LINTOBJS}
164188417Sthompsa	@${ECHO} building lint library ${.TARGET}
165188417Sthompsa	@rm -f ${.TARGET}
166188417Sthompsa	${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
167188417Sthompsa.endif
168188417Sthompsa
169188417Sthompsa.endif #!defined(INTERNALLIB)
170188417Sthompsa
171188417Sthompsaall: ${_LIBS}
172192468Ssam
173188417Sthompsa.if !defined(NOMAN)
174188417Sthompsaall: _manpages
175188417Sthompsa.endif
176188417Sthompsa
177188417Sthompsa_EXTRADEPEND:
178188417Sthompsa	@TMP=_depend$$$$; \
179189123Sthompsa	sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
180191746Sthompsa	    > $$TMP; \
181188417Sthompsa	mv $$TMP ${DEPENDFILE}
182188417Sthompsa.if !defined(NOEXTRADEPEND) && defined(SHLIB_NAME)
183188417Sthompsa.if defined(DPADD) && !empty(DPADD)
184188417Sthompsa	echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
185188417Sthompsa.endif
186191746Sthompsa.endif
187188417Sthompsa
188191746Sthompsa.if !target(install)
189188417Sthompsa
190188417Sthompsa.if defined(PRECIOUSLIB) && !defined(NOFSCHG)
191206358SrpauloSHLINSTALLFLAGS+= -fschg
192188417Sthompsa.endif
193206358Srpaulo
194206358Srpaulo_INSTALLFLAGS:=	${INSTALLFLAGS}
195188619Sthompsa.for ie in ${INSTALLFLAGS_EDIT}
196184610Salfred_INSTALLFLAGS:=	${_INSTALLFLAGS${ie}}
197184610Salfred.endfor
198188417Sthompsa_SHLINSTALLFLAGS:=	${SHLINSTALLFLAGS}
199184610Salfred.for ie in ${INSTALLFLAGS_EDIT}
200188417Sthompsa_SHLINSTALLFLAGS:=	${_SHLINSTALLFLAGS${ie}}
201188417Sthompsa.endfor
202188417Sthompsa
203188417Sthompsa.if !defined(INTERNALLIB)
204188417Sthompsarealinstall: _libinstall
205188417Sthompsa.ORDER: beforeinstall _libinstall
206188417Sthompsa_libinstall:
207188417Sthompsa.if defined(LIB) && !empty(LIB) && !defined(NOINSTALLLIB)
208188417Sthompsa	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
209188417Sthompsa	    ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
210188417Sthompsa.endif
211188417Sthompsa.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
212188417Sthompsa	${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
213188417Sthompsa	    ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
214188417Sthompsa.endif
215188417Sthompsa.if defined(SHLIB_NAME)
216188417Sthompsa	${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
217188417Sthompsa	    ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
218188417Sthompsa	    ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
219188417Sthompsa.if defined(SHLIB_LINK)
220188417Sthompsa.if ${SHLIBDIR} == ${LIBDIR}
221184610Salfred	ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
222184610Salfred.else
223184610Salfred	ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \
224184610Salfred	    ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
225184610Salfred.if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME})
226188417Sthompsa	-chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
227184610Salfred	rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
228184610Salfred.endif
229188417Sthompsa.endif
230188417Sthompsa.endif
231188417Sthompsa.endif
232188417Sthompsa.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
233188417Sthompsa	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
234188417Sthompsa	    ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
235188417Sthompsa.endif
236188417Sthompsa.if defined(WANT_LINT) && !defined(NOLINT) && defined(LIB) && !empty(LIB)
237188417Sthompsa	${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
238188417Sthompsa	    ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
239188417Sthompsa.endif
240188417Sthompsa.endif !defined(INTERNALLIB)
241188417Sthompsa
242188417Sthompsa.include <bsd.files.mk>
243188417Sthompsa.include <bsd.incs.mk>
244188417Sthompsa.include <bsd.links.mk>
245188417Sthompsa
246188417Sthompsa.if !defined(NOMAN)
247188417Sthompsarealinstall: _maninstall
248188417Sthompsa.ORDER: beforeinstall _maninstall
249188417Sthompsa.endif
250188417Sthompsa
251188417Sthompsa.endif
252188417Sthompsa
253188417Sthompsa.if !target(lint)
254188417Sthompsalint: ${SRCS:M*.c}
255188417Sthompsa	${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
256188417Sthompsa.endif
257188417Sthompsa
258188417Sthompsa.if !defined(NOMAN)
259188417Sthompsa.include <bsd.man.mk>
260188417Sthompsa.endif
261188417Sthompsa
262184610Salfred.include <bsd.dep.mk>
263184610Salfred
264184610Salfred.if !exists(${.OBJDIR}/${DEPENDFILE})
265184610Salfred.if defined(LIB) && !empty(LIB)
266184610Salfred${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
267184610Salfred.for _S in ${SRCS:N*.[hly]}
268184610Salfred${_S:R}.po: ${_S}
269184610Salfred.endfor
270184610Salfred.endif
271184610Salfred.if defined(SHLIB_NAME) || \
272184610Salfred    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
273184610Salfred${SOBJS}: ${SRCS:M*.h}
274184610Salfred.for _S in ${SRCS:N*.[hly]}
275184610Salfred${_S:R}.So: ${_S}
276184610Salfred.endfor
277184610Salfred.endif
278184610Salfred.endif
279184610Salfred
280184610Salfred.if !target(clean)
281184610Salfredclean:
282184610Salfred.if defined(CLEANFILES) && !empty(CLEANFILES)
283184610Salfred	rm -f ${CLEANFILES}
284184610Salfred.endif
285184610Salfred.if defined(LIB) && !empty(LIB)
286184610Salfred	rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
287184610Salfred.endif
288184610Salfred.if !defined(INTERNALLIB)
289184610Salfred.if !defined(NOPROFILE) && defined(LIB) && !empty(LIB)
290184610Salfred	rm -f ${POBJS} ${POBJS:S/$/.tmp/}
291184610Salfred.endif
292184610Salfred.if defined(SHLIB_NAME) || \
293184610Salfred    defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
294184610Salfred	rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
295184610Salfred.endif
296184610Salfred.if defined(SHLIB_NAME)
297184610Salfred.if defined(SHLIB_LINK)
298184610Salfred	rm -f ${SHLIB_LINK}
299184610Salfred.endif
300184610Salfred.if defined(LIB) && !empty(LIB)
301184610Salfred	rm -f lib${LIB}.so.* lib${LIB}.so
302184610Salfred.endif
303184610Salfred.endif
304184610Salfred.if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
305184610Salfred	rm -f ${LINTOBJS}
306184610Salfred.endif
307184610Salfred.endif !defined(INTERNALLIB)
308184610Salfred.if defined(_LIBS) && !empty(_LIBS)
309184610Salfred	rm -f ${_LIBS}
310184610Salfred.endif
311188417Sthompsa.if defined(CLEANDIRS) && !empty(CLEANDIRS)
312188417Sthompsa	rm -rf ${CLEANDIRS}
313188417Sthompsa.endif
314188417Sthompsa.endif
315188417Sthompsa
316188417Sthompsa.include <bsd.obj.mk>
317188417Sthompsa
318188417Sthompsa.include <bsd.sys.mk>
319188417Sthompsa