]> CyberLeo.Net >> Repos - FreeBSD/releng/10.2.git/blob - share/mk/bsd.lib.mk
- Copy stable/10@285827 to releng/10.2 in preparation for 10.2-RC1
[FreeBSD/releng/10.2.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 .if defined(LIB_CXX)
8 LIB=    ${LIB_CXX}
9 _LD=    ${CXX}
10 .else
11 _LD=    ${CC}
12 .endif
13
14 # Set up the variables controlling shared libraries.  After this section,
15 # SHLIB_NAME will be defined only if we are to create a shared library.
16 # SHLIB_LINK will be defined only if we are to create a link to it.
17 # INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
18 .if defined(NO_PIC)
19 .undef SHLIB_NAME
20 .undef INSTALL_PIC_ARCHIVE
21 .else
22 .if !defined(SHLIB) && defined(LIB)
23 SHLIB=          ${LIB}
24 .endif
25 .if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR)
26 SHLIB_NAME=     lib${SHLIB}.so.${SHLIB_MAJOR}
27 .endif
28 .if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*)
29 SHLIB_LINK?=    ${SHLIB_NAME:R}
30 .endif
31 SONAME?=        ${SHLIB_NAME}
32 .endif
33
34 .if defined(CRUNCH_CFLAGS)
35 CFLAGS+=        ${CRUNCH_CFLAGS}
36 .endif
37
38 .if ${MK_ASSERT_DEBUG} == "no"
39 CFLAGS+= -DNDEBUG
40 NO_WERROR=
41 .endif
42
43 .if defined(DEBUG_FLAGS)
44 CFLAGS+= ${DEBUG_FLAGS}
45
46 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
47 CTFFLAGS+= -g
48 .endif
49 .else
50 STRIP?= -s
51 .endif
52
53 .if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
54     empty(DEBUG_FLAGS:M-gdwarf*)
55 CFLAGS+= -g
56 CTFFLAGS+= -g
57 .endif
58
59 .include <bsd.libnames.mk>
60
61 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
62 # .So used for PIC object files
63 .SUFFIXES:
64 .SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
65
66 .if !defined(PICFLAG)
67 .if ${MACHINE_CPUARCH} == "sparc64"
68 PICFLAG=-fPIC
69 .else
70 PICFLAG=-fpic
71 .endif
72 .endif
73
74 PO_FLAG=-pg
75
76 .c.o:
77         ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
78         ${CTFCONVERT_CMD}
79
80 .c.po:
81         ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
82         ${CTFCONVERT_CMD}
83
84 .c.So:
85         ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
86         ${CTFCONVERT_CMD}
87
88 .cc.o .C.o .cpp.o .cxx.o:
89         ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
90
91 .cc.po .C.po .cpp.po .cxx.po:
92         ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
93
94 .cc.So .C.So .cpp.So .cxx.So:
95         ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
96
97 .f.po:
98         ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
99         ${CTFCONVERT_CMD}
100
101 .f.So:
102         ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
103         ${CTFCONVERT_CMD}
104
105 .s.po .s.So:
106         ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
107         ${CTFCONVERT_CMD}
108
109 .asm.po:
110         ${CC} -x assembler-with-cpp -DPROF ${PO_CFLAGS} ${ACFLAGS} \
111                 -c ${.IMPSRC} -o ${.TARGET}
112         ${CTFCONVERT_CMD}
113
114 .asm.So:
115         ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \
116             -c ${.IMPSRC} -o ${.TARGET}
117         ${CTFCONVERT_CMD}
118
119 .S.po:
120         ${CC} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
121         ${CTFCONVERT_CMD}
122
123 .S.So:
124         ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
125         ${CTFCONVERT_CMD}
126
127 all: beforebuild .WAIT
128 beforebuild: objwarn
129
130 .if defined(PRIVATELIB)
131 _LIBDIR:=${LIBPRIVATEDIR}
132 _SHLIBDIR:=${LIBPRIVATEDIR}
133 .else
134 _LIBDIR:=${LIBDIR}
135 _SHLIBDIR:=${SHLIBDIR}
136 .endif
137
138 .if defined(SHLIB_NAME)
139 .if ${MK_DEBUG_FILES} != "no"
140 SHLIB_NAME_FULL=${SHLIB_NAME}.full
141 # Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
142 .if ${_SHLIBDIR} == "/boot" ||\
143     ${SHLIBDIR:C%/lib(/.*)?$%/lib%} == "/lib" ||\
144     ${SHLIBDIR:C%/usr/lib(32)?(/.*)?%/usr/lib%} == "/usr/lib"
145 DEBUGFILEDIR=${DEBUGDIR}${_SHLIBDIR}
146 .else
147 DEBUGFILEDIR=${_SHLIBDIR}/.debug
148 DEBUGMKDIR=
149 .endif
150 .else
151 SHLIB_NAME_FULL=${SHLIB_NAME}
152 .endif
153 .endif
154
155 .include <bsd.symver.mk>
156
157 # Allow libraries to specify their own version map or have it
158 # automatically generated (see bsd.symver.mk above).
159 .if ${MK_SYMVER} == "yes" && !empty(VERSION_MAP)
160 ${SHLIB_NAME_FULL}:     ${VERSION_MAP}
161 LDFLAGS+=       -Wl,--version-script=${VERSION_MAP}
162 .endif
163
164 .if defined(USEPRIVATELIB)
165 LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR}
166 .endif
167
168 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
169 OBJS+=          ${SRCS:N*.h:R:S/$/.o/}
170 .endif
171
172 .if defined(LIB) && !empty(LIB)
173 _LIBS=          lib${LIB}.a
174
175 lib${LIB}.a: ${OBJS} ${STATICOBJS}
176         @${ECHO} building static ${LIB} library
177         @rm -f ${.TARGET}
178         @${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
179         ${RANLIB} ${RANLIBFLAGS} ${.TARGET}
180 .endif
181
182 .if !defined(INTERNALLIB)
183
184 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
185 _LIBS+=         lib${LIB}_p.a
186 POBJS+=         ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
187
188 lib${LIB}_p.a: ${POBJS}
189         @${ECHO} building profiled ${LIB} library
190         @rm -f ${.TARGET}
191         @${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD}
192         ${RANLIB} ${RANLIBFLAGS} ${.TARGET}
193 .endif
194
195 .if defined(SHLIB_NAME) || \
196     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
197 SOBJS+=         ${OBJS:.o=.So}
198 .endif
199
200 .if defined(SHLIB_NAME)
201 _LIBS+=         ${SHLIB_NAME}
202
203 SOLINKOPTS=     -shared -Wl,-x
204 .if !defined(ALLOW_SHARED_TEXTREL)
205 SOLINKOPTS+=    -Wl,--fatal-warnings -Wl,--warn-shared-textrel
206 .endif
207
208 .if target(beforelinking)
209 beforelinking: ${SOBJS}
210 ${SHLIB_NAME_FULL}: beforelinking
211 .endif
212 ${SHLIB_NAME_FULL}: ${SOBJS}
213         @${ECHO} building shared library ${SHLIB_NAME}
214         @rm -f ${SHLIB_NAME} ${SHLIB_LINK}
215 .if defined(SHLIB_LINK)
216         @${INSTALL_SYMLINK} ${SHLIB_NAME} ${SHLIB_LINK}
217 .endif
218         ${_LD} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
219             -o ${.TARGET} -Wl,-soname,${SONAME} \
220             `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD}
221 .if ${MK_CTF} != "no"
222         ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
223 .endif
224
225 .if ${MK_DEBUG_FILES} != "no"
226 CLEANFILES+=    ${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
227 ${SHLIB_NAME}: ${SHLIB_NAME_FULL} ${SHLIB_NAME}.debug
228         ${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.debug \
229             ${SHLIB_NAME_FULL} ${.TARGET}
230
231 ${SHLIB_NAME}.debug: ${SHLIB_NAME_FULL}
232         ${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET}
233 .endif
234 .endif #defined(SHLIB_NAME)
235
236 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
237 _LIBS+=         lib${LIB}_pic.a
238
239 lib${LIB}_pic.a: ${SOBJS}
240         @${ECHO} building special pic ${LIB} library
241         @rm -f ${.TARGET}
242         @${AR} ${ARFLAGS} ${.TARGET} ${SOBJS} ${ARADD}
243         ${RANLIB} ${RANLIBFLAGS} ${.TARGET}
244 .endif
245
246 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
247 LINTLIB=        llib-l${LIB}.ln
248 _LIBS+=         ${LINTLIB}
249 LINTOBJS+=      ${SRCS:M*.c:.c=.ln}
250
251 ${LINTLIB}: ${LINTOBJS}
252         @${ECHO} building lint library ${.TARGET}
253         @rm -f ${.TARGET}
254         ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
255 .endif
256
257 .endif # !defined(INTERNALLIB)
258
259 all: ${_LIBS}
260
261 .if ${MK_MAN} != "no"
262 all: _manpages
263 .endif
264
265 _EXTRADEPEND:
266         @TMP=_depend$$$$; \
267         sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
268             > $$TMP; \
269         mv $$TMP ${DEPENDFILE}
270 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
271 .if defined(DPADD) && !empty(DPADD)
272         echo ${SHLIB_NAME_FULL}: ${DPADD} >> ${DEPENDFILE}
273 .endif
274 .endif
275
276 .if !target(install)
277
278 .if defined(PRECIOUSLIB)
279 .if !defined(NO_FSCHG)
280 SHLINSTALLFLAGS+= -fschg
281 .endif
282 SHLINSTALLFLAGS+= -S
283 .endif
284
285 _INSTALLFLAGS:= ${INSTALLFLAGS}
286 .for ie in ${INSTALLFLAGS_EDIT}
287 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
288 .endfor
289 _SHLINSTALLFLAGS:=      ${SHLINSTALLFLAGS}
290 .for ie in ${INSTALLFLAGS_EDIT}
291 _SHLINSTALLFLAGS:=      ${_SHLINSTALLFLAGS${ie}}
292 .endfor
293
294 .if !defined(INTERNALLIB)
295 realinstall: _libinstall
296 .ORDER: beforeinstall _libinstall
297 _libinstall:
298 .if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no"
299         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
300             ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${_LIBDIR}
301 .endif
302 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
303         ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
304             ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${_LIBDIR}
305 .endif
306 .if defined(SHLIB_NAME)
307         ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
308             ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
309             ${SHLIB_NAME} ${DESTDIR}${_SHLIBDIR}
310 .if ${MK_DEBUG_FILES} != "no"
311 .if defined(DEBUGMKDIR)
312         ${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
313 .endif
314         ${INSTALL} -T debug -o ${LIBOWN} -g ${LIBGRP} -m ${DEBUGMODE} \
315             ${_INSTALLFLAGS} \
316             ${SHLIB_NAME}.debug ${DESTDIR}${DEBUGFILEDIR}
317 .endif
318 .if defined(SHLIB_LINK)
319 # ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building
320 # and when building 32 bits library shims.  ${_SHLIBDIRPREFIX} is the directory
321 # prefix where shared objects will be installed by the install target.
322 #
323 # ${_LDSCRIPTROOT} is the directory prefix that will be used when generating
324 # ld(1) scripts.  The crosstools' ld is configured to lookup libraries in an
325 # alternative directory which is called "sysroot", so during buildworld binaries
326 # won't be linked against the running system libraries but against the ones of
327 # the current source tree.  ${_LDSCRIPTROOT} behavior is twisted because of
328 # the location where we store them:
329 # - 64 bits libs are located under sysroot, so ${_LDSCRIPTROOT} must be empty
330 #   because ld(1) will manage to find them from sysroot;
331 # - 32 bits shims are not, so ${_LDSCRIPTROOT} is used to specify their full
332 #   path, outside of sysroot.
333 # Note that ld(1) scripts are generated both during buildworld and
334 # installworld; in the later case ${_LDSCRIPTROOT} must be obviously empty
335 # because on the target system, libraries are meant to be looked up from /.
336 .if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
337         sed -e 's,@@SHLIB@@,${_LDSCRIPTROOT}${_SHLIBDIR}/${SHLIB_NAME},g' \
338             -e 's,@@LIBDIR@@,${_LDSCRIPTROOT}${_LIBDIR},g' \
339             ${.CURDIR}/${SHLIB_LDSCRIPT} > ${DESTDIR}${_LIBDIR}/${SHLIB_LINK:R}.ld
340         ${INSTALL} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
341             ${_INSTALLFLAGS} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK:R}.ld \
342             ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
343         rm -f ${DESTDIR}${_LIBDIR}/${SHLIB_LINK:R}.ld
344
345 .else
346 .if ${_SHLIBDIR} == ${_LIBDIR}
347         ${INSTALL_SYMLINK} ${SHLIB_NAME} ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
348 .else
349         ${INSTALL_SYMLINK} ${_SHLIBDIRPREFIX}${_SHLIBDIR}/${SHLIB_NAME} \
350             ${DESTDIR}${_LIBDIR}/${SHLIB_LINK}
351 .if exists(${DESTDIR}${_LIBDIR}/${SHLIB_NAME})
352         -chflags noschg ${DESTDIR}${_LIBDIR}/${SHLIB_NAME}
353         rm -f ${DESTDIR}${_LIBDIR}/${SHLIB_NAME}
354 .endif
355 .endif
356 .endif # SHLIB_LDSCRIPT
357 .endif # SHLIB_LINK
358 .endif # SHIB_NAME
359 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
360         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
361             ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${_LIBDIR}
362 .endif
363 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
364         ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
365             ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR}
366 .endif
367 .endif # !defined(INTERNALLIB)
368
369 .if !defined(LIBRARIES_ONLY)
370 .include <bsd.nls.mk>
371 .include <bsd.files.mk>
372 .include <bsd.incs.mk>
373 .endif
374
375 .include <bsd.links.mk>
376
377 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
378 realinstall: _maninstall
379 .ORDER: beforeinstall _maninstall
380 .endif
381
382 .endif
383
384 .if !target(lint)
385 lint: ${SRCS:M*.c}
386         ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
387 .endif
388
389 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
390 .include <bsd.man.mk>
391 .endif
392
393 .include <bsd.dep.mk>
394
395 .if !exists(${.OBJDIR}/${DEPENDFILE})
396 .if defined(LIB) && !empty(LIB)
397 ${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h}
398 .for _S in ${SRCS:N*.[hly]}
399 ${_S:R}.po: ${_S}
400 .endfor
401 .endif
402 .if defined(SHLIB_NAME) || \
403     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
404 ${SOBJS}: ${SRCS:M*.h}
405 .for _S in ${SRCS:N*.[hly]}
406 ${_S:R}.So: ${_S}
407 .endfor
408 .endif
409 .endif
410
411 .if !target(clean)
412 clean:
413 .if defined(CLEANFILES) && !empty(CLEANFILES)
414         rm -f ${CLEANFILES}
415 .endif
416 .if defined(LIB) && !empty(LIB)
417         rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
418 .endif
419 .if !defined(INTERNALLIB)
420 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
421         rm -f ${POBJS} ${POBJS:S/$/.tmp/}
422 .endif
423 .if defined(SHLIB_NAME) || \
424     defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
425         rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
426 .endif
427 .if defined(SHLIB_NAME)
428 .if defined(SHLIB_LINK)
429 .if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
430         rm -f lib${LIB}.ld
431 .endif
432         rm -f ${SHLIB_LINK}
433 .endif
434 .endif # defined(SHLIB_NAME)
435 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
436         rm -f ${LINTOBJS}
437 .endif
438 .endif # !defined(INTERNALLIB)
439 .if defined(_LIBS) && !empty(_LIBS)
440         rm -f ${_LIBS}
441 .endif
442 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
443         rm -rf ${CLEANDIRS}
444 .endif
445 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
446         rm -f ${VERSION_MAP}
447 .endif
448 .endif
449
450 .include <bsd.obj.mk>
451
452 .include <bsd.sys.mk>