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.
84 lines
1.8 KiB
84 lines
1.8 KiB
8 years ago
|
#!/usr/bin/env python
|
||
|
|
||
|
from __future__ import print_function
|
||
9 years ago
|
|
||
|
# Generates a static library, object file, source
|
||
|
# file and a header file.
|
||
|
|
||
|
import sys, os
|
||
6 years ago
|
import subprocess
|
||
9 years ago
|
|
||
8 years ago
|
with open(sys.argv[1]) as f:
|
||
|
funcname = f.readline().strip()
|
||
9 years ago
|
outdir = sys.argv[2]
|
||
8 years ago
|
buildtype_args = sys.argv[3]
|
||
6 years ago
|
compiler_type = sys.argv[4]
|
||
|
compiler = sys.argv[5:]
|
||
9 years ago
|
|
||
|
if not os.path.isdir(outdir):
|
||
|
print('Outdir does not exist.')
|
||
|
sys.exit(1)
|
||
|
|
||
6 years ago
|
if compiler_type == 'msvc':
|
||
9 years ago
|
libsuffix = '.lib'
|
||
|
is_vs = True
|
||
6 years ago
|
if any(['clang-cl' in c for c in compiler]):
|
||
|
linker = 'llvm-lib'
|
||
|
else:
|
||
|
linker = 'lib'
|
||
9 years ago
|
else:
|
||
|
libsuffix = '.a'
|
||
|
is_vs = False
|
||
|
linker = 'ar'
|
||
9 years ago
|
|
||
|
objsuffix = '.o'
|
||
|
|
||
|
outo = os.path.join(outdir, funcname + objsuffix)
|
||
|
outa = os.path.join(outdir, funcname + libsuffix)
|
||
|
outh = os.path.join(outdir, funcname + '.h')
|
||
|
outc = os.path.join(outdir, funcname + '.c')
|
||
|
|
||
|
tmpc = 'diibadaaba.c'
|
||
|
tmpo = 'diibadaaba' + objsuffix
|
||
|
|
||
8 years ago
|
with open(outc, 'w') as f:
|
||
|
f.write('''#include"%s.h"
|
||
9 years ago
|
int %s_in_src() {
|
||
|
return 0;
|
||
|
}
|
||
|
''' % (funcname, funcname))
|
||
|
|
||
8 years ago
|
with open(outh, 'w') as f:
|
||
|
f.write('''#pragma once
|
||
9 years ago
|
int %s_in_lib();
|
||
|
int %s_in_obj();
|
||
|
int %s_in_src();
|
||
|
''' % (funcname, funcname, funcname))
|
||
|
|
||
8 years ago
|
with open(tmpc, 'w') as f:
|
||
|
f.write('''int %s_in_obj() {
|
||
9 years ago
|
return 0;
|
||
|
}
|
||
|
''' % funcname)
|
||
|
|
||
9 years ago
|
if is_vs:
|
||
6 years ago
|
subprocess.check_call(compiler + ['/nologo', '/c', buildtype_args, '/Fo' + outo, tmpc])
|
||
9 years ago
|
else:
|
||
6 years ago
|
subprocess.check_call(compiler + ['-c', '-o', outo, tmpc])
|
||
9 years ago
|
|
||
8 years ago
|
with open(tmpc, 'w') as f:
|
||
|
f.write('''int %s_in_lib() {
|
||
9 years ago
|
return 0;
|
||
|
}
|
||
|
''' % funcname)
|
||
|
|
||
9 years ago
|
if is_vs:
|
||
6 years ago
|
subprocess.check_call(compiler + ['/nologo', '/c', '/Fo' + tmpo, tmpc])
|
||
9 years ago
|
subprocess.check_call([linker, '/NOLOGO', '/OUT:' + outa, tmpo])
|
||
|
else:
|
||
6 years ago
|
subprocess.check_call(compiler + ['-c', '-o', tmpo, tmpc])
|
||
9 years ago
|
subprocess.check_call([linker, 'csr', outa, tmpo])
|
||
|
|
||
9 years ago
|
os.unlink(tmpo)
|
||
|
os.unlink(tmpc)
|