pkg-config.scm 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2012, 2013, 2014, 2016 Ludovic Courtès <ludo@gnu.org>
  3. ;;; Copyright © 2019 Mathieu Othacehe <m.othacehe@gmail.com>
  4. ;;; Copyright © 2021 Maxime Devos <maximedevos@telenet.be>
  5. ;;;
  6. ;;; This file is part of GNU Guix.
  7. ;;;
  8. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  9. ;;; under the terms of the GNU General Public License as published by
  10. ;;; the Free Software Foundation; either version 3 of the License, or (at
  11. ;;; your option) any later version.
  12. ;;;
  13. ;;; GNU Guix is distributed in the hope that it will be useful, but
  14. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  15. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. ;;; GNU General Public License for more details.
  17. ;;;
  18. ;;; You should have received a copy of the GNU General Public License
  19. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  20. (define-module (gnu packages pkg-config)
  21. #:use-module (guix licenses)
  22. #:use-module (guix packages)
  23. #:use-module (guix download)
  24. #:use-module (guix gexp)
  25. #:use-module (guix build-system gnu)
  26. #:use-module (guix build-system trivial)
  27. #:use-module (gnu packages bash)
  28. #:use-module (guix memoization)
  29. #:export (pkg-config))
  30. ;; This is the "primitive" pkg-config package. People should use `pkg-config'
  31. ;; (see below) rather than `%pkg-config', but we export `%pkg-config' so that
  32. ;; `fold-packages' finds it.
  33. (define-public %pkg-config
  34. (package
  35. (name "pkg-config")
  36. (version "0.29.2")
  37. (source (origin
  38. (method url-fetch)
  39. (uri (list
  40. (string-append
  41. "http://fossies.org/linux/misc/pkg-config-" version
  42. ".tar.gz")
  43. ;; FIXME: The following URL redirects to HTTPS, which
  44. ;; creates bootstrapping problems:
  45. ;; <http://bugs.gnu.org/22774>.
  46. (string-append
  47. "http://pkgconfig.freedesktop.org/releases/pkg-config-"
  48. version ".tar.gz")))
  49. (sha256
  50. (base32
  51. "14fmwzki1rlz8bs2p810lk6jqdxsk966d8drgsjmi54cd00rrikg"))))
  52. (build-system gnu-build-system)
  53. (arguments
  54. `(#:configure-flags
  55. '("--with-internal-glib"
  56. ;; Those variables are guessed incorrectly when cross-compiling.
  57. ;; See: https://developer.gimp.org/api/2.0/glib/glib-cross-compiling.html.
  58. ,@(if (%current-target-system)
  59. '("glib_cv_stack_grows=no"
  60. "glib_cv_uscore=no"
  61. "ac_cv_func_posix_getpwuid_r=yes"
  62. "ac_cv_func_posix_getgrgid_r=yes")
  63. '()))))
  64. (native-search-paths
  65. (list (search-path-specification
  66. (variable "PKG_CONFIG_PATH")
  67. (files '("lib/pkgconfig" "lib64/pkgconfig" "share/pkgconfig")))))
  68. (home-page "https://www.freedesktop.org/wiki/Software/pkg-config")
  69. (license gpl2+)
  70. (synopsis "Helper tool used when compiling applications and libraries")
  71. (description
  72. "pkg-config is a helper tool used when compiling applications and
  73. libraries. It helps you insert the correct compiler options on the
  74. command line so an application can use gcc -o test test.c `pkg-config
  75. --libs --cflags glib-2.0` for instance, rather than hard-coding values
  76. on where to find glib (or other libraries). It is language-agnostic, so
  77. it can be used for defining the location of documentation tools, for
  78. instance.")))
  79. (define cross-pkg-config
  80. (mlambda (target)
  81. "Return a pkg-config for TARGET, essentially just a wrapper called
  82. `TARGET-pkg-config', as `configure' scripts like it."
  83. ;; See <http://www.flameeyes.eu/autotools-mythbuster/pkgconfig/cross-compiling.html>
  84. ;; for details.
  85. (package
  86. (inherit %pkg-config)
  87. (name (string-append (package-name %pkg-config) "-" target))
  88. (build-system trivial-build-system)
  89. (arguments
  90. `(#:modules ((guix build utils))
  91. #:builder (begin
  92. (use-modules (guix build utils))
  93. (let* ((in (assoc-ref %build-inputs "pkg-config"))
  94. (out (assoc-ref %outputs "out"))
  95. (bin (string-append out "/bin"))
  96. (prog (string-append ,target "-pkg-config"))
  97. (native (string-append in "/bin/pkg-config")))
  98. (mkdir-p bin)
  99. ;; Create a `TARGET-pkg-config' -> `pkg-config' symlink.
  100. ;; This satisfies the pkg.m4 macros, which use
  101. ;; AC_PROG_TOOL to determine the `pkg-config' program
  102. ;; name.
  103. (symlink native (string-append bin "/" prog))
  104. ;; Also make 'pkg.m4' available, some packages might
  105. ;; expect it.
  106. (mkdir-p (string-append out "/share"))
  107. (symlink (string-append in "/share/aclocal")
  108. (string-append out "/share/aclocal"))
  109. #t))))
  110. (native-inputs `(("pkg-config" ,%pkg-config)))
  111. ;; Ignore native inputs, and set `PKG_CONFIG_PATH' for target inputs.
  112. (native-search-paths '())
  113. (search-paths (package-native-search-paths %pkg-config)))))
  114. (define (pkg-config-for-target target)
  115. "Return a pkg-config package for TARGET, which may be either #f for a native
  116. build, or a GNU triplet."
  117. (if target
  118. (cross-pkg-config target)
  119. %pkg-config))
  120. ;; This hack allows us to automatically choose the native or the cross
  121. ;; `pkg-config' depending on whether it's being used in a cross-build
  122. ;; environment or not.
  123. (define-syntax pkg-config
  124. (identifier-syntax (pkg-config-for-target (%current-target-system))))
  125. ;; This hack allows for using both "pkg-config" and "TARGET-pkg-config"
  126. ;; at the same time. Simply using '%pkg-config' and 'pkg-config' won't
  127. ;; work because they both use the "PKG_CONFIG_PATH" environment variable.
  128. (define-public pkg-config-for-build
  129. (package
  130. (inherit (hidden-package %pkg-config))
  131. (name "pkg-config-for-build")
  132. (version "0")
  133. (source #f)
  134. (build-system trivial-build-system)
  135. (inputs
  136. `(("bash-minimal" ,bash-minimal)
  137. ("pkg-config" ,%pkg-config)))
  138. (arguments
  139. `(#:modules ((guix build utils))
  140. #:builder
  141. ,#~(begin
  142. (use-modules (guix build utils))
  143. (define where (string-append #$output "/bin/pkg-config"))
  144. (mkdir-p (dirname where))
  145. (call-with-output-file where
  146. (lambda (port)
  147. (format port "#!~a
  148. export PKG_CONFIG_PATH=\"$PKG_CONFIG_PATH_FOR_BUILD\"
  149. exec ~a \"$@\""
  150. (search-input-file %build-inputs "bin/bash")
  151. (search-input-file %build-inputs "bin/pkg-config"))))
  152. (chmod where #o500))))
  153. (native-search-paths
  154. (map (lambda (original)
  155. (search-path-specification
  156. (inherit original)
  157. (variable "PKG_CONFIG_PATH_FOR_BUILD")))
  158. (package-native-search-paths %pkg-config)))))