bsd.lib.mk revision 95114
1138818Strhodes# from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91 2138818Strhodes# $FreeBSD: head/share/mk/bsd.lib.mk 95114 2002-04-20 08:41:55Z obrien $ 3138818Strhodes# 4138818Strhodes 5138818Strhodes.include <bsd.init.mk> 6138818Strhodes 7138818Strhodes.if exists(${.CURDIR}/shlib_version) 8138818StrhodesSHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major 9138818Strhodes.if ${OBJFORMAT} == aout 10138818StrhodesSHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor 11138818Strhodes.endif 12138818Strhodes.endif 13138818Strhodes 14138818Strhodes# Set up the variables controlling shared libraries. After this section, 15138818Strhodes# SHLIB_NAME will be defined only if we are to create a shared library. 16138818Strhodes# SHLIB_LINK will be defined only if we are to create a link to it. 17138818Strhodes# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive. 18138818Strhodes.if defined(NOPIC) 19138818Strhodes.undef SHLIB_NAME 20138818Strhodes.undef INSTALL_PIC_ARCHIVE 21138818Strhodes.else 22138818Strhodes.if ${OBJFORMAT} == elf 23138818Strhodes.if !defined(SHLIB_NAME) && defined(SHLIB_MAJOR) 24138818StrhodesSHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR} 25138818StrhodesSHLIB_LINK?= lib${LIB}.so 26138818Strhodes.endif 27138818StrhodesSONAME?= ${SHLIB_NAME} 28138818Strhodes.else 29138818Strhodes.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR) 30138818StrhodesSHLIB_NAME?= lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR} 31138818Strhodes.endif 32138854Strhodes.endif 33138854Strhodes.endif 34138854Strhodes 35138854Strhodes.if defined(DEBUG_FLAGS) 36138854StrhodesCFLAGS+= ${DEBUG_FLAGS} 37138854Strhodes.endif 38138818Strhodes 39138854Strhodes.if !defined(DEBUG_FLAGS) 40138818StrhodesSTRIP?= -s 41138818Strhodes.endif 42138818Strhodes 43138818Strhodes.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES) 44138854Strhodes.include <bsd.libnames.mk> 45138818Strhodes.endif 46138854Strhodes 47138854Strhodes# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries 48138854Strhodes# .So used for PIC object files 49138854Strhodes.SUFFIXES: 50138854Strhodes.SUFFIXES: .out .o .po .So .S .s .asm .c .cc .cpp .cxx .m .C .f .y .l .ln 51138854Strhodes 52138854Strhodes.c.ln: 53138854Strhodes ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.IMPSRC} || \ 54138854Strhodes touch ${.TARGET} 55138854Strhodes 56138854Strhodes.cc.ln .C.ln .cpp.ln .cxx.ln: 57138854Strhodes ${LINT} ${LINTOBJFLAGS} ${CXXFLAGS:M-[DIU]*} ${.IMPSRC} || \ 58138854Strhodes touch ${.TARGET} 59138818Strhodes 60138818Strhodes.c.o: 61138854Strhodes ${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 62138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 63138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 64138818Strhodes 65138818Strhodes.c.po: 66138818Strhodes ${CC} -pg ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 67138818Strhodes @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 68138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 69138818Strhodes 70138854Strhodes.c.So: 71138818Strhodes ${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET} 72138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 73138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 74138818Strhodes 75138818Strhodes.cc.o .C.o .cpp.o .cxx.o: 76138818Strhodes ${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 77138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 78138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 79138818Strhodes 80138818Strhodes.cc.po .C.po .cpp.po .cxx.po: 81138818Strhodes ${CXX} -pg ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 82138818Strhodes @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 83138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 84138854Strhodes 85138818Strhodes.cc.So .C.So .cpp.So .cxx.So: 86138818Strhodes ${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET} 87138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 88138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 89138818Strhodes 90138818Strhodes.f.o: 91138818Strhodes ${FC} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 92138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 93138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 94138818Strhodes 95138818Strhodes.f.po: 96138818Strhodes ${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 97138818Strhodes @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 98138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 99138818Strhodes 100138818Strhodes.f.So: 101138818Strhodes ${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC} 102138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 103138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 104138818Strhodes 105138818Strhodes.m.o: 106138818Strhodes ${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 107138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 108138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 109138818Strhodes 110138818Strhodes.m.po: 111138818Strhodes ${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET} 112138854Strhodes @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 113138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 114138818Strhodes 115138818Strhodes.m.So: 116138818Strhodes ${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET} 117138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 118138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 119138818Strhodes 120138818Strhodes.s.o: 121138818Strhodes ${CC} -x assembler-with-cpp ${CFLAGS:M-[BID]*} ${AINC} -c \ 122138818Strhodes ${.IMPSRC} -o ${.TARGET} 123138854Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 124138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 125138818Strhodes 126138818Strhodes.s.po: 127138854Strhodes ${CC} -x assembler-with-cpp -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c \ 128138818Strhodes ${.IMPSRC} -o ${.TARGET} 129138818Strhodes @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 130138854Strhodes @mv ${.TARGET}.tmp ${.TARGET} 131138818Strhodes 132138818Strhodes.s.So: 133138818Strhodes ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c \ 134138818Strhodes ${.IMPSRC} -o ${.TARGET} 135138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 136138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 137138818Strhodes 138138818Strhodes.asm.o: 139138818Strhodes ${CC} -x assembler-with-cpp ${CFLAGS:M-[BID]*} ${AINC} -c \ 140138818Strhodes ${.IMPSRC} -o ${.TARGET} 141138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 142138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 143138818Strhodes 144138818Strhodes.asm.po: 145138818Strhodes ${CC} -x assembler-with-cpp -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c \ 146138818Strhodes ${.IMPSRC} -o ${.TARGET} 147138818Strhodes @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 148138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 149138818Strhodes 150138818Strhodes.asm.So: 151138854Strhodes ${CC} -x assembler-with-cpp ${PICFLAG} -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c \ 152138854Strhodes ${.IMPSRC} -o ${.TARGET} 153138818Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 154138854Strhodes @mv ${.TARGET}.tmp ${.TARGET} 155138854Strhodes 156238542Skevlo.S.o: 157138854Strhodes ${CC} ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET} 158138854Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 159138818Strhodes @mv ${.TARGET}.tmp ${.TARGET} 160138854Strhodes 161238542Skevlo.S.po: 162138854Strhodes ${CC} -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET} 163138854Strhodes @${LD} -o ${.TARGET}.tmp -X -r ${.TARGET} 164138854Strhodes @mv ${.TARGET}.tmp ${.TARGET} 165138854Strhodes 166138818Strhodes.S.So: 167138854Strhodes ${CC} ${PICFLAG} -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET} 168138854Strhodes @${LD} -o ${.TARGET}.tmp -x -r ${.TARGET} 169138854Strhodes @mv ${.TARGET}.tmp ${.TARGET} 170138854Strhodes 171138818Strhodes.if !defined(INTERNALLIB) || defined(INTERNALSTATICLIB) 172138854Strhodes.if !defined(NOPROFILE) && !defined(INTERNALLIB) 173138854Strhodes_LIBS=lib${LIB}.a lib${LIB}_p.a 174138854Strhodes.else 175138818Strhodes_LIBS=lib${LIB}.a 176138854Strhodes.endif 177138818Strhodes.endif 178138854Strhodes 179138818Strhodes.if defined(SHLIB_NAME) 180138818Strhodes_LIBS+=${SHLIB_NAME} 181138818Strhodes.endif 182138818Strhodes.if defined(INSTALL_PIC_ARCHIVE) 183138818Strhodes_LIBS+=lib${LIB}_pic.a 184138854Strhodes.endif 185138854Strhodes 186138854Strhodes.if !defined(PICFLAG) 187138818Strhodes.if ${MACHINE_ARCH} == "sparc64" 188138854StrhodesPICFLAG=-fPIC 189138854Strhodes.else 190138854StrhodesPICFLAG=-fpic 191138854Strhodes.endif 192138854Strhodes.endif 193138854Strhodes 194138818StrhodesLINTOBJS+= ${SRCS:M*.c:C/\..+$/.ln/} 195138818Strhodes 196138818Strhodes.if defined(WANT_LINT) && defined(LIB) && defined(LINTOBJS) && !empty(LINTOBJS) 197269498SgjbLINTLIB=llib-l${LIB}.ln 198138818Strhodes_LIBS+=${LINTLIB} 199138818Strhodes.endif 200138818Strhodes 201138818Strhodes.if !defined(NOMAN) 202138818Strhodesall: objwarn ${_LIBS} all-man _SUBDIR 203138818Strhodes.else 204138818Strhodesall: objwarn ${_LIBS} _SUBDIR 205138854Strhodes.endif 206138818Strhodes 207138818StrhodesOBJS+= ${SRCS:N*.h:R:S/$/.o/g} 208138854Strhodes 209138818Strhodeslib${LIB}.a:: ${OBJS} ${STATICOBJS} 210138818Strhodes @${ECHO} building static ${LIB} library 211138818Strhodes @rm -f lib${LIB}.a 212 @${AR} cq lib${LIB}.a `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD} 213 ${RANLIB} lib${LIB}.a 214 215POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po} 216.if !defined(NOPROFILE) 217lib${LIB}_p.a:: ${POBJS} 218 @${ECHO} building profiled ${LIB} library 219 @rm -f lib${LIB}_p.a 220 @${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q` ${ARADD} 221 ${RANLIB} lib${LIB}_p.a 222.endif 223 224SOBJS+= ${OBJS:.o=.So} 225 226.if defined(SHLIB_NAME) 227${SHLIB_NAME}: ${SOBJS} 228 @${ECHO} building shared library ${SHLIB_NAME} 229 @rm -f ${SHLIB_NAME} ${SHLIB_LINK} 230.if defined(SHLIB_LINK) 231 @ln -sf ${SHLIB_NAME} ${SHLIB_LINK} 232.endif 233.if ${OBJFORMAT} == aout 234 @${CC} -shared -Wl,-x,-assert,pure-text \ 235 -o ${SHLIB_NAME} \ 236 `lorder ${SOBJS} | tsort -q` ${LDADD} 237.else 238 @${CC} -shared -Wl,-x \ 239 -o ${SHLIB_NAME} -Wl,-soname,${SONAME} \ 240 `lorder ${SOBJS} | tsort -q` ${LDADD} 241.endif 242.endif 243 244.if defined(INSTALL_PIC_ARCHIVE) 245lib${LIB}_pic.a:: ${SOBJS} 246 @${ECHO} building special pic ${LIB} library 247 @rm -f lib${LIB}_pic.a 248 @${AR} cq lib${LIB}_pic.a ${SOBJS} ${ARADD} 249 ${RANLIB} lib${LIB}_pic.a 250.endif 251 252.if defined(WANT_LINT) && defined(LIB) && defined(LINTOBJS) && !empty(LINTOBJS) 253${LINTLIB}: ${LINTOBJS} 254 @${ECHO} building lint library ${LINTLIB} 255 @rm -f ${LINTLIB} 256 ${LINT} ${LINTLIBFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 257.endif 258 259.if !target(clean) 260clean: _SUBDIR 261 rm -f a.out ${OBJS} ${STATICOBJS} ${OBJS:S/$/.tmp/} ${CLEANFILES} 262 rm -f lib${LIB}.a 263 rm -f ${POBJS} ${POBJS:S/$/.tmp/} lib${LIB}_p.a 264 rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} \ 265 ${SHLIB_NAME} ${SHLIB_LINK} \ 266 lib${LIB}.so.* lib${LIB}.so lib${LIB}_pic.a 267 rm -f ${LINTOBJS} ${LINTLIB} 268.if defined(CLEANDIRS) && !empty(CLEANDIRS) 269 rm -rf ${CLEANDIRS} 270.endif 271.endif 272 273_EXTRADEPEND: 274 @TMP=_depend$$$$; \ 275 sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \ 276 > $$TMP; \ 277 mv $$TMP ${DEPENDFILE} 278.if !defined(NOEXTRADEPEND) && defined(SHLIB_NAME) 279.if ${OBJFORMAT} == aout 280 echo ${SHLIB_NAME}: \ 281 `${CC} -shared -Wl,-f ${LDADD}` \ 282 >> ${DEPENDFILE} 283.else 284.if defined(DPADD) && !empty(DPADD) 285 echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE} 286.endif 287.endif 288.endif 289 290.if !target(install) 291.if !target(beforeinstall) 292beforeinstall: _includeinstall 293.endif 294 295_includeinstall: 296.if defined(INCS) 297.for header in ${INCS} 298 cd ${.CURDIR} && \ 299 ${INSTALL} -C -o ${INCOWN} -g ${INCGRP} -m ${INCMODE} \ 300 ${header} ${DESTDIR}${INCDIR} 301 302.endfor 303.endif 304 305.if defined(PRECIOUSLIB) && !defined(NOFSCHG) 306SHLINSTALLFLAGS+= -fschg 307.endif 308 309_INSTALLFLAGS:= ${INSTALLFLAGS} 310.for ie in ${INSTALLFLAGS_EDIT} 311_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}} 312.endfor 313_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS} 314.for ie in ${INSTALLFLAGS_EDIT} 315_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}} 316.endfor 317 318realinstall: beforeinstall 319.if !defined(INTERNALLIB) 320 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 321 ${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR} 322.if !defined(NOPROFILE) 323 ${INSTALL} -C -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 324 ${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR} 325.endif 326.endif 327.if defined(SHLIB_NAME) 328 ${INSTALL} ${COPY} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 329 ${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \ 330 ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR} 331.if defined(SHLIB_LINK) 332 ln -sf ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}/${SHLIB_LINK} 333.endif 334.endif 335.if defined(INSTALL_PIC_ARCHIVE) 336 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 337 ${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR} 338.endif 339.if defined(LINKS) && !empty(LINKS) 340 @set ${LINKS}; \ 341 while test $$# -ge 2; do \ 342 l=${DESTDIR}$$1; \ 343 shift; \ 344 t=${DESTDIR}$$1; \ 345 shift; \ 346 ${ECHO} $$t -\> $$l; \ 347 ln -f $$l $$t; \ 348 done; true 349.endif 350.if defined(SYMLINKS) && !empty(SYMLINKS) 351 @set ${SYMLINKS}; \ 352 while test $$# -ge 2; do \ 353 l=$$1; \ 354 shift; \ 355 t=${DESTDIR}$$1; \ 356 shift; \ 357 ${ECHO} $$t -\> $$l; \ 358 ln -fs $$l $$t; \ 359 done; true 360.endif 361.if defined(WANT_LINT) && defined(LIB) && defined(LINTOBJS) && !empty(LINTOBJS) 362 ${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \ 363 ${_INSTALLFLAGS} ${LINTLIB} ${DESTDIR}${LINTLIBDIR} 364.endif 365 366install: afterinstall _SUBDIR 367.if !defined(NOMAN) 368afterinstall: realinstall maninstall 369.else 370afterinstall: realinstall 371.endif 372.endif 373 374.if !target(regress) 375regress: 376.endif 377 378DISTRIBUTION?= bin 379.if !target(distribute) 380distribute: _SUBDIR 381.for dist in ${DISTRIBUTION} 382 cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies 383.endfor 384.endif 385 386.if !target(lint) 387lint: ${SRCS:M*.c} _SUBDIR 388 ${LINT} ${LINTOBJFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC} 389.endif 390 391.if !defined(NOMAN) 392.include <bsd.man.mk> 393.else 394.if !target(all-man) 395all-man: 396.endif 397.if !target(maninstall) 398maninstall: 399.endif 400.endif 401 402.include <bsd.dep.mk> 403 404.if !exists(${.OBJDIR}/${DEPENDFILE}) 405${OBJS} ${STATICOBJS} ${POBJS} ${SOBJS}: ${SRCS:M*.h} 406.endif 407 408.include <bsd.obj.mk> 409 410.include <bsd.sys.mk> 411