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