guile-config.in 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #!/bin/sh
  2. PKG_CONFIG_PATH="@pkgconfigdir@:$PKG_CONFIG_PATH"
  3. GUILE_AUTO_COMPILE=0
  4. export PKG_CONFIG_PATH GUILE_AUTO_COMPILE
  5. exec "@installed_guile@" -e main -s $0 "$@"
  6. !#
  7. ;;;; guile-config --- utility for linking programs with Guile
  8. ;;;; Jim Blandy <jim@red-bean.com> --- September 1997
  9. ;;;;
  10. ;;;; Copyright (C) 1998,2001,2004-2006,2008-2009,2011,2018 Free Software Foundation, Inc.
  11. ;;;;
  12. ;;;; This library is free software; you can redistribute it and/or
  13. ;;;; modify it under the terms of the GNU Lesser General Public
  14. ;;;; License as published by the Free Software Foundation; either
  15. ;;;; version 3 of the License, or (at your option) any later version.
  16. ;;;;
  17. ;;;; This library is distributed in the hope that it will be useful,
  18. ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  20. ;;;; Lesser General Public License for more details.
  21. ;;;;
  22. ;;;; You should have received a copy of the GNU Lesser General Public
  23. ;;;; License along with this library; if not, write to the Free
  24. ;;;; Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
  25. ;;;; Boston, MA 02110-1301 USA
  26. ;;; This script has been deprecated. Just use pkg-config.
  27. (use-modules (ice-9 popen)
  28. (ice-9 rdelim))
  29. (define %pkg-config-program "@PKG_CONFIG@")
  30. ;;;; main function, command-line processing
  31. ;;; The script's entry point.
  32. (define (main args)
  33. (set-program-name! (car args))
  34. (let ((args (cdr args)))
  35. (cond
  36. ((null? args) (show-help '())
  37. (quit 1))
  38. ((assoc (car args) command-table)
  39. => (lambda (row)
  40. (set! subcommand-name (car args))
  41. ((cadr row) (cdr args))))
  42. (else (show-help '())
  43. (quit 1)))))
  44. (define program-name #f)
  45. (define subcommand-name #f)
  46. ;;; Given an executable path PATH, set program-name to something
  47. ;;; appropriate f or use in error messages (i.e., with leading
  48. ;;; directory names stripped).
  49. (define (set-program-name! path)
  50. (set! program-name (basename path)))
  51. (define (show-help args)
  52. (cond
  53. ((null? args) (show-help-overview))
  54. ((assoc (car args) command-table)
  55. => (lambda (row) ((caddr row))))
  56. (else
  57. (show-help-overview))))
  58. (define (show-help-overview)
  59. (display-line-error "Usage: ")
  60. (for-each (lambda (row) ((cadddr row)))
  61. command-table))
  62. (define (usage-help)
  63. (let ((dle display-line-error)
  64. (p program-name))
  65. (dle " " p " --help - show usage info (this message)")
  66. (dle " " p " --help SUBCOMMAND - show help for SUBCOMMAND")))
  67. (define guile-module "guile-@GUILE_EFFECTIVE_VERSION@")
  68. (define (pkg-config . args)
  69. (let* ((real-args (cons %pkg-config-program args))
  70. (pipe (apply open-pipe* OPEN_READ real-args))
  71. (output (read-delimited "" pipe))
  72. (ret (close-pipe pipe)))
  73. (case (status:exit-val ret)
  74. ((0) (if (eof-object? output) "" output))
  75. (else (display-line-error
  76. (format #f "error: ~s exited with non-zero error code ~A"
  77. (cons %pkg-config-program args) (status:exit-val ret)))
  78. ;; assume pkg-config sent diagnostics to stdout
  79. (exit (status:exit-val ret))))))
  80. (define (show-version args)
  81. (format (current-error-port) "~A - Guile version ~A"
  82. program-name (pkg-config "--modversion" guile-module)))
  83. (define (help-version)
  84. (let ((dle display-line-error))
  85. (dle "Usage: " program-name " --version")
  86. (dle "Show the version of this script. This is also the version of")
  87. (dle "Guile this script was installed with.")))
  88. (define (usage-version)
  89. (display-line-error
  90. " " program-name " --version - show installed script and Guile version"))
  91. ;;;; the "link" subcommand
  92. ;;; Write a set of linker flags to standard output to include the
  93. ;;; libraries that libguile needs to link against.
  94. ;;;
  95. ;;; In the long run, we want to derive these flags from Guile module
  96. ;;; declarations files that are installed along the load path. For
  97. ;;; now, we're just going to reach into Guile's configuration info and
  98. ;;; hack it out.
  99. (define (build-link args)
  100. (display (apply pkg-config "--libs" guile-module args)))
  101. (define (help-link)
  102. (let ((dle display-line-error))
  103. (dle "Usage: " program-name " link")
  104. (dle "Print linker flags for building the `guile' executable.")
  105. (dle "Print the linker command-line flags necessary to link against")
  106. (dle "the Guile library, and any other libraries it requires.")))
  107. (define (usage-link)
  108. (display-line-error
  109. " " program-name " link - print libraries to link with"))
  110. ;;;; The "compile" subcommand
  111. (define (build-compile args)
  112. (display (apply pkg-config "--cflags" guile-module args)))
  113. (define (help-compile)
  114. (let ((dle display-line-error))
  115. (dle "Usage: " program-name " compile")
  116. (dle "Print C compiler flags for compiling code that uses Guile.")
  117. (dle "This includes any `-I' flags needed to find Guile's header files.")))
  118. (define (usage-compile)
  119. (display-line-error
  120. " " program-name " compile - print C compiler flags to compile with"))
  121. ;;;; The "info" subcommand
  122. (define (build-info args)
  123. (cond
  124. ((null? args)
  125. (display-line-error "guile-config info with no args has been removed")
  126. (quit 2))
  127. ((null? (cdr args))
  128. (cond
  129. ((string=? (car args) "guileversion")
  130. (display (pkg-config "--modversion" guile-module)))
  131. (else
  132. (display (pkg-config (format #f "--variable=~A" (car args))
  133. guile-module)))))
  134. (else (display-line-error "Usage: " program-name " info VAR")
  135. (quit 2))))
  136. (define (help-info)
  137. (let ((d display-line-error))
  138. (d "Usage: " program-name " info VAR")
  139. (d "Display the value of the pkg-config variable VAR used when Guile")
  140. (d "was built.\n")
  141. (d "Use this command to find out where Guile was installed,")
  142. (d "where it will look for Scheme code at run-time, and so on.")))
  143. (define (usage-info)
  144. (display-line-error
  145. " " program-name " info VAR - print Guile build directories"))
  146. ;;;; trivial utilities
  147. (define (display-line . args)
  148. (apply display-line-port (current-output-port) args))
  149. (define (display-line-error . args)
  150. (apply display-line-port (current-error-port) args))
  151. (define (display-line-port port . args)
  152. (for-each (lambda (arg) (display arg port))
  153. args)
  154. (newline port))
  155. ;;;; the command table
  156. ;;; We define this down here, so Guile builds the list after all the
  157. ;;; functions have been defined.
  158. (define command-table
  159. (list
  160. (list "--version" show-version help-version usage-version)
  161. (list "--help" show-help show-help-overview usage-help)
  162. (list "link" build-link help-link usage-link)
  163. (list "compile" build-compile help-compile usage-compile)
  164. (list "info" build-info help-info usage-info)))
  165. ;;; Local Variables:
  166. ;;; mode: scheme
  167. ;;; End: