bsd.lib.mk revision 281056
1# from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91 2# $FreeBSD: stable/10/share/mk/bsd.lib.mk 281056 2015-04-04 00:42:09Z bdrewery $ 3# 4 5.include <bsd.init.mk> 6 7.if defined(LIB_CXX) 8LIB= ${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) 23SHLIB= ${LIB} 24.endif 25.if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR) 26SHLIB_NAME= lib${SHLIB}.so.${SHLIB_MAJOR} 27.endif 28.if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*) 29SHLIB_LINK?= ${SHLIB_NAME:R} 30.endif 31SONAME?= ${SHLIB_NAME} 32.endif 33 34.if defined(CRUNCH_CFLAGS) 35CFLAGS+= ${CRUNCH_CFLAGS} 36.endif 37 38.if ${MK_ASSERT_DEBUG} == "no" 39CFLAGS+= -DNDEBUG 40NO_WERROR= 41.endif 42 43.if defined(DEBUG_FLAGS) 44CFLAGS+= ${DEBUG_FLAGS} 45 46.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != "" 47CTFFLAGS+= -g 48.endif 49.else 50STRIP?= -s 51.endif 52 53.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \ 54 empty(DEBUG_FLAGS:M-gdwarf*) 55CFLAGS+= -g 56CTFFLAGS+= -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" 68PICFLAG=-fPIC 69.else 70PICFLAG=-fpic 71.endif 72.endif 73 74PO_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 127all: beforebuild .WAIT 128beforebuild: 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" 140SHLIB_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" 145DEBUGFILEDIR=${DEBUGDIR}${_SHLIBDIR} 146.else 147DEBUGFILEDIR=${_SHLIBDIR}/.debug 148DEBUGMKDIR= 149.endif 150.else 151SHLIB_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} 161LDFLAGS+= -Wl,--version-script=${VERSION_MAP} 162.endif 163 164.if defined(USEPRIVATELIB) 165LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR} 166.endif 167 168.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 169OBJS+= ${SRCS:N*.h:R:S/$/.o/} 170.endif 171 172.if defined(LIB) && !empty(LIB) 173_LIBS= lib${LIB}.a 174 175lib${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 186POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 187 188lib${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) 197SOBJS+= ${OBJS:.o=.So} 198.endif 199 200.if defined(SHLIB_NAME) 201_LIBS+= ${SHLIB_NAME} 202 203SOLINKOPTS= -shared -Wl,-x 204.if !defined(ALLOW_SHARED_TEXTREL) 205SOLINKOPTS+= -Wl,--fatal-warnings -Wl,--warn-shared-textrel 206.endif 207 208.if target(beforelinking) 209beforelinking: ${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" 226CLEANFILES+= ${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 239lib${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) 247LINTLIB= llib-l${LIB}.ln 248_LIBS+= ${LINTLIB} 249LINTOBJS+= ${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 259all: ${_LIBS} 260 261.if ${MK_MAN} != "no" 262all: _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) 280SHLINSTALLFLAGS+= -fschg 281.endif 282SHLINSTALLFLAGS+= -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) 295realinstall: _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) 378realinstall: _maninstall 379.ORDER: beforeinstall _maninstall 380.endif 381 382.endif 383 384.if !target(lint) 385lint: ${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) 412clean: 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> 453