summaryrefslogtreecommitdiff
path: root/config/windows.config
blob: 6b5ce417f1ecc48a37fcf22e9fafb992c039b620 (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
140
141
142
143
144
145
146
147
148
149
150
151
152
# 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:
    env['WIX'] = os.path.join(build_tools_prefix, 'lib', 'wix')
    env['WINEPREFIX'] = os.path.join(build_tools_prefix, 'share', 'wine')
    separator = ':'

if target_arch == Architecture.X86:
    buildname='windows_x86'
    arch_flags = ' -m32 '
    arch_rcflags = ' -F pe-i386 '
    dlltool_flags = '--as-flags=--32 -m i386'
    host = 'i386-w64-mingw32'
    _path = 'multilib'
else:
    buildname='windows_x86_64'
    arch_flags = ''
    arch_rcflags = ''
    dlltool_flags = ''
    host = 'x86_64-w64-mingw32'
    _path = 'multilib'

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')

if not tools_prefix:
    tools_prefix = host+'-'
    __cc_candidate = os.path.join(toolchain_prefix, 'bin', '%sgcc' % tools_prefix)
    # Check for a multilib toolchain
    if not os.path.exists(__cc_candidate):
        tools_prefix = 'x86_64-w64-mingw32-'

def cmd(command):
    return '%s%s' % (tools_prefix, command)

# Default GCC compiler flags
if not for_shell or 'novisualstudio' in variants:
    env['CFLAGS'] = '-Wall -g -O2 ' + arch_flags
    env['CXXFLAGS'] = '-Wall -g -O2 ' + arch_flags
    env['OBJCFLAGS'] = '-Wall -g -O2 ' + arch_flags
    env['CASFLAGS'] = arch_flags
    env['LDFLAGS'] = arch_flags
    env['RCFLAGS'] = arch_rcflags
else:
    env['CFLAGS'] = ''

ccache = use_ccache and 'ccache ' or ''

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

env['ne_cv_libsfor_socket'] = '-lws2_32'
env['ne_cv_libsfor_gethostbyname'] = '-lws2_32'
env['ac_cv_func_malloc_0_nonnull'] ='yes'
env['ac_cv_func_realloc_0_nonnull'] ='yes'
env['lt_cv_deplibs_check_method'] = 'pass_all'
env['ac_cv_lib_bz2_BZ2_bzlibVersion'] = 'yes'
env['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

    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', '']

    # 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 env:
                # Don't set it twice
                if val in env[var]:
                    continue
                env[var] = '{}{}{}'.format(val, sep, env[var])
            else:
                env[var] = val
# For cross-mingw, we need to set this in the env so it's added to the
# cross file before Meson is run.
mingw_toolchain_env = dict()