File: wscript

package info (click to toggle)
guitarix 0.36.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, sid
  • size: 139,468 kB
  • sloc: cpp: 317,557; python: 42,482; ansic: 18,301; fortran: 2,012; sh: 662; makefile: 422; xml: 208; perl: 183; pascal: 74; lisp: 32
file content (1125 lines) | stat: -rw-r--r-- 44,571 bytes parent folder | download
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
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
#! /usr/bin/env python
# encoding: utf-8

import sys, os, re, shutil
import Build, Utils, Options, Logs, Configure, Scripting
from Constants import HEXVERSION
from Configure import ConfigurationError
from TaskGen import feature
import wscript_dsp

# Waf version check, for global waf installs

try:
    from Constants import WAFVERSION
except:
    WAFVERSION='1.0.0'
if WAFVERSION[:3] != '1.5':
    print('Incompatible Waf, use 1.5')
    sys.exit (1)

# these variables are mandatory ('/' are converted automatically)
srcdir = '.'
blddir = 'build'
use_2to3 = True

# used by waf dist and waf build
VERSION='0.36.1'
APPNAME='guitarix'

good_faust_versions = ['0.9.90']

g_maxlen = 40 # maximum width of message for 2-column display


################################################################
# options defined for waf configure
################################################################

def set_options(opt):
    
    def add_enable_option (option, desc, group=None, disable=False):
        if group == None:
            group = opt
        option_ = option.replace ('-', '_')
        group.add_option ('--enable-' + option, action='store_true',
            default=False, help='Enable ' + desc, dest='enable_' + option_)
        group.add_option ('--disable-' + option, action='store_true',
            default=disable, help='Disable ' + desc, dest='disable_' + option_)

    opt.tool_options('gcov')
    opt.tool_options ('intltool')
    group = opt.add_option_group ('Localization and documentation', '')
    add_enable_option ('nls', 'native language support', group)

    opt.tool_options('compiler_cxx')
    comp = opt.get_option_group("--check-cxx-compiler")

    comp.add_option('--debug',
                    action='store_const',
                    default=False,
                    const=True,
                    help='set compiler flags for a debug build')

    comp.add_option('--cxxflags-release',
                    type='string',
                    default='-O3 -DNDEBUG',
                    dest='cxxflags_release',
                    help='additional C++ compiler flags for release version (not used if --debug) [Default: %default]')

    comp.add_option('--cxxflags-debug',
                    type='string',
                    default='-O2 -g -fstack-protector-all',
                    dest='cxxflags_debug',
                    help='additional C++ compiler flags for debug version (only used if --debug) [Default: %default]')

    comp.add_option('--cxxflags',
                    type='string',
                    default='-Wall', # -fomit-frame-pointer -ffast-math -fstrength-reduce -mmmx -mfpmath=sse -DUSE_XMMINTRIN -pipe
                    dest='cxxflags',
                    help='C++ base compiler flags [Default: %default]')

    comp.add_option('--disable-cxx11',
                    action='store_const',
                    default=False,
                    const=True,
                    help='deselect C++ compiler flag -std=c++11 [Default: False]')

    comp.add_option('--ldflags',
                    type='string',
                    default='', 
                    dest='ldflags',
                    help='C++ base linker flags ')

    comp.add_option('--enable-lfs',
                    action='store_const',
                    default=False, 
                    const=True,
                    help='enable Large File Support (LFS)  ')

    comp.add_option('--optimization',
                    action='store_const',
                    default=False, #'-fomit-frame-pointer -ffast-math -fstrength-reduce -pipe',
                    const=True,
                    help='automatically select additional C++ compiler optimization flags for the current platform')

    comp.add_option('--no-desktop-update',
                    action='store_const',
                    default=False, #'-fomit-frame-pointer -ffast-math -fstrength-reduce -pipe',
                    const=True,
                    help='dont automatically update desktop database')


    opt.recurse('libgxw/gxw')
    opt.recurse('libgxwmm/gxwmm')

    comp = opt.add_option_group("Additional Library Options")

    comp.add_option('--includeresampler',
                    action='store_const',
                    default=False,
                    const=True,
                    help='build with included local zita-resample libary (Default NO)')

    comp.add_option('--includeconvolver',
                    action='store_const',
                    default=False,
                    const=True,
                    help='build with included local zita-convolver libary (Default NO)')

    comp.add_option('--convolver-ffmpeg',
                    action='store_const',
                    default=False,
                    const=True,
                    help='modified zita-convolver libary that uses ffmpeg instead of fftw3 for FFT (Default NO)')

    comp.add_option('--libdir',
                   type='string',
                   default='', 
                   dest='libdir',
                   help=('library install path '),
                   )

    faust = opt.add_option_group("Faust-Compiler")

    if len(good_faust_versions) == 1:
        faust_vers_str = good_faust_versions[0]
    else:
        faust_vers_str = "in [%s]" % ", ".join(good_faust_versions)

    faust.add_option('--faust',
                     action='store_const',
                     default=False,
                     const=True,
                     help=('use faust even if the installed version is not %s'
                           % faust_vers_str))

    faust.add_option('--no-faust',
                     action='store_const',
                     default=False,
                     const=True,
                     help="don't use faust, use the pre-built files in faust-generated")

    faust.add_option('--faust-float',
                     action='store_const',
                     default=False,
                     const=True,
                     help="build with faust, single precision")

    faust.add_option('--faust-vectorize',
                     action='store_const',
                     default=False,
                     const=True,
                     help="call faust with --vectorize")

    faust.add_option('--faust-vectorize-float',
                     action='store_const',
                     default=False,
                     const=True,
                     help=("call faust with --vectorize for sources built"
                           "in single (float) precision"))

    faust.add_option('--faust-options', help="additional faust options")

    ladspa = opt.add_option_group("LADSPA Options (installing ladspa modules)")

    ladspa.add_option('--no-ladspa',
                    action='store_const',
                    default=False,
                    const=True,
                    help="don't build ladspa plugins (Default yes)")

    ladspa.add_option('--no-new-ladspa',
                    action='store_const',
                    default=False,
                    const=True,
                    help=("don't build with new ladspa plugins (Default yes)"))


    ladspa.add_option('--ladspadir',
                    type='string',
                    help='LADSPA plugin directory [Default: <prefix>/lib/ladspa]')

    lv2 = opt.add_option_group("LV2 Options (installing LV2 modules)")

    lv2.add_option('--lv2dir',
                    type='string',
                    help='LV2 plugin directory [Default: <prefix>/lib/lv2]')

    lv2.add_option('--no-lv2',
                    action='store_const',
                    default=False,
                    const=True,
                    help=("don't build new lv2 plugins (Default no)"))

    lv2.add_option('--no-lv2-gui',
                    action='store_const',
                    default=False,
                    const=True,
                    help=("don't build lv2 plugin GUI's (Default no)"))

    lv2.add_option('--lv2-only',
                    action='store_const',
                    default=False,
                    const=True,
                    help=("build only the lv2 plugins (Default no)"))

    lv2.add_option('--no-mod-lv2',
                    action='store_const',
                    default=False,
                    const=True,
                    help=("don't install MOD lv2 GUI's (Default no)"))

    lv2.add_option('--disable-sse',
                    action='store_const',
                    default=False,
                    const=True,
                    help=("disable SSE for lv2 plugins (ARM)"))

    style = opt.add_option_group("Style Options (installing font)")
    
    style.add_option('--install-roboto-font',
                    action='store_const',
                    default=False,
                    const=True,
                    help=("install the included roboto condensed font"))
    
    style.add_option('--fontdir',
                    type='string',
                    help=('roboto condensed font install directory [Default: <prefix>/share/fonts/truetype]'))
    
    style.add_option('--no-font-cache-update',
                    action='store_const',
                    default=False, 
                    const=True,
                    help='dont automatically update font cache')
    

    opt.recurse('pygxw')
    opt.recurse('glade-gxw')

    opt.tool_options('compiler_cc') # for pygxw and glade-gxw

    opt.add_option('--dist-tree',
                   type='string',
                   dest='dist_tree',
                   help=("option for 'dist' command: git tree-ish to build"
                         " the archive from [Default: %s]" % 'V%s' % VERSION))

    opt.sub_options('src/gx_head');


################################################################
# waf configure
################################################################

################################################################
# configuration display helper functions
#

def print_msg(msg, nl=True):
    s = sys.stdout
    if nl:
        t = "\n"
    else:
        t = " "
    s.write(msg+t)

# a bit of waf display formatting
def display_msg(msg, status = None, color = None):
    sr = msg
    global g_maxlen
    g_maxlen = max(g_maxlen, len(msg))
    if status:
        print_msg("%s :" % msg.ljust(g_maxlen),False)
        Utils.pprint(color, status)
    else:
        print_msg("%s" % msg.ljust(g_maxlen))

def error_msg(msg):
    Utils.eprint('RED', msg)

def display_feature(msg, build):
    if build:
        display_msg(msg, "yes", 'CYAN')
    else:
        display_msg(msg, "no", 'YELLOW')

################################################################
# configuration utility functions
#

def option_enabled (option):
    if getattr (Options.options, 'enable_' + option):
        return True
    if getattr (Options.options, 'disable_' + option):
        return False
    return True

def append_optimization_flags(cxxflags):
    cpu_model = None
    x86_flags = None
    try:
        for line in open("/proc/cpuinfo"):
            if cpu_model is None:
                if line.startswith("model name"):
                    cpu_model = line.split(":",1)[1].strip()
            elif x86_flags is None:
                if line.startswith("flags"):
                    x86_flags = line.split(":",1)[1].strip()
            else:
                break
    except IOError:
        pass
    if cpu_model is None or x86_flags is None:
        display_msg("Checking CPU Architecture",
                    "cpu model not found in /proc/cpuinfo",
                    "YELLOW")
        return None
    model = cpu_model.split()
    arch = os.uname()[4]
    if "AMD" in model and "x86_64" in arch:
        cxxflags.append ("-march=k8")
    elif "AMD" in model and "Sempron(tm)" in model:
        cxxflags.append ("-march=native")
    elif "Geode" in model :
        cxxflags.append ("-march=geode")
    elif "Core" in model and "x86_64" in arch:
        cxxflags.append ("-march=core2")
    elif "i386" in arch:
        cxxflags.append ("-march=i386")
    elif "i486" in arch:
        cxxflags.append ("-march=i486")
    elif "i586" in arch:
        cxxflags.append ("-march=i586")
    elif "i686" in arch:
        cxxflags.append ("-march=i686")
    else:
        cxxflags.append ("-march=native")

    if "mmx" in x86_flags:
        cxxflags.append ("-mmmx")
    if "3dnow" in x86_flags:
        cxxflags.append ("-m3dnow")

    if "sse5" in x86_flags:
        cxxflags.append ("-msse5")
        cxxflags.append ("-mfpmath=sse")
    elif "sse4_2" in x86_flags:
        cxxflags.append ("-msse4.2")
        cxxflags.append ("-mfpmath=sse")
    elif "sse4_1" in x86_flags:
        cxxflags.append ("-msse4.1")
        cxxflags.append ("-mfpmath=sse")
    elif "ssse3" in x86_flags:
        cxxflags.append ("-mssse3")
        cxxflags.append ("-mfpmath=sse")
    elif "sse4a" in x86_flags:
        cxxflags.append ("-msse4a")
        cxxflags.append ("-mfpmath=sse")
    elif "sse4" in x86_flags:
        cxxflags.append ("-msse4")
        cxxflags.append ("-mfpmath=sse")
    elif "sse3" in x86_flags:
        cxxflags.append ("-msse3")
        cxxflags.append ("-mfpmath=sse")
    elif "sse2" in x86_flags:
        cxxflags.append ("-msse2")
        cxxflags.append ("-mfpmath=sse")
        #cxxflags.append ("-DUSE_XMMINTRIN")
    elif "sse" in x86_flags:
        cxxflags.append ("-msse")
        cxxflags.append ("-mfpmath=sse")
        # cxxflags.append ("-DUSE_XMMINTRIN")

    if not Options.options.debug:
        cxxflags.append ("-fomit-frame-pointer")
    cxxflags.append ("-ftree-loop-linear")
    cxxflags.append ("-ffinite-math-only")
    cxxflags.append ("-fno-math-errno")
    cxxflags.append ("-fno-signed-zeros")
    #cxxflags.append ("-ffast-math") # quicker but doesn't seem to work (difference in sound output)
    #cxxflags.append ("-malign-double")
    cxxflags.append ("-fstrength-reduce")
    cxxflags.append ("-pipe")
    return cpu_model

@Configure.conf
def cfg_get_variable(self, package, variable, prefix=""):
    p = Utils.pproc.Popen(["pkg-config", "--variable="+variable, package],
                          stdout=Utils.pproc.PIPE, shell=False)
    v = p.communicate()[0].strip()
    if p.returncode or not v:
        self.fatal('fail to get variable %s for package %s' % (variable, package))
    self.env[prefix+variable.upper()] = v


################################################################
# configuration helper functions
#
def sub_file(src_fname, dst_fname, lst):

    f = open(src_fname, 'rU')
    txt = f.read()
    f.close()

    for (key, val) in lst:
        re_pat = re.compile(key, re.M)
        txt = re_pat.sub(val, txt)

    f = open(dst_fname, 'w')
    f.write(txt)
    f.close()

def check_roboto_font(conf):
    if Utils.exec_command("fc-list | grep RobotoCondensed >/dev/null") != 0:
        conf.font_msg = "\nRobotoCondensed font not found: please install the fonts-roboto package from your distribution (recommended)\nor use --install-roboto-font to install the included roboto font."
        conf.check_message('font RobotoCondensed','',0)
        conf.env['FONTMSG'] = True
    else:
        conf.check_message('font RobotoCondensed','',1)
  
def check_faust(conf):
    if Options.options.no_faust:
        conf.env['FAUST'] = None
        return
    conf.find_program("faust", var='FAUST')
    if not conf.env['FAUST']:
        return
    try:
        s = Utils.cmd_output('%s --version' % conf.env['FAUST'])
    except ValueError:
        Logs.warn('count not execute faust')
        return
    m = re.match(r".*Version\s*(.*)", s)
    if not m:
        Logs.warn('could not determine faust version')
    vers = m.group(1)
    conf.env["FAUST_VERSION"] = vers
    if vers not in good_faust_versions and not Options.options.faust:
        conf.env['FAUST'] = None
        conf.check_message_custom('faust','version',"can't use %s (check ./waf --help)" % vers,color='YELLOW')
    else:
        conf.check_message('faust','version',1,vers)
    conf.env['FAUST_DOUBLE'] = not Options.options.faust_float
    conf.env['FAUST_VECTORIZE'] = Options.options.faust_vectorize
    conf.env['FAUST_VECTORIZE_FLOAT'] = Options.options.faust_vectorize_float
    conf.env['FAUST_OPTIONS'] = Options.options.faust_options

def check_cloop(conf):
    code = """
    int
    main (void)
    {
    #define max(x, y) (((x) > (y)) ? (x) : (y))
    #define min(x, y) (((x) < (y)) ? (x) : (y))
    for (int p1=0;p1<=5;p1++) {
        for (int p2=0;p2<=10;p2++) {
            for (int i=max(2*p1,0);i<=min(10,2*p1+1);i++) {
                for (int j=max(2*p2,0);j<=min(20,2*p2+1);j++) {
                    ;
                }
            }
        }
    }
    return 0;
    }
    """
    msg = "Checking for libcloog-ppl0" 
    conf.check_cxx(msg = msg, fragment=code, cxxflags=[ '-O3', '-ftree-loop-linear'], define_name="NOOPT")

def check_boost(conf):
    code="""
    #include <boost/system/error_code.hpp>
    int main() { boost::system::error_code c; }
    """
    msg = "Checking for boost-system " 
    conf.check_cxx(msg = msg, fragment=code, lib="boost_system", uselib_store="BOOST_SYSTEM", mandatory=1)
    # some boost (>1.49) versions depend on boost-system so we will check for it first
    # and later link against boost_system were boost headers are included.
    boost_atleast_version = 104200
    boost_atleast_vermsg = "1.42"
    code="""
    #include <boost/version.hpp>
    #include <boost/format.hpp>
    #include <boost/thread.hpp>
    #if BOOST_VERSION < %d
    #error
    #endif
    int main(){ return 0; }
    """ % boost_atleast_version
    msg = "Checking for boost >= %s" % boost_atleast_vermsg
    conf.check_cxx(msg = msg, fragment=code, lib="boost_system", mandatory=1)
    # not needed: with boost 1.42 Guitarix doesn't generate code which
    #             references the boost threading lib
    #msg = "Checking for boost_thread%%s >= %s" % boost_atleast_vermsg
    #try:
    #    conf.check_cxx(
    #        msg = msg % "", fragment=code, lib="boost_thread", uselib_store="BOOST_THREAD",
    #        errmsg="not found, trying boost_thread-mt", mandatory=1)
    #except ConfigurationError:
    #    conf.check_cxx(
    #        msg = msg % "-mt",fragment=code, lib="boost_thread-mt",
    #        uselib_store="BOOST_THREAD", mandatory=1)

def check_zita_convolver(opt, conf):
    conf.env['CONVOLVER_FFMPEG'] = False
    if opt.includeconvolver:
        conf.env['ZITA_CONVOLVER'] = False
    elif opt.convolver_ffmpeg:
        conf.env['ZITA_CONVOLVER'] = False
        conf.env['CONVOLVER_FFMPEG'] = True
    else:
        expected_zita_convolver_version = 3
        code="""
        #include <zita-convolver.h>
        #if ZITA_CONVOLVER_MAJOR_VERSION != %d
        #error
        #endif
        int main(){ return 0; }
        """ % expected_zita_convolver_version
        conf.check_cxx(
            fragment=code,
            lib="zita-convolver",
            uselib_store='ZITA_CONVOLVER',
            msg='Checking for zita-convolver >= %d.0' % expected_zita_convolver_version,
            errmsg="version %d not found, using ours" % expected_zita_convolver_version,
            define_name="ZITA_CONVOLVER")

def check_zita_resampler(opt, conf):
    if opt.includeresampler:
        conf.env['ZITA_RESAMPLER'] = False
    else:
        expected_zita_resampler_version = 1
        code="""
        #include <zita-resampler/resampler.h>
        #include <zita-resampler/resampler-table.h>
        #if ZITA_RESAMPLER_MAJOR_VERSION != %d
        #error
        #endif
        int main(){ return 0; }
        """ % expected_zita_resampler_version
        conf.check_cxx(
            fragment=code,
            lib='zita-resampler',
            uselib_store='ZITA_RESAMPLER',
            msg='Checking for zita-resampler >= %d.0' % expected_zita_resampler_version,
            errmsg="version %d not found, using ours" % expected_zita_resampler_version,
            define_name="ZITA_RESAMPLER")

# Taken from Geany's wscript, modified to support LINGUAS variable
def write_linguas_file (self):
    linguas = ''
    # Depending on Waf version, getcwd() is different
    if os.path.exists ('./po'):
        podir = './po'
    else:
        podir = '../po'
    if 'LINGUAS' in Build.bld.env:
        files = Build.bld.env['LINGUAS']
        for f in files.split (' '):
            if os.path.exists (podir + '/' + f + '.po'):
                linguas += f + ' '
    else:
        files = os.listdir (podir)
        for f in files:
            if f.endswith ('.po'):
                linguas += '%s \n' % f[:-3]
    f = open (podir + '/LINGUAS', 'w')
    f.write ('# This file is autogenerated. Do not edit.\n%s' % linguas)
    f.close ()
write_linguas_file = feature ('intltool_po')(write_linguas_file)


################################################################
# guitarix waf configuration
#
 
def configure(conf):
    conf.font_msg = ""
    opt = Options.options
    if opt.disable_sse and opt.optimization:
        display_msg("configuration error", " cant use --disable-sse and --optimization together", 'RED')
        sys.exit(1)

    if 'LINGUAS' in os.environ: conf.env['LINGUAS'] = os.environ['LINGUAS']

    platform = Utils.detect_platform()
    conf.env['IS_MACOSX'] = platform == 'darwin'
    conf.env['IS_LINUX'] = platform == 'linux' or platform == 'posix'
    conf.env['IS_SUN'] = platform == 'sunos'

    if conf.env['IS_LINUX']:
        conf.define ('IS_LINUX', platform )

    if conf.env['IS_MACOSX']:
        conf.define ('IS_MACOSX', platform )

    if conf.env['IS_SUN']:
        conf.define ('IS_SUN', platform )

    conf.env['OS'] = platform

    def option_checkfatal (option, desc):
        if hasattr (opt, 'enable_' + option):
            if getattr (opt, 'enable_' + option):
                Utils.pprint ('RED', desc + ' N/A')
                sys.exit (1)
                
    if option_enabled ('nls'):
        conf.check_tool ('intltool')
        if conf.env['INTLTOOL'] and conf.env['POCOM']:
            nls = 'yes'
        else:
            option_checkfatal ('nls', 'localization')
            nls = 'N/A'
            conf.define ('DISABLE_NLS', 1)
    else:
        nls = 'no '
        conf.define ('DISABLE_NLS', 1)
        #sub_file('guitarix.desktop.in', 'build/default/guitarix.desktop', (('^_', '%s' % ""), ))
        sub_file('guitarix.desktop.in', 'guitarix.desktop._in', (('^_', '%s' % ""), ))
    conf.define ('GETTEXT_PACKAGE', APPNAME)

    conf.define ('ENABLE_NLS', [0,1][nls == 'yes'])
    # compiler
    conf.check_tool('compiler_cxx')
    if opt.with_gcov:
        conf.check_tool('gcov')
    if opt.python_wrapper or opt.glade_support:
        conf.check_tool('compiler_cc')
    conf.env['shlib_LINKFLAGS'].append("-fPIC") # error in waf 1.5.18?
    # linker flags
    conf.env.append_value('LDFLAGS', opt.ldflags.split())
    conf.env['LINKFLAGS'] = conf.env['LDFLAGS']
    if opt.lv2_only:
        opt.no_lv2 = False
        opt.no_ladspa = True
        opt.no_new_ladspa = True
        conf.env['NO_MAIN'] = True
        opt.no_desktop_update = True
    # needed libaries
    if not (opt.lv2_only):
        try:
            conf.check_cfg(package='jack', atleast_version='0.116.2', max_version='1.8.0', args='--cflags --libs', uselib_store='JACK', mandatory=1)
        except ConfigurationError:
            conf.check_cfg(package='jack', atleast_version='1.9.2', args='--cflags --libs', uselib_store='JACK', mandatory=1)
    # jack_session support
        code = "#include <jack/session.h>\nint main(){return JackSessionID != 0;}"
        conf.check_cxx(fragment=code, msg="Checking for jack session support", define_name='HAVE_JACK_SESSION')
        conf.check_cfg(package='gmodule-export-2.0', args='--cflags --libs', uselib_store='GMODULE_EXPORT', mandatory=1)

    conf.check_cfg(package='sndfile', atleast_version='1.0.17', args='--cflags --libs', uselib_store='SNDFILE', mandatory=1)
    if not (opt.lv2_only and opt.no_lv2_gui):
        conf.check_cfg(package='gtk+-2.0', atleast_version='2.20', args='--cflags --libs', uselib_store='GTK2', mandatory=1)
    conf.check_cfg(package='gthread-2.0', atleast_version='2.24', args='--cflags --libs', uselib_store='GTHREAD', mandatory=1)
    conf.check_cfg(package='glibmm-2.4', atleast_version='2.24', args='--cflags --libs', uselib_store='GLIBMM', mandatory=1)
    if not (opt.lv2_only and  opt.no_lv2_gui):
        conf.check_cfg(package='gtkmm-2.4', atleast_version='2.20', args='--cflags --libs', uselib_store='GTKMM', mandatory=1)
        conf.check_cfg(package='giomm-2.4', atleast_version='2.24', args='--cflags --libs', uselib_store='GIOMM', mandatory=1)
    conf.check_cfg(package='fftw3f', atleast_version='3.1.2', args='--cflags --libs', uselib_store='FFTW3', mandatory=1)
    if opt.convolver_ffmpeg:
        conf.check_cfg(package='libavcodec', args='--cflags --libs', uselib_store='LIBAVCODEC', mandatory=1)
        conf.check_cfg(package='libavutil', args='--cflags --libs', uselib_store='LIBAVUTIL', mandatory=1)
    if not (opt.lv2_only):
        conf.check_cfg(package='lrdf', args='--cflags --libs', uselib_store='LRDF', mandatory=1)
        conf.check(header_name='ladspa.h', mandatory=1)
        conf.check_cfg(package='lilv-0', args='--cflags --libs', uselib_store='LILV', mandatory=1)
        check_boost(conf)
        if not (opt.install_roboto_font):
            check_roboto_font(conf)

    conf.check_cfg(package='lv2', atleast_version='1.2.0',args='--cflags --libs', uselib_store='LV2CORE', mandatory=1)

    check_zita_convolver(opt, conf)
    check_zita_resampler(opt, conf)
    conf.find_program("gperf", var='HAVE_GPERF')
    check_faust(conf)
    if conf.env['FAUST']:
        if Options.options.faust_vectorize and Options.options.faust_vectorize_float:
            display_msg("configuration error", "conflicting options --faust-vectorize and --faust-vectorize-float", 'RED')
            sys.exit(1)
    else:
        if Options.options.faust_float:
            display_msg("configuration error", " can't use --faust-float without faust", 'RED')
            sys.exit(1)
        if Options.options.faust_vectorize:
            display_msg("configuration error", " can't use --faust-vectorize without faust", 'RED')
            sys.exit(1)
        if Options.options.faust_vectorize_float:
            display_msg("configuration error", " can't use --faust-vectorize-float without faust", 'RED')
            sys.exit(1)
        if Options.options.faust_options:
            display_msg("configuration error", " can't use --faust-options without faust", 'RED')
            sys.exit(1)
    if Options.options.generate_resources:
        conf.find_program('glib-compile-resources', var='HAVE_GLIB')

    # directory
    conf.env['SHAREDIR'] = conf.env['PREFIX'] + '/share'

    # defines for compilation
    gxsharedir = os.path.normpath(os.path.join(conf.env['SHAREDIR'], 'gx_head'))
    conf.define('GX_STYLE_DIR', os.path.join(gxsharedir,'skins'))
    if not opt.no_lv2:
        conf.define('GX_LV2_STYLE_DIR', os.path.join(conf.env['GX_STYLE_DIR'],'LV2'))
    conf.define('GX_FACTORY_DIR', os.path.join(gxsharedir,'factorysettings'))
    conf.define('GX_SOUND_DIR', os.path.join(gxsharedir,'sounds'))
    conf.define('GX_SOUND_BPB_DIR', os.path.join(conf.env['GX_SOUND_DIR'],'bands'))
    conf.define('GX_SOUND_BPA_DIR', os.path.join(conf.env['GX_SOUND_DIR'],'amps'))
    conf.define('GX_BUILDER_DIR', os.path.join(gxsharedir,'builder'))
    conf.define('GX_ICON_DIR', os.path.normpath(os.path.join(conf.env['SHAREDIR'], 'guitarix','icons')))
    conf.define('GX_PIXMAPS_DIR', os.path.normpath(os.path.join(conf.env['SHAREDIR'], 'pixmaps')))

    if opt.fontdir:
        conf.define('GX_FONTS_DIR', opt.fontdir)
    else:
        conf.define('GX_FONTS_DIR', os.path.normpath(os.path.join(conf.env['SHAREDIR'], 'fonts','truetype')))


    conf.define('GX_VERSION', VERSION)
    
    if conf.env.DEST_CPU=='x86_64': 
        conf.define('OS_64_BIT', 1)
    else:
        conf.define('OS_32_BIT', 1)

    if not opt.libdir:
        conf.env['LIBDIR'] = os.path.normpath(os.path.join(conf.env['PREFIX'], 'lib'))
    else:
        conf.env['LIBDIR'] = opt.libdir

    conf.env['BINDIR'] = os.path.normpath(os.path.join(conf.env['PREFIX'], 'bin'))
    conf.env['DESKAPPS_DIR'] = os.path.normpath(os.path.join(conf.env['SHAREDIR'], 'applications'))
    conf.env['BIN_NAME'] = APPNAME

    conf.env['LV2'] =  not opt.no_lv2
    conf.env['LV2ONLY'] =  opt.lv2_only
    conf.env['NOLV2GUI'] = opt.no_lv2_gui
    conf.env['NOMODGUI'] = opt.no_mod_lv2
    conf.env['NOSSE'] =  opt.disable_sse
    if not opt.no_lv2:
        if opt.lv2dir:
            conf.env['LV2DIR'] = opt.lv2dir
        else:
            conf.env['LV2DIR'] = os.path.normpath(os.path.join(conf.env['LIBDIR'], 'lv2'))

    conf.env['NEW_LADSPA'] = not opt.no_ladspa and not opt.no_new_ladspa
    conf.env['LADSPA'] = not opt.no_ladspa
    if not opt.no_ladspa:
        if opt.ladspadir:
            conf.env['LADSPADIR'] = opt.ladspadir
        else:
            conf.env['LADSPADIR'] = os.path.normpath(os.path.join(
                conf.env['LIBDIR'], 'ladspa'))

    conf.env['FONT'] = opt.install_roboto_font
    if opt.no_font_cache_update:
        conf.env["NO_UPDATE_FONT_CACHE"] = True

    # g++ flags
    cxxflags = opt.cxxflags.split()
    if opt.debug:
        cxxflags += opt.cxxflags_debug.split()
    else:
        cxxflags += opt.cxxflags_release.split()
    if  opt.enable_lfs:
        cxxflags.append ("-D_FILE_OFFSET_BITS=64")
    cpu_model = None
    if opt.optimization:
        check_cloop(conf)
        if conf.env['NOOPT']:
            conf.env['OPT'] = False
            cpu_model = append_optimization_flags(cxxflags)
    if not opt.disable_cxx11:
        cxxflags.append ("-std=c++11")
    conf.env['CXXFLAGS'] += cxxflags

    if opt.no_desktop_update:
        conf.env["NO_UPDATE_DESKTOP_DATA_BASE"] = True

    # pygobject is used by both python and c++ wrapper
    if opt.python_wrapper or opt.generate_cpp_wrapper:
        conf.check_tool('python')
        conf.check_cfg(package='pygobject-2.0', args='--cflags --libs', uselib_store='PYGOBJECT', mandatory=True)
        conf.cfg_get_variable(package='pygobject-2.0', variable='codegendir')

    if not conf.env['NO_MAIN']:
        conf.sub_config('src/gx_head');
    if conf.env['FAUST']:
        conf.sub_config('src/faust');
    conf.sub_config('src/plugins');
    if conf.env["LADSPA"]:   
        conf.sub_config('ladspa');
    if conf.env["LV2"]:
        opt.shared_lib = True;
        conf.sub_config('src/LV2');
        
        # config subdirs
    if not (opt.lv2_only and opt.no_lv2_gui):
        conf.sub_config('pygxw');
        conf.sub_config('glade-gxw');
        conf.sub_config('libgxwmm');
        conf.sub_config('libgxw/gxw');

        conf.sub_config('rcstyles');
        if conf.env["GX_LIB_DEV"]:
            pa = conf.env['PREFIX']
            sub_file('./libgxw/gxw.pc.in', './libgxw/gxw.pc', (('prefix=/path', 'prefix=%s' % pa), ))
            sub_file('./libgxw/gxw.pc', './libgxw/gxw.pc', (('libdir=/path','libdir=%s' % conf.env['LIBDIR']), ))
            sub_file('./libgxwmm/gxwmm.pc.in', './libgxwmm/gxwmm.pc', (('prefix=/path', 'prefix=%s' % pa), ))
            sub_file('./libgxwmm/gxwmm.pc', './libgxwmm/gxwmm.pc', (('libdir=/path','libdir=%s' % conf.env['LIBDIR']), ))

    if opt.jobs:
        conf.env['JOBS'] = str(opt.jobs)

    # writing config.h
    conf.write_config_header('config.h')
    
    # some output
    print("")
    display_msg("==================")
    version_msg = "GUITARIX II " + VERSION
    print_msg(version_msg)
    
    print_msg("")
    display_msg("OS ", conf.env['OS'], 'CYAN')
    if conf.env['NO_MAIN']:
        display_msg("Guitarix main build ", "dissabled", 'RED')
    if cpu_model:
        display_msg("CPU version" , "%s" % cpu_model, "CYAN")
    if not conf.env['NOOPT'] and opt.optimization:
        display_msg("package libcloog-ppl0 not found", "optimization is disabled", "RED")
    display_msg("C++ flags", " ".join(conf.env['CXXFLAGS']), 'CYAN')
    display_msg("Link flags", " ".join(conf.env['LINKFLAGS']), 'CYAN')
    display_msg("Compiler %s version" %conf.env["CXX"], "%s" % ".".join(conf.env["CC_VERSION"]), "CYAN")
    if opt.jobs:
        display_msg("Parallel build jobs", conf.env['JOBS'], 'CYAN')
    display_feature("Use prebuild faust files", not conf.env['FAUST'])
    if not opt.faust_float:
        display_msg("Use faust precision", "double", 'CYAN')
    else:
        display_msg("Use faust precision", "single", 'CYAN')
    if opt.faust_vectorize:
        display_msg("call faust with --vectorize", conf.env['FAUST_VECTORIZE'], 'CYAN')
    if opt.faust_vectorize_float:
        display_msg("faust vectorize float prec.", conf.env['FAUST_VECTORIZE_FLOAT'], 'CYAN')
    if opt.faust_options:
        display_msg("Additional faust options", conf.env['FAUST_OPTIONS'], 'CYAN')
    display_feature("Use prebuild gperf files", not conf.env["HAVE_GPERF"])
    display_feature("Use prebuild gresouce file", not conf.env["HAVE_GLIB"])
    display_feature("Avahi service discovery", conf.env["HAVE_AVAHI"])
    display_feature("Bluetooth rfcomm", conf.env["HAVE_BLUEZ"])
    display_feature("Use internal zita-resampler", not conf.env['ZITA_RESAMPLER'])
    if conf.env['CONVOLVER_FFMPEG']:
        display_feature("Use zita-convolver-ffmpeg", True)
    else:
        display_feature("Use internal zita-convolver", not conf.env['ZITA_CONVOLVER'])
    display_feature("Jack Session Support", conf.env['HAVE_JACK_SESSION'])

    display_feature("build ladspa plugins", conf.env['LADSPA'])
    display_feature("build lv2 plugins", conf.env['LV2'])
    display_feature("build lv2 plugin GUI's", not conf.env['NOLV2GUI'])
    display_feature("install MOD lv2 plugin GUI's", not conf.env['NOMODGUI'])
    if not opt.no_lv2:
        display_feature("SSE2 support found", conf.env['SSE2'])
        display_feature("SSE2 support disabled", conf.env['NOSSE'])
    display_feature("skip Python Library Wrapper", not conf.env['GX_PYTHON_WRAPPER'])
    display_feature("use prebuild C++ Library Wrapper", conf.env['USE_GENERATED_CPP'])
    display_feature("skip building shared lib", not conf.env['GX_LIB_SHARED'])
    display_feature("skip install lib-dev", not conf.env['GX_LIB_DEV'])
    display_feature("run ldconfig tool", not conf.env['NO_LDCONFIG'])
    display_feature("update desktop database", not conf.env['NO_UPDATE_DESKTOP_DATA_BASE'])
    display_feature("Localization  (intltool)", conf.env['ENABLE_NLS'])
    display_feature("skip glade support", not conf.env['GX_GLADE_SUPPORT'])
    if conf.env['GX_GLADE_SUPPORT']:
        display_msg("glade catalog dir", conf.env['GLADE_CATALOG_DIR'], 'CYAN')
        display_msg("glade modules dir", conf.env['GLADE_MODULES_DIR'], 'CYAN')
    display_msg("Install prefix", conf.env['PREFIX'], 'CYAN')
    if not conf.env['NO_MAIN']:
        display_msg("Install binary", conf.env['BINDIR'], 'CYAN')
    display_msg("Install library", conf.env['LIBDIR'], 'CYAN')
    if conf.env['FONT']:
        display_msg("Install font roboto condensed", conf.env['GX_FONTS_DIR'], 'CYAN')
        display_feature("Update Font config cache", not conf.env["NO_UPDATE_FONT_CACHE"])
    if not opt.no_ladspa:
        display_msg("Install ladspa", conf.env['LADSPADIR'], 'CYAN')
    if not opt.no_lv2:
        display_msg("Install lv2", conf.env['LV2DIR'], 'CYAN')
    if not conf.env['NO_MAIN']:
        display_msg("Guitarix shared files directory", gxsharedir, 'CYAN')
        display_msg("Guitarix pixmaps directory", conf.env['GX_PIXMAPS_DIR'], 'CYAN')
    if conf.env['g++']:
       error_msg("ERROR       !!! Compiler version is too old !!!")
    if conf.env['FONTMSG']:
        display_msg('Font config',conf.font_msg,'RED')
    print_msg("")


################################################################
# Build / Install
################################################################

def install_hook(ctx):
    try:
        Utils.exec_command("fc-cache -fv")
    except:
        pass

def post(ctx):
    if os.geteuid() == 0:
        Utils.exec_command('/sbin/ldconfig')

def build(bld):
    if bld.env['JOBS'] and Options.options.jobs == Options.default_jobs:
        Options.options.jobs = int(bld.env['JOBS'])

    if bld.env['INTLTOOL']:
        obj = bld.new_task_gen ('intltool_po')
        obj.podir = 'po'
        obj.appname = APPNAME


    # process subfolders from here
    if bld.env["LADSPA"]:
        bld.add_subdirs('ladspa')
    if not (bld.env['LV2ONLY'] and bld.env['NOLV2GUI']):
        bld.add_subdirs('libgxw/gxw')
        bld.add_group()
        bld.add_subdirs('libgxwmm')
        bld.add_subdirs('glade-gxw')
        bld.add_subdirs('pygxw')
    if not bld.env['NO_MAIN']:
        bld.add_subdirs('src/faust')
        bld.add_subdirs('src/plugins')
        bld.add_subdirs('rcstyles')
        bld.add_subdirs('pixmaps')
        bld.add_subdirs('src/gx_head')
    if bld.env["NEW_LADSPA"]:
        bld.add_subdirs('src/ladspa')
    if bld.env["LV2"]:
        bld.add_subdirs('src/LV2')

    if not bld.env['NO_MAIN']:
        if bld.env['FONT']:
            bld.install_files(os.path.join(bld.env['GX_FONTS_DIR'], 'robotocondensed'), './fonts/*', chmod=0o644)
            if not bld.env["NO_UPDATE_FONT_CACHE"]:
                bld.add_post_fun(install_hook)

        bld.install_files(bld.env['DESKAPPS_DIR'], 'guitarix.desktop', chmod=0o644)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/dirlist.js', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/brummer.gx', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/HarryVH.gx', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/Sonnie_Tele.gx', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/univibe', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/univibe_mono', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/flanger_mono_gx', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/jconv', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/mbc', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/mbcs', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/graphiceq', chmod=0o664)
        bld.install_files(bld.env['GX_FACTORY_DIR'], 'factorysettings/jconv_mono', chmod=0o664)
        # "greathall.wav" is referenced in the source (keep in sync when changing)
        bld.install_files(bld.env['GX_SOUND_DIR'], './IR/greathall.wav', chmod=0o664)
        bld.install_files(bld.env['GX_SOUND_BPB_DIR'], './IR/BestPlugins_Bands/*', chmod=0o664)
        bld.install_files(bld.env['GX_SOUND_BPA_DIR'], './IR/BestPlugins_Amps/*', chmod=0o664)

        if not bld.env['DISABLE_NLS']:
            gen_desktop = bld(features  = "intltool_in",
                podir     = "po",
                flags     = ["-d", "-q", "-u", "-c"],
                source    = 'guitarix.desktop.in',
                target    = 'guitarix.desktop',
                install_path = "${DATADIR}/applications",
            )
        
            # hacked in scanner method so the desktop file gets rebuild
            # when any po file changes; don't know if there is a better way
            gen_desktop_create_task = gen_desktop.create_task
            def gen_desktop_add_scanner(*args,**kw):
                task = gen_desktop_create_task(*args,**kw)
                def po_scanner():
                    gen = task.generator
                    podir = gen.bld.srcnode.find_dir(gen.podir)
                    return (podir.ant_glob("*.po", flat=False), [])
                task.scan = po_scanner
                return task
            gen_desktop.create_task = gen_desktop_add_scanner
        else:
            gen_desktop = bld(features  = "subst",
                source    = 'guitarix.desktop._in',
                target    = 'guitarix.desktop',
                install_path = "${DATADIR}/applications",
                VAR        = ""
            )
            gen_desktop.create_task
        if Options.commands["install"]:  ## newer waf version: bld.cmd == 'install'
            if not bld.env["NO_UPDATE_DESKTOP_DATA_BASE"]:
                try:
                    bld.exec_command(["update-desktop-database", Utils.subst_vars("${DATADIR}/applications", bld.env)])
                except:
                    pass


    if bld.env["GX_LIB_SHARED"]:
        if not bld.env["NO_LDCONFIG"]:
            bld.add_post_fun(post)
    if bld.env["GX_LIB_DEV"]:
        bld.install_files('${PREFIX}/include/gxw','libgxw/gxw/*.h')
        bld.install_files('${PREFIX}/include','libgxw/gxw.h')
        bld.install_files('${LIBDIR}/pkgconfig', './libgxw/gxw.pc')
        bld.install_files('${PREFIX}/include/gxwmm','libgxwmm/gxwmm-generated/*.h')
        bld.install_files('${PREFIX}/include/gxwmm','libgxwmm/gxwmm/*.h')
        bld.install_files('${PREFIX}/include','libgxwmm/gxwmm.h')
        bld.install_files('${LIBDIR}/pkgconfig', './libgxwmm/gxwmm.pc')

################################################################
# other commands
################################################################

def etags(ctx):
    "Create an Emacs ETAGS file for the src directory"
    cmd = ("etags -o TAGS libgxw/gxw/*.cpp libgxwmm/gxwmm/*.ccg libgxwmm/gxwmm/*.hg"
           " libgxw/gxw/*.h src/gx_head/engine/*.cpp src/gx_head/engine/*.cc"
           " src/gx_head/gui/*.cpp src/headers/*.h")
    Logs.debug("runner: system command -> %s" % cmd)
    Utils.exec_command(cmd)

def update_pot(ctx):
    "extract all text for localization into po/untitled.pot"
    Utils.exec_command("cd po && intltool-update -p")

dir_prefix = "guitarix"
tar_prefix = "guitarix2"
tar_ext = ".tar.xz"

def _make_dict():
    import Options
    t = Options.options.dist_tree
    if not t:
        t = 'V%s' % VERSION
    d = dict(t=t, d=dir_prefix, p=tar_prefix, e=tar_ext)
    if re.match(r"V\d", t):
        d["v"] = t[1:]
        if Utils.exec_command("git show-ref --verify --quiet --tags refs/tags/'%(t)s'" % d) != 0:
            raise Utils.WafError(
                "tag '%(t)s' not found: please create revision tag" % d)
    else:
        d["v"] = t[1:]
        try:
            s = Utils.cmd_output("git show-ref --hash=8 '%(t)s' | sort -u" % d)
            if not s:
                raise ValueError
            s = s.split()
            if len(s) > 1:
                raise Utils.WafError(
                    "git tree-ish '%(t)s' is ambiguous" % d)
            s = s[0]
        except ValueError:
            raise Utils.WafError(
                "git tree-ish '%(t)s' not found" % d)
        d["v"] = "git-" + s.strip()
    return d

def dist(ctx):
    "makes a tarball for redistributing the sources"
    Utils.exec_command("git config tar.tar.xz.command \"xz -c\"")
    Utils.exec_command(
        "git archive --format=tar.xz --prefix=%(d)s-%(v)s/ %(t)s ."
        " > %(p)s-%(v)s%(e)s" % _make_dict())

def distcheck(ctx):
    '''checks if the sources compile (tarball from 'dist')'''
    import tempfile, tarfile, lzma, contextlib
    waf = os.path.abspath(sys.argv[0])
    d = _make_dict()
    tarball = "%(p)s-%(v)s%(e)s" % d
    path = "%(d)s-%(v)s" % d
    if os.path.exists(path):
        try:
            raw_input("%s exists, press enter to remove (stop with Ctrl-C)\n" % path)
        except KeyboardInterrupt:
            print("")
            raise Utils.WafError('distcheck cancelled')
            return
        else:
            print("removing %s" % path)
        shutil.rmtree(path)
    print("creating tarball and extracting files into %s" % path)
    dist(ctx)
    with contextlib.closing(lzma.LZMAFile(tarball)) as xz:
        with tarfile.open(fileobj=xz) as t:
            for x in t:
                t.extract(x)
        t.close()
    build_path = path
    instdir = tempfile.mkdtemp('.inst', path)
    cmdargs = [waf,'configure','build','install','uninstall', '--destdir='+instdir]
    print('starting "%s"' % (" ".join(cmdargs)))
    print("")
    ret = Utils.pproc.Popen(cmdargs, cwd=build_path).wait()
    if ret:
        raise Utils.WafError('distcheck failed with code %i'%ret)
    if os.path.exists(instdir):
        raise Utils.WafError('distcheck succeeded, but files were left in %s'%instdir)
    shutil.rmtree(path)