bsd.lib.mk revision 24761
1#	from: @(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
2#	$Id: bsd.lib.mk,v 1.51 1997/04/09 16:10:24 bde 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/${CXX}
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-[ID]*} ${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-[ID]*} ${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-[ID]*} ${AINC} -c \
84	    ${.IMPSRC} -o ${.TARGET}
85	@${LD} -O ${.TARGET} -x -r ${.TARGET}
86
87.S.o:
88	${CC} ${CFLAGS:M-[ID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
89
90.S.po:
91	${CC} -DPROF ${CFLAGS:M-[ID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
92
93.S.so:
94	${CC} -fpic -DPIC ${CFLAGS:M-[ID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
95	@${LD} -O ${.TARGET} -x -r ${.TARGET}
96
97.m.po:
98	${CC} ${CFLAGS} -fgnu-runtime -pg -c ${.IMPSRC} -o ${.TARGET}
99	@${LD} -O ${.TARGET} -X -r ${.TARGET}
100
101.m.o:
102	${CC} ${CFLAGS} -fgnu-runtime -c ${.IMPSRC} -o ${.TARGET}
103	@${LD} -O ${.TARGET} -X -r ${.TARGET}
104
105.if !defined(INTERNALLIB) || defined(INTERNALSTATICLIB)
106.if !defined(NOPROFILE) && !defined(INTERNALLIB)
107_LIBS=lib${LIB}.a lib${LIB}_p.a
108.else
109_LIBS=lib${LIB}.a
110.endif
111.endif
112
113.if !defined(NOPIC)
114.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
115_LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
116.endif
117.if defined(INSTALL_PIC_ARCHIVE)
118_LIBS+=lib${LIB}_pic.a
119.endif
120.endif
121
122.if !defined(PICFLAG)
123PICFLAG=-fpic
124.endif
125
126all: objwarn ${_LIBS} all-man _SUBDIR # llib-l${LIB}.ln
127
128OBJS+=	${SRCS:N*.h:R:S/$/.o/g}
129
130lib${LIB}.a:: ${OBJS}
131	@${ECHO} building standard ${LIB} library
132	@rm -f lib${LIB}.a
133	@${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q` ${ARADD}
134	${RANLIB} lib${LIB}.a
135
136.if !defined(NOPROFILE)
137POBJS+=	${OBJS:.o=.po}
138lib${LIB}_p.a:: ${POBJS}
139	@${ECHO} building profiled ${LIB} library
140	@rm -f lib${LIB}_p.a
141	@${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q` ${ARADD}
142	${RANLIB} lib${LIB}_p.a
143.endif
144
145.if defined(DESTDIR)
146LDDESTDIR?=	-L${DESTDIR}${SHLIBDIR} -L${DESTDIR}/usr/lib
147# LDDESTDIR+=	-nostdlib
148.endif
149
150.if !defined(NOPIC)
151.if defined(CPLUSPLUSLIB) && !make(clean) && !make(cleandir)
152SOBJS+= ${DESTDIR}/usr/lib/c++rt0.o
153.endif
154
155SOBJS+= ${OBJS:.o=.so}
156lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: ${SOBJS}
157	@${ECHO} building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
158	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
159	@${LD} -Bshareable -x \
160	    -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
161	    `lorder ${SOBJS} | tsort -q` ${LDDESTDIR} ${LDADD}
162
163lib${LIB}_pic.a:: ${SOBJS}
164	@${ECHO} building special pic ${LIB} library
165	@rm -f lib${LIB}_pic.a
166	@${AR} cq lib${LIB}_pic.a ${SOBJS} ${ARADD}
167	${RANLIB} lib${LIB}_pic.a
168.endif
169
170llib-l${LIB}.ln: ${SRCS}
171	${LINT} -C${LIB} ${CFLAGS} ${.ALLSRC:M*.c}
172
173.if !target(clean)
174clean:	_SUBDIR
175	rm -f a.out Errs errs mklog ${CLEANFILES} ${OBJS}
176	rm -f lib${LIB}.a llib-l${LIB}.ln
177	rm -f ${POBJS} profiled/*.o lib${LIB}_p.a
178	rm -f ${SOBJS} shared/*.o
179	rm -f lib${LIB}.so.*.* lib${LIB}_pic.a
180.if defined(CLEANDIRS) && !empty(CLEANDIRS)
181	rm -rf ${CLEANDIRS}
182.endif
183.endif
184
185.if defined(SRCS)
186_EXTRADEPEND::
187	@TMP=_depend$$$$; \
188	sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so:/' < ${DEPENDFILE} \
189	    > $$TMP; \
190	mv $$TMP ${DEPENDFILE}
191.endif
192.if defined(LDADD)
193_EXTRADEPEND::
194	echo lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: \
195	    `ld -Bshareable -x -f ${LDDESTDIR} ${LDADD}` >> ${DEPENDFILE}
196.endif
197
198.if !target(install)
199.if !target(beforeinstall)
200beforeinstall:
201.endif
202
203.if defined(PRECIOUSLIB)
204SHLINSTALLFLAGS+= -fschg
205.endif
206
207realinstall: beforeinstall
208.if !defined(INTERNALLIB)
209	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
210	    ${INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
211.if !defined(NOPROFILE)
212	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
213	    ${INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
214.endif
215.endif
216.if !defined(NOPIC)
217.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
218	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
219	    ${INSTALLFLAGS} ${SHLINSTALLFLAGS} \
220	    lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
221	    ${DESTDIR}${SHLIBDIR}
222.endif
223.if defined(INSTALL_PIC_ARCHIVE)
224	${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
225	    ${INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
226.endif
227.endif
228.if defined(LINKS) && !empty(LINKS)
229	@set ${LINKS}; \
230	while test $$# -ge 2; do \
231		l=${DESTDIR}$$1; \
232		shift; \
233		t=${DESTDIR}$$1; \
234		shift; \
235		${ECHO} $$t -\> $$l; \
236		rm -f $$t; \
237		ln ${LN_FLAGS} $$l $$t; \
238	done; true
239.endif
240
241install: afterinstall _SUBDIR
242.if !defined(NOMAN)
243afterinstall: realinstall maninstall
244.else
245afterinstall: realinstall
246.endif
247.endif
248
249DISTRIBUTION?=	bin
250.if !target(distribute)
251distribute:	_SUBDIR
252	cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${DISTRIBUTION} SHARED=copies
253.endif
254
255.if !target(lint)
256lint:
257.endif
258
259.if !target(tags)
260tags: ${SRCS} _SUBDIR
261	-cd ${.CURDIR}; ctags -f /dev/stdout ${.ALLSRC:M*.c} | \
262	    sed "s;\${.CURDIR}/;;" > tags
263.endif
264
265.if !defined(NOMAN)
266.include <bsd.man.mk>
267.elif !target(maninstall)
268maninstall:
269all-man:
270.endif
271
272.include <bsd.dep.mk>
273.include <bsd.obj.mk>
274