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) 16SHLIB= ${LIB} 17.endif 18.if !defined(SHLIB_NAME) && defined(SHLIB) && defined(SHLIB_MAJOR) 19SHLIB_NAME= lib${SHLIB}.so.${SHLIB_MAJOR} 20.endif 21.if defined(SHLIB_NAME) && !empty(SHLIB_NAME:M*.so.*) 22SHLIB_LINK?= ${SHLIB_NAME:R} 23.endif 24SONAME?= ${SHLIB_NAME} 25.endif 26 27.if defined(CRUNCH_CFLAGS) 28CFLAGS+= ${CRUNCH_CFLAGS} 29.endif 30 31.if ${MK_ASSERT_DEBUG} == "no" 32CFLAGS+= -DNDEBUG 33NO_WERROR= 34.endif 35 36.if defined(DEBUG_FLAGS) 37CFLAGS+= ${DEBUG_FLAGS} 38 39.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != "" 40CTFFLAGS+= -g 41.endif 42.else 43STRIP?= -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" 55PICFLAG=-fPIC 56.else 57PICFLAG=-fpic 58.endif 59.endif 60 61PO_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.if !defined(_SKIP_BUILD) 115all: prebuild .WAIT 116prebuild: objwarn 117.if !defined(.PARSEDIR) 118# this is a no-op 119.WAIT: 120.endif 121.endif 122 123.include <bsd.symver.mk> 124 125# Allow libraries to specify their own version map or have it 126# automatically generated (see bsd.symver.mk above). 127.if ${MK_SYMVER} == "yes" && !empty(VERSION_MAP) 128${SHLIB_NAME}: ${VERSION_MAP} 129LDFLAGS+= -Wl,--version-script=${VERSION_MAP} 130.endif 131 132.if defined(LIB) && !empty(LIB) || defined(SHLIB_NAME) 133OBJS+= ${SRCS:N*.h:R:S/$/.o/} 134.endif 135 136.if defined(LIB) && !empty(LIB) 137_LIBS= lib${LIB}.a 138 139lib${LIB}.a: ${OBJS} ${STATICOBJS} 140 @${ECHO} building static ${LIB} library 141 @rm -f ${.TARGET} 142.if !defined(NM) 143 @${AR} ${ARFLAGS} ${.TARGET} `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 144.else 145 @${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 146.endif 147 ${RANLIB} ${.TARGET} 148.endif 149 150.if !defined(INTERNALLIB) 151 152.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 153_LIBS+= lib${LIB}_p.a 154POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 155 156lib${LIB}_p.a: ${POBJS} 157 @${ECHO} building profiled ${LIB} library 158 @rm -f ${.TARGET} 159.if !defined(NM) 160 @${AR} ${ARFLAGS} ${.TARGET} `lorder ${POBJS} | tsort -q` ${ARADD} 161.else 162 @${AR} ${ARFLAGS} ${.TARGET} `NM='${NM}' lorder ${POBJS} | tsort -q` ${ARADD} 163.endif 164 ${RANLIB} ${.TARGET} 165.endif 166 167.if defined(SHLIB_NAME) || \ 168 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 169SOBJS+= ${OBJS:.o=.So} 170.endif 171 172.if defined(SHLIB_NAME) 173_LIBS+= ${SHLIB_NAME} 174 175.if defined(DEBUG_FLAGS) 176SHLIB_NAME_FULL=${SHLIB_NAME}.debug 177.else 178SHLIB_NAME_FULL=${SHLIB_NAME} 179.endif 180 181SOLINKOPTS= -shared -Wl,-x 182.if !defined(ALLOW_SHARED_TEXTREL) 183SOLINKOPTS+= -Wl,--fatal-warnings -Wl,--warn-shared-textrel 184.endif 185 186.if target(beforelinking) 187beforelinking: ${SOBJS} 188${SHLIB_NAME_FULL}: beforelinking 189.endif 190${SHLIB_NAME_FULL}: ${SOBJS} 191 @${ECHO} building shared library ${SHLIB_NAME} 192 @rm -f ${SHLIB_NAME} ${SHLIB_LINK} 193.if defined(SHLIB_LINK) 194 @${INSTALL_SYMLINK} ${SHLIB_NAME} ${SHLIB_LINK} 195.endif 196.if !defined(NM) 197 @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \ 198 -o ${.TARGET} -Wl,-soname,${SONAME} \ 199 `lorder ${SOBJS} | tsort -q` ${LDADD} 200.else 201 @${CC} ${LDFLAGS} ${SSP_CFLAGS} ${SOLINKOPTS} \ 202 -o ${.TARGET} -Wl,-soname,${SONAME} \ 203 `NM='${NM}' lorder ${SOBJS} | tsort -q` ${LDADD} 204.endif 205.if ${MK_CTF} != "no" 206 ${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${SOBJS} 207.endif 208 209.if defined(DEBUG_FLAGS) 210${SHLIB_NAME}: ${SHLIB_NAME_FULL} ${SHLIB_NAME}.symbols 211 ${OBJCOPY} --strip-debug --add-gnu-debuglink=${SHLIB_NAME}.symbols \ 212 ${SHLIB_NAME_FULL} ${.TARGET} 213 214${SHLIB_NAME}.symbols: ${SHLIB_NAME_FULL} 215 ${OBJCOPY} --only-keep-debug ${SHLIB_NAME_FULL} ${.TARGET} 216.endif 217.endif 218 219.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 220_LIBS+= lib${LIB}_pic.a 221 222lib${LIB}_pic.a: ${SOBJS} 223 @${ECHO} building special pic ${LIB} library 224 @rm -f ${.TARGET} 225 @${AR} ${ARFLAGS} ${.TARGET} ${SOBJS} ${ARADD} 226 ${RANLIB} ${.TARGET} 227.endif 228 229.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 230LINTLIB= llib-l${LIB}.ln 231_LIBS+= ${LINTLIB} 232LINTOBJS+= ${SRCS:M*.c:.c=.ln} 233 234${LINTLIB}: ${LINTOBJS} 235 @${ECHO} building lint library ${.TARGET} 236 @rm -f ${.TARGET} 237 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 238.endif 239 240.endif # !defined(INTERNALLIB) 241 242.if defined(_SKIP_BUILD) 243all: 244.else 245all: ${_LIBS} 246 247.if ${MK_MAN} != "no" 248all: _manpages 249.endif 250.endif 251 252_EXTRADEPEND: 253 @TMP=_depend$$$$; \ 254 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \ 255 > $$TMP; \ 256 mv $$TMP ${DEPENDFILE} 257.if !defined(NO_EXTRADEPEND) && defined(SHLIB_NAME) 258.if defined(DPADD) && !empty(DPADD) 259 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE} 260.endif 261.endif 262 263.if !target(install) 264 265.if defined(PRECIOUSLIB) 266.if !defined(NO_FSCHG) 267SHLINSTALLFLAGS+= -fschg 268.endif 269SHLINSTALLFLAGS+= -S 270.endif 271 272_INSTALLFLAGS:= ${INSTALLFLAGS} 273.for ie in ${INSTALLFLAGS_EDIT} 274_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 275.endfor 276_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 277.for ie in ${INSTALLFLAGS_EDIT} 278_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 279.endfor 280 281.if !defined(INTERNALLIB) 282realinstall: _libinstall 283.ORDER: beforeinstall _libinstall 284_libinstall: 285.if defined(LIB) && !empty(LIB) && ${MK_INSTALLLIB} != "no" 286 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 287 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR} 288.endif 289.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 290 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 291 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR} 292.endif 293.if defined(SHLIB_NAME) 294 ${INSTALL} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 295 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ 296 ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR} 297.if defined(DEBUG_FLAGS) 298 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 299 ${_INSTALLFLAGS} \ 300 ${SHLIB_NAME}.symbols ${DESTDIR}${SHLIBDIR} 301.endif 302.if defined(SHLIB_LINK) 303# ${_SHLIBDIRPREFIX} and ${_LDSCRIPTROOT} are both needed when cross-building 304# and when building 32 bits library shims. ${_SHLIBDIRPREFIX} is the directory 305# prefix where shared objects will be installed. ${_LDSCRIPTROOT} is the 306# directory prefix that will be used in generated ld(1) scripts. They cannot 307# be coalesced because of the way ld(1) handles the sysroot prefix (used in the 308# cross-toolchain): 309# - 64 bits libs are located under sysroot, so ${_LDSCRIPTROOT} must be empty. 310# - 32 bits shims are not, so ${_LDSCRIPTROOT} is used to specify their full 311# path. Note that ld(1) scripts are generated both during buildworld and 312# installworld; in the later case ${_LDSCRIPTROOT} must be obviously empty. 313# On the other hand, the use of ${_SHLIBDIRPREFIX} is more consistent since it 314# does not involve the logic of a tool we do not own. 315.if defined(SHLIB_LDSCRIPT) && !empty(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT}) 316 sed -e 's,@@SHLIB@@,${_LDSCRIPTROOT}${SHLIBDIR}/${SHLIB_NAME},g' \ 317 -e 's,@@LIBDIR@@,${_LDSCRIPTROOT}${LIBDIR},g' \ 318 ${.CURDIR}/${SHLIB_LDSCRIPT} > lib${LIB}.ld 319 ${INSTALL} -S -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 320 ${_INSTALLFLAGS} lib${LIB}.ld ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 321.else 322.if ${SHLIBDIR} == ${LIBDIR} 323 ${INSTALL_SYMLINK} ${SHLIB_NAME} ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 324.else 325 ${INSTALL_SYMLINK} ${_SHLIBDIRPREFIX}${SHLIBDIR}/${SHLIB_NAME} \ 326 ${DESTDIR}${LIBDIR}/${SHLIB_LINK} 327.if exists(${DESTDIR}${LIBDIR}/${SHLIB_NAME}) 328 -chflags noschg ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 329 rm -f ${DESTDIR}${LIBDIR}/${SHLIB_NAME} 330.endif 331.endif 332.endif # SHLIB_LDSCRIPT 333.endif # SHLIB_LINK 334.endif # SHIB_NAME 335.if defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) && ${MK_TOOLCHAIN} != "no" 336 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 337 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 338.endif 339.if defined(WANT_LINT) && !defined(NO_LINT) && defined(LIB) && !empty(LIB) 340 ${INSTALL} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 341 ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR} 342.endif 343.endif # !defined(INTERNALLIB) 344 345.if !defined(LIBRARIES_ONLY) 346.include <bsd.nls.mk> 347.include <bsd.files.mk> 348.include <bsd.incs.mk> 349.endif 350 351.include <bsd.links.mk> 352 353.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY) 354realinstall: _maninstall 355.ORDER: beforeinstall _maninstall 356.endif 357 358.endif 359 360.if !target(lint) 361lint: ${SRCS:M*.c} 362 ${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 363.endif 364 365.if ${MK_MAN} != "no" && !defined(LIBRARIES_ONLY) 366.include <bsd.man.mk> 367.endif 368 369.include <bsd.dep.mk> 370 371.if !exists(${.OBJDIR}/${DEPENDFILE}) 372.if defined(LIB) && !empty(LIB) 373${OBJS} ${STATICOBJS} ${POBJS}: ${SRCS:M*.h} 374.for _S in ${SRCS:N*.[hly]} 375${_S:R}.po: ${_S} 376.endfor 377.endif 378.if defined(SHLIB_NAME) || \ 379 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 380${SOBJS}: ${SRCS:M*.h} 381.for _S in ${SRCS:N*.[hly]} 382${_S:R}.So: ${_S} 383.endfor 384.endif 385.endif 386 387.if !target(clean) 388clean: 389.if defined(CLEANFILES) && !empty(CLEANFILES) 390 rm -f ${CLEANFILES} 391.endif 392.if defined(LIB) && !empty(LIB) 393 rm -f a.out ${OBJS} ${OBJS:S/$/.tmp/} ${STATICOBJS} 394.endif 395.if !defined(INTERNALLIB) 396.if ${MK_PROFILE} != "no" && defined(LIB) && !empty(LIB) 397 rm -f ${POBJS} ${POBJS:S/$/.tmp/} 398.endif 399.if defined(SHLIB_NAME) || \ 400 defined(INSTALL_PIC_ARCHIVE) && defined(LIB) && !empty(LIB) 401 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} 402.endif 403.if defined(SHLIB_NAME) 404.if defined(SHLIB_LINK) 405.if defined(SHLIB_LDSCRIPT) && exists(${.CURDIR}/${SHLIB_LDSCRIPT}) 406 rm -f lib${LIB}.ld 407.endif 408 rm -f ${SHLIB_LINK} 409.endif 410.if defined(LIB) && !empty(LIB) 411 rm -f lib${LIB}.so.* lib${LIB}.so 412.endif 413.endif 414.if defined(WANT_LINT) && defined(LIB) && !empty(LIB) 415 rm -f ${LINTOBJS} 416.endif 417.endif # !defined(INTERNALLIB) 418.if defined(_LIBS) && !empty(_LIBS) 419 rm -f ${_LIBS} 420.endif 421.if defined(CLEANDIRS) && !empty(CLEANDIRS) 422 rm -rf ${CLEANDIRS} 423.endif 424.if !empty(VERSION_DEF) && !empty(SYMBOL_MAPS) 425 rm -f ${VERSION_MAP} 426.endif 427.endif 428 429.include <bsd.obj.mk> 430 431.include <bsd.sys.mk> 432 433.if ${MK_STAGING} != "no" 434.if defined(_SKIP_BUILD) 435stage_libs stage_files stage_as: 436.else 437.if !empty(_LIBS) && !defined(INTERNALLIB) 438stage_libs: ${_LIBS} 439.for t in stage_libs stage_files stage_as 440.if target($t) 441all: $t 442.endif 443.endfor 444.endif 445.if !empty(INCS) || !empty(INCSGROUPS) 446prebuild: buildincludes 447.endif 448.include <meta.stage.mk> 449.endif 450.endif 451