projects/guix·blob javascript-team · refs

227 lines · 9.2 KiB

1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2012, 2013, 2014, 2016 Ludovic Courtès <[email protected]>
3;;; Copyright © 2019 Mathieu Othacehe <[email protected]>
4;;; Copyright © 2021 Maxime Devos <[email protected]>
5;;; Copyright © 2022, 2024 Maxim Cournoyer <[email protected]>
6;;; Copyright © 2023 Zheng Junjie <[email protected]>
7;;;
8;;; This file is part of GNU Guix.
9;;;
10;;; GNU Guix is free software; you can redistribute it and/or modify it
11;;; under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 3 of the License, or (at
13;;; your option) any later version.
14;;;
15;;; GNU Guix is distributed in the hope that it will be useful, but
16;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19;;;
20;;; You should have received a copy of the GNU General Public License
21;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23(define-module (gnu packages pkg-config)
24 #:use-module (guix licenses)
25 #:use-module (guix packages)
26 #:use-module (guix download)
27 #:use-module (guix gexp)
28 #:use-module (guix utils)
29 #:use-module (guix search-paths)
30 #:use-module (guix build-system gnu)
31 #:use-module (guix build-system trivial)
32 #:use-module (gnu packages bash)
33 #:use-module (guix memoization)
34 #:export (pkg-config))
35
36;; This is the "primitive" pkg-config package. People should use `pkg-config'
37;; (see below) rather than `%pkg-config', but we export `%pkg-config' so that
38;; `fold-packages' finds it.
39(define-public %pkg-config
40 (package
41 (name "pkg-config")
42 (version "0.29.2")
43 (source (origin
44 (method url-fetch)
45 (uri (list
46 (string-append
47 "http://fossies.org/linux/misc/pkg-config-" version
48 ".tar.gz")
49
50 ;; FIXME: The following URL redirects to HTTPS, which
51 ;; creates bootstrapping problems:
52 ;; <http://bugs.gnu.org/22774>.
53 (string-append
54 "http://pkgconfig.freedesktop.org/releases/pkg-config-"
55 version ".tar.gz")))
56 (sha256
57 (base32
58 "14fmwzki1rlz8bs2p810lk6jqdxsk966d8drgsjmi54cd00rrikg"))))
59 (build-system gnu-build-system)
60 (arguments
61 `(#:configure-flags
62 '("--with-internal-glib"
63 ;; Those variables are guessed incorrectly when cross-compiling.
64 ;; See: https://developer.gimp.org/api/2.0/glib/glib-cross-compiling.html.
65 ,@(if (%current-target-system)
66 '("glib_cv_stack_grows=no"
67 "glib_cv_uscore=no"
68 "ac_cv_func_posix_getpwuid_r=yes"
69 "ac_cv_func_posix_getgrgid_r=yes")
70 '()))))
71 (native-search-paths
72 (list $PKG_CONFIG_PATH))
73 (home-page "https://www.freedesktop.org/wiki/Software/pkg-config")
74 (license gpl2+)
75 (synopsis "Helper tool used when compiling applications and libraries")
76 (description
77 "pkg-config is a helper tool used when compiling applications and
78libraries. It helps you insert the correct compiler options on the
79command line so an application can use gcc -o test test.c `pkg-config
80--libs --cflags glib-2.0` for instance, rather than hard-coding values
81on where to find glib (or other libraries). It is language-agnostic, so
82it can be used for defining the location of documentation tools, for
83instance.")))
84
85(define cross-pkg-config
86 (mlambda (target)
87 "Return a pkg-config for TARGET, essentially just a wrapper called
88`TARGET-pkg-config', as `configure' scripts like it."
89 ;; See <http://www.flameeyes.eu/autotools-mythbuster/pkgconfig/cross-compiling.html>
90 ;; for details.
91 (package
92 (inherit %pkg-config)
93 (name (string-append (package-name %pkg-config) "-" target))
94 (build-system trivial-build-system)
95 (arguments
96 `(#:modules ((guix build utils))
97 #:builder (begin
98 (use-modules (guix build utils))
99
100 (let* ((in (assoc-ref %build-inputs "pkg-config"))
101 (out (assoc-ref %outputs "out"))
102 (bin (string-append out "/bin"))
103 (prog (string-append ,target "-pkg-config"))
104 (native (string-append in "/bin/pkg-config")))
105
106 (mkdir-p bin)
107
108 ;; Create a `TARGET-pkg-config' -> `pkg-config' symlink.
109 ;; This satisfies the pkg.m4 macros, which use
110 ;; AC_PROG_TOOL to determine the `pkg-config' program
111 ;; name.
112 (symlink native (string-append bin "/" prog))
113
114 ;; Also make 'pkg.m4' available, some packages might
115 ;; expect it.
116 (mkdir-p (string-append out "/share"))
117 (symlink (string-append in "/share/aclocal")
118 (string-append out "/share/aclocal"))
119 #t))))
120 (native-inputs `(("pkg-config" ,%pkg-config)))
121
122 ;; Ignore native inputs, and set `PKG_CONFIG_PATH' for target inputs.
123 (native-search-paths '())
124 (search-paths (package-native-search-paths %pkg-config)))))
125
126(define (pkg-config-for-target target)
127 "Return a pkg-config package for TARGET, which may be either #f for a native
128build, or a GNU triplet."
129 (if target
130 (cross-pkg-config target)
131 %pkg-config))
132
133;; This hack allows us to automatically choose the native or the cross
134;; `pkg-config' depending on whether it's being used in a cross-build
135;; environment or not.
136(define-syntax pkg-config
137 (identifier-syntax (pkg-config-for-target (%current-target-system))))
138
139;; This hack allows for using both "pkg-config" and "TARGET-pkg-config"
140;; at the same time. Simply using '%pkg-config' and 'pkg-config' won't
141;; work because they both use the "PKG_CONFIG_PATH" environment variable.
142(define-public pkg-config-for-build
143 (package
144 (inherit (hidden-package %pkg-config))
145 (name "pkg-config-for-build")
146 (version "0")
147 (source #f)
148 (build-system trivial-build-system)
149 (inputs
150 (list bash-minimal %pkg-config))
151 (arguments
152 `(#:modules ((guix build utils))
153 #:builder
154 ,#~(begin
155 (use-modules (guix build utils))
156 (define where (string-append #$output "/bin/pkg-config"))
157 (mkdir-p (dirname where))
158 (call-with-output-file where
159 (lambda (port)
160 (format port "#!~a
161export PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH_FOR_BUILD\"
162exec ~a \"$@\""
163 (search-input-file %build-inputs "bin/bash")
164 (search-input-file %build-inputs "bin/pkg-config"))))
165 (chmod where #o500))))
166 (native-search-paths
167 (map (lambda (original)
168 (search-path-specification
169 (inherit original)
170 (variable "PKG_CONFIG_PATH_FOR_BUILD")))
171 (package-native-search-paths %pkg-config)))))
172
173(define-public pkgconf
174 (package
175 (name "pkgconf")
176 (version "3.0.7")
177 (source (origin
178 (method url-fetch)
179 (uri (string-append "https://distfiles.ariadne.space/"
180 name "/" name "-" version ".tar.xz"))
181 (sha256
182 (base32
183 "02llwsmxyb4g6ccsb62i9ndp9cbsv4dq2q4ib0d376mx3i4zy9n9"))))
184 (build-system gnu-build-system)
185 (arguments
186 (list
187 #:phases
188 #~(modify-phases %standard-phases
189 (add-after 'unpack 'fix-makefile
190 (lambda _
191 (substitute* "Makefile.in"
192 (("PWD") "CURDIR")))))))
193 (native-search-paths (list $PKG_CONFIG_PATH))
194 (home-page "https://github.com/pkgconf/pkgconf")
195 (synopsis "Package compiler and linker metadata toolkit")
196 (description "@command{pkgconf} is a program which helps to configure
197compiler and linker flags for development libraries. It is similar to
198pkg-config from freedesktop.org. @code{libpkgconf} is a library which
199provides access to most of pkgconf's functionality, to allow other tooling
200such as compilers and IDEs to discover and use libraries configured by
201pkgconf.")
202 (license isc)))
203
204(define-public pkgconf-as-pkg-config
205 (package/inherit pkgconf
206 (name "pkgconf-as-pkg-config")
207 (build-system gnu-build-system)
208 (arguments
209 (list
210 #:tests? #f
211 #:phases
212 #~(modify-phases %standard-phases
213 (delete 'configure)
214 (delete 'build)
215 (replace 'install
216 (lambda* (#:key inputs #:allow-other-keys)
217 (let ((pkgconf (search-input-file inputs "bin/pkgconf")))
218 (mkdir-p (string-append #$output "/bin"))
219 (symlink pkgconf (string-append #$output "/bin/pkg-config"))
220 ;; Also make 'pkg.m4' available, some packages might expect it.
221 (mkdir-p (string-append #$output "/share"))
222 (symlink (string-append (dirname (dirname pkgconf))
223 "/share/aclocal")
224 (string-append #$output "/share/aclocal"))))))))
225 (native-inputs '())
226 (inputs (list pkgconf))
227 (propagated-inputs '())))