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