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