]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - share/mk/bsd.lib.mk
MFC r245752,246913,247162,250119
[FreeBSD/stable/9.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
39 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
40 CTFFLAGS+= -g
41 .endif
42 .endif
43
44 .if !defined(DEBUG_FLAGS)
45 STRIP?= -s
46 .endif
47
48 .include <bsd.libnames.mk>
49
50 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
51 # .So used for PIC object files
52 .SUFFIXES:
53 .SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
54
55 .if !defined(PICFLAG)
56 .if ${MACHINE_CPUARCH} == "sparc64"
57 PICFLAG=-fPIC
58 .else
59 PICFLAG=-fpic
60 .endif
61 .endif
62
63 PO_FLAG=-pg
64
65 .c.o:
66         ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
67         ${CTFCONVERT_CMD}
68
69 .c.po:
70         ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
71         ${CTFCONVERT_CMD}
72
73 .c.So:
74         ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
75         ${CTFCONVERT_CMD}
76
77 .cc.o .C.o .cpp.o .cxx.o:
78         ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
79
80 .cc.po .C.po .cpp.po .cxx.po:
81         ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
82
83 .cc.So .C.So .cpp.So .cxx.So:
84         ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
85
86 .f.po:
87         ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
88         ${CTFCONVERT_CMD}
89
90 .f.So:
91         ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
92         ${CTFCONVERT_CMD}
93
94 .s.po .s.So:
95         ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
96         ${CTFCONVERT_CMD}
97
98 .asm.po:
99         ${CC} -x assembler-with-cpp -DPROF ${PO_CFLAGS} ${ACFLAGS} \
100                 -c ${.IMPSRC} -o ${.TARGET}
101         ${CTFCONVERT_CMD}
102
103 .asm.So:
104         ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \
105             -c ${.IMPSRC} -o ${.TARGET}
106         ${CTFCONVERT_CMD}
107
108 .S.po:
109         ${CC} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
110         ${CTFCONVERT_CMD}
111
112 .S.So:
113         ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
114         ${CTFCONVERT_CMD}
115
116 all: objwarn
117
118 .include <bsd.symver.mk>
119
120 # Allow libraries to specify their own version map or have it
121 # automatically generated (see bsd.symver.mk above).
122 .if ${MK_SYMVER} == "yes" && !empty(VERSION_MAP)
123 ${SHLIB_NAME}:  ${VERSION_MAP}
124 LDFLAGS+=       -Wl,--version-script=${VERSION_MAP}
125 .endif
126
127 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
128 OBJS+=          ${SRCS:N*.h:R:S/$/.o/}
129 .endif
130
131 .if defined(LIB) && !empty(LIB)
132 _LIBS=          lib${LIB}.a
133
134 lib${LIB}.a: ${OBJS} ${STATICOBJS}
135         @${ECHO} building static ${LIB} library
136         @rm -f ${.TARGET}
137 .if !defined(NM)
138         @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
139 .else
140         @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
141 .endif
142         ${RANLIB} ${.TARGET}
143 .endif
144
145 .if !defined(INTERNALLIB)
146
147 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
148 _LIBS+=         lib${LIB}_p.a
149 POBJS+=         ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
150
151 lib${LIB}_p.a: ${POBJS}
152         @${ECHO} building profiled ${LIB} library
153         @rm -f ${.TARGET}
154 .if !defined(NM)
155         @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
156 .else
157         @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD}
158 .endif
159         ${RANLIB} ${.TARGET}
160 .endif
161
162 .if defined(SHLIB_NAME) || \
163     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
164 SOBJS+=         ${OBJS:.o=.So}
165 .endif
166
167 .if defined(SHLIB_NAME)
168 _LIBS+=         ${SHLIB_NAME}
169
170 SOLINKOPTS=     -shared -Wl,-x
171 .if !defined(ALLOW_SHARED_TEXTREL)
172 SOLINKOPTS+=    -Wl,--fatal-warnings -Wl,--warn-shared-textrel
173 .endif
174
175 .if target(beforelinking)
176 ${SHLIB_NAME}: ${SOBJS} beforelinking
177 .else
178 ${SHLIB_NAME}: ${SOBJS}
179 .endif
180         @${ECHO} building shared library ${SHLIB_NAME}
181         @rm -f ${.TARGET} ${SHLIB_LINK}
182 .if defined(SHLIB_LINK)
183         @${INSTALL_SYMLINK} ${SHLIB_NAME} ${SHLIB_LINK}
184 .endif
185 .if !defined(NM)
186         @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
187             -o ${.TARGET} -Wl,-soname,${SONAME} \
188             `lorder ${SOBJS} | tsort -q` ${LDADD}
189 .else
190         @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
191             -o ${.TARGET} -Wl,-soname,${SONAME} \
192             `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD}
193 .endif
194 .if ${MK_CTF} != "no"
195         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
196 .endif
197 .endif
198
199 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
200 _LIBS+=         lib${LIB}_pic.a
201
202 lib${LIB}_pic.a: ${SOBJS}
203         @${ECHO} building special pic ${LIB} library
204         @rm -f ${.TARGET}
205         @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
206         ${RANLIB} ${.TARGET}
207 .endif
208
209 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
210 LINTLIB=        llib-l${LIB}.ln
211 _LIBS+=         ${LINTLIB}
212 LINTOBJS+=      ${SRCS:M*.c:.c=.ln}
213
214 ${LINTLIB}: ${LINTOBJS}
215         @${ECHO} building lint library ${.TARGET}
216         @rm -f ${.TARGET}
217         ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
218 .endif
219
220 .endif # !defined(INTERNALLIB)
221
222 all: ${_LIBS}
223
224 .if ${MK_MAN} != "no"
225 all: _manpages
226 .endif
227
228 _EXTRADEPEND:
229         @TMP=_depend$$$$; \
230         sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
231             > $$TMP; \
232         mv $$TMP ${DEPENDFILE}
233 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
234 .if defined(DPADD) && !empty(DPADD)
235         echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
236 .endif
237 .endif
238
239 .if !target(install)
240
241 .if defined(PRECIOUSLIB)
242 .if !defined(NO_FSCHG)
243 SHLINSTALLFLAGS+= -fschg
244 .endif
245 SHLINSTALLFLAGS+= -S
246 .endif
247
248 _INSTALLFLAGS:= ${INSTALLFLAGS}
249 .for ie in ${INSTALLFLAGS_EDIT}
250 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
251 .endfor
252 _SHLINSTALLFLAGS:=      ${SHLINSTALLFLAGS}
253 .for ie in ${INSTALLFLAGS_EDIT}
254 _SHLINSTALLFLAGS:=      ${_SHLINSTALLFLAGS${ie}}
255 .endfor
256
257 .if !defined(INTERNALLIB)
258 realinstall: _libinstall
259 .ORDER: beforeinstall _libinstall
260 _libinstall:
261 .if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
262         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
263             ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
264 .endif
265 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
266         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
267             ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
268 .endif
269 .if defined(SHLIB_NAME)
270         ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
271             ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
272             ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
273 .if defined(SHLIB_LINK)
274 # ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building
275 # and when building 32 bits library shims.  ${_SHLIBDIRPREFIX} is the directory
276 # prefix where shared objects will be installed.  ${_LDSCRIPTROOT} is the
277 # directory prefix that will be used in generated ld(1) scripts.  They cannot
278 # be coalesced because of the way ld(1) handles the sysroot prefix (used in the
279 # cross-toolchain):
280 # - 64 bits libs are located under sysroot, so ${_LDSCRIPTROOT} must be empty.
281 # - 32 bits shims are not, so ${_LDSCRIPTROOT} is used to specify their full
282 #   path.  Note that ld(1) scripts are generated both during buildworld and
283 #   installworld; in the later case ${_LDSCRIPTROOT} must be obviously empty.
284 # On the other hand, the use of ${_SHLIBDIRPREFIX} is more consistent since it
285 # does not involve the logic of a tool we do not own.
286 .if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
287         sed -e 's,@@SHLIB@@,${_LDSCRIPTROOT}${SHLIBDIR}/${SHLIB_NAME},g' \
288             -e 's,@@LIBDIR@@,${_LDSCRIPTROOT}${LIBDIR},g' \
289             ${.CURDIR}/${SHLIB_LDSCRIPT} > lib${LIB}.ld
290         ${INSTALL} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
291             ${_INSTALLFLAGS} lib${LIB}.ld ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
292 .else
293 .if ${SHLIBDIR} == ${LIBDIR}
294         ${INSTALL_SYMLINK} ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
295 .else
296         ${INSTALL_SYMLINK} ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \
297             ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
298 .if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME})
299         -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
300         rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
301 .endif
302 .endif
303 .endif # SHLIB_LDSCRIPT
304 .endif # SHLIB_LINK
305 .endif # SHIB_NAME
306 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
307         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
308             ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
309 .endif
310 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
311         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
312             ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
313 .endif
314 .endif # !defined(INTERNALLIB)
315
316 .if !defined(LIBRARIES_ONLY)
317 .include <bsd.nls.mk>
318 .include <bsd.files.mk>
319 .include <bsd.incs.mk>
320 .endif
321
322 .include <bsd.links.mk>
323
324 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
325 realinstall: _maninstall
326 .ORDER: beforeinstall _maninstall
327 .endif
328
329 .endif
330
331 .if !target(lint)
332 lint: ${SRCS:M*.c}
333         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
334 .endif
335
336 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
337 .include <bsd.man.mk>
338 .endif
339
340 .include <bsd.dep.mk>
341
342 .if !exists(${.OBJDIR}/${DEPENDFILE})
343 .if defined(LIB) && !empty(LIB)
344 ${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
345 .for _S in ${SRCS:N*.[hly]}
346 ${_S:R}.po: ${_S}
347 .endfor
348 .endif
349 .if defined(SHLIB_NAME) || \
350     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
351 ${SOBJS}: ${SRCS:M*.h}
352 .for _S in ${SRCS:N*.[hly]}
353 ${_S:R}.So: ${_S}
354 .endfor
355 .endif
356 .endif
357
358 .if !target(clean)
359 clean:
360 .if defined(CLEANFILES) && !empty(CLEANFILES)
361         rm -f ${CLEANFILES}
362 .endif
363 .if defined(LIB) && !empty(LIB)
364         rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
365 .endif
366 .if !defined(INTERNALLIB)
367 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
368         rm -f ${POBJS} ${POBJS:S/$/.tmp/}
369 .endif
370 .if defined(SHLIB_NAME) || \
371     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
372         rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
373 .endif
374 .if defined(SHLIB_NAME)
375 .if defined(SHLIB_LINK)
376 .if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
377         rm -f lib${LIB}.ld
378 .endif
379         rm -f ${SHLIB_LINK}
380 .endif
381 .if defined(LIB) && !empty(LIB)
382         rm -f lib${LIB}.so.* lib${LIB}.so
383 .endif
384 .endif
385 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
386         rm -f ${LINTOBJS}
387 .endif
388 .endif # !defined(INTERNALLIB)
389 .if defined(_LIBS) && !empty(_LIBS)
390         rm -f ${_LIBS}
391 .endif
392 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
393         rm -rf ${CLEANDIRS}
394 .endif
395 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
396         rm -f ${VERSION_MAP}
397 .endif
398 .endif
399
400 .include <bsd.obj.mk>
401
402 .include <bsd.sys.mk>