Skip to content

Commit

Permalink
Merge pull request #57 from kiwix/fix_env_var
Browse files Browse the repository at this point in the history
Fix env var
  • Loading branch information
mgautierfr authored Jun 26, 2017
2 parents 6026daf + e27f170 commit f620d36
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 18 deletions.
4 changes: 2 additions & 2 deletions dependency_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def _configure(self, context):
v = v.format(buildEnv=self.buildEnv, env=env)
self.configure_env[k[8:]] = v
env.update(self.configure_env)
self.buildEnv.run_command(command, self.build_path, context, env=env, cross_path_only=True)
self.buildEnv.run_command(command, self.build_path, context, env=env, cross_env_only=True)


class MesonBuilder(Builder):
Expand Down Expand Up @@ -327,7 +327,7 @@ def _configure(self, context):
buildEnv=self.buildEnv,
cross_option="--cross-file {}".format(self.buildEnv.meson_crossfile) if self.buildEnv.meson_crossfile else ""
)
self.buildEnv.run_command(command, self.source_path, context, cross_path_only=True)
self.buildEnv.run_command(command, self.source_path, context, cross_env_only=True)

def _compile(self, context):
command = "{} -v".format(self.buildEnv.ninja_command)
Expand Down
43 changes: 27 additions & 16 deletions kiwix-build.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__))


_fedora_common = ['automake', 'cmake', 'git', 'subversion', 'ccache', 'pkg-config', 'gcc-c++']
_fedora_common = ['automake', 'cmake', 'git', 'subversion', 'ccache', 'pkgconfig', 'gcc-c++']
_debian_common = ['automake', 'cmake', 'git', 'subversion', 'ccache', 'pkg-config', 'gcc']
PACKAGE_NAME_MAPPERS = {
'fedora_native_dyn': {
Expand Down Expand Up @@ -355,7 +355,7 @@ def cmake_option(self):
cmake_options = [tlc.cmake_option for tlc in self.toolchains]
return " ".join(cmake_options)

def _set_env(self, env, cross_compile_env, cross_compile_path):
def _set_env(self, env, cross_compile_env, cross_compile_compiler, cross_compile_path):
if env is None:
env = Defaultdict(str, os.environ)

Expand All @@ -368,6 +368,9 @@ def _set_env(self, env, cross_compile_env, cross_compile_path):
env[k] = v
for toolchain in self.toolchains:
toolchain.set_env(env)
if cross_compile_compiler:
for toolchain in self.toolchains:
toolchain.set_compiler(env)
if cross_compile_path:
for tlc in self.toolchains:
bin_dirs += tlc.get_bin_dir()
Expand Down Expand Up @@ -398,16 +401,18 @@ def _set_env(self, env, cross_compile_env, cross_compile_path):
env['LDFLAGS']])
return env

def run_command(self, command, cwd, context, env=None, input=None, cross_path_only=False):
def run_command(self, command, cwd, context, env=None, input=None, cross_env_only=False):
os.makedirs(cwd, exist_ok=True)
cross_compile_env = True
cross_compile_compiler = True
cross_compile_path = True
if context.force_native_build:
cross_compile_env = False
cross_compile_compiler = False
cross_compile_path = False
if cross_path_only:
cross_compile_env = False
env = self._set_env(env, cross_compile_env, cross_compile_path)
if cross_env_only:
cross_compile_compiler = False
env = self._set_env(env, cross_compile_env, cross_compile_compiler, cross_compile_path)
log = None
try:
if not self.options.verbose:
Expand Down Expand Up @@ -528,6 +533,9 @@ def _log_dir(self):
def set_env(self, env):
pass

def set_compiler(self, env):
pass

def command(self, name, function, *args):
print(" {} {} : ".format(name, self.name), end="", flush=True)
log = pj(self._log_dir, 'cmd_{}_{}.log'.format(name, self.name))
Expand Down Expand Up @@ -579,12 +587,13 @@ def get_bin_dir(self):
return [pj(self.root_path, 'bin')]

def set_env(self, env):
for k, v in self.binaries.items():
env[k] = v

env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS']

def set_compiler(self, env):
for k, v in self.binaries.items():
env[k] = v


class android_ndk(Toolchain):
name = 'android-ndk'
Expand Down Expand Up @@ -696,20 +705,21 @@ def get_bin_dir(self):
return [pj(self.builder.install_path, 'bin')]

def set_env(self, env):
env['CC'] = self.binaries['CC']
env['CXX'] = self.binaries['CXX']

env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
env['CFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} '.format(self.root_path) + env['CFLAGS']
env['CXXFLAGS'] = '-fPIC -D_LARGEFILE64_SOURCE=1 -D_FILE_OFFSET_BITS=64 --sysroot={} '.format(self.root_path) + env['CXXFLAGS']
env['LDFLAGS'] = ' -fPIE -pie --sysroot={} '.format(self.root_path) + env['LDFLAGS']
env['LDFLAGS'] = '--sysroot={} '.format(self.root_path) + env['LDFLAGS']
#env['CFLAGS'] = ' -fPIC -D_FILE_OFFSET_BITS=64 -O3 '+env['CFLAGS']
#env['CXXFLAGS'] = (' -D__OPTIMIZE__ -fno-strict-aliasing '
# ' -DU_HAVE_NL_LANGINFO_CODESET=0 '
# '-DU_STATIC_IMPLEMENTATION -O3 '
# '-DU_HAVE_STD_STRING -DU_TIMEZONE=0 ')+env['CXXFLAGS']
env['NDK_DEBUG'] = '0'

def set_compiler(self, env):
env['CC'] = self.binaries['CC']
env['CXX'] = self.binaries['CXX']


class android_sdk(Toolchain):
name = 'android-sdk'
Expand Down Expand Up @@ -795,14 +805,15 @@ def get_bin_dir(self):
return [pj(self.root_path, 'bin')]

def set_env(self, env):
env['CC'] = self.binaries['CC']
env['CXX'] = self.binaries['CXX']

env['PKG_CONFIG_LIBDIR'] = pj(self.root_path, 'lib', 'pkgconfig')
env['CFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CFLAGS']
env['CXXFLAGS'] = " -O2 -g -pipe -Wall -Wp,-D_FORTIFY_SOURCE=2 -fexceptions --param=ssp-buffer-size=4 "+env['CXXFLAGS']
env['LIBS'] = " ".join(self.buildEnv.cross_config['extra_libs']) + " " +env['LIBS']

def set_compiler(self, env):
env['CC'] = self.binaries['CC']
env['CXX'] = self.binaries['CXX']


class Builder:
def __init__(self, options):
Expand Down

0 comments on commit f620d36

Please sign in to comment.