]> CyberLeo.Net >> Repos - FreeBSD/releng/10.0.git/blob - share/mk/bsd.crunchgen.mk
- Copy stable/10 (r259064) to releng/10.0 as part of the
[FreeBSD/releng/10.0.git] / share / mk / bsd.crunchgen.mk
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
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 CRUNCH_GENERATE_LINKS?= yes
47
48 CLEANFILES+= $(CONF) *.o *.lo *.c *.mk *.cache *.a *.h
49
50 # Don't try to extract debug info from ${PROG}.
51 NO_DEBUG_FILES=
52
53 # Program names and their aliases contribute hardlinks to 'rescue' executable,
54 # except for those that get suppressed.
55 .for D in $(CRUNCH_SRCDIRS)
56 .for P in $(CRUNCH_PROGS_$(D))
57 .ifdef CRUNCH_SRCDIR_${P}
58 $(OUTPUTS): $(CRUNCH_SRCDIR_${P})/Makefile
59 .else
60 $(OUTPUTS): $(.CURDIR)/../../$(D)/$(P)/Makefile
61 .endif
62 .if ${CRUNCH_GENERATE_LINKS} == "yes"
63 .ifndef CRUNCH_SUPPRESS_LINK_${P}
64 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(P)
65 .endif
66 .for A in $(CRUNCH_ALIAS_$(P))
67 .ifndef CRUNCH_SUPPRESS_LINK_${A}
68 LINKS+= $(BINDIR)/$(PROG) $(BINDIR)/$(A)
69 .endif
70 .endfor
71 .endif
72 .endfor
73 .endfor
74
75 all: $(PROG)
76 exe: $(PROG)
77
78 $(CONF): Makefile
79         echo \# Auto-generated, do not edit >$(.TARGET)
80 .ifdef CRUNCH_BUILDOPTS
81         echo buildopts $(CRUNCH_BUILDOPTS) >>$(.TARGET)
82 .endif
83 .ifdef CRUNCH_LIBS
84         echo libs $(CRUNCH_LIBS) >>$(.TARGET)
85 .endif
86 .ifdef CRUNCH_SHLIBS
87         echo libs_so $(CRUNCH_SHLIBS) >>$(.TARGET)
88 .endif
89 .for D in $(CRUNCH_SRCDIRS)
90 .for P in $(CRUNCH_PROGS_$(D))
91         echo progs $(P) >>$(.TARGET)
92 .ifdef CRUNCH_SRCDIR_${P}
93         echo special $(P) srcdir $(CRUNCH_SRCDIR_${P}) >>$(.TARGET)
94 .else
95         echo special $(P) srcdir $(.CURDIR)/../../$(D)/$(P) >>$(.TARGET)
96 .endif
97 .ifdef CRUNCH_BUILDOPTS_${P}
98         echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ \
99             $(CRUNCH_BUILDOPTS_${P}) >>$(.TARGET)
100 .else
101         echo special $(P) buildopts DIRPRFX=${DIRPRFX}${P}/ >>$(.TARGET)
102 .endif
103 .for A in $(CRUNCH_ALIAS_$(P))
104         echo ln $(P) $(A) >>$(.TARGET)
105 .endfor
106 .endfor
107 .endfor
108
109 # XXX Make sure we don't pass -P to crunchgen(1).
110 .MAKEFLAGS:= ${.MAKEFLAGS:N-P}
111 .ORDER: $(OUTPUTS) objs
112 $(OUTPUTS): $(CONF)
113         MAKE=${MAKE} MAKEOBJDIRPREFIX=${CRUNCHOBJS} crunchgen -fq -m $(OUTMK) \
114             -c $(OUTC) $(CONF)
115
116 $(PROG): $(OUTPUTS) objs
117         MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) exe
118
119 objs: $(OUTMK)
120         MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) objs
121
122 # <sigh> Someone should replace the bin/csh and bin/sh build-tools with
123 # shell scripts so we can remove this nonsense.
124 build-tools:
125 .for _tool in $(CRUNCH_BUILDTOOLS)
126         cd $(.CURDIR)/../../${_tool}; \
127         MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} obj; \
128         MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} build-tools
129 .endfor
130
131 # Use a separate build tree to hold files compiled for this crunchgen binary
132 # Yes, this does seem to partly duplicate bsd.subdir.mk, but I can't
133 # get that to cooperate with bsd.prog.mk.  Besides, many of the standard
134 # targets should NOT be propagated into the components.
135 cleandepend cleandir obj objlink:
136 .for D in $(CRUNCH_SRCDIRS)
137 .for P in $(CRUNCH_PROGS_$(D))
138 .ifdef CRUNCH_SRCDIR_${P}
139         cd ${CRUNCH_SRCDIR_$(P)} && \
140             MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
141             DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
142 .else
143         cd $(.CURDIR)/../../${D}/${P} && \
144             MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
145             DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
146 .endif
147 .endfor
148 .endfor
149
150 clean:
151         rm -f ${CLEANFILES}
152         if [ -e ${.OBJDIR}/$(OUTMK) ]; then                             \
153                 MAKEOBJDIRPREFIX=${CRUNCHOBJS} ${MAKE} -f $(OUTMK) clean;       \
154         fi
155 .for D in $(CRUNCH_SRCDIRS)
156 .for P in $(CRUNCH_PROGS_$(D))
157 .ifdef CRUNCH_SRCDIR_${P}
158         cd ${CRUNCH_SRCDIR_$(P)} && \
159             MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
160             DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
161 .else
162         cd $(.CURDIR)/../../${D}/${P} && \
163             MAKEOBJDIRPREFIX=${CANONICALOBJDIR} ${MAKE} \
164             DIRPRFX=${DIRPRFX}${P}/ ${CRUNCH_BUILDOPTS} ${.TARGET}
165 .endif
166 .endfor
167 .endfor