2013-11-06 00:54:13 +00:00
|
|
|
#
|
|
|
|
# This file is part of Mapnik (c++ mapping toolkit)
|
|
|
|
#
|
2015-06-16 10:49:16 +00:00
|
|
|
# Copyright (C) 2015 Artem Pavlenko
|
2013-11-06 00:54:13 +00:00
|
|
|
#
|
|
|
|
# Mapnik is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the Free Software
|
|
|
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
#
|
|
|
|
#
|
2010-07-18 21:34:08 +00:00
|
|
|
|
|
|
|
import re
|
|
|
|
import os
|
2011-08-13 17:07:05 +00:00
|
|
|
import sys
|
2011-08-29 21:12:22 +00:00
|
|
|
from copy import copy
|
2012-08-22 21:44:58 +00:00
|
|
|
from subprocess import Popen, PIPE
|
2019-09-16 21:17:09 +00:00
|
|
|
from SCons.Environment import OverrideEnvironment
|
2010-07-18 21:34:08 +00:00
|
|
|
|
2011-06-29 14:44:40 +00:00
|
|
|
Import('env')
|
2011-08-13 17:07:05 +00:00
|
|
|
|
2011-06-29 14:44:40 +00:00
|
|
|
config_env = env.Clone()
|
|
|
|
|
2015-10-12 20:42:08 +00:00
|
|
|
|
|
|
|
def GetMapnikLibVersion():
|
|
|
|
ver = []
|
|
|
|
for line in open('../../include/mapnik/version.hpp').readlines():
|
|
|
|
if line.startswith('#define MAPNIK_MAJOR_VERSION'):
|
|
|
|
ver.append(line.split(' ')[2].strip())
|
|
|
|
if line.startswith('#define MAPNIK_MINOR_VERSION'):
|
|
|
|
ver.append(line.split(' ')[2].strip())
|
|
|
|
if line.startswith('#define MAPNIK_PATCH_VERSION'):
|
|
|
|
ver.append(line.split(' ')[2].strip())
|
|
|
|
version_string = ".".join(ver)
|
|
|
|
return version_string
|
|
|
|
|
|
|
|
if (GetMapnikLibVersion() != config_env['MAPNIK_VERSION_STRING']):
|
2017-11-16 10:59:55 +00:00
|
|
|
print ('Error: version.hpp mismatch (%s) to cached value (%s): please reconfigure mapnik' % (GetMapnikLibVersion(),config_env['MAPNIK_VERSION_STRING']))
|
2015-10-12 20:42:08 +00:00
|
|
|
Exit(1)
|
|
|
|
|
2019-09-16 21:17:09 +00:00
|
|
|
def write_config(env, template_filename, config_filename):
|
|
|
|
"""
|
|
|
|
Load shell script `template_filename`, replace values in variable
|
|
|
|
assignments of the form `CONFIG_key='default'` with corresponding
|
|
|
|
value `env['key']`, and save the result as `config_filename`.
|
|
|
|
"""
|
|
|
|
with open(template_filename, 'r') as template_file:
|
|
|
|
template = template_file.read()
|
|
|
|
with open(config_filename, 'w') as config_file:
|
|
|
|
escape = env['ESCAPE']
|
|
|
|
def subst(matchobj):
|
|
|
|
key = matchobj.group(1)
|
2020-01-30 14:15:14 +00:00
|
|
|
if key not in env:
|
2019-09-16 21:17:09 +00:00
|
|
|
return matchobj.group(0)
|
|
|
|
else:
|
2020-01-30 14:15:14 +00:00
|
|
|
val = env.subst('$' + key)
|
|
|
|
return 'CONFIG_%s=%s' % (key, escape(val))
|
2019-09-16 21:17:09 +00:00
|
|
|
config = re.sub(r'^CONFIG_(\w+)=.*', subst, template, flags=re.M)
|
|
|
|
config_file.write(config)
|
2011-08-13 17:07:05 +00:00
|
|
|
try:
|
2019-09-16 21:17:09 +00:00
|
|
|
os.chmod(config_filename, 0o755)
|
2011-08-13 17:07:05 +00:00
|
|
|
except: pass
|
|
|
|
|
2016-08-31 18:09:11 +00:00
|
|
|
|
2019-09-16 21:17:09 +00:00
|
|
|
template_env = OverrideEnvironment(config_env, {})
|
|
|
|
|
|
|
|
# strip any -Warning flags
|
|
|
|
cxxflags_cleaned = [x for x in config_env['LIBMAPNIK_CXXFLAGS']
|
|
|
|
if x.startswith('-Wp,') or not x.startswith('-W')]
|
2016-08-31 18:09:11 +00:00
|
|
|
# strip clang specific flags to avoid breaking gcc
|
|
|
|
# while it is not recommended to mix compilers, this nevertheless
|
|
|
|
# makes it easier to compile apps with gcc and mapnik-config against mapnik built with clang
|
2019-09-16 21:17:09 +00:00
|
|
|
cxxflags_cleaned = [x for x in cxxflags_cleaned if x != '-Qunused-arguments']
|
|
|
|
cxx_cleaned = config_env['CXX'].replace(' -Qunused-arguments', '')
|
2016-08-31 18:09:11 +00:00
|
|
|
|
2019-09-16 21:17:09 +00:00
|
|
|
template_env['CXXFLAGS'] = ' '.join(cxxflags_cleaned)
|
|
|
|
template_env['CXX'] = re.sub(r'^ccache +', '', cxx_cleaned)
|
2011-06-29 14:44:40 +00:00
|
|
|
|
2019-09-16 21:17:09 +00:00
|
|
|
template_env['DEFINES'] = ' '.join(config_env['LIBMAPNIK_DEFINES'])
|
2011-09-01 15:06:11 +00:00
|
|
|
|
2019-09-16 21:30:01 +00:00
|
|
|
dep_includes = ['-I%s' % i for i in config_env['CPPPATH'] if not i.startswith('#')]
|
2011-08-30 05:17:50 +00:00
|
|
|
if config_env['HAS_CAIRO']:
|
2019-09-16 21:30:01 +00:00
|
|
|
dep_includes += ['-I%s' % i for i in env['CAIRO_CPPPATHS'] if not i.startswith('#')]
|
|
|
|
template_env['DEP_INCLUDES'] = ' '.join(dep_includes)
|
2011-09-01 15:06:11 +00:00
|
|
|
|
2019-09-16 21:30:01 +00:00
|
|
|
ldflags = ' '.join('-L%s' % i for i in config_env['LIBPATH'] if not i.startswith('#'))
|
2013-05-16 18:33:23 +00:00
|
|
|
ldflags += config_env['LIBMAPNIK_LINKFLAGS']
|
2019-09-16 21:17:09 +00:00
|
|
|
template_env['LDFLAGS'] = ldflags
|
2010-07-18 21:34:08 +00:00
|
|
|
|
2012-05-25 00:05:51 +00:00
|
|
|
# remove local agg from public linking
|
2019-09-16 21:30:01 +00:00
|
|
|
dep_libs = ' '.join('-l%s' % i for i in env['LIBMAPNIK_LIBS'] if i != 'agg')
|
2019-09-16 21:17:09 +00:00
|
|
|
template_env['DEP_LIBS'] = dep_libs
|
2014-10-23 07:42:10 +00:00
|
|
|
|
|
|
|
try:
|
2019-09-16 21:17:09 +00:00
|
|
|
stdin, stderr = Popen("git rev-list --max-count=1 HEAD",
|
|
|
|
shell=True, universal_newlines=True,
|
|
|
|
stdout=PIPE, stderr=PIPE).communicate()
|
2012-08-22 21:44:58 +00:00
|
|
|
if not stderr:
|
2019-09-16 21:17:09 +00:00
|
|
|
template_env["GIT_REVISION"] = stdin.strip()
|
2011-10-18 22:22:47 +00:00
|
|
|
|
2019-09-16 21:17:09 +00:00
|
|
|
stdin, stderr = Popen("git describe",
|
|
|
|
shell=True, universal_newlines=True,
|
|
|
|
stdout=PIPE, stderr=PIPE).communicate()
|
2013-03-14 02:49:59 +00:00
|
|
|
if not stderr:
|
2019-09-16 21:17:09 +00:00
|
|
|
template_env["GIT_DESCRIBE"] = stdin.strip()
|
2014-10-23 07:42:10 +00:00
|
|
|
except:
|
|
|
|
pass
|
2013-03-14 02:49:59 +00:00
|
|
|
|
2016-10-15 18:07:52 +00:00
|
|
|
## if we are statically linking dependencies
|
2013-01-24 06:00:25 +00:00
|
|
|
## then they do not need to be reported in ldflags
|
2013-04-11 00:05:33 +00:00
|
|
|
#if env['RUNTIME_LINK'] == 'static':
|
2019-09-16 21:17:09 +00:00
|
|
|
# template_env['LDFLAGS'] = ''
|
|
|
|
# template_env['DEP_LIBS'] = ''
|
2010-07-18 21:34:08 +00:00
|
|
|
|
2011-08-13 17:07:05 +00:00
|
|
|
template = 'mapnik-config.template.sh'
|
|
|
|
config_file = 'mapnik-config'
|
2019-09-16 21:17:09 +00:00
|
|
|
write_config(template_env, template, config_file)
|
2011-08-13 17:07:05 +00:00
|
|
|
target_path = os.path.normpath(os.path.join(config_env['INSTALL_PREFIX'],'bin'))
|
|
|
|
full_target = os.path.join(target_path,config_file)
|
2010-07-18 21:40:24 +00:00
|
|
|
|
2014-10-23 06:46:33 +00:00
|
|
|
Depends(full_target, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME']))
|
2015-10-12 20:42:08 +00:00
|
|
|
Depends(full_target, '../../include/mapnik/version.hpp')
|
2011-08-29 21:12:22 +00:00
|
|
|
|
2010-07-18 21:34:08 +00:00
|
|
|
if 'install' in COMMAND_LINE_TARGETS:
|
|
|
|
# we must add 'install' catch here because otherwise
|
|
|
|
# custom command will be run when not installing
|
|
|
|
env.Alias('install',full_target)
|
2011-10-18 22:22:47 +00:00
|
|
|
|
2011-08-13 17:07:05 +00:00
|
|
|
env.Command(full_target, config_file,
|
2010-07-18 21:34:08 +00:00
|
|
|
[
|
|
|
|
Copy("$TARGET","$SOURCE"),
|
2017-11-16 10:59:55 +00:00
|
|
|
Chmod("$TARGET", 0o755),
|
2010-07-18 21:34:08 +00:00
|
|
|
])
|
|
|
|
|
2011-08-13 17:07:05 +00:00
|
|
|
config_env['create_uninstall_target'](env,os.path.join(target_path,config_file))
|