File: build.py

package info (click to toggle)
mapnik 4.2.1%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 18,656 kB
  • sloc: cpp: 163,870; python: 1,332; sh: 690; xml: 161; makefile: 123; perl: 28; lisp: 13
file content (144 lines) | stat: -rw-r--r-- 5,469 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#
# This file is part of Mapnik (c++ mapping toolkit)
#
# Copyright (C) 2015 Artem Pavlenko
#
# 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
#
#

import re
import os
import sys
from copy import copy
from subprocess import Popen, PIPE
from SCons.Environment import OverrideEnvironment

Import('env')

config_env = env.Clone()


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']):
    print ('Error: version.hpp mismatch (%s) to cached value (%s): please reconfigure mapnik' % (GetMapnikLibVersion(),config_env['MAPNIK_VERSION_STRING']))
    Exit(1)

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)
            if key not in env:
                return matchobj.group(0)
            else:
                val = env.subst('$' + key)
                return 'CONFIG_%s=%s' % (key, escape(val))
        config = re.sub(r'^CONFIG_(\w+)=.*', subst, template, flags=re.M)
        config_file.write(config)
    try:
        os.chmod(config_filename, 0o755)
    except: pass


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')]
# 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
cxxflags_cleaned = [x for x in cxxflags_cleaned if x != '-Qunused-arguments']
cxx_cleaned = config_env['CXX'].replace(' -Qunused-arguments', '')

template_env['CXXFLAGS'] = ' '.join(cxxflags_cleaned)
template_env['CXX'] = re.sub(r'^ccache +', '', cxx_cleaned)

template_env['DEFINES'] = ' '.join(config_env['LIBMAPNIK_DEFINES'])

dep_includes = ['-I%s' % i for i in config_env['CPPPATH'] if not i.startswith('#')]
if config_env['HAS_CAIRO']:
    dep_includes += ['-I%s' % i for i in env['CAIRO_CPPPATHS'] if not i.startswith('#')]
template_env['DEP_INCLUDES'] = ' '.join(dep_includes)

ldflags = ' '.join('-L%s' % i for i in config_env['LIBPATH'] if not i.startswith('#'))
ldflags += config_env['LIBMAPNIK_LINKFLAGS']
template_env['LDFLAGS'] = ldflags

# remove local agg from public linking
dep_libs = ' '.join('-l%s' % i for i in env['LIBMAPNIK_LIBS'] if i != 'agg')
template_env['DEP_LIBS'] = dep_libs

try:
    stdin, stderr = Popen("git rev-list --max-count=1 HEAD",
                        shell=True, universal_newlines=True,
                        stdout=PIPE, stderr=PIPE).communicate()
    if not stderr:
        template_env["GIT_REVISION"] = stdin.strip()

    stdin, stderr = Popen("git describe",
                        shell=True, universal_newlines=True,
                        stdout=PIPE, stderr=PIPE).communicate()
    if not stderr:
        template_env["GIT_DESCRIBE"] = stdin.strip()
except:
    pass

## if we are statically linking dependencies
## then they do not need to be reported in ldflags
#if env['RUNTIME_LINK'] == 'static':
#    template_env['LDFLAGS'] = ''
#    template_env['DEP_LIBS'] = ''

template = 'mapnik-config.template.sh'
config_file = 'mapnik-config'
write_config(template_env, template, config_file)
target_path = os.path.normpath(os.path.join(config_env['INSTALL_PREFIX'],'bin'))
full_target = os.path.join(target_path,config_file)

Depends(full_target, env.subst('../../src/%s' % env['MAPNIK_LIB_NAME']))
Depends(full_target, '../../include/mapnik/version.hpp')

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)

    env.Command(full_target, config_file,
       [
       Copy("$TARGET","$SOURCE"),
       Chmod("$TARGET", 0o755),
       ])

config_env['create_uninstall_target'](env,os.path.join(target_path,config_file))