xref: /netbsd-src/share/mk/bsd.lib.mk (revision ae9172d6cd9432a6a1a56760d86b32c57a66c39c)
1#	$NetBSD: bsd.lib.mk,v 1.55 1994/12/13 08:46:22 mycroft Exp $
2#	@(#)bsd.lib.mk	5.26 (Berkeley) 5/2/91
3
4.if exists(${.CURDIR}/../Makefile.inc)
5.include "${.CURDIR}/../Makefile.inc"
6.endif
7
8.include <bsd.own.mk>				# for 'NOPIC' definition
9
10.if exists(${.CURDIR}/shlib_version)
11SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
12SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
13.endif
14
15.MAIN: all
16
17# prefer .S to a .c, add .po, remove stuff not used in the BSD libraries
18# .so used for PIC object files
19.SUFFIXES:
20.SUFFIXES: .out .o .po .so .S .s .c .cc .C .f .y .l .m4
21
22.c.o:
23	${COMPILE.c} ${.IMPSRC}
24	@${LD} -x -r ${.TARGET}
25	@mv a.out ${.TARGET}
26
27.c.po:
28	${COMPILE.c} -p ${.IMPSRC} -o ${.TARGET}
29	@${LD} -X -r ${.TARGET}
30	@mv a.out ${.TARGET}
31
32.c.so:
33	${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}
34	@${LD} -x -r ${.TARGET}
35	@mv a.out ${.TARGET}
36
37.cc.o .C.o:
38	${COMPILE.cc} ${.IMPSRC}
39	@${LD} -x -r ${.TARGET}
40	@mv a.out ${.TARGET}
41
42.cc.po .C.po:
43	${COMPILE.cc} -p ${.IMPSRC} -o ${.TARGET}
44	@${LD} -X -r ${.TARGET}
45	@mv a.out ${.TARGET}
46
47.cc.so .C.so:
48	${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}
49	@${LD} -x -r ${.TARGET}
50	@mv a.out ${.TARGET}
51
52.S.o .s.o:
53	${CPP} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
54	    ${AS} -o ${.TARGET}
55	@${LD} -x -r ${.TARGET}
56	@mv a.out ${.TARGET}
57
58.S.po .s.po:
59	${CPP} -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
60	    ${AS} -o ${.TARGET}
61	@${LD} -X -r ${.TARGET}
62	@mv a.out ${.TARGET}
63
64.S.so .s.so:
65	${CPP} -DPIC ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} | \
66	    ${AS} -k -o ${.TARGET}
67	@${LD} -x -r ${.TARGET}
68	@mv a.out ${.TARGET}
69
70.if !defined(NOPROFILE)
71_LIBS=lib${LIB}.a lib${LIB}_p.a
72.else
73_LIBS=lib${LIB}.a
74.endif
75
76.if !defined(NOPIC)
77_LIBS+=lib${LIB}_pic.a
78.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
79_LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
80.endif
81.endif
82
83.if !defined(PICFLAG)
84PICFLAG=-fpic
85.endif
86
87all: ${_LIBS} _SUBDIRUSE # llib-l${LIB}.ln
88
89OBJS+=	${SRCS:N*.h:R:S/$/.o/g}
90
91lib${LIB}.a:: ${OBJS}
92	@echo building standard ${LIB} library
93	@rm -f lib${LIB}.a
94	@${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort`
95	${RANLIB} lib${LIB}.a
96
97POBJS+=	${OBJS:.o=.po}
98lib${LIB}_p.a:: ${POBJS}
99	@echo building profiled ${LIB} library
100	@rm -f lib${LIB}_p.a
101	@${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort`
102	${RANLIB} lib${LIB}_p.a
103
104SOBJS+=	${OBJS:.o=.so}
105lib${LIB}_pic.a:: ${SOBJS}
106	@echo building shared object ${LIB} library
107	@rm -f lib${LIB}_pic.a
108	@${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort`
109	${RANLIB} lib${LIB}_pic.a
110
111lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}
112	@echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
113	@rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
114	$(LD) -x -Bshareable -Bforcearchive \
115	    -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}_pic.a ${LDADD}
116
117llib-l${LIB}.ln: ${SRCS}
118	${LINT} -C${LIB} ${CFLAGS} ${.ALLSRC:M*.c}
119
120.if !target(clean)
121clean: _SUBDIRUSE
122	rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
123	rm -f ${OBJS}
124	rm -f ${POBJS} profiled/*.o
125	rm -f ${SOBJS} shared/*.o
126	rm -f lib${LIB}.a lib${LIB}_p.a lib${LIB}_pic.a llib-l${LIB}.ln
127	rm -f lib${LIB}.so.*.*
128.endif
129
130cleandir: _SUBDIRUSE clean
131
132.if defined(SRCS)
133afterdepend:
134	@(TMP=/tmp/_depend$$$$; \
135	    sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so:/' < .depend > $$TMP; \
136	    mv $$TMP .depend)
137.endif
138
139.if !target(install)
140.if !target(beforeinstall)
141beforeinstall:
142.endif
143
144realinstall:
145#	ranlib lib${LIB}.a
146	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} lib${LIB}.a \
147	    ${DESTDIR}${LIBDIR}
148	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
149.if !defined(NOPROFILE)
150#	ranlib lib${LIB}_p.a
151	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
152	    lib${LIB}_p.a ${DESTDIR}${LIBDIR}
153	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
154.endif
155.if !defined(NOPIC)
156#	ranlib lib${LIB}_pic.a
157	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
158	    lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
159	${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
160.endif
161.if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
162	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
163	    lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR}
164.endif
165#	install ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
166#	    llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
167.if defined(LINKS) && !empty(LINKS)
168	@set ${LINKS}; \
169	while test $$# -ge 2; do \
170		l=${DESTDIR}$$1; \
171		shift; \
172		t=${DESTDIR}$$1; \
173		shift; \
174		echo $$t -\> $$l; \
175		rm -f $$t; \
176		ln $$l $$t; \
177	done; true
178.endif
179
180install: maninstall _SUBDIRUSE
181maninstall: afterinstall
182afterinstall: realinstall
183realinstall: beforeinstall
184.endif
185
186.if !defined(NOMAN)
187.include <bsd.man.mk>
188.endif
189
190.include <bsd.obj.mk>
191.include <bsd.dep.mk>
192.include <bsd.subdir.mk>
193