installers.scm 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  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. (define-module (gnu packages installers)
  19. #:use-module ((guix licenses) #:prefix license:)
  20. #:use-module (gnu packages)
  21. #:use-module (gnu packages compression)
  22. #:use-module (gnu packages cross-base)
  23. #:use-module (gnu packages python-xyz)
  24. #:use-module (guix packages)
  25. #:use-module (guix download)
  26. #:use-module (guix build-system scons)
  27. #:use-module (guix utils))
  28. (define (make-nsis machine target-arch nsis-target-type)
  29. (let* ((triplet (string-append machine "-" "w64-mingw32"))
  30. (xbinutils (cross-binutils triplet))
  31. (xlibc (cross-libc triplet))
  32. (xgcc (cross-gcc triplet #:libc xlibc)))
  33. (package
  34. (name (string-append "nsis-" machine))
  35. (version "3.05")
  36. (source (origin
  37. (method url-fetch)
  38. (uri (string-append "http://prdownloads.sourceforge.net/nsis/nsis-"
  39. version "-src.tar.bz2"))
  40. (sha256
  41. (base32
  42. "1sbwx5vzpddharkb7nj4q5z3i5fbg4lan63ng738cw4hmc4v7qdn"))
  43. (patches (search-patches "nsis-env-passthru.patch"
  44. "nsis-source-date-epoch.patch"))))
  45. (build-system scons-build-system)
  46. (native-inputs `(("xgcc" ,xgcc)
  47. ("xbinutils" ,xbinutils)
  48. ("mingw-w64" ,xlibc)))
  49. (inputs (list zlib))
  50. (arguments
  51. `(#:scons ,scons-python2
  52. #:modules ((srfi srfi-1)
  53. (srfi srfi-26)
  54. (guix build utils)
  55. (guix build scons-build-system))
  56. #:tests? #f
  57. #:scons-flags `("UNICODE=yes"
  58. "SKIPUTILS=MakeLangId,Makensisw,NSIS Menu,SubStart,zip2exe"
  59. "SKIPDOC=COPYING"
  60. "STRIP_CP=no"
  61. ,(string-append "PREFIX=" %output)
  62. ,(string-append "TARGET_ARCH=" ,target-arch)
  63. ,(string-append "XGCC_W32_PREFIX=" ,triplet "-")
  64. ,(string-append "PREFIX_PLUGINAPI_INC=" (assoc-ref %build-inputs "mingw-w64") "/include/")
  65. ,(string-append "PREFIX_PLUGINAPI_LIB=" (assoc-ref %build-inputs "mingw-w64") "/lib/"))
  66. #:build-targets '("makensis"
  67. "stubs"
  68. "plugins"
  69. "utils")
  70. #:install-targets '("install-stubs"
  71. "install-plugins"
  72. "install-data"
  73. "install-utils"
  74. "install-compiler"
  75. "install-conf")
  76. #:phases (modify-phases %standard-phases
  77. (add-before 'build 'fix-env
  78. (lambda _
  79. (define* (filter-delimited-string delimited-string predicate #:optional (delimiter #\:))
  80. ;; Given a DELIMITED-STRING delimited by DELIMITER,
  81. ;; only keep items that satisfy PREDICATE
  82. (string-join
  83. (filter predicate (string-split delimited-string delimiter))
  84. (string delimiter)))
  85. (define (mingw-path? path)
  86. (string-prefix? (assoc-ref %build-inputs "mingw-w64") path))
  87. (for-each
  88. (lambda (env-name)
  89. (let ((env-val (getenv env-name)))
  90. ;; Remove all mingw-w64 paths from env vars meant
  91. ;; for native toolchain
  92. (setenv env-name
  93. (filter-delimited-string env-val (negate mingw-path?)))
  94. ;; Add the removed paths back into CROSS_-prefixed
  95. ;; version of env vars
  96. (setenv (string-append "CROSS_" env-name)
  97. (filter-delimited-string env-val mingw-path?))))
  98. '("C_INCLUDE_PATH" "CPLUS_INCLUDE_PATH" "LIBRARY_PATH"))
  99. ;; Hack to place mingw-w64 path at the end of search
  100. ;; paths. Could probably use a specfile and dirafter
  101. (setenv "CROSS_C_INCLUDE_PATH"
  102. (string-join
  103. `(,@(map (cut string-append
  104. (assoc-ref %build-inputs "xgcc")
  105. "/lib/gcc/" ,triplet "/"
  106. ,(package-version xgcc) <>)
  107. '("/include"
  108. "/include-fixed"))
  109. ,(getenv "CROSS_C_INCLUDE_PATH"))
  110. ":"))
  111. (setenv "CROSS_CPLUS_INCLUDE_PATH"
  112. (string-join
  113. `(,@(map (cut string-append (assoc-ref %build-inputs "xgcc") <>)
  114. `("/include/c++"
  115. ,(string-append "/include/c++/" ,triplet)
  116. "/include/c++/backward"
  117. ,@(map (cut string-append "/lib/gcc/" ,triplet "/" ,(package-version xgcc) <>)
  118. '("/include"
  119. "/include-fixed"))))
  120. ,(getenv "CROSS_CPLUS_INCLUDE_PATH"))
  121. ":"))))
  122. (add-before 'build 'fix-target-detection
  123. (lambda _
  124. ;; NSIS target detection is screwed up, manually change
  125. ;; it ourselves
  126. (substitute* "Source/build.cpp" (("m_target_type=TARGET_X86ANSI")
  127. (string-append "m_target_type=" ,nsis-target-type))))))))
  128. (home-page "https://nsis.sourceforge.io/Main_Page")
  129. (synopsis "System to create Windows installers")
  130. (description
  131. "NSIS (Nullsoft Scriptable Install System) is a system to create
  132. Windows installers. It is designed to be as small and flexible as possible
  133. and is therefore very suitable for internet distribution.")
  134. (license (license:non-copyleft "file://COPYING"
  135. "See COPYING in the distribution.")))))
  136. (define-public nsis-x86_64
  137. (make-nsis "x86_64" "amd64" "TARGET_AMD64"))
  138. (define-public nsis-i686
  139. (make-nsis "i686" "x86" "TARGET_X86UNICODE"))