]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - share/mk/bsd.lib.mk
This commit was generated by cvs2svn to compensate for changes in r162852,
[FreeBSD/FreeBSD.git] / share / mk / bsd.lib.mk
1 #       from: @(#)bsd.lib.mk    5.26 (Berkeley) 5/2/91
2 # $FreeBSD$
3 #
4
5 .include <bsd.init.mk>
6
7 # Set up the variables controlling shared libraries.  After this section,
8 # SHLIB_NAME will be defined only if we are to create a shared library.
9 # SHLIB_LINK will be defined only if we are to create a link to it.
10 # INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
11 .if defined(NO_PIC)
12 .undef SHLIB_NAME
13 .undef INSTALL_PIC_ARCHIVE
14 .else
15 .if !defined(SHLIB) && defined(LIB)
16 SHLIB=          ${LIB}
17 .endif
18 .if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR)
19 SHLIB_NAME=     lib${SHLIB}.so.${SHLIB_MAJOR}
20 .endif
21 .if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*)
22 SHLIB_LINK?=    ${SHLIB_NAME:R}
23 .endif
24 SONAME?=        ${SHLIB_NAME}
25 .endif
26
27 .if defined(CRUNCH_CFLAGS)
28 CFLAGS+=        ${CRUNCH_CFLAGS}
29 .endif
30
31 .if ${MK_ASSERT_DEBUG} == "no"
32 CFLAGS+= -DNDEBUG
33 NO_WERROR=
34 .endif
35
36 .if defined(DEBUG_FLAGS)
37 CFLAGS+= ${DEBUG_FLAGS}
38 .endif
39
40 .if !defined(DEBUG_FLAGS)
41 STRIP?= -s
42 .endif
43
44 .include <bsd.libnames.mk>
45
46 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
47 # .So used for PIC object files
48 .SUFFIXES:
49 .SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .m .C .f .y .l .ln
50
51 .if !defined(PICFLAG)
52 .if ${MACHINE_ARCH} == "sparc64"
53 PICFLAG=-fPIC
54 .else
55 PICFLAG=-fpic
56 .endif
57 .endif
58
59 .if ${CC} == "icc"
60 PO_FLAG=-p
61 .else
62 PO_FLAG=-pg
63 .endif
64
65 .c.po:
66         ${CC} ${PO_FLAG} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
67
68 .c.So:
69         ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
70
71 .cc.po .C.po .cpp.po .cxx.po:
72         ${CXX} ${PO_FLAG} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
73
74 .cc.So .C.So .cpp.So .cxx.So:
75         ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
76
77 .f.po:
78         ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
79
80 .f.So:
81         ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
82
83 .m.po:
84         ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
85
86 .m.So:
87         ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
88
89 .s.po .s.So:
90         ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
91
92 .asm.po:
93         ${CC} -x assembler-with-cpp -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
94
95 .asm.So:
96         ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} \
97             -c ${.IMPSRC} -o ${.TARGET}
98
99 .S.po:
100         ${CC} -DPROF ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
101
102 .S.So:
103         ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
104
105 all: objwarn
106
107 # Generate the version map given the version definitions
108 # and symbol maps.
109 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
110 # Find the awk script that generates the version map.
111 VERSION_GEN?=   version_gen.awk
112 VERSION_MAP?=   Version.map
113
114 # Compute the make's -m path.
115 _mpath=
116 _oarg=
117 .for _arg in ${.MAKEFLAGS}
118 .if ${_oarg} == "-m"
119 _mpath+= ${_arg}
120 .endif
121 _oarg=  ${_arg}
122 .endfor
123 _mpath+= /usr/share/mk
124
125 # Look up ${VERSION_GEN} in ${_mpath}.
126 _vgen=
127 .for path in ${_mpath}
128 .if empty(_vgen)
129 .if exists(${path}/${VERSION_GEN})
130 _vgen=  ${path}/${VERSION_GEN}
131 .endif
132 .endif
133 .endfor
134
135 ${VERSION_MAP}: ${VERSION_DEF} ${_vgen} ${SYMBOL_MAPS}
136         awk -v vfile=${VERSION_DEF} -f ${_vgen} ${SYMBOL_MAPS} \
137             > ${.TARGET}
138 .endif  # !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
139
140 # Allow librararies to specify their own version map or have it
141 # automatically generated (see above).
142 .if !empty(VERSION_MAP)
143 ${SHLIB_NAME}:  ${VERSION_MAP}
144 LDFLAGS+=       -Wl,--version-script=${VERSION_MAP}
145 .endif
146
147 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
148 OBJS+=          ${SRCS:N*.h:R:S/$/.o/}
149 .endif
150
151 .if defined(LIB) && !empty(LIB)
152 _LIBS=          lib${LIB}.a
153
154 lib${LIB}.a: ${OBJS} ${STATICOBJS}
155         @${ECHO} building static ${LIB} library
156         @rm -f ${.TARGET}
157         @${AR} cq ${.TARGET} `env NM=${NM} lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
158         ${RANLIB} ${.TARGET}
159 .endif
160
161 .if !defined(INTERNALLIB)
162
163 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
164 _LIBS+=         lib${LIB}_p.a
165 POBJS+=         ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
166
167 lib${LIB}_p.a: ${POBJS}
168         @${ECHO} building profiled ${LIB} library
169         @rm -f ${.TARGET}
170         @${AR} cq ${.TARGET} `env NM=${NM} lorder ${POBJS} | tsort -q` ${ARADD}
171         ${RANLIB} ${.TARGET}
172 .endif
173
174 .if defined(SHLIB_NAME) || \
175     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
176 SOBJS+=         ${OBJS:.o=.So}
177 .endif
178
179 .if defined(SHLIB_NAME)
180 _LIBS+=         ${SHLIB_NAME}
181
182 ${SHLIB_NAME}: ${SOBJS}
183         @${ECHO} building shared library ${SHLIB_NAME}
184         @rm -f ${.TARGET} ${SHLIB_LINK}
185 .if defined(SHLIB_LINK)
186         @ln -fs ${.TARGET} ${SHLIB_LINK}
187 .endif
188         @${CC} ${LDFLAGS} -shared -Wl,-x \
189             -o ${.TARGET} -Wl,-soname,${SONAME} \
190             `env NM=${NM} lorder ${SOBJS} | tsort -q` ${LDADD}
191 .endif
192
193 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
194 _LIBS+=         lib${LIB}_pic.a
195
196 lib${LIB}_pic.a: ${SOBJS}
197         @${ECHO} building special pic ${LIB} library
198         @rm -f ${.TARGET}
199         @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
200         ${RANLIB} ${.TARGET}
201 .endif
202
203 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
204 LINTLIB=        llib-l${LIB}.ln
205 _LIBS+=         ${LINTLIB}
206 LINTOBJS+=      ${SRCS:M*.c:.c=.ln}
207
208 ${LINTLIB}: ${LINTOBJS}
209         @${ECHO} building lint library ${.TARGET}
210         @rm -f ${.TARGET}
211         ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
212 .endif
213
214 .endif # !defined(INTERNALLIB)
215
216 all: ${_LIBS}
217
218 .if ${MK_MAN} != "no"
219 all: _manpages
220 .endif
221
222 _EXTRADEPEND:
223         @TMP=_depend$$$$; \
224         sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
225             > $$TMP; \
226         mv $$TMP ${DEPENDFILE}
227 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
228 .if defined(DPADD) && !empty(DPADD)
229         echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
230 .endif
231 .endif
232
233 .if !target(install)
234
235 .if defined(PRECIOUSLIB)
236 .if !defined(NO_FSCHG)
237 SHLINSTALLFLAGS+= -fschg
238 .endif
239 SHLINSTALLFLAGS+= -S
240 .endif
241
242 _INSTALLFLAGS:= ${INSTALLFLAGS}
243 .for ie in ${INSTALLFLAGS_EDIT}
244 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
245 .endfor
246 _SHLINSTALLFLAGS:=      ${SHLINSTALLFLAGS}
247 .for ie in ${INSTALLFLAGS_EDIT}
248 _SHLINSTALLFLAGS:=      ${_SHLINSTALLFLAGS${ie}}
249 .endfor
250
251 .if !defined(INTERNALLIB)
252 realinstall: _libinstall
253 .ORDER: beforeinstall _libinstall
254 _libinstall:
255 .if defined(LIB) && !empty(LIB) && !defined(NO_INSTALLLIB)
256         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
257             ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
258 .endif
259 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
260         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
261             ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
262 .endif
263 .if defined(SHLIB_NAME)
264         ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
265             ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
266             ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
267 .if defined(SHLIB_LINK)
268 .if ${SHLIBDIR} == ${LIBDIR}
269         ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
270 .else
271         ln -fs ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \
272             ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
273 .if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME})
274         -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
275         rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
276 .endif
277 .endif
278 .endif
279 .endif
280 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
281         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
282             ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
283 .endif
284 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
285         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
286             ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
287 .endif
288 .endif # !defined(INTERNALLIB)
289
290 .include <bsd.nls.mk>
291 .include <bsd.files.mk>
292 .include <bsd.incs.mk>
293 .include <bsd.links.mk>
294
295 .if ${MK_MAN} != "no"
296 realinstall: _maninstall
297 .ORDER: beforeinstall _maninstall
298 .endif
299
300 .endif
301
302 .if !target(lint)
303 lint: ${SRCS:M*.c}
304         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
305 .endif
306
307 .if ${MK_MAN} != "no"
308 .include <bsd.man.mk>
309 .endif
310
311 .include <bsd.dep.mk>
312
313 .if !exists(${.OBJDIR}/${DEPENDFILE})
314 .if defined(LIB) && !empty(LIB)
315 ${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
316 .for _S in ${SRCS:N*.[hly]}
317 ${_S:R}.po: ${_S}
318 .endfor
319 .endif
320 .if defined(SHLIB_NAME) || \
321     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
322 ${SOBJS}: ${SRCS:M*.h}
323 .for _S in ${SRCS:N*.[hly]}
324 ${_S:R}.So: ${_S}
325 .endfor
326 .endif
327 .endif
328
329 .if !target(clean)
330 clean:
331 .if defined(CLEANFILES) && !empty(CLEANFILES)
332         rm -f ${CLEANFILES}
333 .endif
334 .if defined(LIB) && !empty(LIB)
335         rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
336 .endif
337 .if !defined(INTERNALLIB)
338 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
339         rm -f ${POBJS} ${POBJS:S/$/.tmp/}
340 .endif
341 .if defined(SHLIB_NAME) || \
342     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
343         rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
344 .endif
345 .if defined(SHLIB_NAME)
346 .if defined(SHLIB_LINK)
347         rm -f ${SHLIB_LINK}
348 .endif
349 .if defined(LIB) && !empty(LIB)
350         rm -f lib${LIB}.so.* lib${LIB}.so
351 .endif
352 .endif
353 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
354         rm -f ${LINTOBJS}
355 .endif
356 .endif # !defined(INTERNALLIB)
357 .if defined(_LIBS) && !empty(_LIBS)
358         rm -f ${_LIBS}
359 .endif
360 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
361         rm -rf ${CLEANDIRS}
362 .endif
363 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
364         rm -f ${VERSION_MAP}
365 .endif
366 .endif
367
368 .include <bsd.obj.mk>
369
370 .include <bsd.sys.mk>