bsd.lib.mk revision 27910
1#	from: @(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
2#	$Id: bsd.lib.mk,v 1.59 1997/06/21 15:40:32 jkh Exp $
3#
4
5.if exists(${.CURDIR}/../Makefile.inc)
6.include "${.CURDIR}/../Makefile.inc"
7.endif
8
9.if exists(${.CURDIR}/shlib_version)
10SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
11SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
12.endif
13
14.if defined(DESTDIR)
15CFLAGS+= -I${DESTDIR}/usr/include
16CXXINCLUDES+= -I${DESTDIR}/usr/include/g++
17.endif
18
19.if defined(DEBUG_FLAGS)
20CFLAGS+= ${DEBUG_FLAGS}
21.endif
22
23.if !defined(DEBUG_FLAGS)
24STRIP?=	-s
25.endif
26
27.include <bsd.libnames.mk>
28
29.MAIN: all
30
31# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
32# .so used for PIC object files
33.SUFFIXES:
34.SUFFIXES: .out .o .po .so .s .S .c .cc .cxx .m .C .f .y .l
35
36.c.o:
37	${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
38	@${LD} -O ${.TARGET} -x -r ${.TARGET}
39
40.c.po:
41	${CC} -pg ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
42	@${LD} -O ${.TARGET} -X -r ${.TARGET}
43
44.c.so:
45	${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
46	@${LD} -O ${.TARGET} -x -r ${.TARGET}
47
48.cc.o .C.o .cxx.o:
49	${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
50	@${LD} -O ${.TARGET} -x -r ${.TARGET}
51
52.cc.po .C.po .cxx.po:
53	${CXX} -pg ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
54	@${LD} -O ${.TARGET} -X -r ${.TARGET}
55
56.cc.so .C.so .cxx.so:
57	${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
58	@${LD} -O ${.TARGET} -x -r ${.TARGET}
59
60.f.o:
61	${FC} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 
62	@${LD} -O ${.TARGET} -x -r ${.TARGET}
63
64.f.po:
65	${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 
66	@${LD} -O ${.TARGET} -X -r ${.TARGET}
67
68.f.so:
69	${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
70	@${LD} -O ${.TARGET} -x -r ${.TARGET}
71
72.s.o:
73	${CC} -x assembler-with-cpp ${CFLAGS:M-[BID]*} ${AINC} -c \
74	    ${.IMPSRC} -o ${.TARGET}
75	@${LD} -O ${.TARGET} -x -r ${.TARGET}
76
77.s.po:
78	${CC} -x assembler-with-cpp -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c \
79	    ${.IMPSRC} -o ${.TARGET}
80	@${LD} -O ${.TARGET} -X -r ${.TARGET}
81
82.s.so:
83	${CC} -x assembler-with-cpp -fpic -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c \
84	    ${.IMPSRC} -o ${.TARGET}
85	@${LD} -O ${.TARGET} -x -r ${.TARGET}
86
87.S.o:
88	${CC} ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
89	@${LD} -O ${.TARGET} -x -r ${.TARGET}
90
91.S.po:
92	${CC} -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
93	@${LD} -O ${.TARGET} -X -r ${.TARGET}
94
95.S.so:
96	${CC} -fpic -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
97	@${LD} -O ${.TARGET} -x -r ${.TARGET}
98
99.m.o:
100	${CC} ${CFLAGS} -fgnu-runtime -c ${.IMPSRC} -o ${.TARGET}
101	@${LD} -O ${.TARGET} -x -r ${.TARGET}
102
103.m.po:
104	${CC} ${CFLAGS} -fgnu-runtime -pg -c ${.IMPSRC} -o ${.TARGET}
105	@${LD} -O ${.TARGET} -X -r ${.TARGET}
106
107.if !defined(INTERNALLIB) || defined(INTERNALSTATICLIB)
108.if !defined(NOPROFILE) && !defined(INTERNALLIB)
109_LIBS=lib${LIB}.a lib${LIB}_p.a
110.else
111_LIBS=lib${LIB}.a
112.endif
113.endif
114
115.if !defined(NOPIC)
116.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
117_LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
118.endif
119.if defined(INSTALL_PIC_ARCHIVE)
120_LIBS+=lib${LIB}_pic.a
121.endif
122.endif
123
124.if !defined(PICFLAG)
125PICFLAG=-fpic
126.endif
127
128all: objwarn ${_LIBS} all-man _SUBDIR # llib-l${LIB}.ln
129
130OBJS+=	${SRCS:N*.h:R:S/$/.o/g}
131
132lib${LIB}.a:: ${OBJS}
133	@${ECHO} building standard ${LIB} library
134	@rm -f lib${LIB}.a
135	@${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q` ${ARADD}
136	${RANLIB} lib${LIB}.a
137
138.if !defined(NOPROFILE)
139POBJS+=	${OBJS:.o=.po}
140lib${LIB}_p.a:: ${POBJS}
141	@${ECHO} building profiled ${LIB} library
142	@rm -f lib${LIB}_p.a
143	@${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q` ${ARADD}
144	${RANLIB} lib${LIB}_p.a
145.endif
146
147.if defined(DESTDIR)
148LDDESTDIRENV?=	LIBRARY_PATH=${DESTDIR}${SHLIBDIR}:${DESTDIR}/usr/lib
149.endif
150
151.if !defined(NOPIC)
152SOBJS+= ${OBJS:.o=.so}
153lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: ${SOBJS}
154	@${ECHO} building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
155	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
156	@${LDDESTDIRENV} ${CC} -shared -Wl,-x -Wl,-assert -Wl,pure-text \
157	    -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
158	    `lorder ${SOBJS} | tsort -q` ${LDDESTDIR} ${LDADD}
159
160lib${LIB}_pic.a:: ${SOBJS}
161	@${ECHO} building special pic ${LIB} library
162	@rm -f lib${LIB}_pic.a
163	@${AR} cq lib${LIB}_pic.a ${SOBJS} ${ARADD}
164	${RANLIB} lib${LIB}_pic.a
165.endif
166
167llib-l${LIB}.ln: ${SRCS}
168	${LINT} -C${LIB} ${CFLAGS} ${.ALLSRC:M*.c}
169
170.if !target(clean)
171clean:	_SUBDIR
172	rm -f a.out Errs errs mklog ${CLEANFILES} ${OBJS}
173	rm -f lib${LIB}.a llib-l${LIB}.ln
174	rm -f ${POBJS} profiled/*.o lib${LIB}_p.a
175	rm -f ${SOBJS} shared/*.o
176	rm -f lib${LIB}.so.*.* lib${LIB}_pic.a
177.if defined(CLEANDIRS) && !empty(CLEANDIRS)
178	rm -rf ${CLEANDIRS}
179.endif
180.endif
181
182.if defined(SRCS)
183_EXTRADEPEND::
184	@TMP=_depend$$$$; \
185	sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so:/' < ${DEPENDFILE} \
186	    > $$TMP; \
187	mv $$TMP ${DEPENDFILE}
188.endif
189.if !defined(NOEXTRADEPEND)
190_EXTRADEPEND::
191	echo lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: \
192	    `${LDDESTDIRENV} ${CC} -shared -Wl,-f ${LDDESTDIR} ${LDADD}` \
193	    >> ${DEPENDFILE}
194.endif
195
196.if !target(install)
197.if !target(beforeinstall)
198beforeinstall:
199.endif
200
201.if defined(PRECIOUSLIB)
202SHLINSTALLFLAGS+= -fschg
203.endif
204
205realinstall: beforeinstall
206.if !defined(INTERNALLIB)
207	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
208	    ${INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
209.if !defined(NOPROFILE)
210	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
211	    ${INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
212.endif
213.endif
214.if !defined(NOPIC)
215.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
216	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
217	    ${INSTALLFLAGS} ${SHLINSTALLFLAGS} \
218	    lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
219	    ${DESTDIR}${SHLIBDIR}
220.endif
221.if defined(INSTALL_PIC_ARCHIVE)
222	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
223	    ${INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
224.endif
225.endif
226.if defined(LINKS) && !empty(LINKS)
227	@set ${LINKS}; \
228	while test $$# -ge 2; do \
229		l=${DESTDIR}$$1; \
230		shift; \
231		t=${DESTDIR}$$1; \
232		shift; \
233		${ECHO} $$t -\> $$l; \
234		rm -f $$t; \
235		ln ${LN_FLAGS} $$l $$t; \
236	done; true
237.endif
238
239install: afterinstall _SUBDIR
240.if !defined(NOMAN)
241afterinstall: realinstall maninstall
242.else
243afterinstall: realinstall
244.endif
245.endif
246
247DISTRIBUTION?=	bin
248.if !target(distribute)
249distribute:	_SUBDIR
250.for dist in ${DISTRIBUTION}
251	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
252.endfor
253.endif
254
255.if !target(lint)
256lint:
257.endif
258
259.if defined(NOTAGS)
260tags:
261.endif
262
263.if !target(tags)
264tags: ${SRCS} _SUBDIR
265	@cd ${.CURDIR} && gtags ${GTAGSFLAGS}
266.if defined(HTML)
267	@cd ${.CURDIR} && htags ${HTAGSFLAGS}
268.endif
269.endif
270
271.if !defined(NOMAN)
272.include <bsd.man.mk>
273.elif !target(maninstall)
274maninstall:
275all-man:
276.endif
277
278.include <bsd.dep.mk>
279.include <bsd.obj.mk>
280