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 26# $FreeBSD$ 27 28################################################################## 29# The following is pretty nearly a generic crunchgen-handling makefile 30# 31 32CONF= $(PROG).conf 33OUTMK= $(PROG).mk 34OUTC= $(PROG).c 35OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache 36CRUNCHOBJS= ${.OBJDIR} 37.if defined(MAKEOBJDIRPREFIX) 38CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR} 39.else 40CANONICALOBJDIR:= /usr/obj${.CURDIR} 41.endif 42 43CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h 44 45# Program names and their aliases contribute hardlinks to 'rescue' executable, 46# except for those that get suppressed. 47.for D in $(CRUNCH_SRCDIRS) 48.for P in $(CRUNCH_PROGS_$(D)) 49.ifdef CRUNCH_SRCDIR_${P} 50$(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile 51.else 52$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile 53.endif 54.ifndef CRUNCH_SUPPRESS_LINK_${P} 55LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P) 56.endif 57.for A in $(CRUNCH_ALIAS_$(P)) 58.ifndef CRUNCH_SUPPRESS_LINK_${A} 59LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A) 60.endif 61.endfor 62.endfor 63.endfor 64 65all: $(PROG) 66exe: $(PROG) 67 68$(CONF): Makefile 69 echo \# Auto-generated, do not edit >$(.TARGET) 70.ifdef CRUNCH_BUILDOPTS 71 echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET) 72.endif 73.ifdef CRUNCH_LIBS 74 echo libs $(CRUNCH_LIBS) >>$(.TARGET) 75.endif 76.ifdef CRUNCH_SHLIBS 77 echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET) 78.endif 79.for D in $(CRUNCH_SRCDIRS) 80.for P in $(CRUNCH_PROGS_$(D)) 81 echo progs $(P) >>$(.TARGET) 82.ifdef CRUNCH_SRCDIR_${P} 83 echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET) 84.else 85 echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET) 86.endif 87.ifdef CRUNCH_BUILDOPTS_${P} 88 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \ 89 $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET) 90.else 91 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET) 92.endif 93.for A in $(CRUNCH_ALIAS_$(P)) 94 echo ln $(P) $(A) >>$(.TARGET) 95.endfor 96.endfor 97.endfor 98 99# XXX Make sure we don't pass -P to crunchgen(1). 100.MAKEFLAGS:= ${.MAKEFLAGS:N-P} 101.ORDER: $(OUTPUTS) objs 102$(OUTPUTS): $(CONF) 103 MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \ 104 -c $(OUTC) $(CONF) 105 106$(PROG): $(OUTPUTS) objs 107 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe 108 109objs: $(OUTMK) 110 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs 111 112# <sigh> Someone should replace the bin/csh and bin/sh build-tools with 113# shell scripts so we can remove this nonsense. 114build-tools: 115.for _tool in $(CRUNCH_BUILDTOOLS) 116 cd $(.CURDIR)/../../${_tool}; \ 117 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \ 118 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools 119.endfor 120 121# Use a separate build tree to hold files compiled for this crunchgen binary 122# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't 123# get that to cooperate with bsd.prog.mk. Besides, many of the standard 124# targets should NOT be propagated into the components. 125cleandepend cleandir obj objlink: 126.for D in $(CRUNCH_SRCDIRS) 127.for P in $(CRUNCH_PROGS_$(D)) 128.ifdef CRUNCH_SRCDIR_${P} 129 cd ${CRUNCH_SRCDIR_$(P)} && \ 130 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 131 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} 132.else 133 cd $(.CURDIR)/../../${D}/${P} && \ 134 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 135 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} 136.endif 137.endfor 138.endfor 139 140clean: 141 rm -f ${CLEANFILES} 142 if [ -e ${.OBJDIR}/$(OUTMK) ]; then \ 143 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \ 144 fi 145.for D in $(CRUNCH_SRCDIRS) 146.for P in $(CRUNCH_PROGS_$(D)) 147.ifdef CRUNCH_SRCDIR_${P} 148 cd ${CRUNCH_SRCDIR_$(P)} && \ 149 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 150 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} 151.else 152 cd $(.CURDIR)/../../${D}/${P} && \ 153 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \ 154 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET} 155.endif 156.endfor 157.endfor 158