1import os, os.path, sys, string, shutil, glob, pickle
2
3# this file defines the commands for updating the init
4# methods (constructors) of the widget classes for pyFLTK
5# run this before issuing the SWIG command
6
7
8PythonOwns = ['Fl_Preferences']
9
10
11def is_msys_mingw():
12    #if os.environ.has_key("MSYSTEM"):
13    if "MSYSTEM" in os.environ:
14        if os.environ["MSYSTEM"] == "MINGW32":
15            return True
16    return False
17
18
19if __name__=='__main__':
20
21    # call SWIG
22    include = ['-I/usr/include']
23    try:
24        fltk_dir = os.environ['FLTK_HOME']
25        include.insert(0, "-I%s"%fltk_dir)
26    except:
27        print("Using default location for FLTK!")
28        if is_msys_mingw():
29            result = os.popen('sh fltk-config --cxxflags').readlines()
30        else:
31            result = os.popen('fltk-config --cxxflags').readlines()
32        #print(result)
33        if len(result) > 0:
34            p_inc = map(lambda x: x.strip(), result[0].split(' '))
35            for item in p_inc:
36                #if string.find(item, '-I') == 0:
37                if item.find('-I') == 0:
38                    include.insert(0, item)
39        else:
40            print("FLTK not found!")
41            sys.exit(0)
42
43    #add_incl = string.join(include, ' ')
44    add_incl = ' '.join(include)
45
46    # command line for swig-1.3.28 or later
47    versionIdentifier = ""
48    if sys.version >= "3.0":
49        versionIdentifier = "-DPYTHON3"
50    cmd_line = "swig -w312 -w451 -w473 -I../swig %s -DFL_EXPORT -DPYTHON %s -module fltk -c++ -python -shadow -modern -fastdispatch -o fltk_wrap.cpp ../swig/fltk.i "%(add_incl, versionIdentifier)
51    # command line for swig-1.3.27
52    # cmd_line = "swig -w312 -w451 -w473 -I../swig %s -DFL_EXPORT -DPYTHON -module fltk -c++ -python -shadow -modern -dirprot -o fltk_wrap.cpp ../swig/fltk.i "%add_incl
53    if is_msys_mingw():
54        # adjust the paths so that MinGW can understand it
55        cmd_line = cmd_line.replace("\\", "/")
56        cmd_line = cmd_line.replace("c:", "/c")
57        cmd_line = cmd_line.replace("C:", "/c")
58
59        import tempfile
60        tmpfn = tempfile.mktemp(suffix='run_swig')
61        tmpf = open(tmpfn, "w+b")
62        tmpf.write(cmd_line)
63        tmpf.close()
64        r = os.system("sh %s" % tmpfn)
65
66        os.remove(tmpfn)
67        if r != 0:
68            raise DistutilsExecError("command '%s' failed with exit status :%d: command was :%s:.  " % (cmd[0], r, cmpl))
69
70        print("return value of the command is :%s:" % r)
71    else:
72        print(cmd_line)
73        os.system(cmd_line)
74
75    #print("Copy fltk.py")
76    if os.path.isdir("../fltk"):
77        shutil.rmtree("../fltk");
78    os.mkdir("../fltk");
79    os.mkdir("../fltk/test");
80    os.mkdir("../fltk/docs");
81
82    shutil.copyfile("fltk.py", "../fltk/__init__.py")
83    #print(glob.glob("../test/*.py"))
84    for x in glob.glob("../test/*.py"): shutil.copy(x, "../fltk/test")
85    for x in glob.glob("../test/*.html"): shutil.copy(x, "../fltk/test")
86    for x in glob.glob("../test/*.gif"): shutil.copy(x, "../fltk/test")
87    for x in glob.glob("../docs/*.html"): shutil.copy(x, "../fltk/docs")
88    for x in glob.glob("../docs/*.jpg"): shutil.copy(x, "../fltk/docs")
89
90
91
92
93
94