bsd.lib.mk revision 1.85 1 # $NetBSD: bsd.lib.mk,v 1.85 1997/03/14 00:52:50 cgd 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)
11 SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
12 SHLIB_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. .ln used for lint output files.
19 .SUFFIXES:
20 .SUFFIXES: .out .o .po .so .S .s .c .cc .C .f .y .l .ln .m4
21
22 CFLAGS+= ${COPTS}
23
24 .c.o:
25 @echo ${COMPILE.c:Q} ${.IMPSRC}
26 @${COMPILE.c} ${.IMPSRC} -o ${.TARGET}.o
27 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
28 @rm -f ${.TARGET}.o
29
30 .c.po:
31 @echo ${COMPILE.c:Q} -pg ${.IMPSRC} -o ${.TARGET}
32 @${COMPILE.c} -pg ${.IMPSRC} -o ${.TARGET}.o
33 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
34 @rm -f ${.TARGET}.o
35
36 .c.so:
37 @echo ${COMPILE.c:Q} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}
38 @${COMPILE.c} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
39 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
40 @rm -f ${.TARGET}.o
41
42 .c.ln:
43 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[IDU]*} -i ${.IMPSRC}
44
45 .cc.o .C.o:
46 @echo ${COMPILE.cc:Q} ${.IMPSRC}
47 @${COMPILE.cc} ${.IMPSRC} -o ${.TARGET}.o
48 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
49 @rm -f ${.TARGET}.o
50
51 .cc.po .C.po:
52 @echo ${COMPILE.cc:Q} -pg ${.IMPSRC} -o ${.TARGET}
53 @${COMPILE.cc} -pg ${.IMPSRC} -o ${.TARGET}.o
54 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
55 @rm -f ${.TARGET}.o
56
57 .cc.so .C.so:
58 @echo ${COMPILE.cc:Q} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}
59 @${COMPILE.cc} ${PICFLAG} -DPIC ${.IMPSRC} -o ${.TARGET}.o
60 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
61 @rm -f ${.TARGET}.o
62
63 .S.o .s.o:
64 @echo ${COMPILE.S:Q} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC}
65 @${COMPILE.S} ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
66 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
67 @rm -f ${.TARGET}.o
68
69 .S.po .s.po:
70 @echo ${COMPILE.S:Q} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
71 @${COMPILE.S} -DGPROF -DPROF ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
72 @${LD} -X -r ${.TARGET}.o -o ${.TARGET}
73 @rm -f ${.TARGET}.o
74
75 .S.so .s.so:
76 @echo ${COMPILE.S:Q} ${PICFLAG} -DPIC ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}
77 @${COMPILE.S} ${PICFLAG} -DPIC ${CFLAGS:M-[ID]*} ${AINC} ${.IMPSRC} -o ${.TARGET}.o
78 @${LD} -x -r ${.TARGET}.o -o ${.TARGET}
79 @rm -f ${.TARGET}.o
80
81 .if !defined(PICFLAG)
82 PICFLAG=-fpic
83 .endif
84
85 .if !defined(NOPROFILE)
86 _LIBS=lib${LIB}.a lib${LIB}_p.a
87 .else
88 _LIBS=lib${LIB}.a
89 .endif
90
91 .if !defined(NOPIC)
92 _LIBS+=lib${LIB}_pic.a
93 .if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
94 _LIBS+=lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
95 .endif
96 .endif
97
98 .if !defined(NOLINT)
99 _LIBS+=llib-l${LIB}.ln
100 .endif
101
102 all: ${_LIBS} _SUBDIRUSE
103
104 OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
105
106 lib${LIB}.a:: ${OBJS}
107 @echo building standard ${LIB} library
108 @rm -f lib${LIB}.a
109 @${AR} cq lib${LIB}.a `lorder ${OBJS} | tsort -q`
110 ${RANLIB} lib${LIB}.a
111
112 POBJS+= ${OBJS:.o=.po}
113 lib${LIB}_p.a:: ${POBJS}
114 @echo building profiled ${LIB} library
115 @rm -f lib${LIB}_p.a
116 @${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q`
117 ${RANLIB} lib${LIB}_p.a
118
119 SOBJS+= ${OBJS:.o=.so}
120 lib${LIB}_pic.a:: ${SOBJS}
121 @echo building shared object ${LIB} library
122 @rm -f lib${LIB}_pic.a
123 @${AR} cq lib${LIB}_pic.a `lorder ${SOBJS} | tsort -q`
124 ${RANLIB} lib${LIB}_pic.a
125
126 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}: lib${LIB}_pic.a ${DPADD}
127 @echo building shared ${LIB} library \(version ${SHLIB_MAJOR}.${SHLIB_MINOR}\)
128 @rm -f lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
129 .if (${MACHINE_ARCH} != "alpha")
130 $(LD) -x -Bshareable -Bforcearchive \
131 -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} lib${LIB}_pic.a ${LDADD}
132 .else
133 $(LD) -shared -o lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
134 -soname lib${LIB}.so.${SHLIB_MAJOR} \
135 ${DESTDIR}/usr/lib/crtbeginS.o \
136 --whole-archive lib${LIB}_pic.a --no-whole-archive ${LDADD} \
137 ${DESTDIR}/usr/lib/crtendS.o
138 .endif
139
140 LOBJS+= ${LSRCS:.c=.ln} ${SRCS:M*.c:.c=.ln}
141 LLIBS?= -lc
142 llib-l${LIB}.ln: ${LOBJS}
143 @echo building llib-l${LIB}.ln
144 @rm -f llib-l${LIB}.ln
145 @${LINT} -C${LIB} ${LOBJS} ${LLIBS}
146
147 .if !target(clean)
148 cleanlib:
149 rm -f a.out [Ee]rrs mklog core *.core ${CLEANFILES}
150 rm -f lib${LIB}.a ${OBJS}
151 rm -f lib${LIB}_p.a ${POBJS}
152 rm -f lib${LIB}_pic.a lib${LIB}.so.*.* ${SOBJS}
153 rm -f llib-l${LIB}.ln ${LOBJS}
154
155 clean: _SUBDIRUSE cleanlib
156 cleandir: _SUBDIRUSE cleanlib
157 .else
158 cleandir: _SUBDIRUSE clean
159 .endif
160
161 .if defined(SRCS)
162 afterdepend: .depend
163 @(TMP=/tmp/_depend$$$$; \
164 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.so \1.ln:/' \
165 < .depend > $$TMP; \
166 mv $$TMP .depend)
167 .endif
168
169 .if !target(install)
170 .if !target(beforeinstall)
171 beforeinstall:
172 .endif
173
174 realinstall:
175 # ranlib lib${LIB}.a
176 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 lib${LIB}.a \
177 ${DESTDIR}${LIBDIR}
178 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}.a
179 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}.a
180 .if !defined(NOPROFILE)
181 # ranlib lib${LIB}_p.a
182 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
183 lib${LIB}_p.a ${DESTDIR}${LIBDIR}
184 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
185 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_p.a
186 .endif
187 .if !defined(NOPIC)
188 # ranlib lib${LIB}_pic.a
189 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m 600 \
190 lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
191 ${RANLIB} -t ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
192 chmod ${LIBMODE} ${DESTDIR}${LIBDIR}/lib${LIB}_pic.a
193 .endif
194 .if !defined(NOPIC) && defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
195 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
196 lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} ${DESTDIR}${LIBDIR}
197 .if (${MACHINE_ARCH} == "alpha")
198 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
199 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
200 ${DESTDIR}${LIBDIR}/lib${LIB}.so.${SHLIB_MAJOR}
201 rm -f ${DESTDIR}${LIBDIR}/lib${LIB}.so
202 ln -s lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} \
203 ${DESTDIR}${LIBDIR}/lib${LIB}.so
204 .endif
205 .endif
206 .if !defined(NOLINT)
207 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
208 llib-l${LIB}.ln ${DESTDIR}${LINTLIBDIR}
209 .endif
210 .if defined(LINKS) && !empty(LINKS)
211 @set ${LINKS}; \
212 while test $$# -ge 2; do \
213 l=${DESTDIR}$$1; \
214 shift; \
215 t=${DESTDIR}$$1; \
216 shift; \
217 echo $$t -\> $$l; \
218 rm -f $$t; \
219 ln $$l $$t; \
220 done; true
221 .endif
222 .if defined(SYMLINKS) && !empty(SYMLINKS)
223 @set ${SYMLINKS}; \
224 while test $$# -ge 2; do \
225 l=${DESTDIR}$$1; \
226 shift; \
227 t=${DESTDIR}$$1; \
228 shift; \
229 echo $$t -\> $$l; \
230 rm -f $$t; \
231 ln -s $$l $$t; \
232 done; true
233 .endif
234
235 install: maninstall _SUBDIRUSE
236 maninstall: afterinstall
237 afterinstall: realinstall
238 realinstall: beforeinstall
239 .endif
240
241 .if !defined(NOMAN)
242 .include <bsd.man.mk>
243 .endif
244
245 .if !defined(NONLS)
246 .include <bsd.nls.mk>
247 .endif
248
249 .include <bsd.obj.mk>
250 .include <bsd.dep.mk>
251 .include <bsd.subdir.mk>
252 .include <bsd.sys.mk>
253