GNUmakefile now called test-build.mk
[platform/upstream/binutils.git] / test-build.mk
1 ###
2 ### Makefile used to three-stage build a tree of source code.  Also used to
3 ### compile other bundles, first with cc, then with gcc.
4 ###
5
6 ### This file was written and is maintained by K. Richard Pixley,
7 ### <rich@cygnus.com>.
8
9 ### Every invocation of this Makefile needs to have a variable set (host), 
10 ### which is the named used for ./configure, and also the prefix for the
11 ### various files and directories used in a three stage.
12
13 ifndef host
14 error:; @echo You must set the variable \"host\" to use this Makefile ; exit 1
15 else
16
17 ### from here to very near the end of the file is the real guts of this 
18 ### Makefile, and it is not seen if the variable 'host' is not set 
19
20 ###
21 ### START EDITTING HERE!!!
22 ### These things will need to be set differently for each release.
23 ###
24
25 ### from which cvs tree are we working?
26 TREE := devo
27
28 ### binaries should be installed into?
29 ROOTING := /usr/cygnus
30
31 ### When working from a tagged set of source, this should be the tag.  If not,
32 ### then set the macro to be empty.
33 #CVS_TAG := -r emacs-920529
34 CVS_TAG :=
35
36 ### The name of the cvs module for this release.  The intersection of
37 ### CVS_MODULE and CVS_TAG defines the source files in this release.
38 CVS_MODULE := devo
39
40 ### Historically, this was identical to CVS_TAG.  This is changing.
41 RELEASE_TAG := latest
42
43 ### Historically, binaries were installed here.  This is changing.
44 release_root := $(ROOTING)/$(RELEASE_TAG)
45
46 ### STOP EDITTING HERE!!!
47 ### With luck, eventually, nothing else will need to be editted.
48
49 TIME := time
50 GCC := gcc -O
51 GNU_MAKE := /usr/latest/bin/make -f test-build.mk
52 override MAKE := make
53 override MAKEFLAGS :=
54 override MFLAGS :=
55
56 SHELL := /bin/sh
57
58 .NOEXPORT:
59
60 FLAGS_TO_PASS := \
61         "GCC=$(GCC)" \
62         "TIME=$(TIME)" \
63         "MF=$(MF)"
64
65 ### general config stuff
66 WORKING_DIR := $(host)-objdir
67 STAGE1DIR := $(WORKING_DIR).1
68 STAGE2DIR := $(WORKING_DIR).2
69 STAGE3DIR := $(WORKING_DIR).3
70 HOLESDIR := $(host)-holes
71
72 .PHONY: all
73 all:    $(TREE) do1 do2 do3 comparison
74
75 .PHONY: do1
76 do1:    $(host)-stamp-holes $(host)-stamp-stage1
77
78 $(host)-stamp-stage1:
79         if [ -d $(STAGE1DIR) ] ; then \
80                 mv $(STAGE1DIR) $(WORKING_DIR) ; \
81         else \
82                 true ; \
83         fi
84         PATH=`pwd`/$(HOLESDIR) ; \
85                 export PATH ; \
86                 SHELL=sh ; export SHELL ; \
87                 $(TIME) $(GNU_MAKE) $(host)-stamp-stage1-installed host=$(host) $(FLAGS_TO_PASS)
88         touch $(host)-stamp-stage1
89         mv $(WORKING_DIR) $(STAGE1DIR)
90
91 $(host)-stamp-stage1-installed: $(host)-stamp-stage1-checked
92         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) $(MF) install host=$(host))
93         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) $(MF) install-info host=$(host))
94         touch $@
95
96 $(host)-stamp-stage1-checked: $(host)-stamp-stage1-built
97 #       (cd $(WORKING_DIR) ; $(TIME) $(MAKE) $(MF) check host=$(host))
98         touch $@
99
100 $(host)-stamp-stage1-built: $(host)-stamp-stage1-configured
101         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) $(MF) all host=$(host))
102         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) $(MF) info host=$(host))
103         touch $@
104
105 $(host)-stamp-stage1-configured:
106         [ -d $(WORKING_DIR) ] || mkdir $(WORKING_DIR)
107         (cd $(WORKING_DIR) ; \
108                 $(TIME) ../$(TREE)/configure $(host) -v -srcdir=../$(TREE) \
109                         -prefix=$(release_root) \
110                         -exec_prefix=$(release_root)/H-$(host))
111         touch $@
112
113 .PHONY: do2
114 do2:    $(HOLESDIR) $(host)-stamp-stage2
115
116 $(host)-stamp-stage2:
117         if [ -d $(STAGE2DIR) ] ; then \
118                 mv $(STAGE2DIR) $(WORKING_DIR) ; \
119         else \
120                 true ; \
121         fi
122         PATH=$(release_root)/H-$(host)/bin:`pwd`/$(HOLESDIR) ; \
123                 export PATH ; \
124                 SHELL=sh ; export SHELL ; \
125                 $(TIME) $(MAKE) -w $(STAGE2DIR) host=$(host) $(FLAGS_TO_PASS)
126         touch $(host)-stamp-stage2
127
128 $(STAGE2DIR): $(host)-stamp-stage2-installed
129         mv $(WORKING_DIR) $(STAGE2DIR)
130
131 $(host)-stamp-stage2-installed: $(host)-stamp-stage2-checked
132         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" install host=$(host))
133         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" install-info host=$(host))
134         touch $@
135
136 $(host)-stamp-stage2-checked: $(host)-stamp-stage2-built
137 #       (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" check host=$(host))
138         touch $@
139
140 $(host)-stamp-stage2-built: $(host)-stamp-stage2-configured
141         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" all host=$(host))
142         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" info host=$(host))
143         touch $@
144
145 $(host)-stamp-stage2-configured:
146         [ -d $(WORKING_DIR) ] || mkdir $(WORKING_DIR)
147         (cd $(WORKING_DIR) ; \
148                 $(TIME) ../$(TREE)/configure $(host) -v -srcdir=../$(TREE) \
149                         -prefix=$(release_root) \
150                         -exec_prefix=$(release_root)/H-$(host))
151         touch $@
152
153 .PHONY: do3
154 do3:    $(HOLESDIR) $(host)-stamp-stage3
155
156 $(host)-stamp-stage3:
157         if [ -d $(STAGE3DIR) ] ; then \
158                 mv $(STAGE3DIR) $(WORKING_DIR) ; \
159         else \
160                 true ; \
161         fi
162         PATH=$(release_root)/H-$(host)/bin:`pwd`/$(HOLESDIR) ; \
163                 export PATH ; \
164                 SHELL=sh ; export SHELL ; \
165                 $(TIME) $(MAKE) -w $(STAGE3DIR) host=$(host) $(FLAGS_TO_PASS)
166         touch $(host)-stamp-stage3
167
168 $(STAGE3DIR): $(host)-stamp-stage3-checked
169         mv $(WORKING_DIR) $(STAGE3DIR)
170
171 $(host)-stamp-stage3-installed: $(host)-stamp-stage3-checked
172         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" install host=$(host))
173         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" install-info host=$(host))
174         touch $@
175
176 $(host)-stamp-stage3-checked: $(host)-stamp-stage3-built
177 #       (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" check host=$(host))
178         touch $@
179
180 $(host)-stamp-stage3-built: $(host)-stamp-stage3-configured
181         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" all host=$(host))
182         (cd $(WORKING_DIR) ; $(TIME) $(MAKE) -w $(MF) "CC=$(GCC)" info host=$(host))
183         touch $@
184
185 $(host)-stamp-stage3-configured:
186         [ -d $(WORKING_DIR) ] || mkdir $(WORKING_DIR)
187         (cd $(WORKING_DIR) ; \
188                 $(TIME) ../$(TREE)/configure $(host) -v -srcdir=../$(TREE) \
189                         -prefix=$(release_root) \
190                         -exec_prefix=$(release_root)/H-$(host))
191         touch $@
192
193 # These things are needed by a three-stage, but are not included locally.
194
195 HOLES := \
196         [ \
197         ar \
198         as \
199         awk \
200         basename \
201         cat \
202         cc \
203         chmod \
204         cmp \
205         cp \
206         date \
207         diff \
208         echo \
209         egrep \
210         ex \
211         expr \
212         find \
213         grep \
214         hostname \
215         install \
216         ld \
217         lex \
218         ln \
219         ls \
220         make \
221         mkdir \
222         mv \
223         nm \
224         pwd \
225         ranlib \
226         rm \
227         rmdir \
228         sed \
229         sh \
230         sort \
231         test \
232         time \
233         touch \
234         tr \
235         true \
236         whoami
237
238 ### so far only sun make supports VPATH
239 ifeq ($(subst sun3,sun4,$(host)),sun4)
240 MAKE_HOLE :=
241 else
242 MAKE_HOLE := make
243 endif
244
245 ### rs6000 as is busted.  We cache a patched version in unsupported.
246 ifeq ($(subst sun3,rs6000,$(host)),rs6000)
247 AS_HOLE := as
248 else
249 AS_HOLE :=
250 endif
251
252 ### These things are also needed by a three-stage, but in this case, the GNU version of the tool is required.
253 PARTIAL_HOLES := \
254         $(AS_HOLE) \
255         $(MAKE_HOLE) \
256         flex \
257         m4
258
259 ### look in these directories for things missing from a three-stage
260 HOLE_DIRS := \
261         /bin \
262         /usr/bin \
263         /usr/ucb \
264         /usr/unsupported/bin
265
266 ### look in these directories for alternate versions of some tools.
267 PARTIAL_HOLE_DIRS := \
268         /usr/latest/bin \
269         /usr/progressive/bin \
270         /usr/vintage/bin \
271         /usr/unsupported/bin
272
273 $(HOLESDIR): $(host)-stamp-holes
274
275 $(host)-stamp-holes:
276         -rm -rf $(HOLESDIR)
277         -mkdir $(HOLESDIR)
278         for i in $(HOLES) ; do \
279                 found= ; \
280                 for j in $(HOLE_DIRS) ; do \
281                         if [ -x $$j/$$i ] ; then \
282                                 cp $$j/$$i $(HOLESDIR) ; \
283                                 echo $$i from $$j ; \
284                                 found=t ; \
285                                 break ; \
286                         fi ; \
287                 done ; \
288                 case "$$found" in \
289                 t) ;; \
290                 *) echo $$i is NOT found ;; \
291                 esac ; \
292         done
293         for i in $(PARTIAL_HOLES) ; do \
294                 found= ; \
295                 for j in $(PARTIAL_HOLE_DIRS) ; do \
296                         if [ -x $$j/$$i ] ; then \
297                                 rm -f $(HOLESDIR)/$$i ; \
298                                 cp $$j/$$i $(HOLESDIR)/$$i || exit 1; \
299                                 echo $$i from $$j ; \
300                                 found=t ; \
301                                 break ; \
302                         fi ; \
303                 done ; \
304                 case "$$found" in \
305                 t) ;; \
306                 *) echo $$i is NOT found ;; \
307                 esac ; \
308         done
309         touch $(host)-stamp-holes
310
311 .PHONY: comparison
312 comparison:
313 ifeq ($(subst rs6000,iris4,$(subst decstation,iris4,$(host))),iris4)
314         for i in `cd $(STAGE3DIR) ; find . -name \*.o -print` ; do \
315                 tail +10c $(STAGE2DIR)/$$i > foo1 ; \
316                 tail +10c $(STAGE3DIR)/$$i > foo2 ; \
317                 cmp foo1 foo2 || echo $$i ; \
318         done
319 else
320         for i in `cd $(STAGE3DIR) ; find . -name \*.o -print` ; do \
321                 cmp $(STAGE2DIR)/$$i $(STAGE3DIR)/$$i ; \
322         done
323 endif
324
325 .PHONY: clean
326 clean:
327         rm -rf $(HOLESDIR) $(WORKING_DIR)* $(host)-stamp-* *~
328
329 .PHONY: very
330 very:
331         rm -rf $(TREE)
332
333 $(TREE):
334         $(TIME) cvs co $(CVS_TAG) $(CVS_MODULE)
335
336 force:
337
338 endif # host
339
340 ### Local Variables:
341 ### fill-column: 131
342 ### End: