gnu: nsis: Respect SOURCE-DATE-EPOCH for reproducibility
[jackhill/guix/guix.git] / gnu / packages / installers.scm
CommitLineData
e214a220
CD
1;;; GNU Guix --- Functional package management for GNU
2;;; Copyright © 2019 Carl Dong <contact@carldong.me>
3;;;
4;;; This file is part of GNU Guix.
5;;;
6;;; GNU Guix is free software; you can redistribute it and/or modify it
7;;; under the terms of the GNU General Public License as published by
8;;; the Free Software Foundation; either version 3 of the License, or (at
9;;; your option) any later version.
10;;;
11;;; GNU Guix is distributed in the hope that it will be useful, but
12;;; WITHOUT ANY WARRANTY; without even the implied warranty of
13;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14;;; GNU General Public License for more details.
15;;;
16;;; You should have received a copy of the GNU General Public License
17;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
18
19(define-module (gnu packages installers)
20 #:use-module ((guix licenses) #:prefix license:)
21 #:use-module (gnu packages)
22 #:use-module (gnu packages compression)
23 #:use-module (gnu packages cross-base)
24 #:use-module (gnu packages python-xyz)
25 #:use-module (guix packages)
26 #:use-module (guix download)
27 #:use-module (guix build-system scons)
28 #:use-module (guix utils))
29
a7d03e96 30(define (make-nsis machine target-arch nsis-target-type)
21486743
CD
31 (let* ((triplet (string-append machine "-" "w64-mingw32"))
32 (xbinutils (cross-binutils triplet))
33 (xlibc (cross-libc triplet))
34 (xgcc (cross-gcc triplet #:libc xlibc)))
e214a220
CD
35 (package
36 (name (string-append "nsis-" machine))
cdf00cf7 37 (version "3.05")
e214a220
CD
38 (source (origin
39 (method url-fetch)
40 (uri (string-append "http://prdownloads.sourceforge.net/nsis/nsis-"
41 version "-src.tar.bz2"))
42 (sha256
43 (base32
cdf00cf7 44 "1sbwx5vzpddharkb7nj4q5z3i5fbg4lan63ng738cw4hmc4v7qdn"))
20d9535e
CD
45 (patches (search-patches "nsis-env-passthru.patch"
46 "nsis-source-date-epoch.patch"))))
e214a220 47 (build-system scons-build-system)
21486743
CD
48 (native-inputs `(("xgcc" ,xgcc)
49 ("xbinutils" ,xbinutils)
50 ("mingw-w64" ,xlibc)))
e214a220
CD
51 (inputs `(("zlib" ,zlib)))
52 (arguments
53 `(#:scons ,scons-python2
54 #:modules ((srfi srfi-1)
21486743 55 (srfi srfi-26)
e214a220
CD
56 (guix build utils)
57 (guix build scons-build-system))
58 #:tests? #f
59 #:scons-flags `("UNICODE=yes"
60 "SKIPUTILS=MakeLangId,Makensisw,NSIS Menu,SubStart,zip2exe"
61 "SKIPDOC=COPYING"
62 "STRIP_CP=no"
63 ,(string-append "PREFIX=" %output)
64 ,(string-append "TARGET_ARCH=" ,target-arch)
65 ,(string-append "XGCC_W32_PREFIX=" ,triplet "-")
66 ,(string-append "PREFIX_PLUGINAPI_INC=" (assoc-ref %build-inputs "mingw-w64") "/include/")
67 ,(string-append "PREFIX_PLUGINAPI_LIB=" (assoc-ref %build-inputs "mingw-w64") "/lib/"))
68 #:build-targets '("makensis"
69 "stubs"
70 "plugins"
71 "utils")
72 #:install-targets '("install-stubs"
73 "install-plugins"
74 "install-data"
75 "install-utils"
76 "install-compiler"
77 "install-conf")
78 #:phases (modify-phases %standard-phases
79 (add-before 'build 'fix-env
80 (lambda _
81 (define* (filter-delimited-string delimited-string predicate #:optional (delimiter #\:))
82 ;; Given a DELIMITED-STRING delimited by DELIMITER,
83 ;; only keep items that satisfy PREDICATE
84 (string-join
85 (filter predicate (string-split delimited-string delimiter))
86 (string delimiter)))
87 (define (mingw-path? path)
88 (string-prefix? (assoc-ref %build-inputs "mingw-w64") path))
89 (for-each
90 (lambda (env-name)
91 (let ((env-val (getenv env-name)))
92 ;; Remove all mingw-w64 paths from env vars meant
93 ;; for native toolchain
94 (setenv env-name
95 (filter-delimited-string env-val (negate mingw-path?)))
811a2015
CD
96 ;; Add the removed paths back into CROSS_-prefixed
97 ;; version of env vars
e214a220
CD
98 (setenv (string-append "CROSS_" env-name)
99 (filter-delimited-string env-val mingw-path?))))
811a2015 100 '("C_INCLUDE_PATH" "CPLUS_INCLUDE_PATH" "LIBRARY_PATH"))
21486743
CD
101 ;; Hack to place mingw-w64 path at the end of search
102 ;; paths. Could probably use a specfile and dirafter
811a2015
CD
103 (setenv "CROSS_C_INCLUDE_PATH"
104 (string-join
105 `(,@(map (cut string-append
106 (assoc-ref %build-inputs "xgcc")
107 "/lib/gcc/" ,triplet "/"
108 ,(package-version xgcc) <>)
109 '("/include"
110 "/include-fixed"))
111 ,(getenv "CROSS_C_INCLUDE_PATH"))
112 ":"))
21486743
CD
113 (setenv "CROSS_CPLUS_INCLUDE_PATH"
114 (string-join
115 `(,@(map (cut string-append (assoc-ref %build-inputs "xgcc") <>)
116 `("/include/c++"
117 ,(string-append "/include/c++/" ,triplet)
118 "/include/c++/backward"
119 ,@(map (cut string-append "/lib/gcc/" ,triplet "/" ,(package-version xgcc) <>)
120 '("/include"
121 "/include-fixed"))))
811a2015 122 ,(getenv "CROSS_CPLUS_INCLUDE_PATH"))
21486743 123 ":"))))
e214a220
CD
124 (add-before 'build 'fix-target-detection
125 (lambda _
811a2015
CD
126 ;; NSIS target detection is screwed up, manually change
127 ;; it ourselves
e214a220
CD
128 (substitute* "Source/build.cpp" (("m_target_type=TARGET_X86ANSI")
129 (string-append "m_target_type=" ,nsis-target-type))))))))
130 (home-page "http://nsis.sourceforge.net/")
131 (synopsis "A professional open source system to create Windows installers")
132 (description
811a2015
CD
133 "NSIS (Nullsoft Scriptable Install System) is a professional open source
134system to create Windows installers. It is designed to be as small and flexible
135as possible and is therefore very suitable for internet distribution.")
e214a220
CD
136 (license (license:non-copyleft "file://COPYING"
137 "See COPYING in the distribution.")))))
138
139(define-public nsis-x86_64
140 (make-nsis "x86_64" "amd64" "TARGET_AMD64"))
141
142(define-public nsis-i686
143 (make-nsis "i686" "x86" "TARGET_X86UNICODE"))