firejail/contrib/fj-mkdeb.py
Kelvin M. Klann 011d84b462 build: reduce autoconf input files from 32 to 2
Configure summary: autoconf essentially only parses configure.ac and
generates the configure script (that is, the "./configure" shell
script).  The latter is what actually checks what is available on the
system and internally sets the value of the output variables.  It then,
for every filename foo in AC_CONFIG_FILES (and for every output variable
name BAR in AC_SUBST), reads foo.in, replaces every occurrence of
`@BAR@` with the value of the shell variable `$BAR` and generates the
file foo from the result.  After this, configure is finished and `make`
could be executed to start the build.

Now that (as of #5140) all output variables are only defined on
config.mk.in and on config.sh.in, there is no need to generate any
makefile nor any other mkfile or shell script at configure time.  So
rename every "Makefile.in" to "Makefile", mkdeb.sh.in to mkdeb.sh,
src/common.mk.in to src/common.mk and leave just config.mk and config.sh
as the files to be generated at configure time.

This allows editing and committing all makefiles directly, without
potentially having to run ./configure in between.

Commands used to rename the makefiles:

    $ git ls-files -z -- '*Makefile.in' | xargs -0 -I '{}' sh -c \
      "git mv '{}' \"\$(dirname '{}')/Makefile\""

Additionally, from my (rudimentary) testing, this commit reduces the
time it takes to run ./configure by about 20~25% compared to commit
72ece92ea ("Transmission fixes: drop private-lib (#5213)", 2022-06-22).
Environment: dash 0.5.11.5-1, gcc 12.1.0-2, Artix Linux, ext4 on an HDD.

Commands used for benchmarking each commit:

    $ : >time_configure && ./configure && make distclean &&
      for i in $(seq 1 10); do
      { time -p ./configure; } 2>>time_configure; done
    $ grep real time_configure |
      awk '{ total += $2 } END { print total/NR }'
2022-06-30 05:30:14 -03:00

74 lines
2.5 KiB
Python
Executable file

#!/usr/bin/env python3
# This file is part of Firejail project
# Copyright (C) 2014-2022 Firejail Authors
# License GPL v2
# This script automates the creation of a .deb package. It was originally
# created to work around https://github.com/netblue30/firejail/issues/772
import os, subprocess, sys
def run(srcdir, args):
if srcdir: os.chdir(srcdir)
if not (os.path.isfile('./mkdeb.sh')):
print('Error: Not a firejail source tree? Exiting.')
return 1
# Ignore unsupported arguments.
for a in args[:]:
if a.startswith('--prefix'):
# prefix should ALWAYS be /usr here. Discard user-set values
args.remove(a)
# Run configure to generate config.sh.
first_config = subprocess.call(['./configure', '--prefix=/usr'] + args)
if first_config != 0:
return first_config
# Create the dist file used by mkdeb.sh.
make_dist = subprocess.call(['make', 'dist'])
if make_dist != 0:
return make_dist
# Run mkdeb.sh with the custom configure options.
return subprocess.call(['./mkdeb.sh'] + args)
if __name__ == '__main__':
if len(sys.argv) == 2 and sys.argv[1] == '--help':
print('''Build a .deb of firejail with custom configure options
usage:
{script} [--fj-src=SRCDIR] [CONFIGURE_OPTIONS [...]]
--fj-src=SRCDIR: manually specify the location of firejail source tree
as SRCDIR. If not specified, looks in the parent directory
of the directory where this script is located, and then the
current working directory, in that order.
CONFIGURE_OPTIONS: arguments for configure
'''.format(script=sys.argv[0]))
sys.exit(0)
else:
# Find the source directory
srcdir = None
args = sys.argv[1:]
for a in args:
if a.startswith('--fj-src='):
args.remove(a)
srcdir = a[9:]
break
if not (srcdir):
# srcdir not manually specified, try to auto-detect
srcdir = os.path.dirname(os.path.abspath(sys.argv[0] + '/..'))
if not (os.path.isfile(srcdir + '/mkdeb.sh')):
# Script is probably installed. Check the cwd.
if os.path.isfile('./mkdeb.sh'):
srcdir = None
else:
print(
'Error: Could not find the firejail source tree. Exiting.'
)
sys.exit(1)
sys.exit(run(srcdir, args))