summaryrefslogtreecommitdiff
path: root/config/windows.config
blob: 658e5cfebf77f5499ebfed7dd9727e2b853d2217 (plain)
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
# This file contains the default configuration to compile for Windows
# platforms. It contains sensitive enviroment configuration that
# shouldn't be modified unless you now what you are doing.
# PLEASE, DO NOT EDIT THIS FILE

import os
from cerbero.config import Architecture, Platform

# We don't want anything from mingw or msys detected in configure and
# used later.
allow_system_libs = False

# We currently don't use Visual Studio by default anywhere
if 'visualstudio' not in variants:
    variants.append('novisualstudio')

if platform == Platform.WINDOWS:
    separator = ';'
    if target_arch == Architecture.X86:
        build = 'i686-w64-mingw32'
    if target_arch == Architecture.X86_64:
        build = 'x86_64-w64-mingw32'
else:
    separator = ':'

if target_arch == Architecture.X86:
    buildname='windows_x86'
    host = 'i686-w64-mingw32'
    _path = 'w32'
else:
    buildname='windows_x86_64'
    host = 'x86_64-w64-mingw32'
    _path = 'w64'

target = host

if not toolchain_prefix:
    toolchain_prefix = os.path.join(home_dir, 'mingw', _path)
if not mingw_perl_prefix:
    mingw_perl_prefix = os.path.join(home_dir, 'mingw', 'perl')

def cmd(command):
    return '%s-%s' % (host, command)

# Default GCC compiler flags
if not for_shell or 'novisualstudio' in variants:
    os.environ['CFLAGS'] = '-Wall -g -O2 '
    os.environ['CXXFLAGS'] = '-Wall -g -O2 '
    os.environ['OBJCFLAGS'] = '-Wall -g -O2 '
else:
    os.environ['CFLAGS'] = ''

ccache = use_ccache and 'ccache ' or ''

# Toolchain environment
os.environ['CFLAGS'] += " -DWINVER=0x0600 -D_WIN32_WINNT=0x0600 "
os.environ['CXXFLAGS']=os.environ['CFLAGS']
os.environ['PERL'] = 'perl'
os.environ['NM']= cmd('nm')
os.environ['DLLTOOL']= cmd('dlltool')
if not for_shell or 'novisualstudio' in variants:
    os.environ['LIBRARY_PATH'] = "{0}/lib{1}".format(prefix, lib_suffix)
    os.environ['CC']= '%s%s' % (ccache, cmd('gcc'))
    os.environ['CXX']= '%s%s' % (ccache, cmd('g++'))
    os.environ['LD']= cmd('ld')
    os.environ['CPP']= cmd('cpp')
    os.environ['RANLIB']= cmd('ranlib')
    os.environ['AR']= cmd('ar')
    os.environ['AS']= cmd('as')
    os.environ['STRIP']= cmd('strip')
    os.environ['WINDRES']= cmd('windres')
    os.environ['RC']= cmd('windres')
    # MinGW toolchain PATH
    toolchainbin = os.path.join(toolchain_prefix, 'bin')
    if os.path.isdir(toolchainbin) and toolchainbin not in os.environ['PATH']:
        os.environ['PATH'] = '%s%s%s' % (toolchainbin, separator, os.environ['PATH'])

os.environ['ne_cv_libsfor_socket'] = '-lws2_32'
os.environ['ne_cv_libsfor_gethostbyname'] = '-lws2_32'
os.environ['ac_cv_func_malloc_0_nonnull'] ='yes'
os.environ['ac_cv_func_realloc_0_nonnull'] ='yes'
os.environ['lt_cv_deplibs_check_method'] = 'pass_all'
os.environ['ac_cv_lib_bz2_BZ2_bzlibVersion'] = 'yes'
os.environ['ac_cv_c_attribute_aligned'] = '64'

if platform == Platform.WINDOWS:
    # Make's job server is buggy and broken on Windows, which causes it to
    # either hang or print server errors like:
    # 2068442963 [sig] make 18324 sig_dispatch_pending: Win32 error 298 releasing sigcatch_nosync(0x150)
    # Only use one process to make the build more reliable.
    allow_parallel_build = False

    os.environ['ACLOCAL'] = 'aclocal-1.11'

    from cerbero.ide.vs.env import get_msvc_env, append_path
    # Contains only the env vars that MSVC needs, including any existing vars
    # that were appended/prepended and have new values
    # FIXME: Use EnvVarOp class from cerbero/build/build.py
    msvc_toolchain_env = {}
    env, msvc_version = get_msvc_env(arch, target_arch)
    for key, value in env.items():
        if key in ('PATH', 'PATHEXT', 'INCLUDE', 'LIB'):
            sep = separator
        else:
            sep = ' '
        msvc_toolchain_env.update({key: [value, sep]})
    # We want the MSVC compiler and linker to find the headers and libraries
    # provided by recipes built by us, so append to INCLUDE and LIB.
    # NOTE: We do not want to add the MinGW toolchain paths here
    msvc_toolchain_env['INCLUDE'][0] = append_path(msvc_toolchain_env['INCLUDE'][0],
                                                   os.path.join(prefix, 'include'))
    msvc_toolchain_env['LIB'][0] = append_path(msvc_toolchain_env['LIB'][0],
                                               os.path.join(prefix, 'lib' + lib_suffix))
    msvc_toolchain_env['WINDRES'] = ['rc', '']
    # With MinGW, DirectX headers are inside a subdir, and we don't want to
    # accidentally use these when building with MSVC, so we don't unconditionally
    # add them to CFLAGS.
    mingw_toolchain_env = {'CPPFLAGS': ('-I%s/%s/include/directx' % (toolchain_prefix, host), ' ')}

    # If no BOM is found from source file, msvc assumes the file is encoded
    # using the current user code page unless '/utf-8' option was specified.
    # Auto detected (by msvc) code page might cause compile error depending on locale
    # https://docs.microsoft.com/en-us/cpp/build/reference/utf-8-set-source-and-executable-character-sets-to-utf-8
    msvc_toolchain_env['CFLAGS'] = ['/utf-8', '']

    # Export the env for an MSVC shell
    if for_shell and 'novisualstudio' not in variants:
        for var, (val, sep) in msvc_toolchain_env.items():
            if var in os.environ:
                # Don't set it twice
                if val in os.environ[var]:
                    continue
                os.environ[var] = '{}{}{}'.format(val, sep, os.environ[var])
            else:
                os.environ[var] = val
else:
    # For cross-mingw, we need to set this in the env so it's added to the
    # cross file before Meson is run.
    os.environ['CFLAGS'] += '-I%s/%s/include/directx' % (toolchain_prefix, host)