bsd.crunchgen.mk revision 270291
11638Srgrimes#################################################################
21638Srgrimes#
31638Srgrimes# General notes:
41638Srgrimes#
51638Srgrimes# A number of Make variables are used to generate the crunchgen config file.
61638Srgrimes#
71638Srgrimes#  CRUNCH_SRCDIRS: lists directories to search for included programs
81638Srgrimes#  CRUNCH_PROGS:  lists programs to be included
91638Srgrimes#  CRUNCH_LIBS:  libraries to statically link with
101638Srgrimes#  CRUNCH_SHLIBS:  libraries to dynamically link with
111638Srgrimes#  CRUNCH_BUILDOPTS: generic build options to be added to every program
121638Srgrimes#  CRUNCH_BUILDTOOLS: lists programs that need build tools built in the
131638Srgrimes#       local architecture.
141638Srgrimes#
151638Srgrimes# Special options can be specified for individual programs
161638Srgrimes#  CRUNCH_SRCDIR_$(P): base source directory for program $(P)
171638Srgrimes#  CRUNCH_BUILDOPTS_$(P): additional build options for $(P)
181638Srgrimes#  CRUNCH_ALIAS_$(P): additional names to be used for $(P)
191638Srgrimes#
201638Srgrimes# By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
211638Srgrimes# will be used to generate a hard link to the resulting binary.
221638Srgrimes# Specific links can be suppressed by setting
231638Srgrimes# CRUNCH_SUPPRESS_LINK_$(NAME) to 1.
241638Srgrimes#
251638Srgrimes# If CRUNCH_GENERATE_LINKS is set to no, no links will be generated.
261638Srgrimes#
271638Srgrimes
281638Srgrimes# $FreeBSD: stable/10/share/mk/bsd.crunchgen.mk 270291 2014-08-21 19:32:54Z emaste $
291638Srgrimes
301638Srgrimes##################################################################
311638Srgrimes#  The following is pretty nearly a generic crunchgen-handling makefile
321638Srgrimes#
3350476Speter
341638SrgrimesCONF=	$(PROG).conf
351638SrgrimesOUTMK=	$(PROG).mk
361638SrgrimesOUTC=   $(PROG).c
3779538SruOUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
381638SrgrimesCRUNCHOBJS= ${.OBJDIR}
391638Srgrimes.if defined(MAKEOBJDIRPREFIX)
401638SrgrimesCANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
411638Srgrimes.elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
421638SrgrimesCANONICALOBJDIR:=${MAKEOBJDIR}
43131530Sru.else
44131530SruCANONICALOBJDIR:= /usr/obj${.CURDIR}
451638Srgrimes.endif
461638SrgrimesCRUNCH_GENERATE_LINKS?=	yes
471638Srgrimes
48131530SruCLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
49131530Sru
501638Srgrimes# Don't try to extract debug info from ${PROG}.
511638SrgrimesMK_DEBUG_FILES=no
521638Srgrimes
531638Srgrimes# Program names and their aliases contribute hardlinks to 'rescue' executable,
541638Srgrimes# except for those that get suppressed.
551638Srgrimes.for D in $(CRUNCH_SRCDIRS)
561638Srgrimes.for P in $(CRUNCH_PROGS_$(D))
571638Srgrimes.ifdef CRUNCH_SRCDIR_${P}
581638Srgrimes$(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile
591638Srgrimes.else
601638Srgrimes$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
611638Srgrimes.endif
62131530Sru.if ${CRUNCH_GENERATE_LINKS} == "yes"
63131530Sru.ifndef CRUNCH_SUPPRESS_LINK_${P}
641638SrgrimesLINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
651638Srgrimes.endif
661638Srgrimes.for A in $(CRUNCH_ALIAS_$(P))
671638Srgrimes.ifndef CRUNCH_SUPPRESS_LINK_${A}
681638SrgrimesLINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
691638Srgrimes.endif
70131530Sru.endfor
71131530Sru.endif
721638Srgrimes.endfor
731638Srgrimes.endfor
741638Srgrimes
751638Srgrimesall: $(PROG)
761638Srgrimesexe: $(PROG)
771638Srgrimes
781638Srgrimes$(CONF): Makefile
791638Srgrimes	echo \# Auto-generated, do not edit >$(.TARGET)
801638Srgrimes.ifdef CRUNCH_BUILDOPTS
811638Srgrimes	echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
821638Srgrimes.endif
831638Srgrimes.ifdef CRUNCH_LIBS
841638Srgrimes	echo libs $(CRUNCH_LIBS) >>$(.TARGET)
851638Srgrimes.endif
861638Srgrimes.ifdef CRUNCH_SHLIBS
871638Srgrimes	echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET)
881638Srgrimes.endif
891638Srgrimes.for D in $(CRUNCH_SRCDIRS)
901638Srgrimes.for P in $(CRUNCH_PROGS_$(D))
911638Srgrimes	echo progs $(P) >>$(.TARGET)
921638Srgrimes.ifdef CRUNCH_SRCDIR_${P}
931638Srgrimes	echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
941638Srgrimes.else
951638Srgrimes	echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
961638Srgrimes.endif
971638Srgrimes.ifdef CRUNCH_BUILDOPTS_${P}
98131530Sru	echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
99131530Sru	    $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
1001638Srgrimes.else
1011638Srgrimes	echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
1021638Srgrimes.endif
1031638Srgrimes.for A in $(CRUNCH_ALIAS_$(P))
104131530Sru	echo ln $(P) $(A) >>$(.TARGET)
105131530Sru.endfor
1061638Srgrimes.endfor
107131530Sru.endfor
108131530Sru
1091638Srgrimes# XXX Make sure we don't pass -P to crunchgen(1).
1101638Srgrimes.MAKEFLAGS:= ${.MAKEFLAGS:N-P}
1111638Srgrimes.ORDER: $(OUTPUTS) objs
1121638Srgrimes$(OUTPUTS): $(CONF)
1131638Srgrimes	MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
114131530Sru	    -c $(OUTC) $(CONF)
115131530Sru
1161638Srgrimes$(PROG): $(OUTPUTS) objs
1171638Srgrimes	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
1181638Srgrimes
119131530Sruobjs: $(OUTMK)
120131530Sru	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
1211638Srgrimes
1221638Srgrimes# <sigh> Someone should replace the bin/csh and bin/sh build-tools with
1231638Srgrimes# shell scripts so we can remove this nonsense.
1241638Srgrimesbuild-tools:
1251638Srgrimes.for _tool in $(CRUNCH_BUILDTOOLS)
1261638Srgrimes	cd $(.CURDIR)/../../${_tool}; \
1271638Srgrimes	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
1281638Srgrimes	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
1291638Srgrimes.endfor
1301638Srgrimes
1311638Srgrimes# Use a separate build tree to hold files compiled for this crunchgen binary
1321638Srgrimes# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
1331638Srgrimes# get that to cooperate with bsd.prog.mk.  Besides, many of the standard
1341638Srgrimes# targets should NOT be propagated into the components.
1351638Srgrimescleandepend cleandir obj objlink:
1361638Srgrimes.for D in $(CRUNCH_SRCDIRS)
1371638Srgrimes.for P in $(CRUNCH_PROGS_$(D))
1381638Srgrimes.ifdef CRUNCH_SRCDIR_${P}
1391638Srgrimes	cd ${CRUNCH_SRCDIR_$(P)} && \
140131530Sru	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
141131530Sru	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
1421638Srgrimes.else
1431638Srgrimes	cd $(.CURDIR)/../../${D}/${P} && \
1441638Srgrimes	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
14520920Swosch	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
14620920Swosch.endif
14720920Swosch.endfor
14820920Swosch.endfor
14920920Swosch
15020920Swoschclean:
1511638Srgrimes	rm -f ${CLEANFILES}
1521638Srgrimes	if [ -e ${.OBJDIR}/$(OUTMK) ]; then				\
15320243Smpp		MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean;	\
15420243Smpp	fi
1551638Srgrimes.for D in $(CRUNCH_SRCDIRS)
1561638Srgrimes.for P in $(CRUNCH_PROGS_$(D))
1571638Srgrimes.ifdef CRUNCH_SRCDIR_${P}
1581638Srgrimes	cd ${CRUNCH_SRCDIR_$(P)} && \
1591638Srgrimes	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
1601638Srgrimes	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
1611638Srgrimes.else
1621638Srgrimes	cd $(.CURDIR)/../../${D}/${P} && \
163	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
164	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
165.endif
166.endfor
167.endfor
168