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