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.
28 ##################################################################
29 # The following is pretty nearly a generic crunchgen-handling makefile
35 OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
36 CRUNCHOBJS= ${.OBJDIR}
37 .if defined(MAKEOBJDIRPREFIX)
38 CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
40 CANONICALOBJDIR:= /usr/obj${.CURDIR}
43 CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
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
52 $(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
54 .ifndef CRUNCH_SUPPRESS_LINK_${P}
55 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
57 .for A in $(CRUNCH_ALIAS_$(P))
58 .ifndef CRUNCH_SUPPRESS_LINK_${A}
59 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
69 echo \# Auto-generated, do not edit >$(.TARGET)
70 .ifdef CRUNCH_BUILDOPTS
71 echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
74 echo libs $(CRUNCH_LIBS) >>$(.TARGET)
77 echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET)
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)
85 echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
87 .ifdef CRUNCH_BUILDOPTS_${P}
88 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
89 $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
91 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
93 .for A in $(CRUNCH_ALIAS_$(P))
94 echo ln $(P) $(A) >>$(.TARGET)
99 # XXX Make sure we don't pass -P to crunchgen(1).
100 .MAKEFLAGS:= ${.MAKEFLAGS:N-P}
101 .ORDER: $(OUTPUTS) objs
103 MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
106 $(PROG): $(OUTPUTS) objs
107 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
110 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
112 # <sigh> Someone should replace the bin/csh and bin/sh build-tools with
113 # shell scripts so we can remove this nonsense.
115 .for _tool in $(CRUNCH_BUILDTOOLS)
116 cd $(.CURDIR)/../../${_tool}; \
117 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
118 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
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.
125 cleandepend 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}
133 cd $(.CURDIR)/../../${D}/${P} && \
134 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
135 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
142 if [ -e ${.OBJDIR}/$(OUTMK) ]; then \
143 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \
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}
152 cd $(.CURDIR)/../../${D}/${P} && \
153 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
154 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}