3 # Helper for building resource files when building for windows. Always
4 # generates a .rc from the input .rc file. When building with msvc we
5 # additionally generate a .res file with 'rc', when building with gcc, we use
6 # windres to directly generate a .o. Additionally we generate basic
7 # dependencies if depfile is specified.
14 parser = argparse.ArgumentParser(description='generate PostgreSQL rc file')
16 parser.add_argument('--srcdir', type=os.path.abspath,
18 parser.add_argument('--builddir', type=os.path.abspath,
21 binaries = parser.add_argument_group('binaries')
22 binaries.add_argument('--windres', type=os.path.abspath)
23 binaries.add_argument('--rc', type=os.path.abspath)
25 inout = parser.add_argument_group('inout')
26 inout.add_argument('--depfile', type=argparse.FileType('w'))
27 inout.add_argument('--input', type=argparse.FileType('r'),
29 inout.add_argument('--rcout', type=argparse.FileType('w'),
31 inout.add_argument('--out', type=str,
34 replacements = parser.add_argument_group('replacements')
35 replacements.add_argument('--FILEDESC', type=str)
36 replacements.add_argument('--NAME', type=str, required=True)
37 replacements.add_argument('--VFT_TYPE', type=str, required=True)
38 replacements.add_argument('--FILEENDING', type=str, required=True)
39 replacements.add_argument('--ICO', type=str)
41 args = parser.parse_args()
43 # determine replacement strings
45 internal_name = '"{0}"'.format(args.NAME)
46 original_name = '"{0}.{1}"'.format(args.NAME, args.FILEENDING)
48 # if no description is passed in, generate one based on the name
50 filedesc = args.FILEDESC
52 if args.VFT_TYPE == 'VFT_DLL':
53 filedesc = 'PostgreSQL {0} library'.format(args.NAME)
55 filedesc = 'PostgreSQL {0} binary'.format(args.NAME)
56 filedesc = '"{0}"'.format(filedesc)
60 ico = 'IDI_ICON ICON "{0}"'.format(args.ICO)
62 args.depfile.write("{0} : {1}\n".format(args.rcout.name, args.ICO))
67 data = args.input.read()
69 data = data.replace('VFT_APP', args.VFT_TYPE)
70 data = data.replace('_INTERNAL_NAME_', internal_name)
71 data = data.replace('_ORIGINAL_NAME_', original_name)
72 data = data.replace('FILEDESC', filedesc)
73 data = data.replace("_ICO_", ico)
75 args.rcout.write(data)
81 '-I{0}/src/include/'.format(args.builddir),
82 '-I{0}/src/include/'.format(args.srcdir),
83 '-o', args.out, '-i', args.rcout.name,
88 '-I{0}/src/include/'.format(args.builddir),
89 '-I{0}/src/include/'.format(args.srcdir),
90 '/fo', args.out, args.rcout.name,
93 sys.exit('either --windres or --rc needs to be specified')
95 sp = subprocess.run(cmd)
96 if sp.returncode != 0:
97 sys.exit(sp.returncode)
99 # It'd be nicer if we could generate correct dependencies here, but 'rc'
100 # doesn't support doing so. It's unlikely we'll ever need more, so...
102 args.depfile.write("{0} : {1}\n".format(
103 args.rcout.name, args.input.name))
104 args.depfile.write("{0} : {1}/{2}\n".format(
105 args.out, args.builddir, 'src/include/pg_config.h'))