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.
27 # If CRUNCH_GENERATE_LINKS is set to no, no links will be generated.
32 ##################################################################
33 # The following is pretty nearly a generic crunchgen-handling makefile
39 OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
40 CRUNCHOBJS= ${.OBJDIR}
41 .if defined(MAKEOBJDIRPREFIX)
42 CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
43 .elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
44 CANONICALOBJDIR:=${MAKEOBJDIR}
46 CANONICALOBJDIR:= /usr/obj${.CURDIR}
48 CRUNCH_GENERATE_LINKS?= yes
50 CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
52 # Don't try to extract debug info from ${PROG}.
55 # Program names and their aliases contribute hardlinks to 'rescue' executable,
56 # except for those that get suppressed.
57 .for D in $(CRUNCH_SRCDIRS)
58 .for P in $(CRUNCH_PROGS_$(D))
59 .ifdef CRUNCH_SRCDIR_${P}
60 $(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile
62 $(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
64 .if ${CRUNCH_GENERATE_LINKS} == "yes"
65 .ifndef CRUNCH_SUPPRESS_LINK_${P}
66 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
68 .for A in $(CRUNCH_ALIAS_$(P))
69 .ifndef CRUNCH_SUPPRESS_LINK_${A}
70 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
81 echo \# Auto-generated, do not edit >$(.TARGET)
82 .ifdef CRUNCH_BUILDOPTS
83 echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
86 echo libs $(CRUNCH_LIBS) >>$(.TARGET)
89 echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET)
91 .for D in $(CRUNCH_SRCDIRS)
92 .for P in $(CRUNCH_PROGS_$(D))
93 echo progs $(P) >>$(.TARGET)
94 .ifdef CRUNCH_SRCDIR_${P}
95 echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
97 echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
99 .ifdef CRUNCH_BUILDOPTS_${P}
100 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
101 $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
103 echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
105 .for A in $(CRUNCH_ALIAS_$(P))
106 echo ln $(P) $(A) >>$(.TARGET)
111 # XXX Make sure we don't pass -P to crunchgen(1).
112 .MAKEFLAGS:= ${.MAKEFLAGS:N-P}
113 .ORDER: $(OUTPUTS) objs
115 MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
118 $(PROG): $(OUTPUTS) objs
119 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
122 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
124 # <sigh> Someone should replace the bin/csh and bin/sh build-tools with
125 # shell scripts so we can remove this nonsense.
127 .for _tool in $(CRUNCH_BUILDTOOLS)
128 cd $(.CURDIR)/../../${_tool}; \
129 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
130 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
133 # Use a separate build tree to hold files compiled for this crunchgen binary
134 # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
135 # get that to cooperate with bsd.prog.mk. Besides, many of the standard
136 # targets should NOT be propagated into the components.
137 cleandepend cleandir obj objlink:
138 .for D in $(CRUNCH_SRCDIRS)
139 .for P in $(CRUNCH_PROGS_$(D))
140 .ifdef CRUNCH_SRCDIR_${P}
141 cd ${CRUNCH_SRCDIR_$(P)} && \
142 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
143 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
145 cd $(.CURDIR)/../../${D}/${P} && \
146 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
147 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
154 if [ -e ${.OBJDIR}/$(OUTMK) ]; then \
155 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean; \
157 .for D in $(CRUNCH_SRCDIRS)
158 .for P in $(CRUNCH_PROGS_$(D))
159 .ifdef CRUNCH_SRCDIR_${P}
160 cd ${CRUNCH_SRCDIR_$(P)} && \
161 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
162 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
164 cd $(.CURDIR)/../../${D}/${P} && \
165 MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
166 DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}