-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmake.py
executable file
·84 lines (56 loc) · 1.73 KB
/
make.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
#! /usr/bin/env python
import glob
import os
from fabricate import *
CC = os.getenv('CC', 'gcc')
CCFLAGS = '-std=c99 -Wall -W'
DEBUG_FLAGS = '-O0 -g -DDEBUG'
RELEASE_FLAGS = '-O3'
sources = glob.glob('src/*.c')
# --- TARGETS ---
def build(mode='release'):
compile(mode)
make_library(mode)
def debug():
build('debug')
def test():
build('debug')
compile_tests()
execute_tests()
def clean():
autoclean()
# --- RECIPES ---
def compile(mode='release'):
extra_flags = RELEASE_FLAGS if mode == 'release' else \
DEBUG_FLAGS if mode == 'debug' else None
fnames = [s[len('src/'):-len('.c')] for s in sources]
for s in fnames:
cmd = [CC]
cmd.extend(CCFLAGS.split(' '))
cmd.extend(extra_flags.split(' '))
cmd.extend(['-c', 'src/' + s + '.c',
'-o', 'build/' + mode + '/' + s + '.o'])
run(*cmd)
def compile_tests():
for cfile in glob.glob('tests/test_*.c'):
cmd = [CC]
cmd.extend(CCFLAGS.split(' '))
cmd.extend(DEBUG_FLAGS.split(' '))
cmd.extend(['-Isrc', cfile, 'build/debug/librandomtrees.a',
'-o', strip_ext(cfile) + '.exe', '-lm'])
run(*cmd)
def make_library(mode='release'):
out_dir = 'build/' + mode + '/'
obj = glob.glob(out_dir + '*.o')
run('ar', 'rcs', out_dir + 'librandomtrees.a', *obj)
def execute_tests():
print
print "Running unit test:"
for tmatch in glob.glob('tests/test_*.exe'):
test = os.path.basename(tmatch)
shell('cd', 'tests', '&&', './runner.py', test, silent=False,
shell=True)
# --- utils ---
def strip_ext(s):
return os.path.splitext(s)[0]
main()