#!/usr/bin/env python3 import os import shutil import subprocess from pathlib import Path # On Gentoo, vanilla unpatched autotools are packaged separately. # We place the vanilla names first as we want to prefer those if both exist. autoconf_names = ['autoconf-vanilla-2.69', 'autoconf-2.69'] automake_names = ['automake-vanilla-1.15', 'automake-1.15.1'] aclocal_names = ['aclocal-vanilla-1.15', 'aclocal-1.15.1'] autoheader_names = ['autoheader-vanilla-2.69', 'autoheader-2.69'] # Pick the first for each list that exists on this system. AUTOCONF_BIN = next(name for name in autoconf_names if shutil.which(name)) AUTOMAKE_BIN = next(name for name in automake_names if shutil.which(name)) ACLOCAL_BIN = next(name for name in aclocal_names if shutil.which(name)) AUTOHEADER_BIN = next(name for name in autoheader_names if shutil.which(name)) # autoconf-wrapper and automake-wrapper from Gentoo look at this environment variable. # It's harmless to set it on other systems though. ENV = f'WANT_AUTOCONF={AUTOCONF_BIN.split("-", 1)[1]} ' ENV += f'WANT_AUTOMAKE={AUTOMAKE_BIN.split("-", 1)[1]} ' ENV += f' AUTOCONF={AUTOCONF_BIN} ' ENV += f' ACLOCAL={ACLOCAL_BIN} ' ENV += f' AUTOMAKE={AUTOMAKE_BIN}' # Directories we should skip entirely because they're vendored or have different # autotools versions. skip_dirs = [ # readline and minizip are maintained with different autotools versions 'readline', 'minizip' ] config_folders = [] for root, _, files in os.walk('.'): for file in files: if file == 'configure.ac': config_folders.append(Path(root).resolve()) for folder in sorted(config_folders): print(folder, flush=True) if folder.stem in skip_dirs: continue os.chdir(folder) configure_lines = open('configure.ac').read().splitlines() if any(True for line in configure_lines if line.startswith('AC_CONFIG_MACRO_DIRS')): # aclocal does not support the -f short option for force include_arg = '' include_arg2 = '' if (folder / '..' / 'config').is_dir(): include_arg = '-I../config' # this is really a hack just for binutils-gdb/gprofng/libcollector # make sure that the order of includes is done as --enable-maintainer-mode if (folder / '..' / '..' / 'config').is_dir(): include_arg = '-I../..' include_arg2 = '-I../../config' subprocess.check_output(f'{ENV} {ACLOCAL_BIN} --force {include_arg} {include_arg2}', shell=True, encoding='utf8') if ((folder / 'config.in').is_file() or any(True for line in configure_lines if line.startswith('AC_CONFIG_HEADERS'))): subprocess.check_output(f'{ENV} {AUTOHEADER_BIN} -f', shell=True, encoding='utf8') # apparently automake is somehow unstable -> skip it for gotools if (any(True for line in configure_lines if line.startswith('AM_INIT_AUTOMAKE')) and not str(folder).endswith('gotools')): subprocess.check_output(f'{ENV} {AUTOMAKE_BIN} -f', shell=True, encoding='utf8') subprocess.check_output(f'{ENV} {AUTOCONF_BIN} -f', shell=True, encoding='utf8')