forked from KaisenAmin/c_std
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcompile.py
97 lines (82 loc) · 2.71 KB
/
compile.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
93
94
95
96
97
import os
import platform
import subprocess
import sys
def find_c_files(directory):
c_files = []
for root, dirs, files in os.walk(directory):
for file in files:
if file.endswith(".c"):
c_files.append(os.path.join(root, file))
return c_files
def compile_project(run_after_compile=False):
source_directories = [
# "numeric",
# "algorithm",
# "array",
# "bitset",
# "config",
# "csv",
# "deque",
"encoding",
# "forward_list",
# "list",
"fmt",
"map",
"json",
"file_io",
# "priority_queue",
# "queue",
# "span",
# "stack",
"string",
"vector",
# "time",
# "date",
"dir",
# "crypto",
# "tuple",
# Add other directories containing your .c files
]
source_files = ["./main.c"]
for directory in source_directories:
source_files.extend(find_c_files(directory))
openssl_include_path = "./dependency/include" # No longer pointing to C:/msys64...
openssl_lib_path = "./dependency/lib"
# Compiler flags
flags = "-std=c17 -O3 -march=native -flto -funroll-loops -Wall -Wextra -pedantic -Wno-deprecated-declarations -s"
flags += f" -I{openssl_include_path}" # Include path for OpenSSL headers
flags += f" -L{openssl_lib_path}" # Library path for OpenSSL libraries
build_dir = "./build"
if not os.path.exists(build_dir):
os.makedirs(build_dir)
output = os.path.join(build_dir, "main.exe" if platform.system() == "Windows" else "main")
if os.path.exists(output):
os.remove(output)
# Compile the project with OpenSSL flags
command = f"gcc {flags} -o {output} " + " ".join(source_files) + f" -I{openssl_include_path} -L{openssl_lib_path} -lssl -lcrypto"
if platform.system() == "Windows":
command += " -lAdvapi32" # Add Windows-specific library
if "dir" in source_directories:
command += " -lshlwapi"
result = subprocess.run(command, shell=True)
if result.returncode != 0:
print("Compilation failed.")
else:
print(f"Compilation successful. Output: {output}")
if run_after_compile:
print("Running the program...\n" + '*' * 25)
subprocess.run(output)
def main():
if len(sys.argv) < 2:
print("Usage: python compile_project.py [b|r]")
sys.exit(1)
if sys.argv[1] == 'b':
compile_project()
elif sys.argv[1] == 'r':
compile_project(run_after_compile=True)
else:
print("Invalid argument. Use 'b' to build or 'r' to build and run.")
sys.exit(1)
if __name__ == "__main__":
main()