-
Notifications
You must be signed in to change notification settings - Fork 1
/
setup_C.py
92 lines (78 loc) · 1.82 KB
/
setup_C.py
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
#! /usr/bin/env python
from __future__ import print_function
import sys
import os
import subprocess
do_test = "test" in sys.argv
CC = [os.environ['CC']]
flags = [
"-Wall",
"-Wextra",
"-lm",
"--pedantic",
"-O3",
"-DSTANDALONE"
]
if "gcc" in CC[0]:
flags += [
"-std=c11",
#"-march=native",
#"-mtune=native"
]
elif "clang" in CC[0]:
flags += ["-Wno-unknown-pragmas"]
if not os.path.exists("bin"):
os.mkdir("bin")
def run_command (components):
command = " ".join(components)
print(command)
if subprocess.check_call(components):
exit(1)
def announce(text):
print ((4+len(text)) *"=")
print (" " + text + " ")
print ((4+len(text)) *"=")
def test (commands):
for command in commands:
print(command)
if subprocess.check_call(command, shell=True):
exit(1)
else:
print("Success.")
def O(folder, Cfile, output=None):
if output is None:
return [
os.path.join(folder,Cfile),
"-o", os.path.join("bin", Cfile.replace(".c",""))
]
else:
return [
os.path.join(folder,Cfile),
"-o", os.path.join("bin", output)
]
def build (tests=False):
F = flags
L = [
os.path.join("periodicitytest", "basics_standalone.c"),
os.path.join("periodicitytest", "interval.c"),
os.path.join("periodicitytest", "extremacounting.c"),
os.path.join("periodicitytest", "search.c"),
]
if tests:
F += ["-g"]
L += [os.path.join("tests","testfunctions.c")]
run_command(CC + L + O("tests", "extremacounting_test.c") + F)
run_command(CC + L + O("tests", "search_test.c") + F)
else:
F += ["-DNDEBUG"]
run_command(CC + L + O("periodicitytest", "standalone.c", "periodicitytest") + F)
if do_test:
announce("Building tests.")
build(tests=True)
announce("Running tests.")
test([
os.path.join("bin", "extremacounting_test"),
os.path.join("bin", "search_test")
])
announce("Building executable.")
build()