3 # Simple utility script to generate the basic info
4 # needed in a .pc (pkg-config) file, used especially
5 # for introspection purposes
7 # This can be used in various projects where
8 # there is the need to generate .pc files,
9 # and is copied from GLib's $(srcroot)/win32
11 # Author: Fan, Chun-wei
12 # Date: March 10, 2016
20 self
.base_replace_items
= {}
25 self
.srcdir
= os
.path
.dirname(__file__
)
26 self
.top_srcdir
= self
.srcdir
+ '\\..'
29 def setup(self
, argv
, parser
=None):
31 parser
= argparse
.ArgumentParser(description
='Setup basic .pc file info')
32 parser
.add_argument('--prefix', help='prefix of the installed library',
34 parser
.add_argument('--exec-prefix',
35 help='prefix of the installed programs, \
36 if different from the prefix')
37 parser
.add_argument('--includedir',
38 help='includedir of the installed library, \
39 if different from ${prefix}/include')
40 parser
.add_argument('--libdir',
41 help='libdir of the installed library, \
42 if different from ${prefix}/lib')
43 parser
.add_argument('--version', help='Version of the package',
45 args
= parser
.parse_args()
47 self
.version
= args
.version
49 # check whether the prefix and exec_prefix are valid
50 if not os
.path
.exists(args
.prefix
):
51 raise SystemExit('Specified prefix \'%s\' is invalid' % args
.prefix
)
53 # use absolute paths for prefix
54 self
.prefix
= os
.path
.abspath(args
.prefix
).replace('\\','/')
56 # check and setup the exec_prefix
57 if getattr(args
, 'exec_prefix', None) is None:
58 exec_prefix_use_shorthand
= True
59 self
.exec_prefix
= '${prefix}'
61 if args
.exec_prefix
.startswith('${prefix}'):
62 exec_prefix_use_shorthand
= True
63 input_exec_prefix
= args
.prefix
+ args
.exec_prefix
[len('${prefix}'):]
65 exec_prefix_use_shorthand
= False
66 input_exec_prefix
= args
.exec_prefix
67 if not os
.path
.exists(input_exec_prefix
):
68 raise SystemExit('Specified exec_prefix \'%s\' is invalid' %
70 if exec_prefix_use_shorthand
is True:
71 self
.exec_prefix
= args
.exec_prefix
.replace('\\','/')
73 self
.exec_prefix
= os
.path
.abspath(input_exec_prefix
).replace('\\','/')
75 # check and setup the includedir
76 if getattr(args
, 'includedir', None) is None:
77 self
.includedir
= '${prefix}/include'
79 if args
.includedir
.startswith('${prefix}'):
80 includedir_use_shorthand
= True
81 input_includedir
= args
.prefix
+ args
.includedir
[len('${prefix}'):]
83 if args
.includedir
.startswith('${exec_prefix}'):
84 includedir_use_shorthand
= True
85 input_includedir
= input_exec_prefix
+ args
.includedir
[len('${exec_prefix}'):]
87 includedir_use_shorthand
= False
88 input_includedir
= args
.includedir
89 if not os
.path
.exists(input_includedir
):
90 raise SystemExit('Specified includedir \'%s\' is invalid' %
92 if includedir_use_shorthand
is True:
93 self
.includedir
= args
.includedir
.replace('\\','/')
95 self
.includedir
= os
.path
.abspath(input_includedir
).replace('\\','/')
97 # check and setup the libdir
98 if getattr(args
, 'libdir', None) is None:
99 self
.libdir
= '${prefix}/lib'
101 if args
.libdir
.startswith('${prefix}'):
102 libdir_use_shorthand
= True
103 input_libdir
= args
.prefix
+ args
.libdir
[len('${prefix}'):]
105 if args
.libdir
.startswith('${exec_prefix}'):
106 libdir_use_shorthand
= True
107 input_libdir
= input_exec_prefix
+ args
.libdir
[len('${exec_prefix}'):]
109 libdir_use_shorthand
= False
110 input_libdir
= args
.libdir
111 if not os
.path
.exists(input_libdir
):
112 raise SystemExit('Specified libdir \'%s\' is invalid' %
114 if libdir_use_shorthand
is True:
115 self
.libdir
= args
.libdir
.replace('\\','/')
117 self
.libdir
= os
.path
.abspath(input_libdir
).replace('\\','/')
119 # setup dictionary for replacing items in *.pc.in
120 self
.base_replace_items
.update({'@VERSION@': self
.version
})
121 self
.base_replace_items
.update({'@prefix@': self
.prefix
})
122 self
.base_replace_items
.update({'@exec_prefix@': self
.exec_prefix
})
123 self
.base_replace_items
.update({'@libdir@': self
.libdir
})
124 self
.base_replace_items
.update({'@includedir@': self
.includedir
})