1################################################################# 2# 3# General notes: 4# 5# A number of Make variables are used to generate the crunchgen config file. 6# 7# CRUNCH_SRCDIRS: lists directories to search for included programs 8# CRUNCH_PROGS: lists programs to be included 9# CRUNCH_LIBS: libraries to statically link with 10# CRUNCH_SHLIBS: libraries to dynamically link with 11# CRUNCH_BUILDOPTS: generic build options to be added to every program 12# CRUNCH_BUILDTOOLS: lists programs that need build tools built in the 13# local architecture. 14# 15# Special options can be specified for individual programs 16# CRUNCH_SRCDIR_$(P): base source directory for program $(P) 17# CRUNCH_BUILDOPTS_$(P): additional build options for $(P) 18# CRUNCH_ALIAS_$(P): additional names to be used for $(P) 19# 20# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P} 21# will be used to generate a hard link to the resulting binary. 22# Specific links can be suppressed by setting 23# CRUNCH_SUPPRESS_LINK_$(NAME) to 1. 24# 25# If CRUNCH_GENERATE_LINKS is set to no, no links will be generated. 26# 27 28# $FreeBSD$ 29 30################################################################## 31# The following is pretty nearly a generic crunchgen-handling makefile 32# 33 34CONF= $(PROG).conf 35OUTMK= $(PROG).mk 36OUTC= $(PROG).c 37OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache 38CRUNCHOBJS= ${.OBJDIR} 39.if defined(MAKEOBJDIRPREFIX) 40CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR} 41.else 42CANONICALOBJDIR:= /usr/obj${.CURDIR} 43.endif 44CRUNCH_GENERATE_LINKS?= yes 45 46CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h 47 48# Program names and their aliases contribute hardlinks to 'rescue' executable, 49# except for those that get suppressed. 50.for D in $(CRUNCH_SRCDIRS) 51.for P in $(CRUNCH_PROGS_$(D)) 52.ifdef CRUNCH_SRCDIR_${P} 53$(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile 54.else 55$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile 56.endif 57.if ${CRUNCH_GENERATE_LINKS} == "yes" 58.ifndef CRUNCH_SUPPRESS_LINK_${P} 59LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P) 60.endif 61.for A in $(CRUNCH_ALIAS_$(P)) 62.ifndef CRUNCH_SUPPRESS_LINK_${A} 63LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A) 64.endif 65.endfor 66.endif 67.endfor 68.endfor 69 70all: $(PROG) 71exe: $(PROG) 72 73$(CONF): Makefile 74 echo \# Auto-generated, do not edit >$(.TARGET) 75.ifdef CRUNCH_BUILDOPTS 76 echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET) 77.endif 78.ifdef CRUNCH_LIBS 79 echo libs $(CRUNCH_LIBS) >>$(.TARGET) 80.endif 81.ifdef CRUNCH_SHLIBS 82 echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET) 83.endif 84.for D in $(CRUNCH_SRCDIRS) 85.for P in $(CRUNCH_PROGS_$(D)) 86 echo progs $(P) >>$(.TARGET) 87.ifdef CRUNCH_SRCDIR_${P} 88 echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET) 89.else 90 echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET) 91.endif 92.ifdef CRUNCH_BUILDOPTS_${P} 93 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \ 94 $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET) 95.else 96 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET) 97.endif 98.for A in $(CRUNCH_ALIAS_$(P)) 99 echo ln $(P) $(A) >>$(.TARGET) 100.endfor 101.endfor 102.endfor 103 104# XXX Make sure we don't pass -P to crunchgen(1). 105.MAKEFLAGS:= ${.MAKEFLAGS:N-P} 106.ORDER: $(OUTPUTS) objs 107$(OUTPUTS): $(CONF) 108 MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \ 109 -c $(OUTC) $(CONF) 110 111$(PROG): $(OUTPUTS) objs 112 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe 113 114objs: $(OUTMK) 115 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs 116 117# <sigh> Someone should replace the bin/csh and bin/sh build-tools with 118# shell scripts so we can remove this nonsense. 119build-tools: 120.for _tool in $(CRUNCH_BUILDTOOLS) 121 cd $(.CURDIR)/../../${_tool}; \ 122 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \ 123 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools 124.endfor 125 126# Use a separate build tree to hold files compiled for this crunchgen binary 127# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't 128# get that to cooperate with bsd.prog.mk. Besides, many of the standard 129# targets should NOT be propagated into the components. 130cleandepend cleandir obj objlink: 131.for D in $(CRUNCH_SRCDIRS) 132.for P in $(CRUNCH_PROGS_$(D)) 133.ifdef CRUNCH_SRCDIR_${P} 134 cd ${CRUNCH_SRCDIR_$(P)} && \ 135 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 136 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} 137.else 138 cd $(.CURDIR)/../../${D}/${P} && \ 139 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 140 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} 141.endif 142.endfor 143.endfor 144 145clean: 146 rm -f ${CLEANFILES} 147 if [ -e ${.OBJDIR}/$(OUTMK) ]; then \ 148 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \ 149 fi 150.for D in $(CRUNCH_SRCDIRS) 151.for P in $(CRUNCH_PROGS_$(D)) 152.ifdef CRUNCH_SRCDIR_${P} 153 cd ${CRUNCH_SRCDIR_$(P)} && \ 154 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 155 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} 156.else 157 cd $(.CURDIR)/../../${D}/${P} && \ 158 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 159 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} 160.endif 161.endfor 162.endfor 163