Skip to content

Commit f5dd97c

Browse files
committed
Changed compilation proccess
1 parent e3bf0a0 commit f5dd97c

1 file changed

Lines changed: 32 additions & 11 deletions

File tree

camellia/__init__.py

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
import sys
66
import platform
77

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
1010

1111
MODE_ECB = 1
1212
MODE_CBC = 2
@@ -56,18 +56,39 @@ def version_string():
5656
IN = os.path.join(os.path.dirname(__file__), "camellia.c")
5757
OUT = os.path.join(os.path.dirname(__file__), version_string())
5858

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')
6160

61+
acc = ["cc", "gcc", "clang", "tcc"]
6262

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)
6673
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!")
7192

7293

7394
try:

0 commit comments

Comments
 (0)