Merge pull request #153 from asottile/static_when_needed

Test for -static support before using it
This commit is contained in:
Chris Kuehl 2017-12-01 09:55:34 -08:00 committed by GitHub
commit 5ae82b9611
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,4 +1,8 @@
from __future__ import print_function
import os.path
import subprocess
import tempfile
from distutils.command.build import build as orig_build
from distutils.core import Command
@ -84,16 +88,26 @@ class build_cexe(Command):
compiler = new_compiler(verbose=True)
print('supports -static... ', end='')
with tempfile.NamedTemporaryFile(mode='w', suffix='.c') as f:
f.write('int main(void){}\n')
f.flush()
cmd = compiler.linker_exe + [f.name, '-static', '-o', os.devnull]
with open(os.devnull, 'wb') as devnull:
if not subprocess.call(cmd, stderr=devnull):
print('yes')
link_args = ['-static']
else:
print('no')
link_args = []
for exe in self.distribution.c_executables:
objects = compiler.compile(
exe.sources,
output_dir=self.build_temp,
)
objects = compiler.compile(exe.sources, output_dir=self.build_temp)
compiler.link_executable(
objects,
exe.name,
output_dir=self.build_scripts,
extra_postargs=exe.extra_link_args,
extra_postargs=link_args,
)
def get_outputs(self):
@ -110,13 +124,7 @@ setup(
author='Yelp',
url='https://github.com/Yelp/dumb-init/',
platforms='linux',
c_executables=[
Extension(
'dumb-init',
['dumb-init.c'],
extra_link_args=['-static'],
),
],
c_executables=[Extension('dumb-init', ['dumb-init.c'])],
cmdclass={
'bdist_wheel': bdist_wheel,
'build': build,