mingw.scm 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2016 Jan Nieuwenhuizen <janneke@gnu.org>
  3. ;;; Copyright © 2018 Tobias Geerinckx-Rice <me@tobias.gr>
  4. ;;; Copyright © 2019 Carl Dong <contact@carldong.me>
  5. ;;; Copyright © 2021 Léo Le Bouter <lle-bout@zaclys.net>
  6. ;;;
  7. ;;; This file is part of GNU Guix.
  8. ;;;
  9. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  10. ;;; under the terms of the GNU General Public License as published by
  11. ;;; the Free Software Foundation; either version 3 of the License, or (at
  12. ;;; your option) any later version.
  13. ;;;
  14. ;;; GNU Guix is distributed in the hope that it will be useful, but
  15. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  16. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. ;;; GNU General Public License for more details.
  18. ;;;
  19. ;;; You should have received a copy of the GNU General Public License
  20. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  21. (define-module (gnu packages mingw)
  22. #:use-module ((guix licenses) #:prefix license:)
  23. #:use-module (gnu packages)
  24. #:use-module (gnu packages base)
  25. #:use-module (gnu packages cross-base)
  26. #:use-module (gnu packages gcc)
  27. #:use-module (gnu packages compression)
  28. #:use-module (gnu packages multiprecision)
  29. #:use-module (guix build-system gnu)
  30. #:use-module (guix packages)
  31. #:use-module (guix download)
  32. #:use-module (guix utils)
  33. #:use-module (ice-9 match)
  34. #:export (make-mingw-w64))
  35. (define* (make-mingw-w64 machine
  36. #:key
  37. xgcc
  38. xbinutils
  39. with-winpthreads?)
  40. "Return a mingw-w64 for targeting MACHINE. If XGCC or XBINUTILS is specified,
  41. use that gcc or binutils when cross-compiling. If WITH-WINPTHREADS? is
  42. specified, recurse and return a mingw-w64 with support for winpthreads."
  43. (let* ((triplet (string-append machine "-" "w64-mingw32")))
  44. (package
  45. (name (string-append "mingw-w64" "-" machine
  46. (if with-winpthreads? "-winpthreads" "")))
  47. (version "8.0.0")
  48. (source
  49. (origin
  50. (method url-fetch)
  51. (uri (string-append
  52. "mirror://sourceforge/mingw-w64/mingw-w64/"
  53. "mingw-w64-release/mingw-w64-v" version ".tar.bz2"))
  54. (sha256
  55. (base32 "0qjpb9rviasfshk337j5r32ncmrwml8sv6qnmb1lp4mkdbm41is4"))
  56. (patches
  57. (search-patches "mingw-w64-6.0.0-gcc.patch"
  58. "mingw-w64-dlltool-temp-prefix.patch"
  59. "mingw-w64-reproducible-gendef.patch"))))
  60. (native-inputs `(("xgcc-core" ,(if xgcc xgcc (cross-gcc triplet)))
  61. ("xbinutils" ,(if xbinutils xbinutils
  62. (cross-binutils triplet)))
  63. ,@(if with-winpthreads?
  64. `(("xlibc" ,(make-mingw-w64
  65. machine
  66. #:xgcc xgcc
  67. #:xbinutils xbinutils)))
  68. '())))
  69. (build-system gnu-build-system)
  70. (search-paths
  71. (list (search-path-specification
  72. (variable "CROSS_C_INCLUDE_PATH")
  73. (files `("include" ,(string-append triplet "/include"))))
  74. (search-path-specification
  75. (variable "CROSS_LIBRARY_PATH")
  76. (files
  77. `("lib" "lib64"
  78. ,(string-append triplet "/lib")
  79. ,(string-append triplet "/lib64"))))))
  80. (arguments
  81. `(#:configure-flags '(,(string-append "--host=" triplet)
  82. ,@(if with-winpthreads?
  83. '("--with-libraries=winpthreads")
  84. '()))
  85. #:phases
  86. (modify-phases %standard-phases
  87. (add-before 'configure 'setenv
  88. (lambda* (#:key inputs #:allow-other-keys)
  89. (let ((xgcc-core (assoc-ref inputs "xgcc-core"))
  90. (mingw-headers (string-append
  91. (getcwd) "/mingw-w64-headers")))
  92. (setenv "CPP"
  93. (string-append
  94. xgcc-core ,(string-append "/bin/" triplet "-cpp")))
  95. (setenv "CROSS_C_INCLUDE_PATH"
  96. (string-append
  97. mingw-headers
  98. ":" mingw-headers "/include"
  99. ":" mingw-headers "/crt"
  100. ":" mingw-headers "/defaults/include"
  101. ":" mingw-headers "/direct-x/include"))
  102. (when ,with-winpthreads?
  103. (let ((xlibc (assoc-ref inputs "xlibc")))
  104. (setenv "CROSS_LIBRARY_PATH"
  105. (string-append
  106. xlibc "/lib" ":"
  107. xlibc "/" ,triplet "/lib"))))))))
  108. #:make-flags (list "DEFS=-DHAVE_CONFIG_H -D__MINGW_HAS_DXSDK=1")
  109. #:tests? #f ; compiles and includes glibc headers
  110. #:strip-binaries? #f))
  111. (home-page "https://mingw-w64.org")
  112. (synopsis "Minimalist GNU for Windows")
  113. (description
  114. "Minimalist GNU for Windows (@dfn{MinGW}) is a complete software
  115. development environment for creating native Microsoft Windows applications.
  116. It includes a set of Windows-specific header files and static import libraries
  117. which enable the use of the Windows API. It does not rely on any third-party C
  118. runtime dynamic-link libraries (@dfn{DLL}s).
  119. Mingw-w64 is an advancement of the original mingw.org project and provides
  120. several new APIs such as DirectX and DDK, and 64-bit support.")
  121. (license license:fdl1.3+))))
  122. (define-public mingw-w64-i686
  123. (make-mingw-w64 "i686"))
  124. (define-public mingw-w64-x86_64
  125. (make-mingw-w64 "x86_64"))
  126. (define-public mingw-w64-i686-winpthreads
  127. (make-mingw-w64 "i686"
  128. #:with-winpthreads? #t))
  129. (define-public mingw-w64-x86_64-winpthreads
  130. (make-mingw-w64 "x86_64"
  131. #:with-winpthreads? #t))
  132. (define-public mingw-w64 mingw-w64-i686)
  133. (define-public mingw-w64-tools
  134. (package
  135. (name "mingw-w64-tools")
  136. (version "8.0.0")
  137. (source
  138. (origin
  139. (method url-fetch)
  140. (uri (string-append
  141. "mirror://sourceforge/mingw-w64/mingw-w64/"
  142. "mingw-w64-release/mingw-w64-v" version ".tar.bz2"))
  143. (sha256
  144. (base32 "0qjpb9rviasfshk337j5r32ncmrwml8sv6qnmb1lp4mkdbm41is4"))))
  145. (build-system gnu-build-system)
  146. (arguments
  147. `(#:modules ((guix build gnu-build-system)
  148. (guix build utils)
  149. (srfi srfi-1))
  150. #:phases
  151. (append
  152. (modify-phases %standard-phases
  153. (add-after 'unpack 'cd-gendef
  154. (lambda _
  155. (chdir "mingw-w64-tools/gendef"))))
  156. (modify-phases %standard-phases
  157. (replace 'unpack
  158. (lambda _
  159. (chdir "../genidl"))))
  160. (modify-phases %standard-phases
  161. (replace 'unpack
  162. (lambda _
  163. (chdir "../genlib"))))
  164. (modify-phases %standard-phases
  165. (replace 'unpack
  166. (lambda _
  167. (chdir "../genpeimg"))))
  168. (append-map
  169. (lambda (target)
  170. (modify-phases %standard-phases
  171. (replace 'unpack
  172. (lambda _
  173. (chdir "../widl")
  174. (false-if-exception
  175. (delete-file-recursively "../build"))
  176. #t))
  177. (replace 'configure
  178. (lambda args
  179. (apply (assoc-ref %standard-phases 'configure)
  180. (append args (list #:out-of-source? #t
  181. #:configure-flags
  182. `("--target" ,target
  183. "--program-prefix"
  184. ,(string-append target "-")))))))))
  185. '("i686-w64-mingw32" "x86_64-w64-mingw32")))))
  186. (home-page "https://mingw-w64.org")
  187. (synopsis "Tools of Minimalist GNU for Windows")
  188. (description "This package provides the tools of Minimalist GNU for
  189. Windows, a complete software development environment for creating native
  190. Microsoft Windows applications.")
  191. (license (list license:gpl3+ ;gendef, genidl, genlib, genpeimg, genstubdll
  192. license:lgpl2.1+)))) ;widl