summaryrefslogtreecommitdiff
path: root/gcc/melt-build.tpl
blob: 0537a1c8fa9db7853c3c3c94ee752fcbfe65511e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
[+ AutoGen5 template -*- Mode: Makefile -*-
mk
+][+COMMENT use 'autogen --trace=everything melt-build.def' to debug this
+]
# melt-build.mk is generated from melt-build.tpl by 'autogen melt-build.def'
# DON'T EDIT melt-build.mk but only edit: melt-build.tpl or melt-build.def
#
# Makefile fragment for MELT modules and MELT translator bootstrap.
#   Copyright (C) 2010  Free Software Foundation
#
# This file is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 

## the following Makefile variables are expected to be set
### melt_source_dir - directory containing *.melt (& corresponding *.c) files
### melt_module_dir - directory containing *.so MELT module files
### melt_make_module_makefile - our melt-module.mk Makefile  when making MELT
### melt_make_source_dir - directory containing the *.melt files when making MELT
### melt_make_module_dir - directory containing the *.so files when making MELT
### melt_default_modules_list - basename of the default module list
### melt_make_cc1 - cc1 program with MELT (or loading MELT plugin) or gcc -fplugin=melt.so
### melt_make_cc1_dependency - the make dependency for above i.e. cc1$(exeext) for MELT branch
### melt_make_gencdeps is an extra make dependency of generated C files [leave empty usually]
### melt_is_plugin - should be non empty in plugin mode
### melt_make_move - a copy or move command for files
### melt_cflags - the CFLAGS for compiling MELT generated C code

## the various arguments to MELT - avoid spaces in them!
meltarg_mode=$(if $(melt_is_plugin),-fplugin-arg-melt-mode,-fmelt-mode)
meltarg_init=$(if $(melt_is_plugin),-fplugin-arg-melt-init,-fmelt-init)
meltarg_module_path=$(if $(melt_is_plugin),-fplugin-arg-melt-module-path,-fmelt-module-path)
meltarg_source_path=$(if $(melt_is_plugin),-fplugin-arg-melt-source-path,-fmelt-source-path)
meltarg_tempdir=$(if $(melt_is_plugin),-fplugin-arg-melt-tempdir,-fmelt-tempdir)

meltarg_arg=$(if $(melt_is_plugin),-fplugin-arg-melt-arg,-fmelt-arg)
meltarg_bootstrapping=$(if $(melt_is_plugin),-fplugin-arg-melt-bootstrapping,-fmelt-bootstrapping)
meltarg_makefile=$(if $(melt_is_plugin),-fplugin-arg-melt-module-makefile,-fmelt-module-makefile)
meltarg_makecmd=$(if $(melt_is_plugin),-fplugin-arg-melt-module-make-command,-fmelt-module-make-command)
meltarg_arglist=$(if $(melt_is_plugin),-fplugin-arg-melt-arglist,-fmelt-arglist)
meltarg_output=$(if $(melt_is_plugin),-fplugin-arg-melt-output,-fmelt-output)

## MELT_DEBUG could be set to -fmelt-debug or -fplugin-arg-melt-debug
## the invocation to translate the very first initial MELT file
MELTCCINIT1=$(melt_make_cc1) $(melt_make_cc1flags) -Wno-shadow $(meltarg_mode)=translateinit  \
	      $(meltarg_makefile)=$(melt_make_module_makefile) \
	      $(meltarg_makecmd)=$(MAKE) \
	      $(meltarg_tempdir)=. $(meltarg_bootstrapping) $(MELT_DEBUG)

## the invocation to translate the other files
MELTCCFILE1=$(melt_make_cc1)  $(melt_make_cc1flags) -Wno-shadow $(meltarg_mode)=translatefile  \
	      $(meltarg_makefile)=$(melt_make_module_makefile) \
	      $(meltarg_makecmd)=$(MAKE) \
	      $(meltarg_tempdir)=. $(meltarg_bootstrapping)  $(MELT_DEBUG)


vpath %.so $(melt_make_module_dir) . 
vpath %.c $(melt_make_source_dir)/generated . $(melt_source_dir)
vpath %.h . $(melt_make_source_dir)/generated $(melt_source_dir)
vpath %.melt $(melt_make_source_dir) . $(melt_source_dir)

##
## the invoking command could set MELT_MAKE_MODULE_XTRAMAKEFLAGS=-j2
MELT_MAKE_MODULE=$(MAKE) -f $(melt_make_module_makefile) $(MELT_MAKE_MODULE_XTRAMAKEFLAGS) VPATH=$(VPATH):.

## The base name of the MELT translator files
MELT_TRANSLATOR_BASE= \
  [+FOR melt_translator_file " \\\n"+]  [+base+][+ENDFOR melt_translator_file+]

## The base name of the MELT application files
MELT_APPLICATION_BASE= \
  [+FOR melt_application_file " \\\n"+]  [+base+][+ENDFOR melt_application_file+]



## The cold stage 0 of the translator
[+FOR melt_translator_file +]
MELT_GENERATED_[+mkvarsuf+]_C_FILES= \
                  $(melt_make_source_dir)/generated/[+base+].0.c \
                  $(wildcard $(melt_make_source_dir)/generated/[+base+].0+*.c)
MELT_GENERATED_[+mkvarsuf+]_BASE= \
                  $(basename $(notdir $(MELT_GENERATED_[+mkvarsuf+]_C_FILES)))

[+ENDFOR melt_translator_file+]

## the rules to build the static and dynamic version of stage0, that
## is with static or dynamic field object offsets
[+FOR melt_translator_file +]
## using static object fields offsets for [+base+]
melt-stage0-static/[+base+]-0.so: $(MELT_GENERATED_[+mkvarsuf+]_C_FILES) \
             melt-run.h melt-runtime.h melt-runtime.c \
             melt-predef.h $(melt_make_cc1_dependency)
	$(MELT_MAKE_MODULE) melt_module \
              GCCMELT_MODULE_WORKSPACE=melt-stage0-static/ \
	      GCCMELT_CFLAGS="$(melt_cflags)" \
	      GCCMELT_MODULE_SOURCE=$(melt_make_source_dir)/generated/[+base+].0.c \
              GCCMELT_MODULE_BINARY=melt-stage0-static/[+base+]-0

## using dynamic object fields offsets for [+base+]
melt-stage0-dynamic/[+base+]-0.d.so: $(MELT_GENERATED_[+mkvarsuf+]_C_FILES) \
             melt-run.h melt-runtime.h melt-runtime.c \
             melt-predef.h $(melt_make_cc1_dependency)
	$(MELT_MAKE_MODULE) melt_module_dynamic \
              GCCMELT_MODULE_WORKSPACE=melt-stage0-dynamic/ \
	      GCCMELT_CFLAGS="$(melt_cflags)" \
	      GCCMELT_MODULE_SOURCE=$(melt_make_source_dir)/generated/[+base+].0.c \
              GCCMELT_MODULE_BINARY=melt-stage0-dynamic/[+base+]-0

melt-stage0-dynamic/[+base+]-0.so: melt-stage0-dynamic/[+base+]-0.d.so
	cd melt-stage0-dynamic/ ; rm -f [+base+]-0.so; $(LN_S) [+base+]-0.d.so [+base+]-0.so

[+ENDFOR melt_translator_file+]


melt-stage0-static.timestamp:  melt-stage0-static melt-stage0-static/warmelt-0.modlis
	date +"$@ %c" > $@

melt-stage0-dynamic.timestamp:  melt-stage0-dynamic melt-stage0-dynamic/warmelt-0.modlis
	date +"$@ %c" > $@




melt-stage0-static/warmelt-0.modlis: \
[+FOR melt_translator_file " \\\n" +]             melt-stage0-static/[+base+]-0.so[+
ENDFOR melt_translator_file+]
	date  +"#$@ generated %F" > $@-tmp
[+FOR melt_translator_file+]	echo [+base+]-0 >> $@-tmp
[+ENDFOR melt_translator_file+]	$(melt_make_move) $@-tmp $@

melt-stage0-dynamic/warmelt-0.modlis: \
[+FOR melt_translator_file " \\\n" +]              melt-stage0-dynamic/[+base+]-0.d.so[+
ENDFOR melt_translator_file+]
	date  +"#$@ generated %F" > $@-tmp
[+FOR melt_translator_file+]	echo [+base+]-0 >> $@-tmp
[+ENDFOR melt_translator_file+]
	$(melt_make_move) $@-tmp $@

## An empty file is needed for every MELT translation!
empty-file-for-melt.c:
	date +"/* empty-file-for-melt.c %c */" > $@-tmp
	mv $@-tmp $@

## can be overridden manually to either melt-stage0-dynamic or
## melt-stage0-static
.PHONY: warmelt0
## the default stage0 melt-stage0-dynamic
MELT_STAGE_ZERO?= melt-stage0-dynamic
warmelt0: $(melt_make_cc1_dependency) $(MELT_STAGE_ZERO) $(MELT_STAGE_ZERO).timestamp 
$(MELT_STAGE_ZERO):
	-test -d $(MELT_STAGE_ZERO)/ || mkdir $(MELT_STAGE_ZERO)

[+FOR melt_stage+]
#### rules for [+melt_stage+][+ 
  (define stageindex (+ 1 (for-index)))
  (define previndex (for-index))
  (define prevstage (if (> stageindex 1) (sprintf "melt-stage%d" previndex) "$(MELT_STAGE_ZERO)"))
+], previous [+ (. prevstage)+]
[+FOR melt_translator_file+][+ 
  (define outbase (get "base")) (define outindex (for-index)) +]

################## [+ (. outbase)+] for [+melt_stage+]
[+melt_stage+]/[+(. outbase)+]-[+(. stageindex)+].so: [+melt_stage+]/[+ (. outbase)+]-[+(. stageindex)+].c \
              $(wildcard [+melt_stage+]/[+ (. outbase)+]-[+(. stageindex)+]+*.c) \
              melt-run.h melt-runtime.h melt-predef.h \
              $(melt_make_cc1_dependency)
	$(MELT_MAKE_MODULE) melt_module \
              GCCMELT_MODULE_WORKSPACE=[+melt_stage+]/ \
	      GCCMELT_CFLAGS="$(melt_cflags)" \
	      GCCMELT_MODULE_SOURCE=[+melt_stage+]/[+ (. outbase)+]-[+(. stageindex)+].c \
              GCCMELT_MODULE_BINARY=[+melt_stage+]/[+(. outbase)+]-[+(. stageindex)+]

[+melt_stage+]/[+(. outbase)+]-[+(. stageindex)+].n.so: [+melt_stage+]/[+ (. outbase)+]-[+(. stageindex)+].c \
              $(wildcard [+melt_stage+]/[+ (. outbase)+]-[+(. stageindex)+]+*.c) \
              melt-run.h melt-runtime.h melt-predef.h \
              $(melt_make_cc1_dependency)
	$(MELT_MAKE_MODULE) melt_module_withoutline \
              GCCMELT_MODULE_WORKSPACE=[+melt_stage+]/ \
	      GCCMELT_CFLAGS="$(melt_cflags)" \
	      GCCMELT_MODULE_SOURCE=[+melt_stage+]/[+ (. outbase)+]-[+(. stageindex)+].c \
              GCCMELT_MODULE_BINARY=[+melt_stage+]/[+(. outbase)+]-[+(. stageindex)+]

[+melt_stage+]/[+ (. outbase)+]-[+(. stageindex)+].c: $(melt_make_source_dir)/[+ (. outbase)+].melt \
[+FOR includeload+]        [+includeload+] \
[+ENDFOR includeload
+][+FOR melt_translator_file+][+ (define inbase (get "base")) (define inindex (for-index)) 
  (define depstage (if (< inindex outindex) (get "melt_stage") prevstage))
  (define depindex (if (< inindex outindex) stageindex (- stageindex 1)))
+]                  [+ (. depstage)+]/[+ (. inbase)+]-[+(. depindex)+].so \
[+ENDFOR melt_translator_file
+]             empty-file-for-melt.c melt-run.h melt-runtime.h melt-predef.h \
              $(melt_make_cc1_dependency)[+IF (= outindex 0)
+]
	$(MELTCCINIT1) $(meltarg_init)=\[+ELSE+]
	$(MELTCCFILE1) $(meltarg_init)=\[+ENDIF+]
[+FOR melt_translator_file ":\\\n"+][+ (define inbase (get "base")) (define inindex (for-index)) 
  (define depstage (if (< inindex outindex) (get "melt_stage") prevstage))
  (define depindex (if (< inindex outindex) stageindex (- stageindex 1)))
+][+ (. inbase)+]-[+(. depindex)+][+ENDFOR melt_translator_file
+] \
           $(meltarg_arg)=$<  -frandom-seed=$(shell md5sum $< | cut -b-24) \
	      $(meltarg_module_path)=[+melt_stage+]:[+ (. prevstage)+]:.:$(melt_make_module_dir) \
	      $(meltarg_source_path)=[+melt_stage+]:[+ (. prevstage)+]:.:$(melt_make_source_dir):$(melt_make_source_dir)/generated:$(melt_source_dir) \
	      $(meltarg_output)=$@  empty-file-for-melt.c
[+ENDFOR melt_translator_file+]

[+melt_stage+]/warmelt-[+(. stageindex)+].modlis:  \
[+FOR melt_translator_file " \\\n" +]             [+melt_stage+]/[+base+]-[+(. stageindex)+].so[+
ENDFOR melt_translator_file+]
	date  +"#$@ generated %F" > $@-tmp
[+FOR melt_translator_file+]	echo [+base+]-[+(. stageindex)+] >> $@-tmp
[+ENDFOR melt_translator_file+]	$(melt_make_move) $@-tmp $@
[+ (define laststage (get "melt_stage"))
   (define lastindex stageindex)
+]

[+melt_stage+]/warmelt-[+(. stageindex)+].n.modlis:  \
[+FOR melt_translator_file " \\\n" +]             [+melt_stage+]/[+base+]-[+(. stageindex)+].so[+
ENDFOR melt_translator_file+]
	date  +"#$@ generated %F" > $@-tmp
[+FOR melt_translator_file+]	echo [+base+]-[+(. stageindex)+].n >> $@-tmp
[+ENDFOR melt_translator_file+]	$(melt_make_move) $@-tmp $@
[+ (define laststage (get "melt_stage"))
   (define lastindex stageindex)
+]

.PHONY: warmelt[+(. stageindex)+] warmelt[+(. stageindex)+]n
warmelt[+(. stageindex)+]:  [+melt_stage+] [+melt_stage+]/warmelt-[+(. stageindex)+].modlis
warmelt[+(. stageindex)+]n:  [+melt_stage+] [+melt_stage+]/warmelt-[+(. stageindex)+].n.modlis
[+melt_stage+]:
	if [ -d [+melt_stage+] ]; then true; else mkdir [+melt_stage+]; fi
[+ (define laststage (get "melt_stage"))+]
### end of [+melt_stage+]

[+ENDFOR melt_stage+]

######## last stage [+ (. laststage)+]
MELT_LAST_STAGE=[+ (. laststage)+]
WARMELT_LAST= warmelt[+ (. lastindex)+]
WARMELT_LAST_MODLIS= [+ (. laststage)+]/warmelt-[+ (. lastindex)+].modlis

.PHONY: warmelt
warmelt: $(WARMELT_LAST)

####### final targets
.PHONY: all-melt melt-all-modules melt-all-sources
all-melt: melt-modules melt-sources melt-all-modules melt-all-sources

### the final module directory
melt-modules: 
	test -d melt-modules/ || mkdir  melt-modules/

### the final source directory
melt-sources: 
	test -d melt-sources/ || mkdir  melt-sources/

### the final temporary build directory
melt-tempbuild: 
	test -d melt-tempbuild/ || mkdir  melt-tempbuild/

melt-all-sources: $(WARMELT_LAST_MODLIS) empty-file-for-melt.c \
              melt-run.h melt-runtime.h melt-predef.h melt-sources \
              $(melt_make_cc1_dependency) \
[+FOR melt_translator_file+]	      melt-sources/[+base+].melt \
	      melt-sources/[+base+].c \
[+FOR includeload+] 	              melt-sources/[+includeload+] \
[+ENDFOR includeload+][+ENDFOR melt_translator_file+][+FOR melt_application_file" \\\n"
+]	      melt-sources/[+base+].melt \
	      melt-sources/[+base+].c [+ENDFOR melt_application_file+]


#### melt-sources translator files
[+FOR melt_translator_file+]
[+ (define transindex (for-index)) +]

## melt translator [+base+] # [+ (. transindex) +]
melt-sources/[+base+].melt: $(melt_make_source_dir)/[+base+].melt
	cd melt-sources; rm -f [+base+].melt; $(LN_S) $^

[+FOR includeload+]
# included [+includeload+]
melt-sources/[+includeload+]: [+includeload+]
	rm -f melt-sources/[+includeload+]*
	cp $^ melt-sources/[+includeload+]-tmp
	mv  melt-sources/[+includeload+]-tmp  melt-sources/[+includeload+]
[+ENDFOR includeload+]

melt-sources/[+base+].c: melt-sources/[+base+].melt [+FOR includeload
+]melt-sources/[+includeload+] [+ENDFOR includeload+] \
                    $(WARMELT_LAST) $(WARMELT_LAST_MODLIS) \
                    empty-file-for-melt.c melt-run.h melt-runtime.h \
                    $(melt_make_cc1_dependency) melt-tempbuild 
[+IF (= transindex 0)+]
	$(MELTCCINIT1) \[+ELSE+]
	$(MELTCCFILE1) \[+ENDIF+]
	     $(meltarg_arg)=$<  -frandom-seed=$(shell md5sum $< | cut -b-24) \
	     $(meltarg_module_path)=$(MELT_LAST_STAGE) \
	     $(meltarg_source_path)=$(MELT_LAST_STAGE):melt-sources \
	     $(meltarg_init)=@$(notdir $(basename $(WARMELT_LAST_MODLIS))) \
	     $(meltarg_output)=$@ 

melt-modules/[+base+].so: melt-sources/[+base+].c \
        $(wildcard  melt-sources/[+base+]+*.c) \
        melt-tempbuild melt-run.h melt-runtime.h 
	$(MELT_MAKE_MODULE) melt_module \
	      GCCMELT_CFLAGS="$(melt_cflags)" \
              GCCMELT_MODULE_WORKSPACE=melt-tempbuild \
	      GCCMELT_MODULE_SOURCE=$< \
              GCCMELT_MODULE_BINARY=melt-modules/[+base+]

melt-modules/[+base+].n.so: melt-sources/[+base+].c \
        $(wildcard  melt-sources/[+base+]+*.c) \
        melt-run.h melt-runtime.h 
	$(MELT_MAKE_MODULE) melt_module_withoutline \
	      GCCMELT_CFLAGS="$(melt_cflags)" \
	      GCCMELT_MODULE_SOURCE=$< \
              GCCMELT_MODULE_WORKSPACE=melt-tempbuild \
              GCCMELT_MODULE_BINARY=melt-modules/[+base+]
# end translator [+base+]

[+ENDFOR melt_translator_file+]

#### melt-sources application files
[+ (define prevapplbase (list)) +]
[+FOR melt_application_file+]


## melt application [+base+]
melt-sources/[+base+].melt: $(melt_make_source_dir)/[+base+].melt
	cd melt-sources; rm -f [+base+].melt; $(LN_S) $^


melt-sources/[+base+].c: melt-sources/[+base+].melt [+FOR includeload
+]melt-sources/[+includeload+] [+ENDFOR includeload+] \
                    $(WARMELT_LAST) $(WARMELT_LAST_MODLIS) \
                    empty-file-for-melt.c melt-run.h melt-runtime.h \
                    $(melt_make_cc1_dependency)
	$(MELTCCFILE1) \
	     $(meltarg_arg)=$<  -frandom-seed=$(shell md5sum $< | cut -b-24) \
	     $(meltarg_module_path)=melt-modules:$(MELT_LAST_STAGE) \
	     $(meltarg_source_path)=melt-sources:$(MELT_LAST_STAGE) \
	     $(meltarg_init)=@$(notdir $(basename $(WARMELT_LAST_MODLIS))):[+ (. (join ":" (reverse prevapplbase)))+] \
	     $(meltarg_output)=$@ 

melt-modules/[+base+].so: melt-sources/[+base+].c \
        $(wildcard  melt-sources/[+base+]+*.c) \
        melt-run.h melt-runtime.h melt-tempbuild
	$(MELT_MAKE_MODULE) melt_module \
	      GCCMELT_CFLAGS="$(melt_cflags)" \
	      GCCMELT_MODULE_SOURCE=$< \
              GCCMELT_MODULE_WORKSPACE=melt-tempbuild \
              GCCMELT_MODULE_BINARY=melt-modules/[+base+]

melt-modules/[+base+].n.so: melt-sources/[+base+].c \
        $(wildcard  melt-sources/[+base+]+*.c) \
        melt-run.h melt-runtime.h  melt-tempbuild
	$(MELT_MAKE_MODULE) melt_module_withoutline \
	      GCCMELT_CFLAGS="$(melt_cflags)" \
	      GCCMELT_MODULE_SOURCE=$< \
              GCCMELT_MODULE_WORKSPACE=melt-tempbuild \
              GCCMELT_MODULE_BINARY=melt-modules/[+base+]

[+ (define prevapplbase (cons (get "base") prevapplbase)) +]
# end application [+base+]

[+ENDFOR melt_application_file+]

melt-all-modules: \
[+FOR melt_translator_file+]    melt-modules/[+base+].so \
[+ENDFOR melt_translator_file+][+FOR melt_application_file " \\\n"
+]     melt-modules/[+base+].so[+ENDFOR melt_application_file+]

$(melt_default_modules_list).modlis: melt-all-modules
	date  +"#$@ generated %F" > $@-tmp
	echo "# translator files" >> $@-tmp
[+FOR melt_translator_file+]	echo [+base+] >> $@-tmp
[+ENDFOR melt_translator_file+]
	echo "# application files" >> $@-tmp
[+FOR melt_application_file+]	echo [+base+] >> $@-tmp
[+ENDFOR melt_application_file+]
	echo "#end $@" >> $@-tmp
	$(melt_make_move) $@-tmp $@


### MELT upgrade
.PHONY: warmelt-upgrade-translator

warmelt-upgrade-translator: \
[+FOR melt_translator_file " \\\n"
+]   melt-sources/[+base+].c \
         $(wildcard  melt-sources/[+base+]+*.c)[+
ENDFOR melt_translator_file+]
	@echo upgrading the MELT translator
[+FOR melt_translator_file+]
	@echo upgrading MELT translator [+base+]	
	for f in melt-sources/[+base+]*.c ; do \
	  bf=`basename $$f | sed s/[+base+]/[+base+].0/`; \
	  rm -f $(srcdir)/melt/generated/$$bf-tmp; \
          grep -v '^#line' < $$f \
            | unifdef -UMELTGCC_NOLINENUMBERING \
                 > $(srcdir)/melt/generated/$$bf-tmp; \
	  ls -l $(srcdir)/melt/generated/$$bf-tmp; \
	  if [ -f $(srcdir)/melt/generated/$$bf ]; then \
             mv -f $(srcdir)/melt/generated/$$bf $(srcdir)/melt/generated/$$bf~ ; \
	  fi ; \
	  mv -f $(srcdir)/melt/generated/$$bf-tmp \
                     $(srcdir)/melt/generated/$$bf ; \
        done
[+ENDFOR melt_translator_file+]


### Generated MELT documentation
meltgendoc.texi: $(melt_default_modules_list).modlis \
[+FOR melt_translator_file+]                    melt-sources/[+base+].melt \
[+ENDFOR melt_translator_file+][+FOR melt_application_file+]                    melt-sources/[+base+].melt \
[+ENDFOR melt_application_file+]                    empty-file-for-melt.c melt-run.h melt-runtime.h \
                    $(melt_make_cc1_dependency)
	$(melt_make_cc1)  $(melt_make_cc1flags) $(meltarg_mode)=makedoc  \
	      $(meltarg_makefile)=$(melt_make_module_makefile) \
	      $(meltarg_makecmd)=$(MAKE) \
	      $(meltarg_tempdir)=.  $(meltarg_bootstrapping)  $(MELT_DEBUG) \
	      $(meltarg_init)=@$(melt_default_modules_list) \
	      $(meltarg_module_path)=melt-modules:. \
	      $(meltarg_source_path)=melt-sources:. \
	      $(meltarg_output)=$@  \
              $(meltarg_arglist)=[+FOR melt_translator_file+][+base+].melt,[+ENDFOR melt_translator_file+]\
[+FOR melt_application_file "," +][+base+].melt[+ENDFOR melt_application_file+] \
              empty-file-for-melt.c


vpath %.so $(melt_make_module_dir) . 
vpath %.c $(melt_make_source_dir)/generated . $(melt_source_dir) 
vpath %.h $(melt_make_source_dir)/generated . $(melt_source_dir)




.PHONY: generate-meltrun
generate-meltrun: $(melt_default_modules_list).modlis  empty-file-for-melt.c \
                  melt-all-sources melt-all-modules  $(melt_make_cc1_dependency)
	rm -f $(wildcard meltrunsup*)
	$(melt_make_cc1)  $(melt_make_cc1flags) \
	      $(meltarg_mode)=runtypesupport  \
	      $(meltarg_tempdir)=.  $(meltarg_bootstrapping)  $(MELT_DEBUG) \
	      $(meltarg_init)=@$(melt_default_modules_list) \
	      $(meltarg_module_path)=melt-modules:. \
	      $(meltarg_source_path)=melt-sources:. \
	      $(meltarg_output)=meltrunsup  \
	      empty-file-for-melt.c

### MELT cleanup
.PHONY: melt-clean
melt-clean:
	rm -rf melt-stage0-static melt-stage0-dynamic \
	       melt-stage0-static.timestamp melt-stage0-dynamic.timestamp \
[+FOR melt_stage+]           [+melt_stage+]  [+melt_stage+].timestamp \
[+ENDFOR melt_stage+]               melt-sources melt-modules

## eof melt-build.mk generated from melt-build.tpl & melt-melt-build.def