1 #################################################################
3 # Generate crunched binaries using crunchgen(1).
7 # A number of Make variables are used to generate the crunchgen config file.
9 # CRUNCH_SRCDIRS: lists directories to search for included programs
10 # CRUNCH_PROGS: lists programs to be included
11 # CRUNCH_LIBS: libraries to statically link with
12 # CRUNCH_SHLIBS: libraries to dynamically link with
13 # CRUNCH_BUILDOPTS: generic build options to be added to every program
14 # CRUNCH_BUILDTOOLS: lists programs that need build tools built in the
17 # Special options can be specified for individual programs
18 # CRUNCH_SRCDIR_$(P): base source directory for program $(P)
19 # CRUNCH_BUILDOPTS_$(P): additional build options for $(P)
20 # CRUNCH_ALIAS_$(P): additional names to be used for $(P)
22 # By default, any name appearing in CRUNCH_PROGS or CRUNCH_ALIAS_${P}
23 # will be used to generate a hard link to the resulting binary.
24 # Specific links can be suppressed by setting
25 # CRUNCH_SUPPRESS_LINK_$(NAME) to 1.
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}
47 CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
49 # Don't try to extract debug info from ${PROG}.
52 # Program names and their aliases contribute hardlinks to 'rescue' executable,
53 # except for those that get suppressed.
54 .for D in $(CRUNCH_SRCDIRS)
55 .for P in $(CRUNCH_PROGS_$(D))
56 .ifdef CRUNCH_SRCDIR_${P}
57 $(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile
59 $(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
61 .ifndef CRUNCH_SUPPRESS_LINK_${P}
62 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
64 .for A in $(CRUNCH_ALIAS_$(P))
65 .ifndef CRUNCH_SUPPRESS_LINK_${A}
66 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}