1# $NetBSD: Makefile.crunch,v 1.26 2019/12/29 18:26:16 christos Exp $ 2# 3# Makefile snippet to build a crunchgen(1)ed binary from the provided lists 4# 5# Required variables: 6# NETBSDSRCDIR top level of src tree (set by <bsd.own.mk>) 7# CRUNCHBIN name of crunchgen(1)ed binary 8# LISTS list file(s) to use 9# 10# Optional variables: 11# SMALLPROG if != 0, add SMALLPROG=1 to CRUNCHENV. [default: 1] 12# SMALLPROG_INET6 if != 0 and SMALLPROG != 0, and ${USE_INET6} != "no", 13# add SMALLPROG_INET6=1 to CRUNCHENV. [default: 0] 14# CRUNCHENV environment to pass to crunchgen(1) and when building 15# the crunched program with make(1) (as command line 16# variables, to override any user provided environment 17# or make(1) cmdline vars). 18# CRUNCHGEN_FLAGS extra options to crunchgen(1) 19# DESTDIR destination directory 20# PARSELISTENV environment variables to set for parselist.awk 21# 22# Variables modified by this: 23# CRUNCHENV may get SMALLPROG=1 or SMALLPROG_INET6=1 added 24# 25 26.if !defined(_MAKEFILE_CRUNCH_) 27_MAKEFILE_CRUNCH_=1 28 29DBG?=-Os 30CRUNCHGEN_FLAGS?=\ 31-V LDSTATIC=-static \ 32-V DBG="${DBG}" \ 33-V NOMAN= \ 34-V NOLIBCSANITIZER= \ 35-V NOSANITIZER= \ 36-V NOPIE= \ 37-V NOSSP= \ 38-V NOFORT= 39 40CRUNCHENV+= AWK=${TOOL_AWK:Q} 41 42SMALLPROG?= 1 43SMALLPROG_INET6?= 0 44.if ${SMALLPROG} # { 45CRUNCHENV+= SMALLPROG=1 46.if ${SMALLPROG_INET6} && (${USE_INET6} != "no") 47CRUNCHENV+= SMALLPROG_INET6=1 48.endif 49.endif # } 50 51.include "${DISTRIBDIR}/common/Makefile.parselist" 52 53.PHONY: ${CRUNCHBIN} 54${CRUNCHBIN}: ${CRUNCHBIN}.mk ${CRUNCHBIN}.cache ${CRUNCHBIN}.c 55 ${MAKE} ${CRUNCHENV} -f ${CRUNCHBIN}.mk ${CRUNCHBIN}.crunched 56 57${CRUNCHBIN}.c: ${CRUNCHBIN}.mk 58 [ ! -f ${.TARGET} ] || touch ${.TARGET} 59 60${CRUNCHBIN}.cache: ${CRUNCHBIN}.mk 61 [ ! -f ${.TARGET} ] || touch ${.TARGET} 62 63CRUNCHGEN != command -v ${TOOL_CRUNCHGEN:[-1]} || echo 64 65${CRUNCHBIN}.mk: ${CRUNCHBIN}.conf ${CRUNCHGEN} 66 ${CRUNCHENV} ${TOOL_CRUNCHGEN} -f -D ${NETBSDSRCDIR} \ 67 -L ${DESTDIR}/usr/lib -q ${CRUNCHGEN_FLAGS} ${CRUNCHBIN}.conf 68 69${CRUNCHBIN}.conf: ${LISTS} ${PARSELISTDEP} 70 -rm -f ${.TARGET} ${.TARGET}.tmp 71 ${PARSELIST} -v mode=crunch ${LISTS} > ${.TARGET}.tmp \ 72 && mv ${.TARGET}.tmp ${.TARGET} 73 74CLEANFILES+= ${CRUNCHBIN} ${CRUNCHBIN}.conf ${CRUNCHBIN}.conf.tmp \ 75 ${CRUNCHBIN}.cache *.o *.cro *.c 76 77clean cleandir distclean: cleancrunchgen 78 79.PHONY: cleancrunchgen 80 81cleancrunchgen: 82 if [ -f ${CRUNCHBIN}.mk ]; then \ 83 ${MAKE} -f ${CRUNCHBIN}.mk clean; \ 84 fi 85 rm -f ${CRUNCHBIN}.mk 86 87 88.endif # _MAKEFILE_CRUNCH_ 89