-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.py
44 lines (36 loc) · 1.23 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
import os
import platform
import subprocess
from sys import argv
path_del = "\\" if platform.system() == "Windows" else "/"
COMPILER = "gcc"
BUILDDIR = "build"
LIB = "lib"
ENTRY = "main.c"
DEBUG = '-d' in argv
OPTIMIZE = '--opti' in argv or '-o' in argv
if not os.path.exists(BUILDDIR):
os.makedirs(BUILDDIR)
def compile_source(source, output):
try:
subprocess.run([COMPILER, source, "-c", "-o", output], check=True)
print(f"Compilé {source} avec succès.")
except subprocess.CalledProcessError:
print(f"Erreur: Compilation de {source} a échoué.")
exit(1)
def link_objects(entry, objects, output):
try:
command = [COMPILER, entry] + (['-g'] if DEBUG else []) + (['-O2'] if OPTIMIZE else []) + objects + ["-o", output]
subprocess.run(command, check=True)
print("Liaison réussi.")
except subprocess.CalledProcessError:
print("Erreur: Liaison a échoué.")
exit(1)
path_objs = []
for file in os.listdir(LIB):
filename, ext = os.path.splitext(file)
if ext == '.c':
path_obj = f"{BUILDDIR}{path_del}{filename}.o"
path_objs.append(path_obj)
compile_source(f"{LIB}{path_del}{file}", path_obj)
link_objects(ENTRY, path_objs, "main")