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

282 lines
6.2 KiB
Makefile
Raw Normal View History

# from: @(#)bsd.prog.mk 5.26 (Berkeley) 6/25/91
1999-08-28 00:22:10 +00:00
# $FreeBSD$
1994-05-30 19:09:18 +00:00
.include <bsd.init.mk>
1994-05-30 19:09:18 +00:00
.SUFFIXES: .out .o .c .cc .cpp .cxx .C .m .y .l .ln .s .S .asm
1994-05-30 19:09:18 +00:00
# XXX The use of COPTS in modern makefiles is discouraged.
.if defined(COPTS)
CFLAGS+=${COPTS}
.endif
.if ${MK_ASSERT_DEBUG} == "no"
CFLAGS+= -DNDEBUG
NO_WERROR=
.endif
.if defined(DEBUG_FLAGS)
CFLAGS+=${DEBUG_FLAGS}
CXXFLAGS+=${DEBUG_FLAGS}
Add support for the Compact C Type (CTF) conversions throughout FreeBSD's system makefiles. Note that the CTF conversion defaults to off. We may choose to change this default later if DTrace proves popular and people are prepared to wear the compilation performance impact of compiling with debug symbols all the time. Setting NO_CTF in the make args or user environment turns off CTF conversion. Even if we choose to default CTF generation to on later, we still need NO_CTF so that the buildworld process can bootstrap the tools without needlessly generating CTF data for temporary tools. Setting WITH_CTF in the make args or user environment (and _NOT_ in /etc/make.conf) is the only way to enable CTF data conversion. Nore that this can't be implemented the same way that the WITH_ and WITHOUT_ stuff is implemented throughout the buildworld because the CTF conversion needs to work when building a simple object without a Makefile, using the default rules in sys.mk. Typing 'make test.o' with no makefile and just a source file test.c should work. Also, typing 'make WITH_CTF=1 test.o without a makefile and just a source file test.c should work and produce an object with a CTF elf section. Typing 'make WITH_CTF=1 CFLAGS=-g test.o' without a makefile and just a source file test.c should produce an object with both a CTF elf section and the debug elf sections. In the FreeBSD build where more .mk files are used than just sys.mk which is included my make by default, the use of DEBUG_FLAGS is the correct way to enable a debug build. The important thing to note here is that it is the DEBUG_FLAGS setting that prevents libraries and programs from being stripped on installation. So, for the addition of CTF data conversion, setting DEBUG_FLAGS to contain -g, without NO_CTF, will cause the ctfconvert and ctfmerge build programs to be executed also with the -g arg so that debug symbols are retained rather than being removed after the CTF data elf section has been added. Add DTrace libraries to the list of libnames.
2008-05-22 01:14:43 +00:00
.if ${MK_CTF} != "no" && ${DEBUG_FLAGS:M-g} != ""
Add support for the Compact C Type (CTF) conversions throughout FreeBSD's system makefiles. Note that the CTF conversion defaults to off. We may choose to change this default later if DTrace proves popular and people are prepared to wear the compilation performance impact of compiling with debug symbols all the time. Setting NO_CTF in the make args or user environment turns off CTF conversion. Even if we choose to default CTF generation to on later, we still need NO_CTF so that the buildworld process can bootstrap the tools without needlessly generating CTF data for temporary tools. Setting WITH_CTF in the make args or user environment (and _NOT_ in /etc/make.conf) is the only way to enable CTF data conversion. Nore that this can't be implemented the same way that the WITH_ and WITHOUT_ stuff is implemented throughout the buildworld because the CTF conversion needs to work when building a simple object without a Makefile, using the default rules in sys.mk. Typing 'make test.o' with no makefile and just a source file test.c should work. Also, typing 'make WITH_CTF=1 test.o without a makefile and just a source file test.c should work and produce an object with a CTF elf section. Typing 'make WITH_CTF=1 CFLAGS=-g test.o' without a makefile and just a source file test.c should produce an object with both a CTF elf section and the debug elf sections. In the FreeBSD build where more .mk files are used than just sys.mk which is included my make by default, the use of DEBUG_FLAGS is the correct way to enable a debug build. The important thing to note here is that it is the DEBUG_FLAGS setting that prevents libraries and programs from being stripped on installation. So, for the addition of CTF data conversion, setting DEBUG_FLAGS to contain -g, without NO_CTF, will cause the ctfconvert and ctfmerge build programs to be executed also with the -g arg so that debug symbols are retained rather than being removed after the CTF data elf section has been added. Add DTrace libraries to the list of libnames.
2008-05-22 01:14:43 +00:00
CTFFLAGS+= -g
.endif
.endif
.if defined(PROG_CXX)
PROG= ${PROG_CXX}
.endif
.if defined(PROG) && target(${PROG})
MK_DEBUG_FILES= no
.elif !empty(LDFLAGS:M-Wl,*--oformat,*) || !empty(LDFLAGS:M-static)
MK_DEBUG_FILES= no
.endif
.if defined(CRUNCH_CFLAGS)
CFLAGS+=${CRUNCH_CFLAGS}
.else
.if ${MK_DEBUG_FILES} != "no" && empty(DEBUG_FLAGS:M-g) && \
empty(DEBUG_FLAGS:M-gdwarf-*)
CFLAGS+= -g
CTFFLAGS+= -g
.endif
.endif
1994-05-30 19:09:18 +00:00
.if !defined(DEBUG_FLAGS)
1994-05-30 19:09:18 +00:00
STRIP?= -s
.endif
1994-05-30 19:09:18 +00:00
2004-12-21 09:59:45 +00:00
.if defined(NO_SHARED) && (${NO_SHARED} != "no" && ${NO_SHARED} != "NO")
LDFLAGS+= -static
.endif
1994-05-30 19:09:18 +00:00
.if defined(USEPRIVATELIB)
LDFLAGS+= -L${_SHLIBDIRPREFIX}${LIBPRIVATEDIR} -rpath ${LIBPRIVATEDIR}
.endif
.if ${MK_DEBUG_FILES} != "no"
PROG_FULL=${PROG}.full
# Use ${DEBUGDIR} for base system debug files, else .debug subdirectory
.if defined(BINDIR) && (\
${BINDIR} == "/bin" ||\
${BINDIR} == "/libexec" ||\
${BINDIR} == "/sbin" ||\
${BINDIR:C%/usr/(bin|bsdinstall|games|libexec|lpr|sendmail|sm.bin|sbin)(/.*)?%/usr/bin%} == "/usr/bin"\
)
DEBUGFILEDIR= ${DEBUGDIR}${BINDIR}
.else
DEBUGFILEDIR?= ${BINDIR}/.debug
DEBUGMKDIR=
.endif
.else
PROG_FULL= ${PROG}
.endif
1994-05-30 19:09:18 +00:00
.if defined(PROG)
PROGNAME?= ${PROG}
1994-05-30 19:09:18 +00:00
.if defined(SRCS)
OBJS+= ${SRCS:N*.h:R:S/$/.o/g}
.if target(beforelinking)
beforelinking: ${OBJS}
${PROG_FULL}: beforelinking
.endif
${PROG_FULL}: ${OBJS}
.if defined(PROG_CXX)
${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.else
${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.endif
.if ${MK_CTF} != "no"
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
.endif
.else # !defined(SRCS)
1994-05-30 19:09:18 +00:00
.if !target(${PROG})
.if defined(PROG_CXX)
SRCS= ${PROG}.cc
.else
SRCS= ${PROG}.c
.endif
1994-05-30 19:09:18 +00:00
# Always make an intermediate object file because:
# - it saves time rebuilding when only the library has changed
# - the name of the object gets put into the executable symbol table instead of
# the name of a variable temporary object.
# - it's useful to keep objects around for crunching.
OBJS+= ${PROG}.o
.if target(beforelinking)
beforelinking: ${OBJS}
${PROG_FULL}: beforelinking
.endif
${PROG_FULL}: ${OBJS}
.if defined(PROG_CXX)
${CXX} ${CXXFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
.else
${CC} ${CFLAGS} ${LDFLAGS} -o ${.TARGET} ${OBJS} ${LDADD}
1994-05-30 19:09:18 +00:00
.endif
.if ${MK_CTF} != "no"
${CTFMERGE} ${CTFFLAGS} -o ${.TARGET} ${OBJS}
.endif
.endif # !target(${PROG})
.endif # !defined(SRCS)
1994-05-30 19:09:18 +00:00
.if ${MK_DEBUG_FILES} != "no"
${PROG}: ${PROG_FULL} ${PROGNAME}.debug
${OBJCOPY} --strip-debug --add-gnu-debuglink=${PROGNAME}.debug \
${PROG_FULL} ${.TARGET}
${PROGNAME}.debug: ${PROG_FULL}
${OBJCOPY} --only-keep-debug ${PROG_FULL} ${.TARGET}
.endif
.if ${MK_MAN} != "no" && !defined(MAN) && \
!defined(MAN1) && !defined(MAN2) && !defined(MAN3) && \
1994-05-30 19:09:18 +00:00
!defined(MAN4) && !defined(MAN5) && !defined(MAN6) && \
!defined(MAN7) && !defined(MAN8) && !defined(MAN9)
MAN= ${PROG}.1
MAN1= ${MAN}
1994-05-30 19:09:18 +00:00
.endif
.endif # defined(PROG)
1994-05-30 19:09:18 +00:00
all: objwarn ${PROG} ${SCRIPTS}
.if ${MK_MAN} != "no"
all: _manpages
.endif
1994-05-30 19:09:18 +00:00
.if defined(PROG)
CLEANFILES+= ${PROG}
.if ${MK_DEBUG_FILES} != "no"
CLEANFILES+= ${PROG_FULL} ${PROGNAME}.debug
.endif
.endif
.if defined(OBJS)
CLEANFILES+= ${OBJS}
.endif
1994-05-30 19:09:18 +00:00
.include <bsd.libnames.mk>
.if defined(PROG)
_EXTRADEPEND:
.if defined(LDFLAGS) && !empty(LDFLAGS:M-nostdlib)
.if defined(DPADD) && !empty(DPADD)
echo ${PROG}: ${DPADD} >> ${DEPENDFILE}
.endif
.else
echo ${PROG}: ${LIBC} ${DPADD} >> ${DEPENDFILE}
.if defined(PROG_CXX) && !defined(EARLY_BUILD)
.if ${MK_CLANG_IS_CC} != "no" && empty(CXXFLAGS:M-stdlib=libstdc++)
echo ${PROG}: ${LIBCPLUSPLUS} >> ${DEPENDFILE}
.else
echo ${PROG}: ${LIBSTDCPLUSPLUS} >> ${DEPENDFILE}
.endif
.endif
.endif
.endif
1994-05-30 19:09:18 +00:00
.if !target(install)
2004-11-12 13:24:34 +00:00
.if defined(PRECIOUSPROG)
2004-12-21 09:53:14 +00:00
.if !defined(NO_FSCHG)
INSTALLFLAGS+= -fschg
.endif
2004-11-12 13:24:34 +00:00
INSTALLFLAGS+= -S
.endif
_INSTALLFLAGS:= ${INSTALLFLAGS}
.for ie in ${INSTALLFLAGS_EDIT}
_INSTALLFLAGS:= ${_INSTALLFLAGS${ie}}
.endfor
.if !target(realinstall) && !defined(INTERNALPROG)
realinstall: _proginstall
.ORDER: beforeinstall _proginstall
_proginstall:
1994-05-30 19:09:18 +00:00
.if defined(PROG)
${INSTALL} ${STRIP} -o ${BINOWN} -g ${BINGRP} -m ${BINMODE} \
${_INSTALLFLAGS} ${PROG} ${DESTDIR}${BINDIR}/${PROGNAME}
.if ${MK_DEBUG_FILES} != "no"
.if defined(DEBUGMKDIR)
${INSTALL} -T debug -d ${DESTDIR}${DEBUGFILEDIR}
.endif
${INSTALL} -T debug -o ${BINOWN} -g ${BINGRP} -m ${DEBUGMODE} \
${PROGNAME}.debug ${DESTDIR}${DEBUGFILEDIR}/${PROGNAME}.debug
.endif
.endif
.endif # !target(realinstall)
1994-05-30 19:09:18 +00:00
.if defined(SCRIPTS) && !empty(SCRIPTS)
realinstall: _scriptsinstall
.ORDER: beforeinstall _scriptsinstall
SCRIPTSDIR?= ${BINDIR}
SCRIPTSOWN?= ${BINOWN}
SCRIPTSGRP?= ${BINGRP}
SCRIPTSMODE?= ${BINMODE}
.for script in ${SCRIPTS}
.if defined(SCRIPTSNAME)
SCRIPTSNAME_${script:T}?= ${SCRIPTSNAME}
.else
SCRIPTSNAME_${script:T}?= ${script:T:R}
.endif
SCRIPTSDIR_${script:T}?= ${SCRIPTSDIR}
SCRIPTSOWN_${script:T}?= ${SCRIPTSOWN}
SCRIPTSGRP_${script:T}?= ${SCRIPTSGRP}
SCRIPTSMODE_${script:T}?= ${SCRIPTSMODE}
_scriptsinstall: _SCRIPTSINS_${script:T}
_SCRIPTSINS_${script:T}: ${script}
${INSTALL} -o ${SCRIPTSOWN_${.ALLSRC:T}} \
-g ${SCRIPTSGRP_${.ALLSRC:T}} -m ${SCRIPTSMODE_${.ALLSRC:T}} \
${.ALLSRC} \
${DESTDIR}${SCRIPTSDIR_${.ALLSRC:T}}/${SCRIPTSNAME_${.ALLSRC:T}}
.endfor
.endif
NLSNAME?= ${PROG}
.include <bsd.nls.mk>
.include <bsd.files.mk>
.include <bsd.incs.mk>
.include <bsd.links.mk>
.if ${MK_MAN} != "no"
realinstall: _maninstall
.ORDER: beforeinstall _maninstall
.endif
1994-05-30 19:09:18 +00:00
.endif
.if !target(lint)
lint: ${SRCS:M*.c}
1994-05-30 19:09:18 +00:00
.if defined(PROG)
${LINT} ${LINTFLAGS} ${CFLAGS:M-[DIU]*} ${.ALLSRC}
1994-05-30 19:09:18 +00:00
.endif
.endif
.if ${MK_MAN} != "no"
1994-05-30 19:09:18 +00:00
.include <bsd.man.mk>
.endif
.include <bsd.dep.mk>
.if defined(PROG) && !exists(${.OBJDIR}/${DEPENDFILE})
${OBJS}: ${SRCS:M*.h}
.endif
.include <bsd.obj.mk>
.include <bsd.sys.mk>
.if defined(PORTNAME)
.include <bsd.pkg.mk>
.endif