gnu: mingw-w64: Add -winpthreads variants.
[jackhill/guix/guix.git] / gnu / packages / mingw.scm
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 ;;;
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
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
36 (define* (make-mingw-w64 machine
37 #:key
38 xgcc
39 xbinutils
40 with-winpthreads?)
41 "Return a mingw-w64 for targeting MACHINE. If XGCC or XBINUTILS is specified,
42 use that gcc or binutils when cross-compiling. If WITH-WINPTHREADS? is
43 specified, recurse and return a mingw-w64 with support for winpthreads."
44 (let* ((triplet (string-append machine "-" "w64-mingw32")))
45 (package
46 (name (string-append "mingw-w64" "-" machine
47 (if with-winpthreads? "-winpthreads" "")))
48 (version "6.0.0")
49 (source (origin
50 (method url-fetch)
51 (uri (string-append
52 "https://sourceforge.net/projects/mingw-w64/files/mingw-w64/"
53 "mingw-w64-release/mingw-w64-v" version ".tar.bz2"))
54 (sha256
55 (base32 "1w28mynv500y03h92nh87rgw3fnp82qwnjbxrrzqkmr63q812pl0"))
56 (patches (search-patches "mingw-w64-6.0.0-gcc.patch"))))
57 (native-inputs `(("xgcc-core" ,(if xgcc xgcc (cross-gcc triplet)))
58 ("xbinutils" ,(if xbinutils xbinutils (cross-binutils triplet)))
59 ,@(if with-winpthreads?
60 `(("xlibc" ,(make-mingw-w64 machine
61 #:xgcc xgcc
62 #:xbinutils xbinutils)))
63 '())))
64 (build-system gnu-build-system)
65 (search-paths
66 (list (search-path-specification
67 (variable "CROSS_C_INCLUDE_PATH")
68 (files `("include" ,(string-append triplet "/include"))))
69 (search-path-specification
70 (variable "CROSS_LIBRARY_PATH")
71 (files
72 `("lib" "lib64"
73 ,(string-append triplet "/lib")
74 ,(string-append triplet "/lib64"))))))
75 (arguments
76 `(#:configure-flags '(,(string-append "--host=" triplet)
77 ,@(if with-winpthreads?
78 '("--with-libraries=winpthreads")
79 '()))
80 #:phases
81 (modify-phases %standard-phases
82 (add-before 'configure 'setenv
83 (lambda* (#:key inputs #:allow-other-keys)
84 (let ((xgcc-core (assoc-ref inputs "xgcc-core"))
85 (mingw-headers (string-append (getcwd) "/mingw-w64-headers")))
86 (setenv "CPP"
87 (string-append xgcc-core ,(string-append "/bin/" triplet "-cpp")))
88 (setenv "CROSS_C_INCLUDE_PATH"
89 (string-append
90 mingw-headers
91 ":" mingw-headers "/include"
92 ":" mingw-headers "/crt"
93 ":" mingw-headers "/defaults/include"
94 ":" mingw-headers "/direct-x/include"))
95 (when ,with-winpthreads?
96 (let ((xlibc (assoc-ref inputs "xlibc")))
97 (setenv "CROSS_LIBRARY_PATH"
98 (string-append
99 xlibc "/lib" ":"
100 xlibc "/" ,triplet "/lib"))))))))
101 #:make-flags (list "DEFS=-DHAVE_CONFIG_H -D__MINGW_HAS_DXSDK=1")
102 #:tests? #f ; compiles and includes glibc headers
103 #:strip-binaries? #f))
104 (home-page "https://mingw-w64.org")
105 (synopsis "Minimalist GNU for Windows")
106 (description
107 "Minimalist GNU for Windows (@dfn{MinGW}) is a complete software
108 development environment for creating native Microsoft Windows applications.
109
110 It includes a set of Windows-specific header files and static import libraries
111 which enable the use of the Windows API. It does not rely on any third-party C
112 runtime dynamic-link libraries (@dfn{DLL}s).
113
114 Mingw-w64 is an advancement of the original mingw.org project and provides
115 several new APIs such as DirectX and DDK, and 64-bit support.")
116 (license license:fdl1.3+))))
117
118 (define-public mingw-w64-i686
119 (make-mingw-w64 "i686"))
120
121 (define-public mingw-w64-x86_64
122 (make-mingw-w64 "x86_64"))
123
124 (define-public mingw-w64-i686-winpthreads
125 (make-mingw-w64 "i686"
126 #:with-winpthreads? #t))
127
128 (define-public mingw-w64-x86_64-winpthreads
129 (make-mingw-w64 "x86_64"
130 #:with-winpthreads? #t))
131
132 (define-public mingw-w64 mingw-w64-i686)