1 #################################################################
5 # A number of Make variables are used to generate the crunchgen config file.
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
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)
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.
25 # If CRUNCH_GENERATE_LINKS is set to no, no links will be generated.
30 ##################################################################
31 # The following is pretty nearly a generic crunchgen-handling makefile
37 OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
38 CRUNCHOBJS= ${.OBJDIR}
39 .if defined(MAKEOBJDIRPREFIX)
40 CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
41 .elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
42 CANONICALOBJDIR:=${MAKEOBJDIR}
44 CANONICALOBJDIR:= /usr/obj${.CURDIR}
46 CRUNCH_GENERATE_LINKS?= yes
48 CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
50 # Program names and their aliases contribute hardlinks to 'rescue' executable,
51 # except for those that get suppressed.
52 .for D in $(CRUNCH_SRCDIRS)
53 .for P in $(CRUNCH_PROGS_$(D))
54 .ifdef CRUNCH_SRCDIR_${P}
55 $(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile
57 $(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
59 .if ${CRUNCH_GENERATE_LINKS} == "yes"
60 .ifndef CRUNCH_SUPPRESS_LINK_${P}
61 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
63 .for A in $(CRUNCH_ALIAS_$(P))
64 .ifndef CRUNCH_SUPPRESS_LINK_${A}
65 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
76 echo \# Auto-generated, do not edit >$(.TARGET)
77 .ifdef CRUNCH_BUILDOPTS
78 echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
81 echo libs $(CRUNCH_LIBS) >>$(.TARGET)
84 echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET)
86 .for D in $(CRUNCH_SRCDIRS)
87 .for P in $(CRUNCH_PROGS_$(D))
88 echo progs $(P) >>$(.TARGET)
89 .ifdef CRUNCH_SRCDIR_${P}
90 echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
92 echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
94 .ifdef CRUNCH_BUILDOPTS_${P}
95 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
96 $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
98 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
100 .for A in $(CRUNCH_ALIAS_$(P))
101 echo ln $(P) $(A) >>$(.TARGET)
106 # XXX Make sure we don't pass -P to crunchgen(1).
107 .MAKEFLAGS:= ${.MAKEFLAGS:N-P}
108 .ORDER: $(OUTPUTS) objs
110 MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
113 $(PROG): $(OUTPUTS) objs
114 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
117 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
119 # <sigh> Someone should replace the bin/csh and bin/sh build-tools with
120 # shell scripts so we can remove this nonsense.
122 .for _tool in $(CRUNCH_BUILDTOOLS)
123 cd $(.CURDIR)/../../${_tool}; \
124 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
125 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
128 # Use a separate build tree to hold files compiled for this crunchgen binary
129 # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
130 # get that to cooperate with bsd.prog.mk. Besides, many of the standard
131 # targets should NOT be propagated into the components.
132 cleandepend cleandir obj objlink:
133 .for D in $(CRUNCH_SRCDIRS)
134 .for P in $(CRUNCH_PROGS_$(D))
135 .ifdef CRUNCH_SRCDIR_${P}
136 cd ${CRUNCH_SRCDIR_$(P)} && \
137 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
138 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
140 cd $(.CURDIR)/../../${D}/${P} && \
141 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
142 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
149 if [ -e ${.OBJDIR}/$(OUTMK) ]; then \
150 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \
152 .for D in $(CRUNCH_SRCDIRS)
153 .for P in $(CRUNCH_PROGS_$(D))
154 .ifdef CRUNCH_SRCDIR_${P}
155 cd ${CRUNCH_SRCDIR_$(P)} && \
156 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
157 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
159 cd $(.CURDIR)/../../${D}/${P} && \
160 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
161 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}