commit
23b1ac795b
9 changed files with 121 additions and 1 deletions
@ -0,0 +1,8 @@ |
||||
#include"gen_func.h" |
||||
|
||||
int main(int argc, char **argv) { |
||||
unsigned int i = (unsigned int) gen_func_in_lib(); |
||||
unsigned int j = (unsigned int) gen_func_in_obj(); |
||||
unsigned int k = (unsigned int) gen_func_in_src(); |
||||
return (int)(i + j + k); |
||||
} |
@ -0,0 +1,8 @@ |
||||
project('manygen', 'c') |
||||
|
||||
subdir('subdir') |
||||
|
||||
exe = executable('depuser', 'depuser.c', |
||||
generated) |
||||
|
||||
test('depuser test', exe) |
@ -0,0 +1 @@ |
||||
gen_func |
@ -0,0 +1,69 @@ |
||||
#!/usr/bin/env python3 |
||||
|
||||
# Generates a static library, object file, source |
||||
# file and a header file. |
||||
|
||||
import sys, os |
||||
import shutil, subprocess |
||||
|
||||
funcname = open(sys.argv[1]).readline().strip() |
||||
outdir = sys.argv[2] |
||||
|
||||
if not os.path.isdir(outdir): |
||||
print('Outdir does not exist.') |
||||
sys.exit(1) |
||||
|
||||
if shutil.which('cl'): |
||||
print('VS support not yet added.') |
||||
sys.exit(1) |
||||
|
||||
objsuffix = '.o' |
||||
libsuffix = '.a' |
||||
|
||||
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') |
||||
|
||||
compiler = shutil.which('gcc') |
||||
if compiler is None: |
||||
compiler = shutil.which('clang') |
||||
if compiler is None: |
||||
compiler = shutil.which('cc') |
||||
if compiler is None: |
||||
print('No known compilers found.') |
||||
sys.exit(1) |
||||
linker = 'ar' |
||||
|
||||
tmpc = 'diibadaaba.c' |
||||
tmpo = 'diibadaaba' + objsuffix |
||||
|
||||
open(outc, 'w').write('''#include"%s.h" |
||||
int %s_in_src() { |
||||
return 0; |
||||
} |
||||
''' % (funcname, funcname)) |
||||
|
||||
open(outh, 'w').write('''#pragma once |
||||
int %s_in_lib(); |
||||
int %s_in_obj(); |
||||
int %s_in_src(); |
||||
''' % (funcname, funcname, funcname)) |
||||
|
||||
open(tmpc, 'w').write('''int %s_in_obj() { |
||||
return 0; |
||||
} |
||||
''' % funcname) |
||||
|
||||
subprocess.check_call([compiler, '-c', '-o', outo, tmpc]) |
||||
|
||||
open(tmpc, 'w').write('''int %s_in_lib() { |
||||
return 0; |
||||
} |
||||
''' % funcname) |
||||
|
||||
subprocess.check_call([compiler, '-c', '-o', tmpo, tmpc]) |
||||
subprocess.check_call([linker, 'csr', outa, tmpo]) |
||||
os.unlink(tmpo) |
||||
os.unlink(tmpc) |
||||
|
@ -0,0 +1,7 @@ |
||||
gen = find_program('manygen.py') |
||||
|
||||
generated = custom_target('manygen', |
||||
output : ['gen_func.a', 'gen_func.c', 'gen_func.h', 'gen_func.o'], |
||||
input : ['funcinfo.def'], |
||||
command : [gen, '@INPUT@', '@OUTDIR@'], |
||||
) |
Loading…
Reference in new issue