parent
3fad3cbb81
commit
2c83bd16fc
10 changed files with 84 additions and 2 deletions
@ -0,0 +1 @@ |
||||
usr/bin/prog?exe |
@ -0,0 +1,45 @@ |
||||
project('object generator', 'c') |
||||
|
||||
# FIXME: Note that this will not add a dependency to the compiler executable. |
||||
# Code will not be rebuilt if it changes. |
||||
comp = find_program('obj_generator.py') |
||||
|
||||
if host_machine.system() == 'windows' |
||||
ext = '.obj' |
||||
else |
||||
ext = '.o' |
||||
endif |
||||
|
||||
cc = meson.get_compiler('c').cmd_array().get(-1) |
||||
|
||||
# Generate an object file with configure_file to mimic prebuilt objects |
||||
# provided by the source tree |
||||
source1 = configure_file(input : 'source.c', |
||||
output : 'source' + ext, |
||||
command : [comp, cc, 'source.c', |
||||
join_paths(meson.current_build_dir(), 'source' + ext)]) |
||||
|
||||
obj = static_library('obj', objects : source1) |
||||
|
||||
# Generate an object file manually. |
||||
gen = generator(comp, |
||||
output : '@BASENAME@' + ext, |
||||
arguments : [cc, '@INPUT@', '@OUTPUT@']) |
||||
|
||||
generated = gen.process(['source2.c']) |
||||
|
||||
shr = shared_library('shr', generated, |
||||
vs_module_defs : 'source2.def') |
||||
|
||||
# Generate an object file with indexed OUTPUT replacement. |
||||
gen2 = generator(comp, |
||||
output : '@BASENAME@' + ext, |
||||
arguments : [cc, '@INPUT@', '@OUTPUT0@']) |
||||
generated2 = gen2.process(['source3.c']) |
||||
|
||||
stc = static_library('stc', generated2) |
||||
|
||||
e = executable('prog', 'prog.c', link_with : [obj, shr, stc], |
||||
install : true) |
||||
|
||||
test('objgen', e) |
@ -0,0 +1,18 @@ |
||||
#!/usr/bin/env python |
||||
|
||||
# Mimic a binary that generates an object file (e.g. windres). |
||||
|
||||
import sys, shutil, subprocess |
||||
|
||||
if __name__ == '__main__': |
||||
if len(sys.argv) != 4: |
||||
print(sys.argv[0], 'compiler input_file output_file') |
||||
sys.exit(1) |
||||
compiler = sys.argv[1] |
||||
ifile = sys.argv[2] |
||||
ofile = sys.argv[3] |
||||
if compiler.endswith('cl'): |
||||
cmd = [compiler, '/nologo', '/MDd', '/Fo'+ofile, '/c', ifile] |
||||
else: |
||||
cmd = [compiler, '-c', ifile, '-o', ofile] |
||||
sys.exit(subprocess.call(cmd)) |
@ -0,0 +1,7 @@ |
||||
int func1_in_obj(); |
||||
int func2_in_obj(); |
||||
int func3_in_obj(); |
||||
|
||||
int main(int argc, char **argv) { |
||||
return func1_in_obj() + func2_in_obj() + func3_in_obj(); |
||||
} |
@ -0,0 +1,3 @@ |
||||
int func1_in_obj() { |
||||
return 0; |
||||
} |
@ -0,0 +1,3 @@ |
||||
int func2_in_obj() { |
||||
return 0; |
||||
} |
@ -0,0 +1,2 @@ |
||||
EXPORTS |
||||
func2_in_obj |
@ -0,0 +1,3 @@ |
||||
int func3_in_obj() { |
||||
return 0; |
||||
} |
Loading…
Reference in new issue