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