2010-11-13 03:11:27 +00:00
|
|
|
#################################################################
|
|
|
|
#
|
2015-10-24 04:55:17 +00:00
|
|
|
# Generate crunched binaries using crunchgen(1).
|
|
|
|
#
|
2010-11-13 03:11:27 +00:00
|
|
|
# General notes:
|
|
|
|
#
|
|
|
|
# A number of Make variables are used to generate the crunchgen config file.
|
|
|
|
#
|
|
|
|
# CRUNCH_SRCDIRS: lists directories to search for included programs
|
|
|
|
# CRUNCH_PROGS: lists programs to be included
|
|
|
|
# CRUNCH_LIBS: libraries to statically link with
|
|
|
|
# CRUNCH_SHLIBS: libraries to dynamically link with
|
|
|
|
# CRUNCH_BUILDOPTS: generic build options to be added to every program
|
|
|
|
# CRUNCH_BUILDTOOLS: lists programs that need build tools built in the
|
|
|
|
# local architecture.
|
|
|
|
#
|
|
|
|
# Special options can be specified for individual programs
|
2015-10-22 04:47:52 +00:00
|
|
|
# CRUNCH_SRCDIR_${P}: base source directory for program ${P}
|
|
|
|
# CRUNCH_BUILDOPTS_${P}: additional build options for ${P}
|
|
|
|
# CRUNCH_ALIAS_${P}: additional names to be used for ${P}
|
2010-11-13 03:11:27 +00:00
|
|
|
#
|
|
|
|
# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
|
|
|
|
# will be used to generate a hard link to the resulting binary.
|
|
|
|
# Specific links can be suppressed by setting
|
2015-10-22 04:47:52 +00:00
|
|
|
# CRUNCH_SUPPRESS_LINK_${NAME} to 1.
|
2010-11-13 03:11:27 +00:00
|
|
|
#
|
2012-01-05 21:49:43 +00:00
|
|
|
# If CRUNCH_GENERATE_LINKS is set to no, no links will be generated.
|
|
|
|
#
|
2010-11-13 03:11:27 +00:00
|
|
|
|
|
|
|
# $FreeBSD$
|
|
|
|
|
|
|
|
##################################################################
|
|
|
|
# The following is pretty nearly a generic crunchgen-handling makefile
|
|
|
|
#
|
|
|
|
|
2015-10-22 04:47:52 +00:00
|
|
|
CONF= ${PROG}.conf
|
|
|
|
OUTMK= ${PROG}.mk
|
|
|
|
OUTC= ${PROG}.c
|
|
|
|
OUTPUTS=${OUTMK} ${OUTC} ${PROG}.cache
|
2010-11-13 03:11:27 +00:00
|
|
|
CRUNCHOBJS= ${.OBJDIR}
|
2015-10-22 04:47:52 +00:00
|
|
|
CRUNCH_GENERATE_LINKS?= yes
|
2016-05-26 23:20:36 +00:00
|
|
|
# Don't let the prog.mk use MK_AUTO_OBJ, but do let the component builds use
|
|
|
|
# it.
|
2017-10-31 02:12:09 +00:00
|
|
|
CRUNCHARGS+= MK_AUTO_OBJ=no
|
2016-05-26 23:20:36 +00:00
|
|
|
CRUNCH_BUILDOPTS+= MK_AUTO_OBJ=${MK_AUTO_OBJ}
|
2010-11-13 03:11:27 +00:00
|
|
|
|
2015-10-22 04:47:52 +00:00
|
|
|
CLEANFILES+= ${CONF} *.o *.lo *.c *.mk *.cache *.a *.h
|
2010-11-13 03:11:27 +00:00
|
|
|
|
2013-06-07 21:40:02 +00:00
|
|
|
# Don't try to extract debug info from ${PROG}.
|
2015-10-22 04:47:52 +00:00
|
|
|
MK_DEBUG_FILES= no
|
2013-06-07 21:40:02 +00:00
|
|
|
|
2015-10-23 19:41:58 +00:00
|
|
|
# Set a default SRCDIR for each for simpler handling below.
|
|
|
|
.for D in ${CRUNCH_SRCDIRS}
|
|
|
|
.for P in ${CRUNCH_PROGS_${D}}
|
|
|
|
CRUNCH_SRCDIR_${P}?= ${.CURDIR}/../../${D}/${P}
|
|
|
|
.endfor
|
|
|
|
.endfor
|
|
|
|
|
2010-11-13 03:11:27 +00:00
|
|
|
# Program names and their aliases contribute hardlinks to 'rescue' executable,
|
|
|
|
# except for those that get suppressed.
|
2015-10-22 04:47:52 +00:00
|
|
|
.for D in ${CRUNCH_SRCDIRS}
|
|
|
|
.for P in ${CRUNCH_PROGS_${D}}
|
|
|
|
${OUTPUTS}: ${CRUNCH_SRCDIR_${P}}/Makefile
|
2012-01-05 21:49:43 +00:00
|
|
|
.if ${CRUNCH_GENERATE_LINKS} == "yes"
|
2010-11-16 22:23:20 +00:00
|
|
|
.ifndef CRUNCH_SUPPRESS_LINK_${P}
|
2015-10-22 04:47:52 +00:00
|
|
|
LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${P}
|
2010-11-16 22:23:20 +00:00
|
|
|
.endif
|
2015-10-22 04:47:52 +00:00
|
|
|
.for A in ${CRUNCH_ALIAS_${P}}
|
2010-11-16 22:23:20 +00:00
|
|
|
.ifndef CRUNCH_SUPPRESS_LINK_${A}
|
2015-10-22 04:47:52 +00:00
|
|
|
LINKS+= ${BINDIR}/${PROG} ${BINDIR}/${A}
|
2010-11-16 22:23:20 +00:00
|
|
|
.endif
|
|
|
|
.endfor
|
2012-01-05 21:49:43 +00:00
|
|
|
.endif
|
2010-11-13 03:11:27 +00:00
|
|
|
.endfor
|
|
|
|
.endfor
|
|
|
|
|
2016-02-26 22:13:48 +00:00
|
|
|
.if !defined(_SKIP_BUILD)
|
2015-10-22 04:47:52 +00:00
|
|
|
all: ${PROG}
|
2016-02-26 22:13:48 +00:00
|
|
|
.endif
|
2015-10-22 04:47:52 +00:00
|
|
|
exe: ${PROG}
|
2010-11-13 03:11:27 +00:00
|
|
|
|
2015-10-22 04:47:52 +00:00
|
|
|
${CONF}: Makefile
|
|
|
|
echo \# Auto-generated, do not edit >${.TARGET}
|
2010-11-13 03:11:27 +00:00
|
|
|
.ifdef CRUNCH_BUILDOPTS
|
2015-10-22 04:47:52 +00:00
|
|
|
echo buildopts ${CRUNCH_BUILDOPTS} >>${.TARGET}
|
2010-11-13 03:11:27 +00:00
|
|
|
.endif
|
|
|
|
.ifdef CRUNCH_LIBS
|
2015-10-22 04:47:52 +00:00
|
|
|
echo libs ${CRUNCH_LIBS} >>${.TARGET}
|
2010-11-13 03:11:27 +00:00
|
|
|
.endif
|
|
|
|
.ifdef CRUNCH_SHLIBS
|
2015-10-22 04:47:52 +00:00
|
|
|
echo libs_so ${CRUNCH_SHLIBS} >>${.TARGET}
|
2010-11-13 03:11:27 +00:00
|
|
|
.endif
|
2015-10-22 04:47:52 +00:00
|
|
|
.for D in ${CRUNCH_SRCDIRS}
|
|
|
|
.for P in ${CRUNCH_PROGS_${D}}
|
|
|
|
echo progs ${P} >>${.TARGET}
|
|
|
|
echo special ${P} srcdir ${CRUNCH_SRCDIR_${P}} >>${.TARGET}
|
2010-11-13 03:11:27 +00:00
|
|
|
.ifdef CRUNCH_BUILDOPTS_${P}
|
2015-10-22 04:47:52 +00:00
|
|
|
echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ \
|
|
|
|
${CRUNCH_BUILDOPTS_${P}} >>${.TARGET}
|
2010-11-13 03:11:27 +00:00
|
|
|
.else
|
2015-10-22 04:47:52 +00:00
|
|
|
echo special ${P} buildopts DIRPRFX=${DIRPRFX}${P}/ >>${.TARGET}
|
2010-11-13 03:11:27 +00:00
|
|
|
.endif
|
2017-11-10 07:52:46 +00:00
|
|
|
.ifdef CRUNCH_LIBS_${P}
|
|
|
|
echo special ${P} lib ${CRUNCH_LIBS_${P}} >>${.TARGET}
|
|
|
|
.endif
|
2015-10-22 04:47:52 +00:00
|
|
|
.for A in ${CRUNCH_ALIAS_${P}}
|
|
|
|
echo ln ${P} ${A} >>${.TARGET}
|
2010-11-13 03:11:27 +00:00
|
|
|
.endfor
|
|
|
|
.endfor
|
|
|
|
.endfor
|
|
|
|
|
2015-06-13 15:36:13 +00:00
|
|
|
CRUNCHGEN?= crunchgen
|
2016-05-26 23:20:36 +00:00
|
|
|
CRUNCHENV+= MK_TESTS=no \
|
2016-05-26 23:20:40 +00:00
|
|
|
UPDATE_DEPENDFILE=no \
|
2016-05-26 23:20:20 +00:00
|
|
|
_RECURSING_CRUNCH=1
|
2015-10-22 04:47:52 +00:00
|
|
|
.ORDER: ${OUTPUTS} objs
|
2016-05-26 23:20:24 +00:00
|
|
|
${OUTPUTS:[1]}: .META
|
2016-09-01 23:20:54 +00:00
|
|
|
${OUTPUTS:[2..-1]}: .NOMETA
|
2016-05-26 23:20:24 +00:00
|
|
|
${OUTPUTS}: ${CONF}
|
2017-10-31 02:12:09 +00:00
|
|
|
MAKE="${MAKE}" ${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
|
2016-05-26 23:20:36 +00:00
|
|
|
MK_AUTO_OBJ=${MK_AUTO_OBJ} \
|
2016-05-26 23:20:20 +00:00
|
|
|
${CRUNCHGEN} -fq -m ${OUTMK} -c ${OUTC} ${CONF}
|
2016-05-26 23:20:30 +00:00
|
|
|
# Avoid redundantly calling 'make objs' which we've done by our
|
|
|
|
# own dependencies.
|
2017-11-10 19:53:17 +00:00
|
|
|
sed -i '' \
|
|
|
|
-e "s/^\(${PROG}:.*\) \$$(SUBMAKE_TARGETS)/\1/" \
|
|
|
|
${OUTMK}
|
2010-11-13 03:11:27 +00:00
|
|
|
|
2015-10-22 04:28:22 +00:00
|
|
|
# These 2 targets cannot use .MAKE since they depend on the generated
|
|
|
|
# ${OUTMK} above.
|
2016-09-01 23:21:08 +00:00
|
|
|
${PROG}: ${OUTPUTS} objs .NOMETA .PHONY
|
2016-05-26 23:20:36 +00:00
|
|
|
${CRUNCHENV} \
|
2016-05-26 23:20:27 +00:00
|
|
|
CC="${CC} ${CFLAGS} ${LDFLAGS}" \
|
|
|
|
CXX="${CXX} ${CXXFLAGS} ${LDFLAGS}" \
|
2017-10-31 02:12:09 +00:00
|
|
|
${MAKE} ${CRUNCHARGS} .MAKE.MODE="${.MAKE.MODE} curdirOk=yes" \
|
2016-09-01 23:21:08 +00:00
|
|
|
.MAKE.META.IGNORE_PATHS="${.MAKE.META.IGNORE_PATHS}" \
|
|
|
|
-f ${OUTMK} exe
|
2010-11-13 03:11:27 +00:00
|
|
|
|
2016-05-26 23:20:40 +00:00
|
|
|
objs: ${OUTMK} .META
|
2016-05-26 23:20:36 +00:00
|
|
|
${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} \
|
2017-10-31 02:12:09 +00:00
|
|
|
${MAKE} -f ${OUTMK} ${CRUNCHARGS} BUILD_TOOLS_META=.NOMETA objs
|
2010-11-13 03:11:27 +00:00
|
|
|
|
|
|
|
# <sigh> Someone should replace the bin/csh and bin/sh build-tools with
|
|
|
|
# shell scripts so we can remove this nonsense.
|
2015-10-22 04:47:52 +00:00
|
|
|
.for _tool in ${CRUNCH_BUILDTOOLS}
|
2015-10-22 04:42:17 +00:00
|
|
|
build-tools-${_tool}:
|
2015-10-22 04:47:52 +00:00
|
|
|
${_+_}cd ${.CURDIR}/../../${_tool}; \
|
2017-10-31 02:12:13 +00:00
|
|
|
if [ "${MK_AUTO_OBJ}" = "no" ]; then \
|
|
|
|
${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
|
|
|
|
fi; \
|
|
|
|
${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
|
2015-10-22 04:42:17 +00:00
|
|
|
build-tools: build-tools-${_tool}
|
2010-11-13 03:11:27 +00:00
|
|
|
.endfor
|
|
|
|
|
|
|
|
# Use a separate build tree to hold files compiled for this crunchgen binary
|
|
|
|
# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
|
|
|
|
# get that to cooperate with bsd.prog.mk. Besides, many of the standard
|
|
|
|
# targets should NOT be propagated into the components.
|
2017-11-10 19:53:14 +00:00
|
|
|
.if ${MK_AUTO_OBJ} == "no"
|
|
|
|
_obj= obj
|
|
|
|
.endif
|
|
|
|
.for __target in clean cleandepend cleandir ${_obj} objlink
|
2015-10-22 04:47:52 +00:00
|
|
|
.for D in ${CRUNCH_SRCDIRS}
|
|
|
|
.for P in ${CRUNCH_PROGS_${D}}
|
2015-10-22 04:42:17 +00:00
|
|
|
${__target}_crunchdir_${P}: .PHONY .MAKE
|
2015-10-23 19:41:58 +00:00
|
|
|
${_+_}cd ${CRUNCH_SRCDIR_${P}} && \
|
2015-10-22 04:42:17 +00:00
|
|
|
${CRUNCHENV} MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
|
2017-10-31 02:12:09 +00:00
|
|
|
${CRUNCHARGS} \
|
2017-11-10 19:53:11 +00:00
|
|
|
DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} \
|
|
|
|
${CRUNCH_BUILDOPTS_${P}} ${__target}
|
2015-10-22 04:42:17 +00:00
|
|
|
${__target}: ${__target}_crunchdir_${P}
|
|
|
|
.endfor
|
2010-11-13 03:11:27 +00:00
|
|
|
.endfor
|
|
|
|
.endfor
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm -f ${CLEANFILES}
|
2015-10-22 04:47:52 +00:00
|
|
|
${_+_}if [ -e ${.OBJDIR}/${OUTMK} ]; then \
|
|
|
|
${CRUNCHENV} MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} \
|
|
|
|
-f ${OUTMK} clean; \
|
2010-11-13 03:11:27 +00:00
|
|
|
fi
|
2016-05-26 23:20:40 +00:00
|
|
|
|
|
|
|
META_XTRAS+= ${find ${CRUNCHOBJS}${SRCTOP} -name '*.meta' 2>/dev/null || true:L:sh}
|
2016-09-01 23:52:20 +00:00
|
|
|
META_XTRAS+= ${echo ${CRUNCHOBJS}/*.lo.meta 2>/dev/null || true:L:sh}
|
2016-09-01 23:21:08 +00:00
|
|
|
META_XTRAS+= ${PROG}.meta
|