summaryrefslogtreecommitdiff
path: root/gcc/melt-build-script.tpl
blob: d62f9e3bdc892145f6693e526b24c1d1a67e456e (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
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
[+ AutoGen5 template -*- Mode: Shell-script -*-
sh
+][+COMMENT use 'autogen --trace=everything melt-build-script.def' to debug this
  See http://www.gnu.org/software/autogen/
+]#!/bin/bash
[+ (. (dne "#@#@# " "#@! ")) +]
# Generated shell script for MELT modules and MELT translator bootstrap
#   Copyright (C) 2012 - 2013  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.
# 
#@ [+ (. (tpl-file-line))+] generated by Autogen [+ (. autogen-version)+] using [+ (.(def-file))+]

## melt-build-script.tpl generates melt-build-script.sh which may
## create meltbuild-* files and directories.  The invoking makefile
## may clean these meltbuild-* things.

## Ypu may want to set the GCCMELT_BUILD_NOTIFICATION environment variable
## to a shell script called with two arguments (a title, and a message)
## e.g. using notify-send or logger in such a script.
shopt -s nullglob

[+(. (define comefromcount 0))+]
[+(. (define (fromline) (set! comefromcount (+ comefromcount 1)) 
	(sprintf "%s/%d" (tpl-file-line "%s:%d") comefromcount)
	))+]

## set the overallgoal  [+(.(fromline))+] 
melt_overall_goal=$1
if [ -z "$melt_overall_goal" ]; then
  melt_overall_goal=gendoc
fi

## source the builtin settings  [+(.(fromline))+] generated from the MELT runtime
. ./melt-build-settings.sh

## source the parameters  [+(.(fromline))+]
. ./melt-build-param.sh

export GAWK=${GAWK:=gawk}
export MD5SUM=${MD5SUM:=md5sum}

## internal variables for this script  [+(.(fromline))+]
## GCCMELT_STAGE is an internal variable; it keeps the current MELT stage
export GCCMELT_STAGE=""
## GCCMELT_BASE is an internal variable; it keeps the current MELT base
export GCCMELT_BASE=""
## GCCMELT_SKIPEMITC is an internal variable; it skips the emission of C code when non-empty
export GCCMELT_SKIPEMITC=""



date +"/*empty file for MELT build %c*/" > meltbuild-empty-file.c

[ -d meltbuild-workdir ] || mkdir  meltbuild-workdir
[ -d meltbuild-tempdir ] || mkdir  meltbuild-tempdir

## our error function  [+(.(fromline))+]
function meltbuild_error () {
    echo MELT BUILD SCRIPT FAILURE: $@ >&2
    exit 1
}

## symbolic linking
function meltbuild_symlink () {
    ln -svf `realpath $1` $2
}

## our info function
function meltbuild_info () {
    echo MELT BUILD SCRIPT INFO: $@ >&2
}

## our notice function - for more important things than info
function meltbuild_notice () {
    meltnotititle=$1
    shift
    (echo; echo; echo MELT BUILD SCRIPT NOTICE "$meltnotititle:" $@ ; echo ) >&2
    if [ -n "$GCCMELT_BUILD_NOTIFICATION" ]; then
	$GCCMELT_BUILD_NOTIFICATION "$meltnotititle:" "$*"
    fi
}

## utility to build MELT specific arguments in meltbuild_emit
function meltbuild_arg () {
    local meltarg=$1
    if [ -z "$GCCMELT_IS_PLUGIN" ]; then
	echo " -fmelt-$meltarg"
    else
	echo " -fplugin-arg-melt-$meltarg"
    fi
}


if [ ! -f "$GCCMELT_RUNTIME_DEPENDENCY" ]; then
    meltbuild_error  [+(.(fromline))+] missing MELT runtime dependency "$GCCMELT_RUNTIME_DEPENDENCY" 
fi

if [ -z "$GCCMELT_CC1PLUS" ]; then
   meltbuild_error  [+(.(fromline))+] missing GCCMELT_CC1PLUS
fi

if [ ! -f meltrunsup.h ]; then 
    meltbuild_symlink $GCCMELT_MELTSOURCEDIR/generated/meltrunsup.h meltrunsup.h 
    meltbuild_info  [+(.(fromline))+] symlinking meltrunsup.h header
fi

GCCMELT_RUNTIME_DEPENDENCY_MD5SUM=$($MD5SUM "$GCCMELT_RUNTIME_DEPENDENCY"  | cut -b 1-32)

case $melt_overall_goal in
    translator) ;;
    applications) ;;
    modlists) ;;
    checkruntime) ;;
    gendoc) ;;
    regenerate) ;;
    *) meltbuild_error  [+(.(fromline))+] bad MELT overall goal "$melt_overall_goal:" \
        expecting translator, applications, modlists, checkruntime or gendoc or regenerate
esac

################################################################
################ stage zero

GCCMELT_ZERO_FLAVOR=${GCCMELT_STAGE_ZERO#meltbuild-stage0-}

## The base name of the MELT translator files [+ (. (fromline))+]
GCCMELT_TRANSLATOR_BASE=([+FOR melt_translator_file " \\\n"+]  [+base+][+ENDFOR melt_translator_file+] )

case $GCCMELT_ZERO_FLAVOR in
    optimized) ;;
    dynamic) ;;
    debugnoline) ;;
    quicklybuilt) ;;
    *) meltbuild_error  [+(.(fromline))+] bad zero flavor $GCCMELT_ZERO_FLAVOR ;;
esac


## our stage0 [+(.(fromline))+]

[ -d $GCCMELT_STAGE_ZERO ] || mkdir  $GCCMELT_STAGE_ZERO


function meltbuild_do_stage_zero () {
meltbuild_notice STAGE0+  [+(.(fromline))+] starting stage zero

[+FOR melt_translator_file+]
  meltbuild_info making stage0 [+base+]  [+(.(fromline))+]

##  stage0 [+(.(fromline))+] symlink descriptor file [+base+]
  if [ ! -f "$GCCMELT_STAGE_ZERO/[+base+]+meltdesc.c" ]; then
      meltbuild_symlink $GCCMELT_MELTSOURCEDIR/generated/[+base+]+meltdesc.c $GCCMELT_STAGE_ZERO/ 
  fi

##  stage0 [+(.(fromline))+] symlink melt/generated source code [+base+]
  if [ ! -f "$GCCMELT_STAGE_ZERO/[+base+].cc" ]; then
      meltbuild_info making stage0 [+base+] symlinking sources [+(.(fromline))+]
      meltbuild_symlink $GCCMELT_MELTSOURCEDIR/generated/[+base+].cc $GCCMELT_STAGE_ZERO/ 
      for f in $GCCMELT_MELTSOURCEDIR/generated/[+base+]+[0-9][0-9].cc ; do
	  meltbuild_symlink $f $GCCMELT_STAGE_ZERO/`basename $f`
      done
  fi

##  stage0 [+(.(fromline))+] symlink stamp [+base+]
  if  [ ! -f "$GCCMELT_STAGE_ZERO/[+base+]+melttime.h" ]; then
      meltbuild_info making stage0 [+base+] symlinking timestamp [+(.(fromline))+]
      meltbuild_symlink $GCCMELT_MELTSOURCEDIR/generated/[+base+]+melttime.h $GCCMELT_STAGE_ZERO/[+base+]+melttime.h 
  fi

  MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5=$($GAWK -F\" '/extern/{next} /melt_cumulated_hexmd5/{print $2}' $GCCMELT_MELTSOURCEDIR/generated/[+base+]+meltdesc.c)


## manually generate the stage0 [+base+]+meltbuild.mk file  [+(.(fromline))+]
  MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK=$GCCMELT_STAGE_ZERO/[+base+]+meltbuild.mk

  date +"# file $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK script-generated %c" > $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo "# generated " [+(.(fromline))+] >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo "MELTGEN_MODULENAME=$GCCMELT_STAGE_ZERO/[+base+]"  >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo "MELTGEN_MODULEIDENT=melt_stage_zero_[+varsuf+]"  >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$

  echo '# zerostage objects of [+base+] [+(.(fromline))+]' >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo $GCCMELT_STAGE_ZERO/[+base+].$MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5.descriptor.meltpic.o: $GCCMELT_STAGE_ZERO/[+base+]+meltdesc.c  >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  for f in $GCCMELT_STAGE_ZERO/[+base+].cc $GCCMELT_STAGE_ZERO/[+base+]+[0-9][0-9].cc; do
      echo >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
      echo $GCCMELT_STAGE_ZERO/`basename $f .cc`._NOMDFIVESUM_.$GCCMELT_ZERO_FLAVOR.meltpic.o: $f >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  done

  echo >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo '# zerostage module of [+base+] [+(.(fromline))+]'  >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo $GCCMELT_STAGE_ZERO/[+base+].meltmod-$MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5.$GCCMELT_ZERO_FLAVOR.so: \\  >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo " " $GCCMELT_STAGE_ZERO/[+base+].$MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5.descriptor.meltpic.o \\  >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  for f in $GCCMELT_STAGE_ZERO/[+base+]+[0-9][0-9].cc; do
      echo " " $GCCMELT_STAGE_ZERO/`basename $f .cc`._NOMDFIVESUM_.$GCCMELT_ZERO_FLAVOR.meltpic.o \\ >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  done
  echo " " $GCCMELT_STAGE_ZERO/[+base+]._NOMDFIVESUM_.$GCCMELT_ZERO_FLAVOR.meltpic.o >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo MELTGENMOD_CUMULATED_MD5SUM_melt_stage_zero_[+varsuf+]=$MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5 >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo MELTGENMOD_NAKED_NAME_melt_stage_zero_[+varsuf+]=[+base+]  >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
  echo '#end of generated file ' $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK >> $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$
##
  mv $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK-tmp$$ $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK
  meltbuild_info [+(.(fromline))+] generated stagezero makedep $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK
  ls -l $MELT_ZERO_GENERATED_[+varsuf+]_BUILDMK >&2

  $GCCMELT_MAKE -f $GCCMELT_MODULE_MK melt_module \
      GCCMELT_FROM=stagezero-[+(.(fromline))+] \
      GCCMELT_COMPILER="$GCCMELT_COMPILER" \
      GCCMELTGEN_BUILD=$GCCMELT_STAGE_ZERO/ \
      GCCMELT_MODULE_WORKSPACE=meltbuild-workdir \
      GCCMELT_MODULE_FLAVOR=$GCCMELT_ZERO_FLAVOR \
      GCCMELT_CFLAGS="$GCCMELT_COMPILER_FLAGS" \
      GCCMELT_MODULE_SOURCEBASE=$GCCMELT_STAGE_ZERO/[+base+] \
      GCCMELT_CUMULATED_MD5=$MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5 \
      GCCMELT_MODULE_BINARYBASE=$GCCMELT_STAGE_ZERO/[+base+] \
      GCCMELT_MODULE_DEPENDENCIES="$GCCMELT_CC1PLUS_DEPENDENCIES" \
      || meltbuild_error  [+(.(fromline))+] stage0 [+base+] did not build "(with $GCCMELT_MAKE  -f $GCCMELT_MODULE_MK)" compiler $GCCMELT_COMPILER cflags $GCCMELT_COMPILER_FLAGS

  meltbuild_info [+(.(fromline))+] stage0 [+base+] module 
  ls -l "$GCCMELT_STAGE_ZERO/[+base+].meltmod-$MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5.$GCCMELT_ZERO_FLAVOR.so" >&2 \
      || meltbuild_error  [+(.(fromline))+] stage0 [+base+] fail to build \
      "$GCCMELT_STAGE_ZERO/[+base+].meltmod-$MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5.$GCCMELT_ZERO_FLAVOR.so"

  meltbuild_info [+(.(fromline))+] successfully build stage0 [+base+]
# end stage0  [+(.(fromline))+] base  [+base+]
[+ENDFOR melt_translator_file+]
} ################ end of function meltbuild_do_stage_zero [+(.(fromline))+]
################################################################

## stage0 stamp file [+(.(fromline))+]
melt_stagezero_stamp=$GCCMELT_STAGE_ZERO/$GCCMELT_STAGE_ZERO.stamp

## test if stage0 should be skipped then do it  [+(.(fromline))+]
if [ ! -f "$melt_stagezero_stamp" -o "$melt_stagezero_stamp" -ot "$GCCMELT_RUNTIME_DEPENDENCY" ]; then
   meltbuild_do_stage_zero
    melt_stagezero_stamptemp=$melt_stagezero_stamp-tmp$$
    echo MELT stagezero stampfile $GCCMELT_STAGE_ZERO.stamp for MELT $MELTGCCBUILTIN_VERSION_STRING from [+(.(fromline))+] >  $melt_stagezero_stamptemp
    echo $GCCMELT_RUNTIME_DEPENDENCY_MD5SUM $GCCMELT_RUNTIME_DEPENDENCY >> $melt_stagezero_stamptemp
[+FOR melt_translator_file+]
#  stagezero stamp [+(.(fromline))+] base  [+base+]
    $MD5SUM $GCCMELT_STAGE_ZERO/[+base+].cc $GCCMELT_STAGE_ZERO/[+base+]+[0-9][0-9].cc >> $melt_stagezero_stamptemp
    $MD5SUM $GCCMELT_STAGE_ZERO/[+base+].meltmod-$MELT_ZERO_GENERATED_[+varsuf+]_CUMULMD5.$GCCMELT_ZERO_FLAVOR.so  >> $melt_stagezero_stamptemp
[+ENDFOR melt_translator_file+]
    $GCCMELT_MOVE_IF_CHANGE $melt_stagezero_stamptemp $melt_stagezero_stamp
else
   meltbuild_info [+(.(fromline))+] skipped stage0 because of stamp file $melt_stagezero_stamp
fi

meltbuild_info [+(.(fromline))+] times after stagezero at `date '+%x %H:%M:%S'`: ;  times >&2


################################################################
## function to run MELT to emit C code  [+(.(fromline))+]
function meltbuild_emit () {
    local meltfrom=$1
    local meltmode=$2
    local meltbase=$3
    local meltstage=$4
    local meltprevstage=$5
    local meltinit=$6
    local meltinclude=$7
    local meltbuildoption=$8
    local meltargs=$meltstage/$meltbase.args
    local meltsrc=$(realpath $GCCMELT_MELTSOURCEDIR/$meltbase.melt)
    meltbuild_info meltfrom=$meltfrom meltmode=$meltmode meltbase=$meltbase meltstage=$meltstage meltprevstage=$meltprevstage meltinit=$meltinit meltinclude=$meltinclude meltsrc=$meltsrc
    local meltsum
    local meltprevf
    if [ -z "$meltmode" ]; then
	meltbuild_error $meltfrom no MELT mode at stage $meltstage
    fi
    if [ ! -f "$meltsrc" ]; then
	meltbuild_error $meltfrom no MELT file $meltsrc at stage $meltstage base $meltbase
    fi
    if [ -z "$meltinit" ]; then
	meltbuild_error $meltfrom no MELT init  at stage $meltstage base $meltbase
    fi
    meltsum=$($MD5SUM $meltsrc | $GAWK '{print $1}')
    meltbuild_info $meltfrom emit C code for $meltbase of $meltstage
    echo -Wno-shadow -frandom-seed=$meltsum > $meltargs-$$-tmp
    ## various arguments
    echo " -DGCCMELT_FROM_ARG=\"$meltfrom\"" >>  $meltargs-$$-tmp
    meltbuild_arg mode=$meltmode >> $meltargs-$$-tmp
    meltbuild_arg arg=$meltsrc >>  $meltargs-$$-tmp
    meltbuild_arg output=$meltstage/$meltbase  >>  $meltargs-$$-tmp
    meltbuild_arg "module-make-command='$GCCMELT_MAKE'" >> $meltargs-$$-tmp
    meltbuild_arg module-makefile=$GCCMELT_MODULE_MK >> $meltargs-$$-tmp
    meltbuild_arg "module-cflags='$GCCMELT_INCLUDES -I. -I$meltstage -I$meltprevstage $GCCMELT_COMPILER_FLAGS'" >>  $meltargs-$$-tmp
    meltbuild_arg init=$meltinit >> $meltargs-$$-tmp
    meltbuild_arg workdir=meltbuild-workdir >> $meltargs-$$-tmp
    meltbuild_arg tempdir=meltbuild-tempdir >> $meltargs-$$-tmp
    meltbuild_arg source-path=$meltstage:$meltprevstage:. >> $meltargs-$$-tmp
    meltbuild_arg module-path=$meltstage:$meltprevstage:. >> $meltargs-$$-tmp
    meltbuild_arg bootstrapping  >> $meltargs-$$-tmp
    meltbuild_arg generate-work-link  >> $meltargs-$$-tmp
    meltbuild_arg generated-c-file-list=$meltstage/$meltbase.cfilist  >> $meltargs-$$-tmp
    if [ -n "$meltbuildoption" ]; then
	echo "$meltbuildoption" >> $meltargs-$$-tmp
    fi
    ## final empty file
    echo meltbuild-empty-file.c >>  $meltargs-$$-tmp
    mv $meltargs-$$-tmp $meltargs
    meltbuild_info $meltfrom argument file $meltargs is
    cat  $meltargs < /dev/null >&2
    if [ -z "$GCCMELT_SKIPEMITC" ]; then
	$GCCMELT_CC1PLUS_PREFIX $GCCMELT_CC1PLUS @$meltargs || meltbuild_error $meltfrom failed with arguments @$meltargs
        ## remove obsolete secondary C files left previously in $meltstage 
	for meltcsecfil in $meltstage/$meltbase+[0-9][0-9].cc ; do
	    if grep -q `basename $meltcsecfil` "$meltstage/$meltbase.cfilist" ; then
		: # at  [+(.(fromline))+]
	    else
		meltbuild_info $meltfrom removing obsolete $meltcsecfil
		rm -f "$meltcsecfil"
	    fi
	done
    else
	meltbuild_info $meltfrom skips emission of C code with  @$meltargs stage $meltstage prevstage $meltprevstage skipreason $GCCMELT_SKIPEMITC  [+(.(fromline))+] 
	ls -l $meltprevstage/$meltbase*
	meltbuild_info $meltfrom symlinking previous stage $meltprevstage  [+(.(fromline))+] 
	for meltprevf in $meltprevstage/$meltbase.cc  $meltprevstage/$meltbase+[0-9][0-9].cc  $meltprevstage/$meltbase+meltdesc.c  $meltprevstage/$meltbase+melttime.h   $meltprevstage/$meltbase+meltbuild.mk ; do
	    meltbuild_symlink $meltprevf $meltstage/`basename $meltprevf`
	done
	meltbuild_info $meltfrom symlinked previous stage $meltprevstage/$meltbase [+(.(fromline))+] 
    fi
    GCCMELT_STAGE=$meltstage
    GCCMELT_BASE=$meltbase
} ################################ end function meltbuild_emit

################################################################
################################################################
#################@ before our stages [+(.(fromline))+] 
### Our stages [+FOR melt_stage " "+][+stagdir+][+ENDFOR meltstage+] 
### are incrementally built, with the former modules of
### the current stage and the later modules of the previous stages
### used to emit the source of the current module in the current stage.
### This is a kind of "diagonalization".


################################################################
#### function to do a stage [+(.(fromline))+]
function meltbuild_do_stage () {
    local meltfrom=$1
    local meltcurstagedir=$2
    local meltcurflavor=$3
    local meltprevstagedir=$4
    local meltprevflavor=$5
    local meltbuildoption=$6
[+FOR melt_translator_file+]
    local meltchecksum_[+varsuf+]
[+ENDFOR melt_translator_file+]
    local meltstamp
    local meltstamptmp
####in meltbuild_do_stage [+(.(fromline))+]
    meltbuild_notice "$meltcurstagedir+" starting  stage $meltcurstagedir flavor $meltcurflavor from $meltfrom
####in meltbuild_do_stage [+(.(fromline))+]
    meltbuild_info $meltfrom starting stage $meltcurstagedir flavor $meltcurflavor previous $meltprevstagedir previous flavor $meltprevflavor
    [ -d $meltcurstagedir ] || mkdir $meltcurstagedir
    if [ ! -d "$meltprevstagedir" -o ! -f "$meltprevstagedir/$meltprevstagedir.stamp" ]; then
	meltbuild_error $meltfrom previous stage "$meltprevstagedir/" without stamp file $meltprevstagedir/$meltprevstagedir.stamp
    fi

[+FOR melt_translator_file+][+ 
  (define outbase (get "base")) (define outindex (for-index)) +]

    #in meltbuild_do_stage [+(.(fromline))+] base [+base+]
    meltbuild_info [+(.(fromline))+] from $meltfrom generating C code of [+base+] in $meltcurstagedir

    #in meltbuild_do_stage [+(.(fromline))+] emit C code for [+base+]
    meltbuild_emit [+(.(fromline))+]-$meltfrom \
	[+IF (= outindex 0)+]translateinit[+ELSE+]translatefile[+ENDIF+] \
	[+base+] \
	"$meltcurstagedir" \
	"$meltprevstagedir" \
	[+FOR melt_translator_file ":"+][+
	(define inindex (for-index)) 
	(define depstage (if (< inindex outindex) "$meltcurstagedir" "$meltprevstagedir"))
	(define depflavor (if (< inindex outindex) "$meltcurflavor" "$meltprevflavor"))
+][+(. depstage)+]/[+base+].[+ (. depflavor)+][+ENDFOR melt_translator_file+] \
    "[+FOR includeload " "+][+includeload+][+ENDFOR includeload+]" \
    "$meltbuildoption"

    #in meltbuild_do_stage [+(.(fromline))+] checksum C code for [+base+]
    meltchecksum_cumul_[+varsuf+]=$(cat "$meltcurstagedir"/[+base+].cc "$meltcurstagedir"/[+base+]+[0-9][0-9].cc | $MD5SUM | cut -b 1-32)

    #in meltbuild_do_stage [+(.(fromline))+] perhaps compiling C code for [+base+]
    if [ -z "$GCCMELT_SKIPEMITC" ]; then
	meltbuild_info [+(.(fromline))+]-$meltfrom compiling module [+base+] in "$meltcurstagedir"
	$GCCMELT_MAKE -f $GCCMELT_MODULE_MK melt_module \
	    GCCMELT_FROM="[+(.(fromline))+]-$meltfrom" \
	    GCCMELT_MODULE_WORKSPACE=meltbuild-workdir \
	    GCCMELT_MODULE_FLAVOR="$meltcurflavor" \
	    GCCMELT_COMPILER="$GCCMELT_COMPILER" \
	    GCCMELT_CFLAGS="$GCCMELT_COMPILER_FLAGS" \
	    GCCMELT_MODULE_SOURCEBASE="$meltcurstagedir/[+base+]" \
	    GCCMELT_MODULE_BINARYBASE="$meltcurstagedir/[+base+]" \
	|| ( meltbuild_info [+(.(fromline))+]-$meltfrom recompiling bad module [+base+] in "$meltcurstagedir" ; \
	$GCCMELT_MAKE -f $GCCMELT_MODULE_MK melt_module \
	    GCCMELT_FROM="[+(.(fromline))+]-$meltfrom" \
	    GCCMELT_MODULE_WORKSPACE=meltbuild-workdir \
	    GCCMELT_MODULE_FLAVOR="$meltcurflavor" \
	    GCCMELT_COMPILER="$GCCMELT_COMPILER" \
	    GCCMELT_CFLAGS="$GCCMELT_COMPILER_FLAGS -DMELTGCC_NOLINENUMBERING" \
	    GCCMELT_MODULE_SOURCEBASE="$meltcurstagedir/[+base+]" \
	    GCCMELT_MODULE_BINARYBASE="$meltcurstagedir/[+base+]" ; \
	    meltbuild_error  [+(.(fromline))+]-$meltfrom in "$meltcurstagedir/" \
                failed to make "($GCCMELT_MAKE -f $GCCMELT_MODULE_MK)" module [+base+] compiler "$GCCMELT_COMPILER" cflags "$GCCMELT_COMPILER_FLAGS" )
    else
	meltbuild_info [+(.(fromline))+]-$meltfrom NOT compiling module [+base+] "in" \
	    "$meltcurstagedir/" but symlinking previous "$meltprevstagedir/" module [+base+] \
	    checksum $meltchecksum_cumul_[+varsuf+] skipemitc=$GCCMELT_SKIPEMITC.
	meltbuild_symlink "$meltprevstagedir/[+base+].meltmod-$meltchecksum_cumul_[+varsuf+].$meltprevflavor.so" \
	    "$meltcurstagedir/[+base+].meltmod-$meltchecksum_cumul_[+varsuf+].$meltcurflavor.so"
    fi
    #in meltbuild_do_stage [+(.(fromline))+] done base [+base+]
[+ENDFOR melt_translator_file+]

    #in meltbuild_do_stage [+(.(fromline))+] generating the stampfile
    meltstamp=$meltcurstagedir/$meltcurstagedir.stamp
    meltstamptmp=$meltstamp-tmp$$
    echo "///timestamp file $meltstamp" > $meltstamptmp
    echo $GCCMELT_RUNTIME_DEPENDENCY_MD5SUM $GCCMELT_RUNTIME_DEPENDENCY >> $meltstamptmp
[+FOR melt_translator_file+]
    $MD5SUM $meltcurstagedir/[+base+].cc $meltcurstagedir/[+base+]+[0-9][0-9].cc  >> $meltstamptmp
    $MD5SUM "$meltcurstagedir/[+base+].meltmod-$meltchecksum_cumul_[+varsuf+].$meltcurflavor.so"  >> $meltstamptmp
[+ENDFOR melt_translator_file+]
    echo "///end timestamp file $meltstamp"
    $GCCMELT_MOVE_IF_CHANGE $meltstamptmp $meltstamp

    #in meltbuild_do_stage [+(.(fromline))+] ending
    meltbuild_info $meltfrom done stage $meltcurstagedir flavor $meltcurflavor previous $meltprevstagedir previous flavor $meltprevflavor timestamp $meltstamp

}			#### end meltbuild_do_stage [+(.(fromline))+]
################################################################

##### possibly run all our stages  [+(.(fromline))+]
[+FOR melt_build_stage+]
#@  [+(.(fromline))+] stagedir [+stagdir+]
GCCMELT_SKIPEMITC=
if [ ! -f [+stagdir+]/[+stagdir+].stamp -o [+stagdir+]/[+stagdir+].stamp -ot $GCCMELT_RUNTIME_DEPENDENCY \
[+FOR melt_translator_file+] -o [+stagdir+]/[+stagdir+].stamp -ot $GCCMELT_MELTSOURCEDIR/[+base+].melt \
[+ENDFOR melt_translator_file+] ]; then
    echo ; echo ; echo ; echo 
    meltbuild_info  [+(.(fromline))+] '++++++++++++++++' building stage [+stagdir+] '++++++++++++++++'
    ## building stage [+stagdir+] previous [+stagprevdir+]  [+(.(fromline))+]
    meltbuild_do_stage  [+(.(fromline))+] [+stagdir+] quicklybuilt [+stagprevdir+] [+stagprevflavor+] "$GCCMELT_EMIT_OPTION_[+stagsuf+]"
else
    meltbuild_info  [+(.(fromline))+] skipping stage [+stagdir+]
fi

##  [+(.(fromline))+]
GCCMELT_LASTSTAGE=[+stagdir+]

[+ENDFOR melt_build_stage+]

################################################################


meltbuild_info [+(.(fromline))+] last stage $GCCMELT_LASTSTAGE

################################################################
################################################################
###########@ before generating meltbuild-sources [+(.(fromline))+]

#### the meltbuild-sources is the final sources directory, to be
#### installed.  They are generated from the last stage, using the
#### modules inside it. Notice that in contrast from the intermediate
#### stages no "diagonalization" is involved.

[ -d meltbuild-sources ] || mkdir meltbuild-sources

#@ from  [+(.(fromline))+]  compiling the modules
[ -d meltbuild-modules ] || mkdir meltbuild-modules

################################################################
function meltbuild_emit_translator_sources () {
[+FOR melt_translator_file+]
  ## meltbuild_emit_source  [+(.(fromline))+] base [+base+]
  meltbuild_info [+(.(fromline))+] generating C code of [+base+] in meltbuild-sources
  meltbuild_emit [+(.(fromline))+] \
      [+IF (= (for-index) 0)+]translateinit[+ELSE+]translatefile[+ENDIF+] \
      [+base+] \
      meltbuild-sources \
      "$GCCMELT_LASTSTAGE" \
      [+FOR melt_translator_file ":"+]$GCCMELT_LASTSTAGE/[+base+].quicklybuilt[+ENDFOR melt_translator_file+] \
      "[+FOR includeload " "+][+includeload+][+ENDFOR includeload+]"
[+ENDFOR melt_translator_file+]
}  # end of function meltbuild_emit_translator_sources


################
function meltbuild_compile_translator_modules () {
[+FOR flavor IN quicklybuilt optimized debugnoline+]

  # in meltbuild_compile_translator_sources [+flavor+] [+(.(fromline))+]
  meltbuild_info [+(.(fromline))+] compiling translator [+flavor+]

[+FOR melt_translator_file+]
   #@ [+(.(fromline))+] flavor [+flavor+] base [+base+]
   $GCCMELT_MAKE -f $GCCMELT_MODULE_MK melt_module \
     GCCMELT_FROM=[+(.(fromline))+] \
     GCCMELT_MODULE_WORKSPACE=meltbuild-workdir \
     GCCMELT_MODULE_FLAVOR=[+flavor+] \
     GCCMELT_COMPILER="$GCCMELT_COMPILER" \
     GCCMELT_CFLAGS="$GCCMELT_COMPILER_FLAGS" \
     GCCMELT_MODULE_SOURCEBASE=meltbuild-sources/[+base+] \
     GCCMELT_MODULE_BINARYBASE=meltbuild-modules/[+base+] \
 || meltbuild_error  [+(.(fromline))+] in meltbuild-modules failed to compile translator [+base+] [+flavor+] make "($GCCMELT_MAKE -f $GCCMELT_MODULE_MK)" compiler "$GCCMELT_COMPILER" cflags $GCCMELT_COMPILER_FLAGS
[+ENDFOR melt_translator_file+]

[+ENDFOR flavor+]
}     # end of function meltbuild_compile_translator_modules
################################################################


#################@ [+(.(fromline))+] 
function meltbuild_symlink_melt_translator_sources () {
[+FOR melt_translator_file+][+ 
  (define outbase (get "base")) (define outindex (for-index)) +]

### symlinking the MELT translator code in meltbuild-sources for [+base+] from [+ (. (fromline))+]

meltbuild_info [+(.(fromline))+] putting MELT translator code of [+base+] in meltbuild-sources

meltbuild_symlink $GCCMELT_MELTSOURCEDIR/[+base+].melt meltbuild-sources/[+base+].melt
[+FOR includeload "\n"+]meltbuild_symlink [+includeload+] meltbuild-sources/[+includeload+][+ENDFOR includeload+]

[+ENDFOR melt_translator_file+]
} 				# end of meltbuild_symlink_melt_translator_sources


################@ final translator [+(.(fromline))+] 
melt_final_translator_stamp=meltbuild-final-translator.stamp

if [ ! -f $melt_final_translator_stamp -o $melt_final_translator_stamp -ot $GCCMELT_RUNTIME_DEPENDENCY \
[+FOR melt_translator_file+] -o $melt_final_translator_stamp -ot $GCCMELT_MELTSOURCEDIR/[+base+].melt \
[+ENDFOR melt_translator_file+] -o $melt_final_translator_stamp -ot $GCCMELT_LASTSTAGE/$GCCMELT_LASTSTAGE.stamp ]; then
    meltbuild_notice 'Emit Translator Source'  [+(.(fromline))+] emit then translate the MELT translator 
    meltbuild_info [+(.(fromline))+] emit then translate the compile translator for  $melt_final_translator_stamp
    meltbuild_emit_translator_sources
    meltbuild_symlink_melt_translator_sources
    meltbuild_compile_translator_modules
    melt_final_translator_stamptemp=$melt_final_translator_stamp-tmp$$
    echo "///MELT translator timestamp file $melt_final_translator_stamp" > $melt_final_translator_stamptemp
    echo $GCCMELT_RUNTIME_DEPENDENCY_MD5SUM $GCCMELT_RUNTIME_DEPENDENCY >>  $melt_final_translator_stamptemp
[+FOR melt_translator_file+]
#@  [+(.(fromline))+] 
    $MD5SUM meltbuild-sources/[+base+].melt  >>  $melt_final_translator_stamptemp
  [+FOR includeload+]
    $MD5SUM meltbuild-sources/[+includeload+]  >>  $melt_final_translator_stamptemp
  [+ENDFOR includeload+]
    $MD5SUM meltbuild-sources/[+base+].cc meltbuild-sources/[+base+]+[0-9][0-9].cc  >> $melt_final_translator_stamptemp
    melt_translator_[+varsuf+]_cumulmd5=$(cat  meltbuild-sources/[+base+].cc meltbuild-sources/[+base+]+[0-9][0-9].cc  | $MD5SUM | cut -b 1-32)
[+ENDFOR melt_translator_file+]
    echo "///end timestamp file $melt_final_translator_stamp"
    $GCCMELT_MOVE_IF_CHANGE $melt_final_translator_stamptemp $melt_final_translator_stamp
else
    meltbuild_info [+(.(fromline))+] skip final translation of translator stamp  $melt_final_translator_stamp
fi

################################################################
#@ [+(.(fromline))+] making the meltbuild-common.args file to make life easier
# I would often use that meltbuild-common.args for testing, etc.
meltcommon_args=meltbuild-common.args
meltbuild_info [+(.(fromline))+] making $meltcommon_args
meltcommon_argstemp=$meltcommon_args-tmp$$
echo ' -DGCCMELT_FROM_ARG="[+(.(fromline))+]"' > $meltcommon_argstemp
meltbuild_arg workdir=meltbuild-workdir >>  $meltcommon_argstemp
meltbuild_arg tempdir=meltbuild-tempdir >> $meltcommon_argstemp
meltbuild_arg source-path=meltbuild-sources:$GCCMELT_LASTSTAGE >> $meltcommon_argstemp
meltbuild_arg module-path=meltbuild-modules:$GCCMELT_LASTSTAGE >> $meltcommon_argstemp
meltbuild_arg "module-cflags=\"$GCCMELT_COMPILER_FLAGS\"" >> $meltcommon_argstemp
meltbuild_arg "module-makefile=\"$GCCMELT_MODULE_MK\""  >>  $meltcommon_argstemp

$GCCMELT_MOVE_IF_CHANGE $meltcommon_argstemp $meltcommon_args
meltbuild_info [+(.(fromline))+] $meltcommon_args is
cat $meltcommon_args < /dev/null >&2


################
### the warmelt modules lists  [+(.(fromline))+]
[+FOR flavor in quicklybuilt optimized debugnoline+]
if [ ! -f meltbuild-sources/warmelt.[+flavor+].modlis \
    -o  meltbuild-sources/warmelt.[+flavor+].modlis -ot  "$melt_final_translator_stamp" ]; then 
  #  [+ (. (fromline))+] warmelt module list [+flavor+]
  melt_modlis_temp="meltbuild-sources/warmelt.[+flavor+].modlis-tmp$$"
  echo "# MELT translator modules:" >> $melt_modlis_temp
 [+FOR melt_translator_file+] 
  echo [+base+].[+flavor+] >> $melt_modlis_temp
 [+ENDFOR melt_translator_file+]
  $GCCMELT_MOVE_IF_CHANGE $melt_modlis_temp  "meltbuild-sources/warmelt.[+flavor+].modlis"
fi
[+ENDFOR flavor+]

################################################################
#@ [+(.(fromline))+]
if [ "$melt_overall_goal" = "translator" ]; then
    meltbuild_info [+(.(fromline))+] done translation overall goal with stamp  $melt_final_translator_stamp
    exit 0
fi

################
#@ [+(.(fromline))+] before application xtramelt* modules
################################################################
meltbuild_info [+(.(fromline))+] before applications GCCMELT_SKIPEMITC=$GCCMELT_SKIPEMITC.

meltbuild_info [+(.(fromline))+] times before applications at `date '+%x %H:%M:%S'`: ;  times >&2
 
melt_final_application_stamp=meltbuild-final-application.stamp

function meltbuild_do_applications () {
meltbuild_notice 'doing applications'  [+(.(fromline))+] doing applications 

[+FOR melt_application_file+]
[+ (define apbase (get "base")) (define apindex (for-index)) +]
  ## meltbuild_do_applications [+base+] [+(.(fromline))+]
  if [ ! -f meltbuild-sources/[+base+].melt ]; then
      meltbuild_symlink $GCCMELT_MELTSOURCEDIR/[+base+].melt meltbuild-sources/[+base+].melt
  fi
  ## meltbuild_do_applications [+base+] [+(.(fromline))+]
  if [ ! -f meltbuild-sources/[+base+].cc -o  ! -f meltbuild-sources/[+base+]+meltdesc.c \
       -o meltbuild-sources/[+base+]+meltdesc.c -ot meltbuild-final-translator.stamp \
       -o meltbuild-sources/[+base+]+meltdesc.c -ot  meltbuild-sources/[+base+].melt \
[+FOR melt_application_file+][+IF (< (for-index) apindex)+] -o meltbuild-sources/[+base+]+meltdesc.c -ot meltbuild-sources/[+(. apbase)+]+meltdesc.c \
[+ENDIF+][+ENDFOR melt_application_file+] ]; then
      meltbuild_info [+(.(fromline))+] emit application C code for [+base+]
      meltbuild_emit [+(.(fromline))+] \
	  translatefile \
	  [+base+] \
	  meltbuild-sources \
	  meltbuild-modules \
	  [+FOR melt_translator_file ":"+][+base+].optimized[+ENDFOR melt_translator_file+][+FOR melt_application_file+][+IF (< (for-index) apindex)+]:[+base+].quicklybuilt[+ENDIF+][+ENDFOR melt_application_file+] \
    "[+FOR includeload " "+][+includeload+][+ENDFOR includeload+]" \
	  || meltbuild_error [+(.(fromline))+] failed to generate C code of application [+base+]
  else
      meltbuild_info [+(.(fromline))+] DONT emit application C code for [+base+]
  fi
  local meltapp_[+varsuf+]_cumulmd5=$(cat  meltbuild-sources/[+base+].cc meltbuild-sources/[+base+]+[0-9][0-9].cc  | $MD5SUM | cut -b 1-32)
 [+FOR flavor IN quicklybuilt optimized debugnoline+]
  if [ ! -f meltbuild-modules/[+base+].meltmod-$meltapp_[+varsuf+]_cumulmd5.[+flavor+].so \
      -o meltbuild-modules/[+base+].meltmod-$meltapp_[+varsuf+]_cumulmd5.[+flavor+].so -ot  meltbuild-final-translator.stamp \
      -o  meltbuild-modules/[+base+].meltmod-$meltapp_[+varsuf+]_cumulmd5.[+flavor+].so -ot  meltbuild-sources/[+base+].cc \
      -o  meltbuild-modules/[+base+].meltmod-$meltapp_[+varsuf+]_cumulmd5.[+flavor+].so -ot  meltbuild-sources/[+base+]+meltdesc.c ]; then
      meltbuild_info [+(.(fromline))+] compiling application module for [+base+] [+flavor+]
      $GCCMELT_MAKE -f $GCCMELT_MODULE_MK melt_module \
	  GCCMELT_FROM=[+(.(fromline))+] \
	  GCCMELT_MODULE_WORKSPACE=meltbuild-workdir \
	  GCCMELT_MODULE_FLAVOR=[+flavor+] \
	  GCCMELT_COMPILER="$GCCMELT_COMPILER" \
	  GCCMELT_CFLAGS="$GCCMELT_COMPILER_FLAGS" \
	  GCCMELT_MODULE_SOURCEBASE=meltbuild-sources/[+base+] \
	  GCCMELT_MODULE_BINARYBASE=meltbuild-modules/[+base+] \
	  || ( meltbuild_notice [+(.(fromline))+] in meltbuild-modules failure to compile application [+base+] [+flavor+] ; \
	       $GCCMELT_MAKE -f $GCCMELT_MODULE_MK melt_module \
			     GCCMELT_FROM=[+(.(fromline))+] \
			     GCCMELT_MODULE_WORKSPACE=meltbuild-workdir \
			     GCCMELT_MODULE_FLAVOR=[+flavor+] \
			     GCCMELT_COMPILER="$GCCMELT_COMPILER" \
			     GCCMELT_CFLAGS="$GCCMELT_COMPILER_FLAGS -DMELTGCC_NOLINENUMBERING" \
			     GCCMELT_MODULE_SOURCEBASE=meltbuild-sources/[+base+] \
			     GCCMELT_MODULE_BINARYBASE=meltbuild-modules/[+base+] ; \
	       meltbuild_error  [+(.(fromline))+] in meltbuild-modules failed to compile application [+base+] [+flavor+] \
				"($GCCMELT_MAKE -f $GCCMELT_MODULE_MK)" compiler $GCCMELT_COMPILER_FLAGS cflags $GCCMELT_COMPILER_FLAGS )
	       else
      meltbuild_info [+(.(fromline))+] not compiling application module for [+base+] [+flavor+]
  fi
 [+ENDFOR flavor+]
[+ENDFOR melt_application_file+]
  ## meltbuild_do_applications [+base+] [+(.(fromline))+]
  local meltappstamptemp=$melt_final_application_stamp-tmp$$
  echo "///MELT application time stamp $melt_final_application_stamp" > $meltappstamptemp
  echo $GCCMELT_RUNTIME_DEPENDENCY_MD5SUM $GCCMELT_RUNTIME_DEPENDENCY >>  $meltappstamptemp
[+FOR melt_application_file+]
  $MD5SUM meltbuild-sources/[+base+].melt >>  $meltappstamptemp
  $MD5SUM meltbuild-sources/[+base+].cc meltbuild-sources/[+base+]+[0-9][0-9].cc  >> $meltappstamptemp
 [+FOR flavor IN quicklybuilt optimized debugnoline+]
  $MD5SUM meltbuild-modules/[+base+].meltmod-$meltapp_[+varsuf+]_cumulmd5.[+flavor+].so >> $meltappstamptemp
 [+ENDFOR flavor+]
[+ENDFOR melt_application_file+]
  echo "///end stamp $melt_final_application_stamp"  >> $meltappstamptemp
  $GCCMELT_MOVE_IF_CHANGE $meltappstamptemp  $melt_final_application_stamp
meltbuild_info [+(.(fromline))+] times after applications at `date '+%x %H:%M:%S'`: ;  times >&2
} ## end meltbuild_do_applications  [+(.(fromline))+]

if [ ! -f  "$melt_final_application_stamp" \
     -o "$melt_final_application_stamp" -ot "$melt_final_translator_stamp" \
[+FOR melt_application_file+] -o "$melt_final_application_stamp" -ot "$GCCMELT_MELTSOURCEDIR/[+base+].melt" \
[+ENDFOR melt_application_file+] ]; then
    meltbuild_info [+(.(fromline))+] building MELT applications
    meltbuild_do_applications
else
    meltbuild_info [+(.(fromline))+] not building MELT applications because of applstamp  "$melt_final_application_stamp"
fi

################################################################
#@ [+(.(fromline))+]
if [ "$melt_overall_goal" = "applications" ]; then
    meltbuild_info [+(.(fromline))+] done applications overall goal with stamp  $melt_final_translator_stamp
    meltbuild_notice 'Done applications' [+(.(fromline))+] applications overall goal 
    exit 0
fi
################################################################
################################################################
### the modules lists [+ (. (fromline))+]
[+FOR flavor in quicklybuilt optimized debugnoline+]
if [ ! -f "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.[+flavor+].modlis" \
    -o "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.[+flavor+].modlis" -ot $melt_final_translator_stamp \
    -o "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.[+flavor+].modlis" -ot $melt_final_application_stamp ]; then
  #  [+ (. (fromline))+] module list [+flavor+]
  meltbuild_info  [+(.(fromline))+] generating module list  "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.[+flavor+].modlis"
  melt_modlis_temp="meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.[+flavor+].modlis-tmp$$"
  echo "# MELT module list file $MELTGCCBUILTIN_DEFAULT_MODLIS.[+flavor+].modlis" >> $melt_modlis_temp
  echo "# MELT translator modules:" >> $melt_modlis_temp
 [+FOR melt_translator_file+] 
  echo [+base+].[+flavor+] >> $melt_modlis_temp
 [+ENDFOR melt_translator_file+]
  #@  [+ (. (fromline))+]
  echo "# MELT application modules:" >> $melt_modlis_temp
 [+FOR melt_application_file+]
  echo [+base+].[+flavor+] >> $melt_modlis_temp
 [+ENDFOR melt_application_file+]
  $GCCMELT_MOVE_IF_CHANGE $melt_modlis_temp  "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.[+flavor+].modlis"
else
  meltbuild_info  [+(.(fromline))+] keeping module list  "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.[+flavor+].modlis"  
fi
[+ENDFOR flavor+]

#@ [+ (. (fromline))+]
if [ ! -f "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.modlis" ]; then
   meltbuild_symlink "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.optimized.modlis" "meltbuild-sources/$MELTGCCBUILTIN_DEFAULT_MODLIS.modlis"
fi

################################################################
#@ [+(.(fromline))+] module lists
if [ "$melt_overall_goal" = "modlists" ]; then
    meltbuild_info [+(.(fromline))+] done modlists overall goal with stamp  $melt_final_application_stamp
    exit 0
fi




################################################################
#@ [+(.(fromline))+] runtime self check

##  [+(.(fromline))+] FIXME: should skip that when cross-compiler MELT plugin..

if [ -z "$GCCMELT_RUNTIME_CC" ]; then 
    meltbuild_error [+(.(fromline))+] failed because no GCCMELT_RUNTIME_CC shell variable
    exit 1
fi

meltcheckruntime_stamp=meltbuild-checkruntime.stamp
if [ ! -f $meltcheckruntime_stamp -o $meltcheckruntime_stamp -ot "$GCCMELT_RUNTIME_ARGS" \
    -o $meltcheckruntime_stamp -ot "$GCCMELT_RUNTIME_CC" \
    -o $meltcheckruntime_stamp -ot $melt_final_application_stamp ]; then
    #@ [+(.(fromline))+] checkruntime
    if [ -f melt-no-check-runtime -o -n "$MELTGCC_NO_CHECK_RUNTIME" -o ! -f melt-runtime.i ]; then
	meltbuild_info [+(.(fromline))+] skipping check of MELT runtime
    else
	meltcheckruntime_args=meltbuild-checkruntime.args 
	meltcheckruntime_argstemp=$meltcheckruntime_args-tmp$$
	echo ' -DGCCMELT_FROM_ARG="[+(.(fromline))+]"' ' -DGCCMELT_CHECKMELTRUNTIME' > $meltcheckruntime_argstemp
	meltbuild_arg mode=meltframe >> $meltcheckruntime_argstemp
	meltbuild_arg workdir=meltbuild-workdir >>  $meltcheckruntime_argstemp
	meltbuild_arg tempdir=meltbuild-tempdir >> $meltcheckruntime_argstemp
	meltbuild_arg source-path=meltbuild-sources >> $meltcheckruntime_argstemp
	meltbuild_arg module-path=meltbuild-modules >> $meltcheckruntime_argstemp
	meltbuild_arg "module-cflags=\"$GCCMELT_COMPILER_FLAGS\"" >> $meltcheckruntime_argstemp
	meltbuild_arg bootstrapping  >> $meltcheckruntime_argstemp
	echo ' -o /dev/null' >> $meltcheckruntime_argstemp
	echo melt-runtime.i >> $meltcheckruntime_argstemp
	$GCCMELT_MOVE_IF_CHANGE  $meltcheckruntime_argstemp $meltcheckruntime_args
	[ -f "$meltcheckruntime_args" ] || meltbuild_error  [+(.(fromline))+] missing check runtime args  "$meltcheckruntime_args"
	meltbuild_info [+(.(fromline))+] $meltcheckruntime_args  is
	cat $meltcheckruntime_args < /dev/null >&2
	if [ -n "$MELTGCCBUILTIN_BUILD_WITH_CXX" ]; then
	    $GCCMELT_CC1PLUS_PREFIX $GCCMELT_CC1PLUS @$meltcheckruntime_args \
		|| meltbuild_error [+(.(fromline))+] failed  $GCCMELT_CC1PLUS with arguments @$meltcheckruntime_args
	else
	    $GCCMELT_CC1PLUS_PREFIX $GCCMELT_CC1PLUS @$meltcheckruntime_args \
		|| meltbuild_error [+(.(fromline))+] failed  $GCCMELT_CC1PLUS with arguments @$meltcheckruntime_args
	fi
	meltbuild_info [+(.(fromline))+] done check runtime with $meltcheckruntime_args
    fi

   #@ [+(.(fromline))+] checkhello
    meltcheckhelloworld_args=meltbuild-checkhelloworld.args 
    meltcheckhelloworld_argstemp=$meltcheckhelloworld_args-tmp$$
    echo ' -DGCCMELT_FROM_ARG="[+(.(fromline))+]"' > $meltcheckhelloworld_argstemp
    meltbuild_arg mode=runfile >> $meltcheckhelloworld_argstemp
    meltbuild_arg workdir=meltbuild-workdir >>  $meltcheckhelloworld_argstemp
    meltbuild_arg module-makefile=$GCCMELT_MODULE_MK >>  $meltcheckhelloworld_argstemp
    meltbuild_arg tempdir=meltbuild-tempdir >> $meltcheckhelloworld_argstemp
    meltbuild_arg source-path=meltbuild-sources >> $meltcheckhelloworld_argstemp
    meltbuild_arg module-path=meltbuild-modules >> $meltcheckhelloworld_argstemp
    meltbuild_arg "module-cflags=\"$GCCMELT_COMPILER_FLAGS\"" >> $meltcheckhelloworld_argstemp
    date +'(code_chunk hello%j #{puts("hello world from MELT %F @" __TIME__"\n")}#)' > meltbuild-hello.melt-tmp$$
    $GCCMELT_MOVE_IF_CHANGE meltbuild-hello.melt-tmp$$  meltbuild-hello.melt
    meltbuild_arg arg=meltbuild-hello.melt >> $meltcheckhelloworld_argstemp
    echo ' meltbuild-empty-file.c -o /dev/null' >> $meltcheckhelloworld_argstemp
    cat $GCCMELT_HELLOWORLD_ARGS < /dev/null >>  $meltcheckhelloworld_argstemp
    $GCCMELT_MOVE_IF_CHANGE  $meltcheckhelloworld_argstemp $meltcheckhelloworld_args
    [ -f "$meltcheckhelloworld_args" ] || meltbuild_error  [+(.(fromline))+] missing check helloworld args  "$meltcheckhelloworld_args"
   meltbuild_info [+(.(fromline))+] $meltcheckhelloworld_args  is
   cat $meltcheckhelloworld_args < /dev/null >&2
    $GCCMELT_CC1PLUS_PREFIX $GCCMELT_CC1PLUS @$meltcheckhelloworld_args \
	|| meltbuild_error [+(.(fromline))+] running helloworld failed with arguments @$meltcheckhelloworld_args
   meltbuild_info [+(.(fromline))+] done check helloworld with $meltcheckhelloworld_args
   #@ [+(.(fromline))+] runtime stamp
    meltcheckruntime_stamptemp=$meltcheckruntime_stamp-tmp$$
    [ -f "$GCCMELT_RUNTIME_CC" ] || meltbuild_error [+(.(fromline))+] missing MELT runtime C++ file $GCCMELT_RUNTIME_CC
    echo "/// MELT check runtime timestamp file $meltcheckruntime_stamp" > $meltcheckruntime_stamptemp
    echo $GCCMELT_RUNTIME_DEPENDENCY_MD5SUM $GCCMELT_RUNTIME_DEPENDENCY >> $meltcheckruntime_stamptemp
    $MD5SUM $GCCMELT_RUNTIME_CC < /dev/null >>  $meltcheckruntime_stamptemp
    $MD5SUM meltbuild-hello.melt < /dev/null >>  $meltcheckruntime_stamptemp
    [ -f "$melt_final_translator_stamp" ] || meltbuild_error [+(.(fromline))+] missing final translator stamp "$melt_final_translator_stamp"
    [ -f "$melt_final_application_stamp" ] || meltbuild_error [+(.(fromline))+] missing final application stamp "$melt_final_application_stamp"
    grep meltbuild-modules/ "$melt_final_translator_stamp" "$melt_final_application_stamp" < /dev/null >>   $meltcheckruntime_stamptemp
    echo "///end timestamp file $meltcheckruntime_stamp" >>   $meltcheckruntime_stamptemp
    $GCCMELT_MOVE_IF_CHANGE  $meltcheckruntime_stamptemp $meltcheckruntime_stamp
    meltbuild_info [+(.(fromline))+] done check runtime  $meltcheckruntime_stamp
else
    meltbuild_info [+(.(fromline))+] keeping runtime checks  $meltcheckruntime_stamp
fi

if [ "$melt_overall_goal" = "checkruntime" ]; then
    meltbuild_info [+(.(fromline))+] done checkruntime overall goal with stamp  $meltcheckruntime_stamp
    exit 0
fi
################################################################
################################################################
#@ [+(.(fromline))+]
if [ "$melt_overall_goal" = "regenerate" ]; then
    meltbuild_notice regenerating runtime support [+(.(fromline))+] 
    [ -d meltbuild-sources/generated ] || mkdir meltbuild-sources/generated
    meltregen_args=meltbuild-regen.args
    meltregen_argstemp="$meltregen_args-tmp$$"
    echo ' -DGCCMELT_FROM_ARG="[+(.(fromline))+]"' > $meltregen_argstemp
   meltbuild_arg mode=runtypesupport >> $meltregen_argstemp
    meltbuild_arg output=meltbuild-sources/generated/meltrunsup >> $meltregen_argstemp
    meltbuild_arg workdir=meltbuild-workdir >>  $meltregen_argstemp
    meltbuild_arg tempdir=meltbuild-tempdir >> $meltregen_argstemp
    meltbuild_arg source-path=meltbuild-sources >> $meltregen_argstemp
    meltbuild_arg module-path=meltbuild-modules >> $meltregen_argstemp
    meltbuild_arg bootstrapping  >> $meltregen_argstemp
    echo meltbuild-empty-file.c >> $meltregen_argstemp
    $GCCMELT_MOVE_IF_CHANGE  $meltregen_argstemp $meltregen_args
   meltbuild_info [+(.(fromline))+] $meltregen_args  is
   cat $meltregen_args < /dev/null >&2
    $GCCMELT_CC1PLUS_PREFIX $GCCMELT_CC1PLUS @$meltregen_args \
	|| meltbuild_error [+(.(fromline))+] failed with arguments @$meltregen_args
    meltbuild_info [+(.(fromline))+] done regenerate overall goal
    exit 0
fi

################################################################
################################################################
### the generated documentation meltgendoc.texi [+ (. (fromline))+]

if [   ! -f meltgendoc.texi [+FOR melt_translator_file " \\\n"+] -o meltbuild-sources/[+base+].melt -nt meltgendoc.texi [+ENDFOR melt_translator_file+] \
 [+FOR melt_application_file " \\\n"+] -o meltbuild-sources/[+base+].melt -nt meltgendoc.texi [+ENDFOR melt_application_file+]  ]; then
   meltbuild_info [+(.(fromline))+] generating meltgendoc.texi
   meltgen_args=meltbuild-gendoc.args-tmp$$
   echo ' -DGCCMELT_FROM_ARG="[+(.(fromline))+]"' > $meltgen_args
   meltbuild_arg mode=makedoc >> $meltgen_args
   meltbuild_arg output=meltgendoc.texi >> $meltgen_args
   meltbuild_arg init=@$MELTGCCBUILTIN_DEFAULT_MODLIS.quicklybuilt >> $meltgen_args
   meltbuild_arg workdir=meltbuild-workdir >>  $meltgen_args
   meltbuild_arg tempdir=meltbuild-tempdir >> $meltgen_args
   meltbuild_arg source-path=meltbuild-sources >> $meltgen_args
   meltbuild_arg module-path=meltbuild-modules >> $meltgen_args
meltbuild_arg "module-cflags=\"$GCCMELT_COMPILER_FLAGS\"" >> $meltgen_args
meltbuild_arg "module-makefile=\"$GCCMELT_MODULE_MK\""  >>  $meltgen_args
   meltbuild_arg bootstrapping  >> $meltgen_args 
   meltbuild_arg arglist=[+FOR melt_translator_file ","+][+base+].melt[+ENDFOR melt_translator_file+],[+FOR melt_application_file ","+][+base+].melt[+ENDFOR melt_application_file+]  >> $meltgen_args 
   echo meltbuild-empty-file.c >> $meltgen_args
   $GCCMELT_MOVE_IF_CHANGE  $meltgen_args meltbuild-gendoc.args
   meltbuild_info [+(.(fromline))+]  meltbuild-gendoc.args is
   cat meltbuild-gendoc.args < /dev/null >&2
   $GCCMELT_CC1PLUS_PREFIX $GCCMELT_CC1PLUS @meltbuild-gendoc.args \
     || meltbuild_error [+(.(fromline))+]  "$GCCMELT_CC1PLUS" failed with arguments @meltbuild-gendoc.args
else
   meltbuild_info [+(.(fromline))+] keeping meltgendoc.texi
fi

################
meltbuild_info [+(.(fromline))+] successfully done with times at `date '+%x %H:%M:%S'`: ; times >&2

################################################################
#@ [+(.(fromline))+]
if [ "$melt_overall_goal" = "gendoc" ]; then
    meltbuild_info [+(.(fromline))+] done gendoc overall goal with stamp  $melt_final_translator_stamp
    exit 0
fi

## #@ [+(.(fromline))+] if we get here something is wrong in this script
meltbuild_error  [+(.(fromline))+] unexpected MELT overall goal "$melt_overall_goal" buggy melt-build-script.tpl
#@ eof [+(.(fromline))+] end of generated melt-build-script.sh