bsd.crunchgen.mk revision 252048
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
26# $FreeBSD: stable/9/share/mk/bsd.crunchgen.mk 252048 2013-06-20 22:50:08Z sjg $
27
28##################################################################
29#  The following is pretty nearly a generic crunchgen-handling makefile
30#
31
32CONF=	$(PROG).conf
33OUTMK=	$(PROG).mk
34OUTC=   $(PROG).c
35OUTPUTS=$(OUTMK) $(OUTC) $(PROG).cache
36CRUNCHOBJS= ${.OBJDIR}
37.if defined(MAKEOBJDIRPREFIX)
38CANONICALOBJDIR:= ${MAKEOBJDIRPREFIX}${.CURDIR}
39.elif defined(MAKEOBJDIR) && ${MAKEOBJDIR:M/*} != ""
40CANONICALOBJDIR:=${MAKEOBJDIR}
41.else
42CANONICALOBJDIR:= /usr/obj${.CURDIR}
43.endif
44
45CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
46
47# Program names and their aliases contribute hardlinks to 'rescue' executable,
48# except for those that get suppressed.
49.for D in $(CRUNCH_SRCDIRS)
50.for P in $(CRUNCH_PROGS_$(D))
51.ifdef CRUNCH_SRCDIR_${P}
52$(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile
53.else
54$(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
55.endif
56.ifndef CRUNCH_SUPPRESS_LINK_${P}
57LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
58.endif
59.for A in $(CRUNCH_ALIAS_$(P))
60.ifndef CRUNCH_SUPPRESS_LINK_${A}
61LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
62.endif
63.endfor
64.endfor
65.endfor
66
67all: $(PROG)
68exe: $(PROG)
69
70$(CONF): Makefile
71	echo \# Auto-generated, do not edit >$(.TARGET)
72.ifdef CRUNCH_BUILDOPTS
73	echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
74.endif
75.ifdef CRUNCH_LIBS
76	echo libs $(CRUNCH_LIBS) >>$(.TARGET)
77.endif
78.ifdef CRUNCH_SHLIBS
79	echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET)
80.endif
81.for D in $(CRUNCH_SRCDIRS)
82.for P in $(CRUNCH_PROGS_$(D))
83	echo progs $(P) >>$(.TARGET)
84.ifdef CRUNCH_SRCDIR_${P}
85	echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
86.else
87	echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
88.endif
89.ifdef CRUNCH_BUILDOPTS_${P}
90	echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
91	    $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
92.else
93	echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
94.endif
95.for A in $(CRUNCH_ALIAS_$(P))
96	echo ln $(P) $(A) >>$(.TARGET)
97.endfor
98.endfor
99.endfor
100
101# XXX Make sure we don't pass -P to crunchgen(1).
102.MAKEFLAGS:= ${.MAKEFLAGS:N-P}
103.ORDER: $(OUTPUTS) objs
104$(OUTPUTS): $(CONF)
105	MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
106	    -c $(OUTC) $(CONF)
107
108$(PROG): $(OUTPUTS) objs
109	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
110
111objs: $(OUTMK)
112	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
113
114# <sigh> Someone should replace the bin/csh and bin/sh build-tools with
115# shell scripts so we can remove this nonsense.
116build-tools:
117.for _tool in $(CRUNCH_BUILDTOOLS)
118	cd $(.CURDIR)/../../${_tool}; \
119	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
120	MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
121.endfor
122
123# Use a separate build tree to hold files compiled for this crunchgen binary
124# Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
125# get that to cooperate with bsd.prog.mk.  Besides, many of the standard
126# targets should NOT be propagated into the components.
127cleandepend cleandir obj objlink:
128.for D in $(CRUNCH_SRCDIRS)
129.for P in $(CRUNCH_PROGS_$(D))
130.ifdef CRUNCH_SRCDIR_${P}
131	cd ${CRUNCH_SRCDIR_$(P)} && \
132	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
133	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
134.else
135	cd $(.CURDIR)/../../${D}/${P} && \
136	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
137	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
138.endif
139.endfor
140.endfor
141
142clean:
143	rm -f ${CLEANFILES}
144	if [ -e ${.OBJDIR}/$(OUTMK) ]; then				\
145		MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean;	\
146	fi
147.for D in $(CRUNCH_SRCDIRS)
148.for P in $(CRUNCH_PROGS_$(D))
149.ifdef CRUNCH_SRCDIR_${P}
150	cd ${CRUNCH_SRCDIR_$(P)} && \
151	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
152	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
153.else
154	cd $(.CURDIR)/../../${D}/${P} && \
155	    MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
156	    DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
157.endif
158.endfor
159.endfor
160