]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - share/mk/bsd.lib.mk
MFC r250992:
[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 by the install target.
277 #
278 # ${_LDSCRIPTROOT} is the directory prefix that will be used when generating
279 # ld(1) scripts.  The crosstools' ld is configured to lookup libraries in an
280 # alternative directory which is called "sysroot", so during buildworld binaries
281 # won't be linked against the running system libraries but against the ones of
282 # the current source tree.  ${_LDSCRIPTROOT} behavior is twisted because of
283 # the location where we store them:
284 # - 64 bits libs are located under sysroot, so ${_LDSCRIPTROOT} must be empty
285 #   because ld(1) will manage to find them from sysroot;
286 # - 32 bits shims are not, so ${_LDSCRIPTROOT} is used to specify their full
287 #   path, outside of sysroot.
288 # Note that ld(1) scripts are generated both during buildworld and
289 # installworld; in the later case ${_LDSCRIPTROOT} must be obviously empty
290 # because on the target system, libraries are meant to be looked up from /.
291 .if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
292         sed -e 's,@@SHLIB@@,${_LDSCRIPTROOT}${SHLIBDIR}/${SHLIB_NAME},g' \
293             -e 's,@@LIBDIR@@,${_LDSCRIPTROOT}${LIBDIR},g' \
294             ${.CURDIR}/${SHLIB_LDSCRIPT} > lib${LIB}.ld
295         ${INSTALL} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
296             ${_INSTALLFLAGS} lib${LIB}.ld ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
297 .else
298 .if ${SHLIBDIR} == ${LIBDIR}
299         ${INSTALL_SYMLINK} ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
300 .else
301         ${INSTALL_SYMLINK} ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \
302             ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
303 .if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME})
304         -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
305         rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME}
306 .endif
307 .endif
308 .endif # SHLIB_LDSCRIPT
309 .endif # SHLIB_LINK
310 .endif # SHIB_NAME
311 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
312         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
313             ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
314 .endif
315 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
316         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
317             ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
318 .endif
319 .endif # !defined(INTERNALLIB)
320
321 .if !defined(LIBRARIES_ONLY)
322 .include <bsd.nls.mk>
323 .include <bsd.files.mk>
324 .include <bsd.incs.mk>
325 .endif
326
327 .include <bsd.links.mk>
328
329 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
330 realinstall: _maninstall
331 .ORDER: beforeinstall _maninstall
332 .endif
333
334 .endif
335
336 .if !target(lint)
337 lint: ${SRCS:M*.c}
338         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
339 .endif
340
341 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
342 .include <bsd.man.mk>
343 .endif
344
345 .include <bsd.dep.mk>
346
347 .if !exists(${.OBJDIR}/${DEPENDFILE})
348 .if defined(LIB) && !empty(LIB)
349 ${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
350 .for _S in ${SRCS:N*.[hly]}
351 ${_S:R}.po: ${_S}
352 .endfor
353 .endif
354 .if defined(SHLIB_NAME) || \
355     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
356 ${SOBJS}: ${SRCS:M*.h}
357 .for _S in ${SRCS:N*.[hly]}
358 ${_S:R}.So: ${_S}
359 .endfor
360 .endif
361 .endif
362
363 .if !target(clean)
364 clean:
365 .if defined(CLEANFILES) && !empty(CLEANFILES)
366         rm -f ${CLEANFILES}
367 .endif
368 .if defined(LIB) && !empty(LIB)
369         rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
370 .endif
371 .if !defined(INTERNALLIB)
372 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
373         rm -f ${POBJS} ${POBJS:S/$/.tmp/}
374 .endif
375 .if defined(SHLIB_NAME) || \
376     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
377         rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
378 .endif
379 .if defined(SHLIB_NAME)
380 .if defined(SHLIB_LINK)
381 .if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
382         rm -f lib${LIB}.ld
383 .endif
384         rm -f ${SHLIB_LINK}
385 .endif
386 .if defined(LIB) && !empty(LIB)
387         rm -f lib${LIB}.so.* lib${LIB}.so
388 .endif
389 .endif
390 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
391         rm -f ${LINTOBJS}
392 .endif
393 .endif # !defined(INTERNALLIB)
394 .if defined(_LIBS) && !empty(_LIBS)
395         rm -f ${_LIBS}
396 .endif
397 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
398         rm -rf ${CLEANDIRS}
399 .endif
400 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
401         rm -f ${VERSION_MAP}
402 .endif
403 .endif
404
405 .include <bsd.obj.mk>
406
407 .include <bsd.sys.mk>