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