1 # from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91
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.
13 .undef INSTALL_PIC_ARCHIVE
15 .if !defined(SHLIB) && defined(LIB)
18 .if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR)
19 SHLIB_NAME= lib${SHLIB}.so.${SHLIB_MAJOR}
21 .if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*)
22 SHLIB_LINK?= ${SHLIB_NAME:R}
24 SONAME?= ${SHLIB_NAME}
27 .if defined(CRUNCH_CFLAGS)
28 CFLAGS+= ${CRUNCH_CFLAGS}
31 .if ${MK_ASSERT_DEBUG} == "no"
36 .if defined(DEBUG_FLAGS)
37 CFLAGS+= ${DEBUG_FLAGS}
39 .if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
44 .if !defined(DEBUG_FLAGS)
48 .include <bsd.libnames.mk>
50 # prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
51 # .So used for PIC object files
53 .SUFFIXES: .out .o .po .So .S .asm .s .c .cc .cpp .cxx .C .f .y .l .ln
56 .if ${MACHINE_CPUARCH} == "sparc64"
66 ${CC} ${STATIC_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
70 ${CC} ${PO_FLAG} ${STATIC_CFLAGS} ${PO_CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
74 ${CC} ${PICFLAG} -DPIC ${SHARED_CFLAGS} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
77 .cc.o .C.o .cpp.o .cxx.o:
78 ${CXX} ${STATIC_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
80 .cc.po .C.po .cpp.po .cxx.po:
81 ${CXX} ${PO_FLAG} ${STATIC_CXXFLAGS} ${PO_CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
83 .cc.So .C.So .cpp.So .cxx.So:
84 ${CXX} ${PICFLAG} -DPIC ${SHARED_CXXFLAGS} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
87 ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
91 ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
95 ${AS} ${AFLAGS} -o ${.TARGET} ${.IMPSRC}
99 ${CC} -x assembler-with-cpp -DPROF ${PO_CFLAGS} ${ACFLAGS} \
100 -c ${.IMPSRC} -o ${.TARGET}
104 ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} \
105 -c ${.IMPSRC} -o ${.TARGET}
109 ${CC} -DPROF ${PO_CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
113 ${CC} ${PICFLAG} -DPIC ${CFLAGS} ${ACFLAGS} -c ${.IMPSRC} -o ${.TARGET}
118 .include <bsd.symver.mk>
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}
127 .if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME)
128 OBJS+= ${SRCS:N*.h:R:S/$/.o/}
131 .if defined(LIB) && !empty(LIB)
134 lib${LIB}.a: ${OBJS} ${STATICOBJS}
135 @${ECHO} building static ${LIB} library
138 @${AR} cq ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
140 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
145 .if !defined(INTERNALLIB)
147 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
148 _LIBS+= lib${LIB}_p.a
149 POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
151 lib${LIB}_p.a: ${POBJS}
152 @${ECHO} building profiled ${LIB} library
155 @${AR} cq ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD}
157 @${AR} cq ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD}
162 .if defined(SHLIB_NAME) || \
163 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
164 SOBJS+= ${OBJS:.o=.So}
167 .if defined(SHLIB_NAME)
168 _LIBS+= ${SHLIB_NAME}
170 SOLINKOPTS= -shared -Wl,-x
171 .if !defined(ALLOW_SHARED_TEXTREL)
172 SOLINKOPTS+= -Wl,--fatal-warnings -Wl,--warn-shared-textrel
175 .if target(beforelinking)
176 ${SHLIB_NAME}: ${SOBJS} beforelinking
178 ${SHLIB_NAME}: ${SOBJS}
180 @${ECHO} building shared library ${SHLIB_NAME}
181 @rm -f ${.TARGET} ${SHLIB_LINK}
182 .if defined(SHLIB_LINK)
183 @ln -fs ${.TARGET} ${SHLIB_LINK}
186 @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
187 -o ${.TARGET} -Wl,-soname,${SONAME} \
188 `lorder ${SOBJS} | tsort -q` ${LDADD}
190 @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \
191 -o ${.TARGET} -Wl,-soname,${SONAME} \
192 `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD}
194 .if ${MK_CTF} != "no"
195 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS}
199 .if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no"
200 _LIBS+= lib${LIB}_pic.a
202 lib${LIB}_pic.a: ${SOBJS}
203 @${ECHO} building special pic ${LIB} library
205 @${AR} cq ${.TARGET} ${SOBJS} ${ARADD}
209 .if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB)
210 LINTLIB= llib-l${LIB}.ln
212 LINTOBJS+= ${SRCS:M*.c:.c=.ln}
214 ${LINTLIB}: ${LINTOBJS}
215 @${ECHO} building lint library ${.TARGET}
217 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
220 .endif # !defined(INTERNALLIB)
224 .if ${MK_MAN} != "no"
230 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
232 mv $$TMP ${DEPENDFILE}
233 .if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME)
234 .if defined(DPADD) && !empty(DPADD)
235 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
241 .if defined(PRECIOUSLIB)
242 .if !defined(NO_FSCHG)
243 SHLINSTALLFLAGS+= -fschg
248 _INSTALLFLAGS:= ${INSTALLFLAGS}
249 .for ie in ${INSTALLFLAGS_EDIT}
250 _INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
252 _SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS}
253 .for ie in ${INSTALLFLAGS_EDIT}
254 _SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}}
257 .if !defined(INTERNALLIB)
258 realinstall: _libinstall
259 .ORDER: beforeinstall _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}
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}
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
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}
293 .if ${SHLIBDIR} == ${LIBDIR}
294 ln -fs ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK}
296 ln -fs ${_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}
303 .endif # SHLIB_LDSCRIPT
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}
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}
314 .endif # !defined(INTERNALLIB)
316 .if !defined(LIBRARIES_ONLY)
317 .include <bsd.nls.mk>
318 .include <bsd.files.mk>
319 .include <bsd.incs.mk>
322 .include <bsd.links.mk>
324 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
325 realinstall: _maninstall
326 .ORDER: beforeinstall _maninstall
333 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
336 .if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY)
337 .include <bsd.man.mk>
340 .include <bsd.dep.mk>
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]}
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]}
360 .if defined(CLEANFILES) && !empty(CLEANFILES)
363 .if defined(LIB) && !empty(LIB)
364 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS}
366 .if !defined(INTERNALLIB)
367 .if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB)
368 rm -f ${POBJS} ${POBJS:S/$/.tmp/}
370 .if defined(SHLIB_NAME) || \
371 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB)
372 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/}
374 .if defined(SHLIB_NAME)
375 .if defined(SHLIB_LINK)
376 .if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT})
381 .if defined(LIB) && !empty(LIB)
382 rm -f lib${LIB}.so.* lib${LIB}.so
385 .if defined(WANT_LINT) && defined(LIB) && !empty(LIB)
388 .endif # !defined(INTERNALLIB)
389 .if defined(_LIBS) && !empty(_LIBS)
392 .if defined(CLEANDIRS) && !empty(CLEANDIRS)
395 .if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS)
400 .include <bsd.obj.mk>
402 .include <bsd.sys.mk>