]> CyberLeo.Net >> Repos - FreeBSD/stable/9.git/blob - share/mk/bsd.crunchgen.mk
MFC r321985:
[FreeBSD/stable/9.git] / share / mk / bsd.crunchgen.mk
1 #################################################################
2 #
3 # Generate crunched binaries using crunchgen(1).
4 #
5 # General notes:
6 #
7 # A number of Make variables are used to generate the crunchgen config file.
8 #
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
15 #       local architecture.
16 #
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)
21 #
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.
26 #
27
28 # $FreeBSD$
29
30 ##################################################################
31 #  The following is pretty nearly a generic crunchgen-handling makefile
32 #
33
34 CONF=   $(PROG).conf
35 OUTMK=  $(PROG).mk
36 OUTC=   $(PROG).c
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}
43 .else
44 CANONICALOBJDIR:= /usr/obj${.CURDIR}
45 .endif
46
47 CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
48
49 # Don't try to extract debug info from ${PROG}.
50 NO_DEBUG_FILES=
51
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
58 .else
59 $(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
60 .endif
61 .ifndef CRUNCH_SUPPRESS_LINK_${P}
62 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
63 .endif
64 .for A in $(CRUNCH_ALIAS_$(P))
65 .ifndef CRUNCH_SUPPRESS_LINK_${A}
66 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
67 .endif
68 .endfor
69 .endfor
70 .endfor
71
72 all: $(PROG)
73 exe: $(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
116 objs: $(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.
121 build-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.
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}
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
147 clean:
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