The Meson Build System
http://mesonbuild.com/
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
74 lines
2.4 KiB
74 lines
2.4 KiB
6 years ago
|
#!/usr/bin/env python3
|
||
|
|
||
6 years ago
|
import shutil, sys, subprocess, argparse, pathlib
|
||
6 years ago
|
|
||
|
parser = argparse.ArgumentParser()
|
||
|
|
||
|
parser.add_argument('--private-dir', required=True)
|
||
|
parser.add_argument('-o', required=True)
|
||
|
parser.add_argument('cmparr', nargs='+')
|
||
|
|
||
|
contents = '''#include<stdio.h>
|
||
|
|
||
|
void flob() {
|
||
|
printf("Now flobbing.\\n");
|
||
|
}
|
||
|
'''
|
||
|
|
||
6 years ago
|
def generate_lib_gnulike(outfile, c_file, private_dir, compiler_array):
|
||
6 years ago
|
if shutil.which('ar'):
|
||
|
static_linker = 'ar'
|
||
|
elif shutil.which('llvm-ar'):
|
||
|
static_linker = 'llvm-ar'
|
||
|
elif shutil.which('gcc-ar'):
|
||
|
static_linker = 'gcc-ar'
|
||
|
else:
|
||
|
sys.exit('Could not detect a static linker.')
|
||
6 years ago
|
o_file = c_file.with_suffix('.o')
|
||
6 years ago
|
compile_cmd = compiler_array + ['-c', '-g', '-O2', '-o', str(o_file), str(c_file)]
|
||
6 years ago
|
subprocess.check_call(compile_cmd)
|
||
|
out_file = pathlib.Path(outfile)
|
||
|
if out_file.exists():
|
||
|
out_file.unlink()
|
||
6 years ago
|
link_cmd = [static_linker, 'csr', outfile, str(o_file)]
|
||
6 years ago
|
subprocess.check_call(link_cmd)
|
||
6 years ago
|
return 0
|
||
|
|
||
|
|
||
|
def generate_lib_msvc(outfile, c_file, private_dir, compiler_array):
|
||
|
static_linker = 'lib'
|
||
|
o_file = c_file.with_suffix('.obj')
|
||
|
compile_cmd = compiler_array + ['/MDd',
|
||
|
'/nologo',
|
||
|
'/ZI',
|
||
|
'/Ob0',
|
||
|
'/Od',
|
||
|
'/c',
|
||
|
'/Fo' + str(o_file),
|
||
|
str(c_file)]
|
||
|
subprocess.check_call(compile_cmd)
|
||
|
out_file = pathlib.Path(outfile)
|
||
|
if out_file.exists():
|
||
|
out_file.unlink()
|
||
|
link_cmd = [static_linker,
|
||
|
'/nologo',
|
||
|
'/OUT:' + str(outfile),
|
||
|
str(o_file)]
|
||
|
subprocess.check_call(link_cmd)
|
||
|
return 0
|
||
|
|
||
|
def generate_lib(outfile, private_dir, compiler_array):
|
||
|
private_dir = pathlib.Path(private_dir)
|
||
|
if not private_dir.exists():
|
||
|
private_dir.mkdir()
|
||
|
c_file = private_dir / 'flob.c'
|
||
|
c_file.write_text(contents)
|
||
|
for i in compiler_array:
|
||
6 years ago
|
if (i.endswith('cl') or i.endswith('cl.exe')) and 'clang-cl' not in i:
|
||
6 years ago
|
return generate_lib_msvc(outfile, c_file, private_dir, compiler_array)
|
||
|
return generate_lib_gnulike(outfile, c_file, private_dir, compiler_array)
|
||
6 years ago
|
|
||
|
if __name__ == '__main__':
|
||
|
options = parser.parse_args()
|
||
6 years ago
|
sys.exit(generate_lib(options.o, options.private_dir, options.cmparr))
|