freebsd-dev/share/mk/bsd.lib.mk

380 lines
9.3 KiB
Makefile
Raw Normal View History

# from: @(#)bsd.lib.mk 5.26 (Berkeley) 5/2/91
1999-08-28 00:22:10 +00:00
# $FreeBSD$
#
1994-05-30 19:09:18 +00:00
.if !target(__initialized__)
__initialized__:
1994-05-30 19:09:18 +00:00
.if exists(${.CURDIR}/../Makefile.inc)
.include "${.CURDIR}/../Makefile.inc"
.endif
.endif
1994-05-30 19:09:18 +00:00
.if exists(${.CURDIR}/shlib_version)
SHLIB_MAJOR != . ${.CURDIR}/shlib_version ; echo $$major
.if ${OBJFORMAT} == aout
SHLIB_MINOR != . ${.CURDIR}/shlib_version ; echo $$minor
.endif
.endif
# Set up the variables controlling shared libraries. After this section,
# SHLIB_NAME will be defined only if we are to create a shared library.
# SHLIB_LINK will be defined only if we are to create a link to it.
# INSTALL_PIC_ARCHIVE will be defined only if we are to create a PIC archive.
.if defined(NOPIC)
.undef SHLIB_NAME
.undef INSTALL_PIC_ARCHIVE
.else
.if ${OBJFORMAT} == elf
.if !defined(SHLIB_NAME) && defined(SHLIB_MAJOR)
SHLIB_NAME= lib${LIB}.so.${SHLIB_MAJOR}
SHLIB_LINK?= lib${LIB}.so
.endif
SONAME?= ${SHLIB_NAME}
.else
.if defined(SHLIB_MAJOR) && defined(SHLIB_MINOR)
SHLIB_NAME?= lib${LIB}.so.${SHLIB_MAJOR}.${SHLIB_MINOR}
.endif
.endif
.endif
.if defined(DESTDIR) && !defined(BOOTSTRAPPING)
CFLAGS+= -I${DESTDIR}/usr/include
CXXINCLUDES+= -I${DESTDIR}/usr/include/g++
.endif
.if defined(DEBUG_FLAGS)
CFLAGS+= ${DEBUG_FLAGS}
.endif
.if !defined(DEBUG_FLAGS)
1994-05-30 19:09:18 +00:00
STRIP?= -s
.endif
1994-05-30 19:09:18 +00:00
.if ${OBJFORMAT} != aout || make(checkdpadd) || defined(NEED_LIBNAMES)
.include <bsd.libnames.mk>
.endif
1994-05-30 19:09:18 +00:00
.MAIN: all
# prefer .s to a .c, add .po, remove stuff not used in the BSD libraries
# .So used for PIC object files
1994-05-30 19:09:18 +00:00
.SUFFIXES:
.SUFFIXES: .out .o .po .So .S .s .c .cc .cpp .cxx .m .C .f .y .l
1994-05-30 19:09:18 +00:00
.c.o:
${CC} ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
1994-05-30 19:09:18 +00:00
.c.po:
${CC} -pg ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
1994-05-30 19:09:18 +00:00
.c.So:
${CC} ${PICFLAG} -DPIC ${CFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.cc.o .C.o .cpp.o .cxx.o:
${CXX} ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.cc.po .C.po .cpp.po .cxx.po:
${CXX} -pg ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.cc.So .C.So .cpp.So .cxx.So:
${CXX} ${PICFLAG} -DPIC ${CXXFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.f.o:
${FC} ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.f.po:
${FC} -pg ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
@${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.f.So:
${FC} ${PICFLAG} -DPIC ${FFLAGS} -o ${.TARGET} -c ${.IMPSRC}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.m.o:
${OBJC} ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.m.po:
${OBJC} ${OBJCFLAGS} -pg -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.m.So:
${OBJC} ${PICFLAG} -DPIC ${OBJCFLAGS} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
1994-05-30 19:09:18 +00:00
.s.o:
${CC} -x assembler-with-cpp ${CFLAGS:M-[BID]*} ${AINC} -c \
${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
1994-05-30 19:09:18 +00:00
.s.po:
${CC} -x assembler-with-cpp -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c \
${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
1994-05-30 19:09:18 +00:00
.s.So:
${CC} -x assembler-with-cpp -fpic -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c \
${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.S.o:
${CC} ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.S.po:
${CC} -DPROF ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -X -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.S.So:
${CC} -fpic -DPIC ${CFLAGS:M-[BID]*} ${AINC} -c ${.IMPSRC} -o ${.TARGET}
@${LD} -o ${.TARGET}.tmp -x -r ${.TARGET}
@mv ${.TARGET}.tmp ${.TARGET}
.if !defined(INTERNALLIB) || defined(INTERNALSTATICLIB)
.if !defined(NOPROFILE) && !defined(INTERNALLIB)
1994-05-30 19:09:18 +00:00
_LIBS=lib${LIB}.a lib${LIB}_p.a
.else
_LIBS=lib${LIB}.a
.endif
.endif
1994-05-30 19:09:18 +00:00
.if defined(SHLIB_NAME)
_LIBS+=${SHLIB_NAME}
.endif
.if defined(INSTALL_PIC_ARCHIVE)
_LIBS+=lib${LIB}_pic.a
.endif
.if !defined(PICFLAG)
PICFLAG=-fpic
1994-05-30 19:09:18 +00:00
.endif
.if !defined(NOMAN)
all: objwarn ${_LIBS} all-man _SUBDIR # llib-l${LIB}.ln
.else
all: objwarn ${_LIBS} _SUBDIR # llib-l${LIB}.ln
.endif
OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
1994-05-30 19:09:18 +00:00
lib${LIB}.a:: ${OBJS} ${STATICOBJS}
@${ECHO} building static ${LIB} library
1994-05-30 19:09:18 +00:00
@rm -f lib${LIB}.a
@${AR} cq lib${LIB}.a `lorder ${OBJS} ${STATICOBJS} | tsort -q` ${ARADD}
${RANLIB} lib${LIB}.a
1994-05-30 19:09:18 +00:00
POBJS+= ${OBJS:.o=.po} ${STATICOBJS:.o=.po}
.if !defined(NOPROFILE)
1994-05-30 19:09:18 +00:00
lib${LIB}_p.a:: ${POBJS}
@${ECHO} building profiled ${LIB} library
1994-05-30 19:09:18 +00:00
@rm -f lib${LIB}_p.a
1996-08-03 06:43:05 +00:00
@${AR} cq lib${LIB}_p.a `lorder ${POBJS} | tsort -q` ${ARADD}
${RANLIB} lib${LIB}_p.a
.endif
Fix cross-building, etc: 1. To cross-build, one now needs to set TARGET_ARCH, and not the MACHINE_ARCH. MACHINE_ARCH should never be changed manually! 2. Initialize DESTDIR= explicitly for bootstrap-tools, build-tools, and cross-tools stages. This fixes broken header and library dependencies problem. We build them in the host environment, and obviously want them to depend on host headers and libraries. The problem with broken header dependencies for bootstrap-tools and cross-tools was already partially solved (see BOOTSTRAPPING tests in bsd.prog.mk and bsd.lib.mk), but it was still there for build-tools if the user ran "make world DESTDIR=/foo". Also, for all of these stages, the library dependencies were broken because of how bsd.libnames.mk define DPADD members. We still provide a glue to install bootstrap- and cross-tools under the ${WORLDTMP}. Removed PATH overrides for bootstrap-, build-, and cross-tools stages. There is just no reason why we would need to override it, and the hacks to clean up the ${WORLDTMP} in the -DNOCLEAN case are no longer needed with fixes from this step. That is, we now never use ${WORLDTMP} headers and libraries, and we don't use any ${WORLDTMP} installed binaries during these stages. Again, these stages depend solely on the host environment, including compiler, headers, and libraries. 3. Moved "miniperl" back from cross-tools (it has nothing to do with a cross-compiler) to build-tools where it belongs. The change from step 1 let to do this. Also, to make this work, build-tools targets of "cc_tools" and "miniperl" were modified to call "depend". Here follow the detailed explanations. There are two categories of build tools, for now. In the first category there are "cc_tools" and "miniperl". They occupy the whole (sub)directory, and nothing needs to be done in this subdirectory later during the "all" stage. They are also constructed using system makefiles. We must build the .depend early in the build-tools stage because: 1) They use (and depend on) the host environment. 2) If we don't do this in build-tools, the "depend" stage of buildworld will do this for us; wrong library and header dependencies will be recorded (DESTDIR=${WORLDTMP}) and, what's worse, the "all" stage may then clobber the build-architecture format tools (that we built in the build-tools stage) with the target-architecture format ones, breaking cross build. In the second category there are all other build-tools. They share their directory with the "main" module that needs them in the "all" stage, and they don't show up themselves in the .depend file. The portion of this fix was already committed in gnu/usr.bin/cc/cc_tools/Makefile,v 1.52. 4. "libperl" is no longer a build tool, and "miniperl" is the stand-alone application. I had to make this change because build-tools and "all" stages share the same object directory. Without this change, if we cross compile, libperl.a is first built for the build architecture during the build-tools stage (for the purposes of immediate linkage with "miniperl"). Later on, the "all" stage sees this library as up-to-date, and doesn't rebuild it. The effect is that the wrong format static libperl library is installed with installworld. 5. Fixed "includes" to install secure/lib/libtelnet headers if required. Reviewed by: bde
2001-09-29 13:17:54 +00:00
.if defined(DESTDIR) && !defined(BOOTSTRAPPING)
1998-06-04 15:15:38 +00:00
LDDESTDIRENV?= LIBRARY_PATH=${DESTDIR}${SHLIBDIR}:${DESTDIR}${LIBDIR}
.endif
SOBJS+= ${OBJS:.o=.So}
.if defined(SHLIB_NAME)
${SHLIB_NAME}: ${SOBJS}
@${ECHO} building shared library ${SHLIB_NAME}
@rm -f ${SHLIB_NAME} ${SHLIB_LINK}
.if defined(SHLIB_LINK)
@ln -sf ${SHLIB_NAME} ${SHLIB_LINK}
.endif
.if ${OBJFORMAT} == aout
@${LDDESTDIRENV} ${CC} -shared -Wl,-x,-assert,pure-text \
-o ${SHLIB_NAME} \
1996-08-03 06:43:05 +00:00
`lorder ${SOBJS} | tsort -q` ${LDDESTDIR} ${LDADD}
.else
@${LDDESTDIRENV} ${CC} -shared -Wl,-x \
-o ${SHLIB_NAME} -Wl,-soname,${SONAME} \
`lorder ${SOBJS} | tsort -q` ${LDDESTDIR} ${LDADD}
.endif
.endif
.if defined(INSTALL_PIC_ARCHIVE)
lib${LIB}_pic.a:: ${SOBJS}
@${ECHO} building special pic ${LIB} library
@rm -f lib${LIB}_pic.a
1994-12-28 00:49:58 +00:00
@${AR} cq lib${LIB}_pic.a ${SOBJS} ${ARADD}
${RANLIB} lib${LIB}_pic.a
.endif
1994-05-30 19:09:18 +00:00
llib-l${LIB}.ln: ${SRCS}
${LINT} -C${LIB} ${CFLAGS:M-[DIU]*} ${.ALLSRC:M*.c}
1994-05-30 19:09:18 +00:00
.if !target(clean)
clean: _SUBDIR
rm -f a.out ${OBJS} ${STATICOBJS} ${OBJS:S/$/.tmp/} ${CLEANFILES}
rm -f lib${LIB}.a # llib-l${LIB}.ln
rm -f ${POBJS} ${POBJS:S/$/.tmp/} lib${LIB}_p.a
rm -f ${SOBJS} ${SOBJS:.So=.so} ${SOBJS:S/$/.tmp/} \
${SHLIB_NAME} ${SHLIB_LINK} \
lib${LIB}.so.* lib${LIB}.so lib${LIB}_pic.a
.if defined(CLEANDIRS) && !empty(CLEANDIRS)
rm -rf ${CLEANDIRS}
.endif
1994-05-30 19:09:18 +00:00
.endif
_EXTRADEPEND:
@TMP=_depend$$$$; \
sed -e 's/^\([^\.]*\).o[ ]*:/\1.o \1.po \1.So:/' < ${DEPENDFILE} \
> $$TMP; \
mv $$TMP ${DEPENDFILE}
.if !defined(NOEXTRADEPEND) && defined(SHLIB_NAME)
.if ${OBJFORMAT} == aout
echo ${SHLIB_NAME}: \
`${LDDESTDIRENV} ${CC} -shared -Wl,-f ${LDDESTDIR} ${LDADD}` \
>> ${DEPENDFILE}
.else
.if defined(DPADD) && !empty(DPADD)
echo ${SHLIB_NAME}: ${DPADD} >> ${DEPENDFILE}
.endif
.endif
.endif
1994-05-30 19:09:18 +00:00
.if !target(install)
.if !target(beforeinstall)
beforeinstall: _includeinstall
.endif
_includeinstall:
.if defined(INCS)
.for header in ${INCS}
cd ${.CURDIR} && \
${INSTALL} -C -o ${INCOWN} -g ${INCGRP} -m ${INCMODE} \
${header} ${DESTDIR}${INCDIR}
.endfor
1994-05-30 19:09:18 +00:00
.endif
.if defined(PRECIOUSLIB) && !defined(NOFSCHG)
SHLINSTALLFLAGS+= -fschg
.endif
_INSTALLFLAGS:= ${INSTALLFLAGS}
.for ie in ${INSTALLFLAGS_EDIT}
_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
.endfor
_SHLINSTALLFLAGS:= ${SHLINSTALLFLAGS}
.for ie in ${INSTALLFLAGS_EDIT}
_SHLINSTALLFLAGS:= ${_SHLINSTALLFLAGS${ie}}
.endfor
1994-05-30 19:09:18 +00:00
realinstall: beforeinstall
.if !defined(INTERNALLIB)
${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} lib${LIB}.a ${DESTDIR}${LIBDIR}
1994-05-30 19:09:18 +00:00
.if !defined(NOPROFILE)
${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} lib${LIB}_p.a ${DESTDIR}${LIBDIR}
1994-05-30 19:09:18 +00:00
.endif
.endif
.if defined(SHLIB_NAME)
${INSTALL} ${COPY} ${STRIP} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} ${_SHLINSTALLFLAGS} \
${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}
.if defined(SHLIB_LINK)
ln -sf ${SHLIB_NAME} ${DESTDIR}${SHLIBDIR}/${SHLIB_LINK}
.endif
.endif
.if defined(INSTALL_PIC_ARCHIVE)
${INSTALL} ${COPY} -o ${LIBOWN} -g ${LIBGRP} -m ${LIBMODE} \
${_INSTALLFLAGS} lib${LIB}_pic.a ${DESTDIR}${LIBDIR}
.endif
1994-05-30 19:09:18 +00:00
.if defined(LINKS) && !empty(LINKS)
@set ${LINKS}; \
while test $$# -ge 2; do \
l=${DESTDIR}$$1; \
shift; \
t=${DESTDIR}$$1; \
shift; \
${ECHO} $$t -\> $$l; \
ln -f $$l $$t; \
done; true
.endif
.if defined(SYMLINKS) && !empty(SYMLINKS)
@set ${SYMLINKS}; \
while test $$# -ge 2; do \
l=$$1; \
shift; \
t=${DESTDIR}$$1; \
shift; \
${ECHO} $$t -\> $$l; \
ln -fs $$l $$t; \
1994-05-30 19:09:18 +00:00
done; true
.endif
install: afterinstall _SUBDIR
1994-05-30 19:09:18 +00:00
.if !defined(NOMAN)
afterinstall: realinstall maninstall
.else
afterinstall: realinstall
1994-05-30 19:09:18 +00:00
.endif
.endif
.if !target(regress)
regress:
.endif
DISTRIBUTION?= bin
.if !target(distribute)
distribute: _SUBDIR
.for dist in ${DISTRIBUTION}
cd ${.CURDIR} ; $(MAKE) install DESTDIR=${DISTDIR}/${dist} SHARED=copies
.endfor
.endif
1994-05-30 19:09:18 +00:00
.if !target(lint)
lint:
.endif
.if !defined(NOMAN)
1994-05-30 19:09:18 +00:00
.include <bsd.man.mk>
.else
.if !target(all-man)
all-man:
.endif
.if !target(maninstall)
maninstall:
.endif
.endif
.include <bsd.dep.mk>
.if !exists(${DEPENDFILE})
${OBJS} ${STATICOBJS} ${POBJS} ${SOBJS}: ${SRCS:M*.h}
.endif
.include <bsd.obj.mk>
.include <bsd.sys.mk>