pascal.scm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  1. ;;; Copyright © 2017, 2018 Kei Kebreau <kkebreau@posteo.net>
  2. ;;;
  3. ;;; This program is free software; you can redistribute it and/or modify it
  4. ;;; under the terms of the GNU General Public License as published by
  5. ;;; the Free Software Foundation; either version 3 of the License, or (at
  6. ;;; your option) any later version.
  7. ;;;
  8. ;;; This program is distributed in the hope that it will be useful, but
  9. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  10. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. ;;; GNU General Public License for more details.
  12. ;;;
  13. ;;; You should have received a copy of the GNU General Public License
  14. ;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
  15. (define-module (pascal)
  16. #:use-module ((guix licenses) #:prefix license:)
  17. #:use-module (guix packages)
  18. #:use-module (gnu packages)
  19. #:use-module (guix gexp)
  20. #:use-module (gnu packages autotools)
  21. #:use-module (gnu packages base)
  22. #:use-module (gnu packages bison)
  23. #:use-module (gnu packages bootstrap)
  24. #:use-module (gnu packages commencement)
  25. #:use-module (gnu packages compression)
  26. #:use-module (gnu packages flex)
  27. #:use-module (gnu packages gcc)
  28. #:use-module (gnu packages multiprecision)
  29. #:use-module (gnu packages ncurses)
  30. #:use-module (gnu packages texinfo)
  31. #:use-module (gnu packages xml)
  32. #:use-module (guix download)
  33. #:use-module (guix build-system gnu)
  34. #:use-module (ice-9 match))
  35. (define %patch-dir
  36. (string-append (if (current-filename)
  37. (dirname (current-filename))
  38. ".")
  39. "/patches"))
  40. (define fpc-bootstrap-x86_64-3.0.4
  41. (origin
  42. (method url-fetch)
  43. (uri
  44. "mirror://sourceforge/freepascal/Linux/3.0.4/fpc-3.0.4.x86_64-linux.tar")
  45. (sha256
  46. (base32
  47. "0xzxh689iyjfmkqkhcqg9plrjmdx82hbyywyyc7jm0n92fpmp5ky"))))
  48. (define fpc-bootstrap-i386-3.0.4
  49. (origin
  50. (method url-fetch)
  51. (uri
  52. "mirror://sourceforge/freepascal/Linux/3.0.4/fpc-3.0.4.i386-linux.tar")
  53. (sha256
  54. (base32
  55. "05xfgxa6vb0y2ryfsgn21m2kwaxhci6l2zxa3akvlnqminjsjvda"))))
  56. (define fpc-bootstrap-armhf-3.0.4
  57. (origin
  58. (method url-fetch)
  59. (uri
  60. "ftp://ftp.freepascal.org/pub/fpc/dist/3.0.4/arm-linux/fpc-3.0.4.arm-linux-eabihf-raspberry.tar")
  61. (sha256
  62. (base32
  63. "0r8g804vhy15744mxgbsmix0vxazxynqw4fdfiyap07wyr3xyh79"))))
  64. (define-public fpc
  65. (let ((arch (match (%current-system)
  66. ("x86_64-linux" "x86_64")
  67. ("i686-linux" "i386")
  68. ("armhf-linux" "arm")
  69. (_ ""))))
  70. (package
  71. (name "fpc")
  72. (version "3.0.4")
  73. (source (origin
  74. (method url-fetch)
  75. (uri (string-append "mirror://sourceforge/freepascal/Source/"
  76. version "/fpcbuild-" version ".tar.gz"))
  77. (file-name (string-append name "-" version ".tar.gz"))
  78. (sha256
  79. (base32
  80. "0xjyhlhz846jbnp12y68c7nq4xmp4i65akfbrjyf3r62ybk18rgn"))
  81. (patches
  82. (list
  83. (local-file
  84. (string-append %patch-dir "/fpc-reproducibility.patch"))))))
  85. (build-system gnu-build-system)
  86. (supported-systems '("i686-linux" "x86_64-linux" "armhf-linux"))
  87. (inputs
  88. `(("expat" ,expat)
  89. ("glibc" ,glibc)
  90. ("ld-wrapper" ,ld-wrapper)
  91. ("ncurses" ,ncurses)
  92. ("zlib" ,zlib)))
  93. (native-inputs
  94. ;; FPC is built with FPC, so we need bootstrap binaries.
  95. `(("fpc-binary"
  96. ,(cond ((string= arch "x86_64") fpc-bootstrap-x86_64-3.0.4)
  97. ((string= arch "i386") fpc-bootstrap-i386-3.0.4)
  98. (else fpc-bootstrap-armhf-3.0.4)))))
  99. (arguments
  100. `(#:tests? #f ; no tests available
  101. #:phases
  102. (let ((fpc-bootstrap-path
  103. (string-append (getcwd) "/" ,name "-"
  104. ,version "/fpc-bin")))
  105. (modify-phases %standard-phases
  106. (add-after 'unpack 'unpack-bin
  107. (lambda* (#:key inputs #:allow-other-keys)
  108. (mkdir-p fpc-bootstrap-path)
  109. (with-directory-excursion fpc-bootstrap-path
  110. (invoke "tar" "xvf" (assoc-ref inputs "fpc-binary")))))
  111. (add-after 'unpack-bin 'install-bin
  112. (lambda* (#:key inputs #:allow-other-keys)
  113. (with-directory-excursion
  114. (string-append fpc-bootstrap-path "/fpc-"
  115. ,version "." ,arch "-linux")
  116. (let ((binary-tarball
  117. (string-append "binary." ,arch "-linux.tar"))
  118. (compiler-tarball
  119. (string-append "base." ,arch "-linux.tar.gz"))
  120. (fpcmake-tarball
  121. (string-append "utils-fpcm." ,arch "-linux.tar.gz")))
  122. (and
  123. ;; Only the base compiler and fpcmake are needed.
  124. (invoke "tar" "xvf" binary-tarball
  125. compiler-tarball
  126. fpcmake-tarball)
  127. (invoke "tar" "xvf" compiler-tarball "-C..")
  128. (invoke "tar" "xvf" fpcmake-tarball "-C.."))))))
  129. (add-after 'patch-source-shebangs 'patch-inline-shebangs
  130. (lambda _
  131. (substitute* "fpcsrc/compiler/script.pas"
  132. (("#!/bin/sh") (string-append "#!" (which "sh"))))
  133. #t))
  134. (replace 'configure
  135. (lambda* (#:key inputs outputs #:allow-other-keys)
  136. (substitute* "fpcsrc/compiler/systems/t_linux.pas"
  137. ;; Point to the current glibc dynamic linker.
  138. (("/lib/ld-linux.*.so.[0-9]")
  139. (string-append (assoc-ref inputs "libc")
  140. ,(glibc-dynamic-linker)))
  141. (("/lib64/ld-linux-x86-64.so.2")
  142. (string-append (assoc-ref inputs "libc")
  143. ,(glibc-dynamic-linker)))
  144. ;; Add glibc to ld's search path.
  145. (("if \\(isdll\\) then")
  146. (string-append
  147. "Add('SEARCH_DIR(\""
  148. (assoc-ref inputs "libc") "/lib"
  149. "\")');\n"
  150. "if (isdll) then")))
  151. (substitute* "fpcsrc/compiler/options.pas"
  152. (("exepath\\+'../etc/'")
  153. (string-append "'" (assoc-ref outputs "out") "/etc'")))
  154. #t))
  155. (replace 'build
  156. (lambda* (#:key inputs #:allow-other-keys)
  157. (let* ((fpc-bin (string-append fpc-bootstrap-path "/bin"))
  158. (fpc (string-append fpc-bin "/fpc"))
  159. (fpcmake (string-append fpc-bin "/fpcmake")))
  160. ;; The fpc binary needs to run the ppc[arch] binary (which
  161. ;; does the actual compiling) in this directory.
  162. (setenv "PATH"
  163. (string-append (getenv "PATH") ":"
  164. fpc-bootstrap-path
  165. "/lib/fpc/" ,version))
  166. (setenv "FPC" fpc)
  167. ;; Enable the compiler to link to glibc by adding glibc
  168. ;; libraries to the compiler's library path.
  169. (setenv "OPT" (string-append
  170. "-Fl"
  171. (assoc-ref %build-inputs "libc") "/lib"))
  172. (and
  173. ;; Specify target operating system using "-T" option
  174. (invoke fpcmake
  175. (string-append "-T" ,arch "-linux"))
  176. (invoke "make" "build" "NOGDB=1")))))
  177. (replace 'install
  178. (lambda* (#:key outputs #:allow-other-keys)
  179. (let* ((out (assoc-ref outputs "out"))
  180. ;; This is the suffix of the ppc[arch] binary.
  181. (suffix (cond ((string= ,arch "x86_64") "x64")
  182. ((string= ,arch "i386") "386")
  183. ((string= ,arch "arm") "arm")
  184. (else "")))
  185. (ppc (string-append "ppc" suffix)))
  186. (invoke "make" "install" "NOGDB=1"
  187. (string-append "INSTALL_PREFIX=" out))
  188. ;; Add a symlink to the ppc[arch] binary so fpc works.
  189. (symlink (string-append out "/lib/fpc/" ,version "/" ppc)
  190. (string-append out "/bin/" ppc))
  191. ;; Install the example configuration file.
  192. (mkdir (string-append out "/etc"))
  193. (invoke
  194. (string-append out "/lib/fpc/" ,version "/samplecfg")
  195. (string-append out "/lib/fpc/" ,version)
  196. (string-append out "/etc")))))
  197. (add-after 'install 'wrap
  198. (lambda* (#:key inputs outputs #:allow-other-keys)
  199. (let* ((out (assoc-ref outputs "out"))
  200. (fpc (string-append out "/bin/fpc"))
  201. (ld (assoc-ref inputs "ld-wrapper"))
  202. (glibc (assoc-ref inputs "glibc")))
  203. (wrap-program fpc
  204. `("PATH" ":" prefix (,(string-append ld "/bin")))
  205. `("LIBRARY_PATH" ":" prefix (,(string-append glibc "/lib"))))
  206. #t)))))))
  207. ;; fpc invokes gcc, so make sure LIBRARY_PATH et.al are set.
  208. ;(native-search-paths (package-native-search-paths gcc))
  209. (home-page "http://www.freepascal.org")
  210. (synopsis "The Free Pascal Compiler")
  211. (description
  212. "Free Pascal is a professional Object Pascal compiler. It supports the
  213. Turbo Pascal 7.0, Delphi, and Mac Pascal dialects. Free Pascal also supports
  214. many useful extensions to the Pascal programming language.")
  215. ;; The majority of the software included is licensed under the GPLv2
  216. ;; or later. For more licensing details, see the appropriate files in
  217. ;; the install/doc directory of the source distribution.
  218. (license license:gpl2+))))
  219. (define* (nix-system->gnu-triplet-for-gpc
  220. #:optional (system (%current-system)))
  221. (match system
  222. ("x86_64-linux" "i686-unknown-linux-gnu")
  223. ("i686-linux" "i686-unknown-linux-gnu")
  224. ("armhf-linux" "armv7-unknown-linux-gnueabihf")
  225. ("aarch64-linux" "aarch64-unknown-linux-gnu")
  226. ("mips64el-linux" "mips64el-unknown-linux-gnuabi64")
  227. (_ (nix-system->gnu-triplet system))))
  228. (define-public gpc
  229. (package
  230. (name "gpc")
  231. (version "2.1")
  232. (source (origin
  233. (method url-fetch)
  234. (uri (string-append "http://www.gnu-pascal.de/stable/gpc-"
  235. version ".tar.gz"))
  236. (sha256
  237. (base32 "16f5q3cp19pxcsvizzap6275ladxi94izgyzbpmkg13xig15v81j"))))
  238. (build-system gnu-build-system)
  239. (arguments
  240. `(#:parallel-build? #f
  241. #:configure-flags '("--enable-languages=pascal")
  242. #:phases
  243. (modify-phases %standard-phases
  244. (add-after 'unpack 'unpack-gcc-core
  245. (lambda* (#:key inputs #:allow-other-keys)
  246. (invoke "tar" "xvf" (assoc-ref inputs "gcc-core"))
  247. (rename-file "p" "gcc-2.95.2/gcc/p")
  248. (chdir "gcc-2.95.2")
  249. #t))
  250. (replace 'configure
  251. ;; The build process fails if the configure script is passed the
  252. ;; option "--enable-fast-install".
  253. (lambda* (#:key inputs outputs (configure-flags '())
  254. #:allow-other-keys)
  255. (let ((out (assoc-ref outputs "out")))
  256. (setenv "CONFIG_SHELL" (which "sh"))
  257. (setenv "SHELL" (which "sh"))
  258. (apply invoke "./configure"
  259. (string-append "--prefix=" out)
  260. (string-append "--build="
  261. ,(nix-system->gnu-triplet-for-gpc))
  262. (string-append "--host="
  263. ,(nix-system->gnu-triplet-for-gpc))
  264. configure-flags)))))))
  265. (native-inputs
  266. `(("gcc-core",
  267. (origin
  268. (method url-fetch)
  269. (uri (string-append
  270. "mirror://gnu/gcc/gcc-2.95.2/gcc-core-2.95.2.tar.gz"))
  271. (sha256
  272. (base32 "1cc7qpgq1kja2y6q3ancqcskn4705yv63qqy8cinnaizp8wqvrk5"))))))
  273. (home-page "http://www.gnu-pascal.de")
  274. (synopsis "The GNU Pascal Compiler")
  275. (description
  276. "GNU Pascal is a Pascal compiler which combines a Pascal front-end with the
  277. proven GCC back-end for code generation and optimization. The current release
  278. implements Standard Pascal (ISO 7185, levels 0 and 1), a large subset of
  279. Extended Pascal (ISO 10206, aiming for full compliance), is highly compatible
  280. to Borland Pascal (version 7.0) with some Delphi extensions, and provides a lot
  281. of useful GNU extensions.")
  282. (license license:gpl2+)))