diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 13:44:03 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-13 13:44:03 +0000 |
commit | 293913568e6a7a86fd1479e1cff8e2ecb58d6568 (patch) | |
tree | fc3b469a3ec5ab71b36ea97cc7aaddb838423a0c /src/tools/rcgen | |
parent | Initial commit. (diff) | |
download | postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.tar.xz postgresql-16-293913568e6a7a86fd1479e1cff8e2ecb58d6568.zip |
Adding upstream version 16.2.upstream/16.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/rcgen')
-rwxr-xr-x | src/tools/rcgen | 105 |
1 files changed, 105 insertions, 0 deletions
diff --git a/src/tools/rcgen b/src/tools/rcgen new file mode 100755 index 0000000..0c84772 --- /dev/null +++ b/src/tools/rcgen @@ -0,0 +1,105 @@ +#!/usr/bin/env python3 + +# Helper for building resource files when building for windows. Always +# generates a .rc from the input .rc file. When building with msvc we +# additionally generate a .res file with 'rc', when building with gcc, we use +# windres to directly generate a .o. Additionally we generate basic +# dependencies if depfile is specified. + +import argparse +import os +import subprocess +import sys + +parser = argparse.ArgumentParser(description='generate PostgreSQL rc file') + +parser.add_argument('--srcdir', type=os.path.abspath, + required=True) +parser.add_argument('--builddir', type=os.path.abspath, + required=True) + +binaries = parser.add_argument_group('binaries') +binaries.add_argument('--windres', type=os.path.abspath) +binaries.add_argument('--rc', type=os.path.abspath) + +inout = parser.add_argument_group('inout') +inout.add_argument('--depfile', type=argparse.FileType('w')) +inout.add_argument('--input', type=argparse.FileType('r'), + required=True) +inout.add_argument('--rcout', type=argparse.FileType('w'), + required=True) +inout.add_argument('--out', type=str, + required=True) + +replacements = parser.add_argument_group('replacements') +replacements.add_argument('--FILEDESC', type=str) +replacements.add_argument('--NAME', type=str, required=True) +replacements.add_argument('--VFT_TYPE', type=str, required=True) +replacements.add_argument('--FILEENDING', type=str, required=True) +replacements.add_argument('--ICO', type=str) + +args = parser.parse_args() + +# determine replacement strings + +internal_name = '"{0}"'.format(args.NAME) +original_name = '"{0}.{1}"'.format(args.NAME, args.FILEENDING) + +# if no description is passed in, generate one based on the name +if args.FILEDESC: + filedesc = args.FILEDESC +elif args.NAME: + if args.VFT_TYPE == 'VFT_DLL': + filedesc = 'PostgreSQL {0} library'.format(args.NAME) + else: + filedesc = 'PostgreSQL {0} binary'.format(args.NAME) +filedesc = '"{0}"'.format(filedesc) + + +if args.ICO: + ico = 'IDI_ICON ICON "{0}"'.format(args.ICO) + if args.depfile: + args.depfile.write("{0} : {1}\n".format(args.rcout.name, args.ICO)) +else: + ico = '' + + +data = args.input.read() + +data = data.replace('VFT_APP', args.VFT_TYPE) +data = data.replace('_INTERNAL_NAME_', internal_name) +data = data.replace('_ORIGINAL_NAME_', original_name) +data = data.replace('FILEDESC', filedesc) +data = data.replace("_ICO_", ico) + +args.rcout.write(data) +args.rcout.close() + +if args.windres: + cmd = [ + args.windres, + '-I{0}/src/include/'.format(args.builddir), + '-I{0}/src/include/'.format(args.srcdir), + '-o', args.out, '-i', args.rcout.name, + ] +elif args.rc: + cmd = [ + args.rc, '/nologo', + '-I{0}/src/include/'.format(args.builddir), + '-I{0}/src/include/'.format(args.srcdir), + '/fo', args.out, args.rcout.name, + ] +else: + sys.exit('either --windres or --rc needs to be specified') + +sp = subprocess.run(cmd) +if sp.returncode != 0: + sys.exit(sp.returncode) + +# It'd be nicer if we could generate correct dependencies here, but 'rc' +# doesn't support doing so. It's unlikely we'll ever need more, so... +if args.depfile: + args.depfile.write("{0} : {1}\n".format( + args.rcout.name, args.input.name)) + args.depfile.write("{0} : {1}/{2}\n".format( + args.out, args.builddir, 'src/include/pg_config.h')) |