|
5 | 5 | import sys |
6 | 6 | import platform |
7 | 7 |
|
8 | | -import camellia.engines.reference as c_reference |
9 | | -import camellia.engines.mini as c_mini |
| 8 | +from .engines import reference as c_reference |
| 9 | +from .engines import mini as c_mini |
10 | 10 |
|
11 | 11 | MODE_ECB = 1 |
12 | 12 | MODE_CBC = 2 |
@@ -56,18 +56,39 @@ def version_string(): |
56 | 56 | IN = os.path.join(os.path.dirname(__file__), "camellia.c") |
57 | 57 | OUT = os.path.join(os.path.dirname(__file__), version_string()) |
58 | 58 |
|
59 | | -GCC = os.environ.get('CC', 'cc') |
60 | | -CMD = "%s %s -shared -fPIC -O3 -o%s" % (GCC, IN, OUT) |
| 59 | +ucc = os.environ.get('CC', 'cc') |
61 | 60 |
|
| 61 | +acc = ["cc", "gcc", "clang", "tcc"] |
62 | 62 |
|
63 | | -if not os.path.exists(OUT) and sys.platform != "win32": # win32 is precompiled |
64 | | - print("Compiling camellia with %s..." % GCC) |
65 | | - print(CMD) |
| 63 | +if ucc in acc: |
| 64 | + i = acc.index(ucc) |
| 65 | + acc.pop(i) |
| 66 | +else: |
| 67 | + acc = [UCC] + acc |
| 68 | +#CMD = "%s %s -shared -fPIC -O3 -o%s" % (GCC, IN, OUT) |
| 69 | + |
| 70 | +def try_compiler(cc, inf, outf): |
| 71 | + cmd = "%s %s -shared -fPIC -O3 -o%s" % (cc, inf, outf) |
| 72 | + print (cmd) |
66 | 73 | try: |
67 | | - assert not os.system(CMD) |
68 | | - except AssertionError: |
69 | | - print("Please install gcc and include camellia.c with this file, " |
70 | | - "then run with sudo to compile!") |
| 74 | + assert not os.system(cmd) |
| 75 | + except: |
| 76 | + print("Compiler %s failed! Not existend or no permission?" % cc) |
| 77 | + return 1 |
| 78 | + else: |
| 79 | + return 0 |
| 80 | + |
| 81 | +if not os.path.exists(OUT) and sys.platform != "win32": # win32 is precompiled |
| 82 | + for cc in acc: |
| 83 | + print("Compiling camellia with %s..." % cc) |
| 84 | + if not try_compiler(cc, IN, OUT): |
| 85 | + break |
| 86 | + |
| 87 | + else: |
| 88 | + raise Exception("Please install gcc, clang or tcc and include " |
| 89 | + "\"camellia.c\" with this file, then run with " |
| 90 | + "sudo to compile!") |
| 91 | + print("Done!") |
71 | 92 |
|
72 | 93 |
|
73 | 94 | try: |
|
0 commit comments