xref: /freebsd/share/mk/bsd.crunchgen.mk (revision 87c1627502a5dde91e5284118eec8682b60f27a2)
1#################################################################
2#
3# General notes:
4#
5# A number of Make variables are used to generate the crunchgen config file.
6#
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
13#       local architecture.
14#
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)
19#
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.
24#
25# If CRUNCH_GENERATE_LINKS is set to no, no links will be generated.
26#
27
28# $FreeBSD$
29
30##################################################################
31#  The following is pretty nearly a generic crunchgen-handling makefile
32#
33
34CONF=	$(PROG).conf
35OUTMK=	$(PROG).mk
36OUTC=   $(PROG).c
37OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
38CRUNCHOBJS= ${.OBJDIR}
39.if defined(MAKEOBJDIRPREFIX)
40CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
41.elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
42CANONICALOBJDIR:=${MAKEOBJDIR}
43.else
44CANONICALOBJDIR:= /usr/obj${.CURDIR}
45.endif
46CRUNCH_GENERATE_LINKS?=	yes
47
48CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
49
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
56.else
57$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
58.endif
59.if ${CRUNCH_GENERATE_LINKS} == "yes"
60.ifndef CRUNCH_SUPPRESS_LINK_${P}
61LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
62.endif
63.for A in $(CRUNCH_ALIAS_$(P))
64.ifndef CRUNCH_SUPPRESS_LINK_${A}
65LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
66.endif
67.endfor
68.endif
69.endfor
70.endfor
71
72all: $(PROG)
73exe: $(PROG)
74
75$(CONF): Makefile
76	echo \# Auto-generated, do not edit >$(.TARGET)
77.ifdef CRUNCH_BUILDOPTS
78	echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
79.endif
80.ifdef CRUNCH_LIBS
81	echo libs $(CRUNCH_LIBS) >>$(.TARGET)
82.endif
83.ifdef CRUNCH_SHLIBS
84	echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET)
85.endif
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)
91.else
92	echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
93.endif
94.ifdef CRUNCH_BUILDOPTS_${P}
95	echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
96	    $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
97.else
98	echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
99.endif
100.for A in $(CRUNCH_ALIAS_$(P))
101	echo ln $(P) $(A) >>$(.TARGET)
102.endfor
103.endfor
104.endfor
105
106# XXX Make sure we don't pass -P to crunchgen(1).
107.MAKEFLAGS:= ${.MAKEFLAGS:N-P}
108.ORDER: $(OUTPUTS) objs
109$(OUTPUTS): $(CONF)
110	MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
111	    -c $(OUTC) $(CONF)
112
113$(PROG): $(OUTPUTS) objs
114	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
115
116objs: $(OUTMK)
117	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
118
119# <sigh> Someone should replace the bin/csh and bin/sh build-tools with
120# shell scripts so we can remove this nonsense.
121build-tools:
122.for _tool in $(CRUNCH_BUILDTOOLS)
123	cd $(.CURDIR)/../../${_tool}; \
124	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
125	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
126.endfor
127
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.
132cleandepend 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}
139.else
140	cd $(.CURDIR)/../../${D}/${P} && \
141	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
142	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
143.endif
144.endfor
145.endfor
146
147clean:
148	rm -f ${CLEANFILES}
149	if [ -e ${.OBJDIR}/$(OUTMK) ]; then				\
150		MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean;	\
151	fi
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}
158.else
159	cd $(.CURDIR)/../../${D}/${P} && \
160	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
161	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
162.endif
163.endfor
164.endfor
165