Skip to content

Commit

Permalink
Fix manygen to work with msvc.
Browse files Browse the repository at this point in the history
  • Loading branch information
jpakkane committed Dec 28, 2015
1 parent df37c79 commit ec0a73b
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 17 deletions.
43 changes: 27 additions & 16 deletions test cases/common/103 manygen/subdir/manygen.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,30 @@
sys.exit(1)

if shutil.which('cl'):
print('VS support not yet added.')
sys.exit(1)
libsuffix = '.lib'
is_vs = True
compiler = 'cl'
linker = 'lib'
else:
libsuffix = '.a'
is_vs = False
linker = 'ar'
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)

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

Expand All @@ -55,15 +58,23 @@
}
''' % funcname)

subprocess.check_call([compiler, '-c', '-o', outo, tmpc])
if is_vs:
subprocess.check_call([compiler, '/nologo', '/c', '/Fo' + outo, tmpc])
else:
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])
if is_vs:
subprocess.check_call([compiler, '/nologo', '/c', '/Fo' + tmpo, tmpc])
subprocess.check_call([linker, '/NOLOGO', '/OUT:' + outa, tmpo])
else:
subprocess.check_call([compiler, '-c', '-o', tmpo, tmpc])
subprocess.check_call([linker, 'csr', outa, tmpo])

os.unlink(tmpo)
os.unlink(tmpc)

8 changes: 7 additions & 1 deletion test cases/common/103 manygen/subdir/meson.build
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
gen = find_program('manygen.py')

if meson.get_compiler('c').get_id() == 'msvc'
outfiles = ['gen_func.lib', 'gen_func.c', 'gen_func.h', 'gen_func.o']
else
outfiles = ['gen_func.a', 'gen_func.c', 'gen_func.h', 'gen_func.o']
endif

generated = custom_target('manygen',
output : ['gen_func.a', 'gen_func.c', 'gen_func.h', 'gen_func.o'],
output : outfiles,
input : ['funcinfo.def'],
command : [gen, '@INPUT@', '@OUTDIR@'],
)

0 comments on commit ec0a73b

Please sign in to comment.