zlib: Don't use PASTE for INTMAX error messages
[jimtcl.git] / autosetup / pkg-config.tcl
blobc2e2bbfabb7987187b52ab38f3b7a038c62da086
1 # Copyright (c) 2016 WorkWare Systems http://www.workware.net.au/
2 # All rights reserved
4 # @synopsis:
6 # The 'pkg-config' module allows package information to be found via pkg-config
8 # If not cross-compiling, the package path should be determined automatically
9 # by pkg-config.
10 # If cross-compiling, the default package path is the compiler sysroot.
11 # If the C compiler doesn't support -print-sysroot, the path can be supplied
12 # by the --sysroot option or by defining SYSROOT.
14 # PKG_CONFIG may be set to use an alternative to pkg-config
16 use cc
18 module-options {
19 sysroot:dir => "Override compiler sysroot for pkg-config search path"
22 # @pkg-config-init ?required?
24 # Initialises the pkg-config system. Unless required is set to 0,
25 # it is a fatal error if the pkg-config
26 # This command will normally be called automatically as required,
27 # but it may be invoked explicitly if lack of pkg-config is acceptable.
29 # Returns 1 if ok, or 0 if pkg-config not found/usable (only if required=0)
31 proc pkg-config-init {{required 1}} {
32 if {[is-defined HAVE_PKG_CONFIG]} {
33 return [get-define HAVE_PKG_CONFIG]
35 set found 0
37 define PKG_CONFIG [get-env PKG_CONFIG pkg-config]
38 msg-checking "Checking for pkg-config..."
40 try {
41 set version [exec [get-define PKG_CONFIG] --version]
42 msg-result $version
43 define PKG_CONFIG_VERSION $version
45 set found 1
47 if {[opt-val sysroot] ne ""} {
48 define SYSROOT [file-normalize [opt-val sysroot]]
49 msg-result "Using specified sysroot [get-define SYSROOT]"
50 } elseif {[get-define build] ne [get-define host]} {
51 if {[catch {exec-with-stderr [get-define CC] -print-sysroot} result errinfo] == 0} {
52 # Use the compiler sysroot, if there is one
53 define SYSROOT $result
54 msg-result "Found compiler sysroot $result"
55 } else {
56 set msg "pkg-config: Cross compiling, but no compiler sysroot and no --sysroot supplied"
57 if {$required} {
58 user-error $msg
59 } else {
60 msg-result $msg
62 set found 0
65 if {[is-defined SYSROOT]} {
66 set sysroot [get-define SYSROOT]
68 # XXX: It's possible that these should be set only when invoking pkg-config
69 global env
70 set env(PKG_CONFIG_DIR) ""
71 # Do we need to try /usr/local as well or instead?
72 set env(PKG_CONFIG_LIBDIR) $sysroot/usr/lib/pkgconfig:$sysroot/usr/share/pkgconfig
73 set env(PKG_CONFIG_SYSROOT_DIR) $sysroot
76 } on error msg {
77 msg-result "[get-define PKG_CONFIG] (not found)"
78 if {$required} {
79 user-error "No usable pkg-config"
82 define HAVE_PKG_CONFIG $found
83 return $found
86 # @pkg-config module ?requirements?
88 # Use pkg-config to find the given module meeting the given requirements.
89 # e.g.
91 ## pkg-config pango >= 1.37.0
93 # If found, returns 1 and sets HAVE_PKG_PANGO to 1 along with:
95 ## PKG_PANGO_VERSION to the found version
96 ## PKG_PANGO_LIBS to the required libs (--libs-only-l)
97 ## PKG_PANGO_LDFLAGS to the required linker flags (--libs-only-L)
98 ## PKG_PANGO_CFLAGS to the required compiler flags (--cflags)
100 # If not found, returns 0.
102 proc pkg-config {module args} {
103 set ok [pkg-config-init]
105 msg-checking "Checking for $module $args..."
107 if {!$ok} {
108 msg-result "no pkg-config"
109 return 0
112 try {
113 set version [exec [get-define PKG_CONFIG] --modversion "$module $args"]
114 msg-result $version
115 set prefix [feature-define-name $module PKG_]
116 define HAVE_${prefix}
117 define ${prefix}_VERSION $version
118 define ${prefix}_LIBS [exec pkg-config --libs-only-l $module]
119 define ${prefix}_LDFLAGS [exec pkg-config --libs-only-L $module]
120 define ${prefix}_CFLAGS [exec pkg-config --cflags $module]
121 return 1
122 } on error msg {
123 msg-result "not found"
124 configlog "pkg-config --modversion $module $args: $msg"
125 return 0
129 # @pkg-config-get module setting
131 # Convenience access to the results of pkg-config
133 # For example, [pkg-config-get pango CFLAGS] returns
134 # the value of PKG_PANGO_CFLAGS, or "" if not defined.
135 proc pkg-config-get {module name} {
136 set prefix [feature-define-name $module PKG_]
137 get-define ${prefix}_${name} ""