parent
7a02b76e70
commit
4b95dd3a6d
4 changed files with 65 additions and 0 deletions
@ -0,0 +1,38 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
import os, sys, subprocess, argparse, pathlib |
||||
|
||||
parser = argparse.ArgumentParser() |
||||
|
||||
parser.add_argument('--private-dir', required=True) |
||||
parser.add_argument('-o', required=True) |
||||
parser.add_argument('cmparr', nargs='+') |
||||
|
||||
static_linker = 'ar' |
||||
|
||||
contents = '''#include<stdio.h> |
||||
|
||||
void flob() { |
||||
printf("Now flobbing.\\n"); |
||||
} |
||||
''' |
||||
|
||||
def generate_lib(outfile, private_dir, compiler_array): |
||||
outdir = pathlib.Path(private_dir) |
||||
if not outdir.exists(): |
||||
outdir.mkdir() |
||||
c_file = outdir / 'flob.c' |
||||
c_file.write_text(contents) |
||||
o_file = c_file.with_suffix('.o') |
||||
compile_cmd = compiler_array + ['-c', '-g', '-O2', '-o', o_file, c_file] |
||||
subprocess.check_call(compile_cmd) |
||||
out_file = pathlib.Path(outfile) |
||||
if out_file.exists(): |
||||
out_file.unlink() |
||||
link_cmd = [static_linker, 'csrD', outfile, o_file] |
||||
subprocess.check_call(link_cmd) |
||||
|
||||
if __name__ == '__main__': |
||||
options = parser.parse_args() |
||||
generate_lib(options.o, options.private_dir, options.cmparr) |
||||
sys.exit(1) |
@ -0,0 +1,20 @@ |
||||
project('linkcustom', 'c') |
||||
|
||||
# This would require passing the static linker to the build script or having |
||||
# it detect it by itself. I'm too lazy to implement it now and it is not |
||||
# really needed for testing that custom targets work. It is the responsibility |
||||
# of the custom target to produce things in the correct format. |
||||
assert(not meson.is_cross(), 'MESON_SKIP_TEST cross checking not implemented.') |
||||
|
||||
cc = meson.get_compiler('c') |
||||
genprog = find_program('custom_stlib.py') |
||||
|
||||
clib = custom_target('linkcustom', |
||||
output: 'libflob.a', |
||||
command: [genprog, |
||||
'-o', '@OUTPUT@', |
||||
'--private-dir', '@PRIVATE_DIR@'] + cc.cmd_array()) |
||||
|
||||
#exe = executable('prog', 'prog.c', link_with: clib) |
||||
#test('linkcustom', exe) |
||||
|
Loading…
Reference in new issue