[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bug#859177: meson is unuseable for package cross compilation



On Sat, Apr 1, 2017 at 7:45 AM, Helmut Grohne <helmut@subdivi.de> wrote:

>> That being said generating them live is probably a good approach, it
>> seems to be mostly a question of mangling the output of
>> dpkg-architecture.
>
> Yes. That's also essentially how the command line parameters for CMake
> are constructed[1].

Attached is a simple script that generates a cross file that works for
me when using a simple project. Use it like this:

./debcrossgen.py armhf generated_cross.txt

And then pass --libdir=lib/archdir_here --cross-file
generated_cross.txt to Meson to use it.

It only takes care of host, not target. Consider it an MVP. :)
#!/usr/bin/env python3

# Copyright 2017 Jussi Pakkanen

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at

#     http://www.apache.org/licenses/LICENSE-2.0

# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import sys, os, subprocess

def run(arch, ofilename):
    output = subprocess.check_output(['dpkg-architecture', '-a' + arch], universal_newlines=True)
    data = {}
    for line in output.split('\n'):
        line = line.strip()
        if line == '':
            continue
        k, v = line.split('=', 1)
        data[k] = v
    host_arch = data['DEB_HOST_GNU_TYPE']
    host_os = data['DEB_HOST_ARCH_OS']
    host_cpu_family = data['DEB_HOST_GNU_CPU']
    host_cpu = data['DEB_HOST_ARCH'] # Not really correct, should be arm7hlf etc but it is not exposed.
    host_endian = data['DEB_HOST_ARCH_ENDIAN']
    ofile = open(ofilename, 'w')
    ofile.write('[binaries]\n')
    ofile.write("c = '/usr/bin/%s-gcc-6'\n" % host_arch)
    ofile.write("cpp = '/usr/bin/%s-g++-6'\n" % host_arch)
    ofile.write("ar = '/usr/bin/%s-ar'\n" % host_arch)
    ofile.write("strip = '/usr/bin/%s-strip'\n" % host_arch)
    ofile.write("pkgconfig = '/usr/bin/%s-pkg-config'\n" % host_arch)
    ofile.write('\n[properties]\n')
    ofile.write('\n[host_machine]\n')
    ofile.write("system = '%s'\n" % host_os)
    ofile.write("cpu_family = '%s'\n" % host_cpu_family)
    ofile.write("cpu = '%s'\n" % host_cpu)
    ofile.write("endian = '%s'\n" % host_endian)
    ofile.close()

if __name__ == '__main__':
    if len(sys.argv) != 3:
        print(sys.argv[0], 'host-arch outputfile')
        sys.exit(1)
    arch = sys.argv[1]
    outfile = sys.argv[2]
    run(arch, outfile)
    print('Remember to add the proper --libdir arg to Meson invocation.')

Reply to: