This repository has been archived by the owner on Jul 24, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pass_and_compile.py
58 lines (51 loc) · 2.09 KB
/
pass_and_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
import os
import fnmatch
# -----------------------------------------------------------
# Passes through given source directory and it's subdirectories,
# compiles with given compiler and flags all finded files with given pattern
# and puts binaries in given directory for compiled files. Compiled files have
# numbered names
#
# Parameters:
#
# source: path to directory with source files for compiling
# compiled: path to directory for putting compiled files
# pattern: regular expression for name of source files. For example, "*.c"
# compiler: compiler for compiling
# flags: list of flags for compiling
# -----------------------------------------------------------
def numbered_pass_and_compile(source, compiled, pattern, compiler, flags):
# Number for naming compiled files. It is incrementing while files are being compiled.
# Default value is 1
numbered_name = 1
# Passing and compiling function
def pass_and_compile(source, compiled, pattern, compiler, flags):
nonlocal numbered_name
# Passing through all subdirectories
for subdir in os.listdir(source):
# Getting subdirectory's path
path_to_subdir = source + "/" + subdir
# If it is subdirectory then call this function
if os.path.isdir(path_to_subdir):
pass_and_compile(path_to_subdir, compiled, pattern, compiler, flags)
# If it is file with given pattern then compile
elif fnmatch.fnmatch(subdir, pattern):
# Printing number
print(numbered_name)
# Setting compiler
compiling_command = compiler + " "
# Setting flags
for flag in flags:
compiling_command = compiling_command + flag + " "
# Setting path to source file
compiling_command = compiling_command + path_to_subdir + " -o "
# Setting path for binary file
compiling_command = compiling_command + compiled + "/" + str(numbered_name) + " "
# Removing output
compiling_command = compiling_command + "2> /dev/null"
# Executing command
os.system(compiling_command)
# Incrementing number for naming
numbered_name = numbered_name + 1
# Passing and compiling
pass_and_compile(source, compiled, pattern, compiler, flags)