diff options
-rw-r--r-- | authors.txt | 1 | ||||
-rw-r--r-- | build.py | 1 | ||||
-rw-r--r-- | compilers.py | 13 | ||||
-rw-r--r-- | dependencies.py | 1 | ||||
-rw-r--r-- | environment.py | 14 | ||||
-rw-r--r-- | interpreter.py | 2 | ||||
-rw-r--r-- | manual tests/1 wrap/meson.build | 11 | ||||
-rw-r--r-- | mesonlib.py | 8 | ||||
-rw-r--r-- | modules/gnome.py | 11 | ||||
-rw-r--r-- | ninjabackend.py | 40 | ||||
-rw-r--r-- | test cases/common/92 skip subdir/meson.build | 3 | ||||
-rw-r--r-- | test cases/common/92 skip subdir/subdir1/meson.build | 1 | ||||
-rw-r--r-- | test cases/common/92 skip subdir/subdir1/subdir2/meson.build | 1 | ||||
-rw-r--r-- | test cases/fortran/6 dynamic/dynamic.f95 | 17 | ||||
-rw-r--r-- | test cases/fortran/6 dynamic/main.f95 | 6 | ||||
-rw-r--r-- | test cases/fortran/6 dynamic/meson.build | 4 | ||||
-rwxr-xr-x | tools/ac_converter.py | 217 | ||||
-rwxr-xr-x | tools/autotools2meson.py | 122 | ||||
-rwxr-xr-x | tools/cmake2meson.py | 2 |
19 files changed, 320 insertions, 155 deletions
diff --git a/authors.txt b/authors.txt index c73fda8..0db0c3d 100644 --- a/authors.txt +++ b/authors.txt @@ -19,3 +19,4 @@ Thibault Saunier Mathieu Duponchelle Jouni Roivas Rafaël Kooi +Marko Raatikainen @@ -630,6 +630,7 @@ class SharedLibrary(BuildTarget): self.prefix = environment.get_shared_lib_prefix() self.suffix = environment.get_shared_lib_suffix() self.importsuffix = environment.get_import_lib_suffix() + self.filename = self.prefix + self.name + '.' + self.suffix def process_kwargs(self, kwargs, environment): super().process_kwargs(kwargs, environment) diff --git a/compilers.py b/compilers.py index fbaf433..1e778d3 100644 --- a/compilers.py +++ b/compilers.py @@ -1056,6 +1056,11 @@ class GnuCCompiler(CCompiler): '2': ['-Wall', '-Wpedantic', '-Winvalid-pch'], '3' : ['-Wall', '-Wpedantic', '-Wextra', '-Winvalid-pch']} + def get_pic_args(self): + if self.gcc_type == GCC_MINGW: + return [] # On Window gcc defaults to fpic being always on. + return ['-fPIC'] + def get_always_args(self): return ['-pipe'] @@ -1240,6 +1245,14 @@ class FortranCompiler(): def get_language(self): return self.language + def get_pic_args(self): + if self.gcc_type == GCC_MINGW: + return [] # On Windows gcc defaults to fpic being always on. + return ['-fPIC'] + + def get_std_shared_lib_link_args(self): + return ['-shared'] + def needs_static_linker(self): return True diff --git a/dependencies.py b/dependencies.py index 08fb864..d47dac8 100644 --- a/dependencies.py +++ b/dependencies.py @@ -902,6 +902,7 @@ class GLDependency(Dependency): return if mesonlib.is_windows(): self.is_found = True + self.linkargs = ['-lopengl32'] return def get_link_args(self): diff --git a/environment.py b/environment.py index 493ee2c..db6d5a2 100644 --- a/environment.py +++ b/environment.py @@ -189,7 +189,12 @@ class Environment(): return GnuCCompiler(ccache + [compiler], version, GCC_OSX, is_cross, exe_wrap) if (out.startswith('cc') or 'gcc' in out) and \ 'Free Software Foundation' in out: - return GnuCCompiler(ccache + [compiler], version, GCC_STANDARD, is_cross, exe_wrap) + lowerout = out.lower() + if 'mingw' in lowerout or 'msys' in lowerout or 'mingw' in compiler.lower(): + gtype = GCC_MINGW + else: + gtype = GCC_STANDARD + return GnuCCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap) if 'clang' in out: return ClangCCompiler(ccache + [compiler], version, is_cross, exe_wrap) if 'Microsoft' in out: @@ -308,7 +313,12 @@ class Environment(): return GnuCPPCompiler(ccache + [compiler], version, GCC_OSX, is_cross, exe_wrap) if (out.startswith('c++ ') or 'g++' in out or 'GCC' in out) and \ 'Free Software Foundation' in out: - return GnuCPPCompiler(ccache + [compiler], version, GCC_STANDARD, is_cross, exe_wrap) + lowerout = out.lower() + if 'mingw' in lowerout or 'msys' in lowerout or 'mingw' in compiler.lower(): + gtype = GCC_MINGW + else: + gtype = GCC_STANDARD + return GnuCPPCompiler(ccache + [compiler], version, gtype, is_cross, exe_wrap) if 'clang' in out: return ClangCPPCompiler(ccache + [compiler], version, is_cross, exe_wrap) if 'Microsoft' in out: diff --git a/interpreter.py b/interpreter.py index 5e8effc..9923892 100644 --- a/interpreter.py +++ b/interpreter.py @@ -1540,7 +1540,7 @@ class Interpreter(): self.visited_subdirs[subdir] = True self.subdir = subdir try: - os.mkdir(os.path.join(self.environment.build_dir, subdir)) + os.makedirs(os.path.join(self.environment.build_dir, subdir)) except FileExistsError: pass buildfilename = os.path.join(self.subdir, environment.build_filename) diff --git a/manual tests/1 wrap/meson.build b/manual tests/1 wrap/meson.build index afdda34..99ea260 100644 --- a/manual tests/1 wrap/meson.build +++ b/manual tests/1 wrap/meson.build @@ -2,10 +2,13 @@ project('downloader', 'c') s = subproject('sqlite') +libdl = find_library('dl', required : false) + e = executable('dtest', 'main.c', -include_directories : s.get_variable('sqinc'), -link_args : ['-pthread', '-ldl'], -c_args : '-pthread', -link_with : s.get_variable('sqlib')) + include_directories : s.get_variable('sqinc'), + link_args : ['-pthread'], + c_args : '-pthread', + dependencies : libdl, + link_with : s.get_variable('sqlib')) test('dltest', e) diff --git a/mesonlib.py b/mesonlib.py index 76fb792..d199725 100644 --- a/mesonlib.py +++ b/mesonlib.py @@ -113,9 +113,13 @@ def detect_vcs(source_dir): return vcs return None +numpart = re.compile('[0-9.]+') + def version_compare(vstr1, vstr2): - if '-' in vstr1: - vstr1 = vstr1.split('-')[0] + match = numpart.match(vstr1.strip()) + if match is None: + raise MesonException('Unconparable version string %s.' % vstr1) + vstr1 = match.group(0) if vstr2.startswith('>='): cmpop = operator.ge vstr2 = vstr2[2:] diff --git a/modules/gnome.py b/modules/gnome.py index 7e51174..ac68515 100644 --- a/modules/gnome.py +++ b/modules/gnome.py @@ -21,6 +21,8 @@ import subprocess from coredata import MesonException import mlog +girwarning_printed = False + class GnomeModule: def compile_resources(self, state, args, kwargs): @@ -49,7 +51,14 @@ class GnomeModule: girtarget = girtarget.held_object if not isinstance(girtarget, (build.Executable, build.SharedLibrary)): raise MesonException('Gir target must be an executable or shared library') - pkgstr = subprocess.check_output(['pkg-config', '--cflags', 'gobject-introspection-1.0']) + try: + pkgstr = subprocess.check_output(['pkg-config', '--cflags', 'gobject-introspection-1.0']) + except Exception: + global girwarning_printed + if not girwarning_printed: + mlog.log(mlog.bold('Warning:'), 'gobject-introspection dependency was not found, disabling gir generation.') + girwarning_printed = True + return [] pkgargs = pkgstr.decode().strip().split() ns = kwargs.pop('namespace') nsversion = kwargs.pop('nsversion') diff --git a/ninjabackend.py b/ninjabackend.py index b9122ee..8e87b13 100644 --- a/ninjabackend.py +++ b/ninjabackend.py @@ -258,7 +258,8 @@ class NinjaBackend(backends.Backend): obj_list.append(self.generate_single_compile(target, outfile, src, True, unity_deps + header_deps)) linker = self.determine_linker(target, src_list) elem = self.generate_link(target, outfile, outname, obj_list, linker, pch_objects) - self.generate_shlib_aliases(target, self.get_target_dir(target), outfile, elem) + self.generate_shlib_aliases(target, self.get_target_dir(target)) + elem.write(outfile) self.processed_targets[name] = True def process_target_dependencies(self, target, outfile): @@ -312,7 +313,7 @@ class NinjaBackend(backends.Backend): def generate_run_target(self, target, outfile): runnerscript = os.path.join(self.environment.get_script_dir(), 'commandrunner.py') elem = NinjaBuildElement(target.name, 'CUSTOM_COMMAND', []) - cmd = [self.detect_pythonbin(), runnerscript, self.environment.get_source_dir(), self.environment.get_build_dir(), + cmd = [sys.executable, runnerscript, self.environment.get_source_dir(), self.environment.get_build_dir(), target.subdir, target.command] + target.args elem.add_item('COMMAND', cmd) elem.add_item('description', 'Running external command %s.' % target.name) @@ -370,12 +371,6 @@ class NinjaBackend(backends.Backend): if not added_rule: mlog.log(mlog.red('Warning:'), 'coverage requested but neither gcovr nor lcov/genhtml found.') - def detect_pythonbin(self): - # Under msys2 Python lies about where sys.executable is. - if 'MSYSTEM' in os.environ: - return os.path.join(os.environ['WD'], 'python3') - return sys.executable - def generate_install(self, outfile): script_root = self.environment.get_script_dir() install_script = os.path.join(script_root, 'meson_install.py') @@ -387,7 +382,7 @@ class NinjaBackend(backends.Backend): elem = NinjaBuildElement('install', 'CUSTOM_COMMAND', '') elem.add_dep('all') elem.add_item('DESC', 'Installing files.') - elem.add_item('COMMAND', [self.detect_pythonbin(), install_script, install_data_file]) + elem.add_item('COMMAND', [sys.executable, install_script, install_data_file]) elem.add_item('pool', 'console') self.generate_depmf_install(d) self.generate_target_install(d) @@ -499,7 +494,7 @@ class NinjaBackend(backends.Backend): script_root = self.environment.get_script_dir() test_script = os.path.join(script_root, 'meson_test.py') test_data = os.path.join(self.environment.get_scratch_dir(), 'meson_test_setup.dat') - cmd = [self.detect_pythonbin(), test_script, test_data] + cmd = [sys.executable, test_script, test_data] elem = NinjaBuildElement('test', 'CUSTOM_COMMAND', ['all', 'PHONY']) elem.add_item('COMMAND', cmd) elem.add_item('DESC', 'Running test suite.') @@ -527,7 +522,7 @@ class NinjaBackend(backends.Backend): outfile.write(' description = $DESC\n') outfile.write(' restat = 1\n\n') outfile.write('rule REGENERATE_BUILD\n') - c = (quote_char + ninja_quote(self.detect_pythonbin()) + quote_char, + c = (quote_char + ninja_quote(sys.executable) + quote_char, quote_char + ninja_quote(self.environment.get_build_command()) + quote_char, quote_char + ninja_quote(self.environment.get_source_dir()) + quote_char, quote_char + ninja_quote(self.environment.get_build_dir()) + quote_char) @@ -834,7 +829,7 @@ class NinjaBackend(backends.Backend): scriptdir = self.environment.get_script_dir() outfile.write('\n') symrule = 'rule SHSYM\n' - symcmd = ' command = "%s" "%s" %s %s $CROSS\n' % (ninja_quote(self.detect_pythonbin()), + symcmd = ' command = "%s" "%s" %s %s $CROSS\n' % (ninja_quote(sys.executable), ninja_quote(os.path.join(scriptdir, 'symbolextractor.py')), '$in', '$out') synstat = ' restat = 1\n' @@ -885,7 +880,7 @@ class NinjaBackend(backends.Backend): rule = 'rule %s_COMPILER\n' % compiler.get_language() invoc = ' '.join([ninja_quote(i) for i in compiler.get_exelist()]) command = ' command = %s %s $out $cratetype %s $ARGS $in\n' % \ - (ninja_quote(self.detect_pythonbin()), + (ninja_quote(sys.executable), ninja_quote(os.path.join(os.path.split(__file__)[0], "rustrunner.py")), invoc) description = ' description = Compiling Rust source $in.\n' @@ -1382,32 +1377,33 @@ rule FORTRAN_DEP_HACK return os.path.join(self.get_target_private_dir(t), self.get_target_filename(t) + '.symbols') return self.get_target_filename(t) - def generate_shlib_aliases(self, target, outdir, outfile, elem): + def generate_shlib_aliases(self, target, outdir): basename = target.get_filename() aliases = target.get_aliaslist() aliascmd = [] if shutil.which('ln'): for alias in aliases: - aliasfile = os.path.join(outdir, alias) - cmd = ["&&", 'ln', '-s', '-f', basename, aliasfile] - aliascmd += cmd + aliasfile = os.path.join(self.environment.get_build_dir(), outdir, alias) + try: + os.remove(aliasfile) + except Exception: + pass + os.symlink(basename, aliasfile) else: - mlog.log("Library versioning disabled because host does not support symlinks.") - elem.add_item('aliasing', aliascmd) - elem.write(outfile) + mlog.debug("Library versioning disabled because host does not support symlinks.") def generate_gcov_clean(self, outfile): gcno_elem = NinjaBuildElement('clean-gcno', 'CUSTOM_COMMAND', 'PHONY') script_root = self.environment.get_script_dir() clean_script = os.path.join(script_root, 'delwithsuffix.py') - gcno_elem.add_item('COMMAND', [self.detect_pythonbin(), clean_script, '.', 'gcno']) + gcno_elem.add_item('COMMAND', [sys.executable, clean_script, '.', 'gcno']) gcno_elem.add_item('description', 'Deleting gcno files') gcno_elem.write(outfile) gcda_elem = NinjaBuildElement('clean-gcda', 'CUSTOM_COMMAND', 'PHONY') script_root = self.environment.get_script_dir() clean_script = os.path.join(script_root, 'delwithsuffix.py') - gcda_elem.add_item('COMMAND', [self.detect_pythonbin(), clean_script, '.', 'gcda']) + gcda_elem.add_item('COMMAND', [sys.executable, clean_script, '.', 'gcda']) gcda_elem.add_item('description', 'Deleting gcda files') gcda_elem.write(outfile) diff --git a/test cases/common/92 skip subdir/meson.build b/test cases/common/92 skip subdir/meson.build new file mode 100644 index 0000000..30ede0e --- /dev/null +++ b/test cases/common/92 skip subdir/meson.build @@ -0,0 +1,3 @@ +project('foo', 'c') + +subdir('subdir1/subdir2') diff --git a/test cases/common/92 skip subdir/subdir1/meson.build b/test cases/common/92 skip subdir/subdir1/meson.build new file mode 100644 index 0000000..51cb003 --- /dev/null +++ b/test cases/common/92 skip subdir/subdir1/meson.build @@ -0,0 +1 @@ +error('This should not be called.') diff --git a/test cases/common/92 skip subdir/subdir1/subdir2/meson.build b/test cases/common/92 skip subdir/subdir1/subdir2/meson.build new file mode 100644 index 0000000..e37cad6 --- /dev/null +++ b/test cases/common/92 skip subdir/subdir1/subdir2/meson.build @@ -0,0 +1 @@ +message('I\'m in subdir subdir.') diff --git a/test cases/fortran/6 dynamic/dynamic.f95 b/test cases/fortran/6 dynamic/dynamic.f95 new file mode 100644 index 0000000..e78a406 --- /dev/null +++ b/test cases/fortran/6 dynamic/dynamic.f95 @@ -0,0 +1,17 @@ +module dynamic + implicit none + + private + public :: hello + + interface hello + module procedure say + end interface hello + +contains + + subroutine say + print *, "Hello, hello..." + end subroutine say + +end module dynamic diff --git a/test cases/fortran/6 dynamic/main.f95 b/test cases/fortran/6 dynamic/main.f95 new file mode 100644 index 0000000..cb3a53f --- /dev/null +++ b/test cases/fortran/6 dynamic/main.f95 @@ -0,0 +1,6 @@ +program main + use dynamic + implicit none + + call hello() +end program main diff --git a/test cases/fortran/6 dynamic/meson.build b/test cases/fortran/6 dynamic/meson.build new file mode 100644 index 0000000..53edaf6 --- /dev/null +++ b/test cases/fortran/6 dynamic/meson.build @@ -0,0 +1,4 @@ +project('dynamic_fortran', 'fortran') + +dynamic = shared_library('dynamic', 'dynamic.f95') +executable('test_exe', 'main.f95', link_with : dynamic) diff --git a/tools/ac_converter.py b/tools/ac_converter.py new file mode 100755 index 0000000..150edb5 --- /dev/null +++ b/tools/ac_converter.py @@ -0,0 +1,217 @@ +#!/usr/bin/env python3 + +# Copyright 2015 The Meson development team + +# 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. + +"""This script reads config.h.meson, looks for header +checks and writes the corresponding meson declaration. + +Copy config.h.in to config.h.meson, replace #undef +with #mesondefine and run this. We can't do this automatically +because some configure scripts have #undef statements +that are unrelated to configure checks. +""" + +import sys + +print('''cc = meson.get_compiler('c') +cdata = configuration_data()''') + +print('check_headers = [') + +for line in open(sys.argv[1]): + line = line.strip() + if line.startswith('#mesondefine') and \ + line.endswith('_H'): + token = line.split()[1] + tarr = token.split('_')[1:-1] + tarr = [x.lower() for x in tarr] + hname = '/'.join(tarr) + '.h' + print(" ['%s', '%s']," % (token, hname)) +print(']\n') + +print('''foreach h : check_headers + if cc.has_header(h.get(1)) + cdata.set(h.get(0), 1) + endif +endforeach +''') + +# Add stuff here as it is encountered. +function_data = \ + {'HAVE_FEENABLEEXCEPT' : ('feenableexcept', 'fenv.h'), + 'HAVE_FECLEAREXCEPT' : ('feclearexcept', 'fenv.h'), + 'HAVE_FEDISABLEEXCEPT' : ('fedisableexcept', 'fenv.h'), + 'HAVE_MMAP' : ('mmap', 'sys/mman.h'), + 'HAVE_GETPAGESIZE' : ('getpagesize', 'unistd.h'), + 'HAVE_GETISAX' : ('getisax', 'sys/auxv.h'), + 'HAVE_GETTIMEOFDAY' : ('gettimeofday', 'sys/time.h'), + 'HAVE_MPROTECT' : ('mprotect', 'sys/mman.h'), + 'HAVE_POSIX_MEMALIGN' : ('posix_memalign', 'stdlib.h'), + 'HAVE_SIGACTION' : ('sigaction', 'signal.h'), + 'HAVE_ALARM' : ('alarm', 'unistd.h'), + 'HAVE_CLOCK_GETTIME' : ('clock_gettime', 'time.h'), + 'HAVE_CTIME_R' : ('ctime_r', 'time.h'), + 'HAVE_DRAND48' : ('drand48', 'stdlib.h'), + 'HAVE_FLOCKFILE' : ('flockfile', 'stdio.h'), + 'HAVE_FORK' : ('fork', 'unistd.h'), + 'HAVE_FUNLOCKFILE' : ('funlockfile', 'stdio.h'), + 'HAVE_GETLINE' : ('getline', 'stdio.h'), + 'HAVE_LINK' : ('link', 'unistd.h'), + 'HAVE_RAISE' : ('raise', 'signal.h'), + 'HAVE_STRNDUP' : ('strndup', 'string.h'), + 'HAVE_SCHED_GETAFFINITY' : ('sched_getaffinity', 'sched.h'), + 'HAVE_WAITPID' : ('waitpid', 'sys/wait.h'), + 'HAVE_XRENDERCREATECONICALGRADIENT' : ('XRenderCreateConicalGradient', 'xcb/render.h'), + 'HAVE_XRENDERCREATELINEARGRADIENT' : ('XRenderCreateLinearGradient', 'xcb/render.h'), + 'HAVE_XRENDERCREATERADIALGRADIENT' : ('XRenderCreateRadialGradient', 'xcb/render.h'), + 'HAVE_XRENDERCREATESOLIDFILL' : ('XRenderCreateSolidFill', 'xcb/render.h'), + 'HAVE_DCGETTEXT': ('dcgettext', 'libintl.h'), + 'HAVE_ENDMNTENT': ('endmntent', 'mntent.h'), + 'HAVE_ENDSERVENT' : ('endservent', 'netdb.h'), + 'HAVE_EVENTFD': ('eventfd', 'sys/eventfd.h'), + 'HAVE_FALLOCATE': ('fallocate', 'fcntl.h'), + 'HAVE_FCHMOD': ('fchmod', 'sys/stat.h'), + 'HAVE_FCHOWN': ('fchown', 'unistd.h'), + 'HAVE_FDWALK': ('fdwalk', 'stdlib.h'), + 'HAVE_FSYNC': ('fsync', 'unistd.h'), + 'HAVE_GETC_UNLOCKED': ('getc_unlocked', 'stdio.h'), + 'HAVE_GETFSSTAT': ('getfsstat', 'sys/mount.h'), + 'HAVE_GETMNTENT_R': ('getmntent_r', 'mntent.h'), + 'HAVE_GETPROTOBYNAME_R': ('getprotobyname_r', 'netdb.h'), + 'HAVE_GETRESUID' : ('getresuid', 'unistd.h'), + 'HAVE_GETVFSSTAT' : ('getvfsstat', 'sys/statvfs.h'), + 'HAVE_GMTIME_R' : ('gmtime_r', 'time.h'), + 'HAVE_HASMNTOPT': ('hasmntopt', 'mntent.h'), + 'HAVE_IF_INDEXTONAME': ('if_indextoname', 'net/if.h'), + 'HAVE_IF_NAMETOINDEX': ('if_nametoindex', 'net/if.h'), + 'HAVE_INOTIFY_INIT1': ('inotify_init1', 'sys/inotify.h'), + 'HAVE_ISSETUGID': ('issetugid', 'unistd.h'), + 'HAVE_KEVENT': ('kevent', 'sys/event.h'), + 'HAVE_KQUEUE': ('kqueue', 'sys/event.h'), + 'HAVE_LCHMOD': ('lchmod', 'sys/stat.h'), + 'HAVE_LCHOWN': ('lchown', 'unistd.h'), + 'HAVE_LSTAT': ('lstat', 'sys/stat.h'), + 'HAVE_MEMCPY': ('memcpy', 'string.h'), + 'HAVE_MEMALIGN': ('memalign', 'stdlib.h'), + 'HAVE_MEMMEM': ('memmem', 'string.h'), + 'HAVE_NEWLOCALE': ('newlocale', 'locale.h'), + 'HAVE_PIPE2': ('pipe2', 'fcntl.h'), + 'HAVE_POLL': ('poll', 'poll.h'), + 'HAVE_PRLIMIT': ('prlimit', 'sys/resource.h'), + 'HAVE_PTHREAD_ATTR_SETSTACKSIZE': ('pthread_attr_setstacksize', 'pthread.h'), + 'HAVE_PTHREAD_CONDATTR_SETCLOCK': ('pthread_condattr_setclock', 'pthread.h'), + 'HAVE_PTHREAD_COND_TIMEDWAIT_RELATIVE_NP': ('pthread_cond_timedwait_relative_np', 'pthread.h'), + 'HAVE_READLINK': ('readlink', 'unistd.h'), + 'HAVE_RES_INIT': ('res_init', 'resolv.h'), + 'HAVE_SENDMMSG': ('sendmmsg', 'sys/socket.h'), + 'HAVE_SETENV': ('setenv', 'stdlib.h'), + 'HAVE_SETMNTENT': ('setmntent', 'mntent.h'), + 'HAVE_SNPRINTF': ('snprintf', 'stdio.h'), + 'HAVE_SPLICE': ('splice', 'fcntl.h'), + 'HAVE_STATFS': ('statfs', 'mount.h'), + 'HAVE_STATVFS': ('statvfs', 'sys/statvfs.h'), + 'HAVE_STPCOPY': ('stpcopy', 'string.h'), + 'HAVE_STRCASECMP': ('strcasecmp', 'strings.h'), + 'HAVE_STRLCPY': ('strlcpy', 'string.h'), + 'HAVE_STRNCASECMP': ('strncasecmp', 'strings.h'), + 'HAVE_STRSIGNAL': ('strsignal', 'signal.h'), + 'HAVE_STRTOD_L': ('strtod_l', 'stdlib.h'), + 'HAVE_STRTOLL_L': ('strtoll_l', 'stdlib.h'), + 'HAVE_STRTOULL_L': ('strtoull_l', 'stdlib.h'), + 'HAVE_SYMLINK': ('symlink', 'unistd.h'), + 'HAVE_SYSCTLBYNAME': ('sysctlbyname', 'sys/sysctl.h'), + 'HAVE_TIMEGM': ('timegm', 'time.h'), + 'HAVE_UNSETENV': ('unsetenv', 'stdlib.h'), + 'HAVE_USELOCALE': ('uselocale', 'xlocale.h'), + 'HAVE_UTIMES': ('utimes', 'sys/time.h'), + 'HAVE_VALLOC': ('valloc', 'stdlib.h'), + 'HAVE_VASPRINTF': ('vasprintf', 'stdio.h'), + 'HAVE_VSNPRINTF': ('vsnprintf', 'stdio.h'), + 'HAVE_BCOPY': ('bcopy', 'strings.h'), + 'HAVE_STRERROR': ('strerror', 'string.h'), + 'HAVE_MEMMOVE': ('memmove', 'string.h'), + 'HAVE_STRTOIMAX': ('strtoimax', 'inttypes.h'), + 'HAVE_STRTOLL': ('strtoll', 'stdlib.h'), + 'HAVE_STRTOQ': ('strtoq', 'stdlib.h'), + 'HAVE_ACCEPT4': ('accept4', 'sys/socket.h'), + 'HAVE_CHMOD': ('chmod', 'sys/stat.h'), + 'HAVE_CHOWN': ('chown', 'unistd.h'), + 'HAVE_FSTAT': ('fstat', 'sys/stat.h'), + 'HAVE_GETADDRINFO': ('getaddrinfo', 'netdb.h'), + 'HAVE_GETGRGID_R': ('getgrgid_r', 'grp.h'), + 'HAVE_GETGRNAM_R': ('getgrnam_r', 'grp.h'), + 'HAVE_GETGROUPS': ('getgroups', 'grp.h'), + 'HAVE_GETOPT_LONG': ('getopt_long', 'getopt.h'), + 'HAVE_GETPWNAM_R': ('getpwnam', 'pwd.h'), + 'HAVE_GETPWUID_R': ('getpwuid_r', 'pwd.h'), + 'HAVE_GETUID': ('getuid', 'unistd.h'), + 'HAVE_LRINTF': ('lrintf', 'math.h'), + 'HAVE_MKFIFO': ('mkfifo', 'sys/stat.h'), + 'HAVE_MLOCK': ('mlock', 'sys/mman.h'), + 'HAVE_NANOSLEEP': ('nanosleep', 'time.h'), + 'HAVE_PIPE': ('pipe', 'unistd.h'), + 'HAVE_PPOLL': ('ppoll', 'poll.h'), + 'HAVE_REGEXEC': ('regexec', 'regex.h'), + 'HAVE_SETEGID': ('setegid', 'unistd.h'), + 'HAVE_SETEUID': ('seteuid', 'unistd.h'), + 'HAVE_SETPGID': ('setpgid', 'unistd.h'), + 'HAVE_SETREGID': ('setregid', 'unistd.h'), + 'HAVE_SETRESGID': ('setresgid', 'unistd.h'), + 'HAVE_SETRESUID': ('setresuid', 'unistd.h'), + 'HAVE_SHM_OPEN': ('shm_open', 'fcntl.h'), + 'HAVE_SLEEP': ('sleep', 'unistd.h'), + 'HAVE_STRERROR_R': ('strerror_r', 'string.h'), + 'HAVE_STRTOF': ('strtof', 'stdlib.h'), + 'HAVE_SYSCONF': ('sysconf', 'unistd.h'), + 'HAVE_USLEEP': ('usleep', 'unistd.h'), + 'HAVE_VFORK': ('vfork', 'unistd.h'), + } + +print('check_functions = [') + +for line in open(sys.argv[1]): + try: + token = line.split()[1] + if token in function_data: + fdata = function_data[token] + print(" ['%s', '%s', '#include<%s>']," % (token, fdata[0], fdata[1])) + elif token.startswith('HAVE_') and not token.endswith('_H'): + print('# check token', token) + except Exception: + pass +print(']\n') + +print('''foreach f : check_functions + if cc.has_function(f.get(1), prefix : f.get(2)) + cdata.set(f.get(0), 1) + endif +endforeach +''') + +# Convert sizeof checks. + +for line in open(sys.argv[1]): + arr = line.strip().split() + if len(arr) != 2: + continue + elem = arr[1] + if elem.startswith('SIZEOF_'): + typename = elem.split('_', 1)[1].replace('_P', '*').replace('_', ' ').lower().replace('size t', 'size_t') + print("cdata.set('%s', cc.sizeof('%s'))" % (elem, typename)) + +print(''' +configure_file(input : 'config.h.in', + output : 'config.h', + configuration : cdata)''') diff --git a/tools/autotools2meson.py b/tools/autotools2meson.py deleted file mode 100755 index 1ec1348..0000000 --- a/tools/autotools2meson.py +++ /dev/null @@ -1,122 +0,0 @@ -#!/usr/bin/python3 - -# Copyright 2014 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, re - -class Converter(): - def __init__(self, root): - self.project_root = root - - def readlines(self, file, continuator): - line = file.readline() - while line != '': - line = line.rstrip() - while line.endswith(continuator): - line = line[:-1] + file.readline().rstrip() - yield line - line = file.readline() - - def convert(self, subdir=None): - if subdir is None: - subdir = self.project_root - try: - ifile = open(os.path.join(subdir, 'Makefile.am')) - except FileNotFoundError: - print('Makefile.am not found in subdir', subdir) - return - ofile = open(os.path.join(subdir, 'meson.build'), 'w') - if subdir == self.project_root: - self.process_autoconf(ofile, subdir) - for line in self.readlines(ifile, '\\'): - items = line.strip().split() - if len(items) == 0: - ofile.write('\n') - continue - if items[0] == 'SUBDIRS': - for i in items[2:]: - if i != '.': - ofile.write("subdir('%s')\n" % i) - self.convert(os.path.join(subdir, i)) - elif items[0].endswith('_SOURCES'): - self.convert_target(ofile, items) - else: - ofile.write("# %s\n" % line) - - def convert_target(self, ofile, items): - if items[0].endswith('la_SOURCES'): - func = 'shared_library' - tname = "'%s'" % items[0][:-11] - elif items[0].endswith('a_SOURCES'): - func = 'static_library' - tname = "'%s'" % items[0][:-10] - else: - func = 'executable' - tname = "'%s'" % items[0][:-8] - sources = [tname] - for s in items[2:]: - if s.startswith('$(') and s.endswith(')'): - s = s[2:-1] - else: - s = "'%s'" % s - sources.append(s) - ofile.write('%s(%s)\n' % (func, ',\n'.join(sources))) - - def process_autoconf(self, ofile, subdir): - ifile = open(os.path.join(subdir, 'configure.ac')) - languages = [] - name = 'undetected' - outlines = [] - for line in self.readlines(ifile, ','): - line = line.strip() - if line == 'AC_PROG_CC': - languages.append("'c'") - elif line == 'AC_PROG_CXX': - languages.append("'cpp'") - elif line.startswith('AC_INIT'): - line = line[8:] - if line[0] == '[': - name = line.split(']')[0][1:] - else: - name = line.split()[0] - elif line.startswith('#'): - outlines.append(line + '\n') - elif line.startswith('PKG_CHECK_MODULES'): - rest = line.split('(', 1)[-1].strip() - pkgstanza = rest.split()[1:] - for i in pkgstanza: - i = i.strip() - dep = None - if '=' in i: - continue - if i.startswith('['): - dep = i[1:] - elif re.match('[a-zA-Z]', i): - dep = i - if dep is not None: - outlines.append("%s_dep = dependency('%s')\n" % (dep, dep)) - else: - outlines.append('# %s\n' % line) - ofile.write("project(%s)\n" % ', '.join(["'%s'" % name] + languages)) - ofile.writelines(outlines) - - -if __name__ == '__main__': - if len(sys.argv) != 2: - print(sys.argv[0], '<Autotools project root>') - sys.exit(1) - c = Converter(sys.argv[1]) - c.convert() diff --git a/tools/cmake2meson.py b/tools/cmake2meson.py index f1720a8..098a6e0 100755 --- a/tools/cmake2meson.py +++ b/tools/cmake2meson.py @@ -1,4 +1,4 @@ -#!/usr/bin/python3 +#!/usr/bin/env python3 # Copyright 2014 Jussi Pakkanen |