pascal.scm 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2017 Kei Kebreau <address@hidden>
  3. ;;; Copyright © 2020 Eric Bavier <bavier@posteo.net>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu packages pascal)
  20. #:use-module ((guix licenses) #:prefix license:)
  21. #:use-module (guix packages)
  22. #:use-module (guix download)
  23. #:use-module (guix utils)
  24. #:use-module (guix build-system gnu)
  25. #:use-module (gnu packages)
  26. #:use-module (gnu packages base)
  27. #:use-module (gnu packages bootstrap)
  28. #:use-module (gnu packages commencement)
  29. #:use-module (gnu packages compression)
  30. #:use-module (gnu packages gcc)
  31. #:use-module (gnu packages ncurses)
  32. #:use-module (gnu packages perl)
  33. #:use-module (gnu packages xml)
  34. #:use-module (ice-9 match))
  35. (define fpc-bootstrap-i386-3.0.4
  36. (origin
  37. (method url-fetch)
  38. (uri
  39. "mirror://sourceforge/freepascal/Linux/3.0.4/fpc-3.0.4.i386-linux.tar")
  40. (sha256
  41. (base32
  42. "05xfgxa6vb0y2ryfsgn21m2kwaxhci6l2zxa3akvlnqminjsjvda"))))
  43. (define fpc-bootstrap-x86_64-3.0.4
  44. (origin
  45. (method url-fetch)
  46. (uri
  47. "mirror://sourceforge/freepascal/Linux/3.0.4/fpc-3.0.4.x86_64-linux.tar")
  48. (sha256
  49. (base32
  50. "0xzxh689iyjfmkqkhcqg9plrjmdx82hbyywyyc7jm0n92fpmp5ky"))))
  51. (define-public fpc
  52. (package
  53. (name "fpc")
  54. (version "3.2.2") ; Update release date below!
  55. (source (origin
  56. (method url-fetch)
  57. (uri (string-append "mirror://sourceforge/freepascal/Source/"
  58. version "/fpcbuild-" version ".tar.gz"))
  59. (file-name (string-append name "-" version ".tar.gz"))
  60. (sha256
  61. (base32
  62. "07qna2pvlpa7j0i2wdixjxpizdvffv51nbr1waczk0xv8cq9kvw5"))
  63. (patches (search-patches "fpc-reproducibility.patch"))
  64. (modules '((guix build utils)))
  65. (snippet
  66. '(begin
  67. (rename-file "install/doc" "install-doc")
  68. (rename-file "install/man" "install-man")
  69. ;; Contains executables--some of them created by
  70. ;; closed-source compilers.
  71. (delete-file-recursively "install")
  72. (mkdir-p "install")
  73. (rename-file "install-doc" "install/doc")
  74. (rename-file "install-man" "install/man")
  75. (delete-file "fpcsrc/tests/utils/dosbox/exitcode.exe")
  76. #t))))
  77. (build-system gnu-build-system)
  78. (supported-systems '("i686-linux" "x86_64-linux"))
  79. (inputs
  80. `(("expat" ,expat)
  81. ("glibc" ,glibc)
  82. ("ld-wrapper" ,ld-wrapper)
  83. ("ncurses" ,ncurses)
  84. ("zlib" ,zlib)))
  85. (native-inputs
  86. ;; FPC is built with FPC, so we need bootstrap binaries.
  87. `(("fpc-binary"
  88. ,(match (or (%current-target-system)
  89. (%current-system))
  90. ("i686-linux" fpc-bootstrap-i386-3.0.4)
  91. ;("powerpc64le-linux" fpc-bootstrap-ppc64le-3.0.4)
  92. ;("powerpc-linux" fpc-bootstrap-ppc-3.0.4)
  93. ("x86_64-linux" fpc-bootstrap-x86_64-3.0.4)
  94. (_ fpc-bootstrap-x86_64-3.0.4)))))
  95. (arguments
  96. `(#:tests? #f ; no tests available
  97. #:phases
  98. (let ((fpc-bootstrap-path
  99. (string-append (getcwd) "/" ,name "-" ,version "/fpc-bin"))
  100. (arch ,(match (or (%current-target-system)
  101. (%current-system))
  102. ("i686-linux" "i386")
  103. ("x86_64-linux" "x86_64")
  104. (_ "unknown"))))
  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-3.0.4."
  115. 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. ;; Only the base compiler and fpcmake are needed.
  123. (invoke "tar" "xvf" binary-tarball compiler-tarball
  124. fpcmake-tarball)
  125. (invoke "tar" "xvf" compiler-tarball "-C..")
  126. (invoke "tar" "xvf" fpcmake-tarball "-C..")))))
  127. (add-after 'patch-source-shebangs 'patch-inline-shebangs
  128. (lambda _
  129. (substitute* "fpcsrc/compiler/cscript.pas"
  130. (("#!/bin/sh") (string-append "#!" (which "sh"))))
  131. #t))
  132. (add-before 'build 'patch-release-date
  133. (lambda _ ; reproducibility
  134. (substitute* (list "fpcdocs/prog.tex"
  135. "fpcsrc/packages/amunits/examples/sortdemo.pas"
  136. "fpcsrc/packages/libogcfpc/src/ogc/libversion.inc"
  137. "fpcsrc/utils/fpcres/fpcjres.pas"
  138. "fpcsrc/utils/fpcres/fpcres.pas"
  139. "fpcsrc/utils/fpcm/fpcmmain.pp"
  140. "fpcsrc/utils/fpcreslipo/fpcreslipo.pp"
  141. "fpcsrc/compiler/version.pas")
  142. (("\\{\\$I(NCLUDE)? %DATE%\\}") "'2020/06/19'"))
  143. #t))
  144. (replace 'configure
  145. (lambda* (#:key inputs outputs #:allow-other-keys)
  146. (substitute* "fpcsrc/compiler/systems/t_linux.pas"
  147. ;; Point to the current glibc dynamic linker.
  148. (("/lib/ld-linux.so.2")
  149. (search-input-file inputs ,(glibc-dynamic-linker)))
  150. (("/lib64/ld-linux-x86-64.so.2")
  151. (search-input-file inputs ,(glibc-dynamic-linker)))
  152. ; TODO: /lib/ld-linux-armhf.so.3
  153. ; TODO: /lib/ld-linux-aarch64.so.1
  154. ; TODO: /lib64/ld64.so.2
  155. ;; Add glibc to ld's search path.
  156. (("if \\(isdll\\) then")
  157. (string-append
  158. "Add('SEARCH_DIR(\""
  159. (assoc-ref inputs "libc") "/lib"
  160. "\")');\n"
  161. "if (isdll) then")))
  162. (substitute* "fpcsrc/compiler/options.pas"
  163. (("exepath\\+'../etc/'")
  164. (string-append "'" (assoc-ref outputs "out") "/etc'")))
  165. #t))
  166. (replace 'build
  167. (lambda* (#:key inputs #:allow-other-keys)
  168. (let* ((fpc-bin (string-append fpc-bootstrap-path "/bin"))
  169. (fpc (string-append fpc-bin "/fpc"))
  170. (fpcmake (string-append fpc-bin "/fpcmake")))
  171. ;; The fpc binary needs to run the ppc[arch] binary (which
  172. ;; does the actual compiling) in this directory.
  173. (setenv "PATH"
  174. (string-append (getenv "PATH") ":"
  175. fpc-bootstrap-path
  176. "/lib/fpc/3.0.4"))
  177. (setenv "FPC" fpc)
  178. ;; Specify target operating system using "-T" option
  179. (invoke fpcmake (string-append "-T" arch "-linux"))
  180. (invoke "make" "build" "NOGDB=1"))))
  181. (replace 'install
  182. (lambda* (#:key outputs #:allow-other-keys)
  183. (let* ((out (assoc-ref outputs "out"))
  184. ;; This is the suffix of the ppc[arch] binary.
  185. (suffix (if (string= arch "x86_64")
  186. "x64"
  187. "386"))
  188. (ppc (string-append "ppc" suffix)))
  189. (invoke "make" "install" "NOGDB=1"
  190. (string-append "INSTALL_PREFIX=" out))
  191. ;; Remove files that fail RUNPATH validation.
  192. ;; TODO: Fix it instead.
  193. (delete-file (string-append out "/lib/libpas2jslib.so"))
  194. ;; Add a symlink to the ppc[arch] binary so fpc works.
  195. (symlink (string-append out "/lib/fpc/" ,version "/" ppc)
  196. (string-append out "/bin/" ppc))
  197. ;; Install the example configuration file.
  198. (mkdir (string-append out "/etc"))
  199. (invoke
  200. (string-append out "/lib/fpc/" ,version "/samplecfg")
  201. (string-append out "/lib/fpc/" ,version)
  202. (string-append out "/etc")))))
  203. (add-after 'install 'wrap
  204. (lambda* (#:key inputs outputs #:allow-other-keys)
  205. (let* ((out (assoc-ref outputs "out"))
  206. (fpc (string-append out "/bin/fpc"))
  207. (ld (assoc-ref inputs "ld-wrapper"))
  208. (glibc (assoc-ref inputs "glibc")))
  209. (wrap-program fpc
  210. `("PATH" ":" prefix (,(string-append ld "/bin")))
  211. `("LIBRARY_PATH" ":" prefix (,(string-append glibc "/lib"))))
  212. #t)))))))
  213. ;; fpc invokes gcc, so make sure LIBRARY_PATH et.al are set.
  214. ;(native-search-paths (package-native-search-paths gcc))
  215. (home-page "https://www.freepascal.org")
  216. (synopsis "The Free Pascal Compiler")
  217. (description
  218. "Free Pascal is a professional Object Pascal compiler. It supports the
  219. Turbo Pascal 7.0, Delphi, and Mac Pascal dialects. Free Pascal also supports
  220. many useful extensions to the Pascal programming language.")
  221. ;; The majority of the software included is licensed under the GPLv2
  222. ;; or later. For more licensing details, see the appropriate files in
  223. ;; the install/doc directory of the source distribution.
  224. (license license:gpl2+)))
  225. (define-public p2c
  226. (package
  227. (name "p2c")
  228. (version "2.01")
  229. (source (origin
  230. (method url-fetch)
  231. (uri (string-append "https://alum.mit.edu/www/toms/p2c/p2c-"
  232. version ".tar.gz"))
  233. (sha256
  234. (base32
  235. "03x72lv6jrvikbrpz4kfq1xp61l2jw5ki6capib71lxs65zndajn"))))
  236. (build-system gnu-build-system)
  237. (arguments
  238. `(#:make-flags
  239. (let ((out (assoc-ref %outputs "out")))
  240. (list (string-append "CC=" ,(cc-for-target))
  241. (string-append "HOMEDIR=" out "/lib/p2c")
  242. (string-append "INCDIR=" out "/include/p2c")
  243. (string-append "BINDIR=" out "/bin")
  244. (string-append "LIBDIR=" out "/lib")
  245. (string-append "MANDIR=" out "/share/man/man1")
  246. "MANFILE=p2c.man.inst"))
  247. #:test-target "test"
  248. #:phases
  249. (modify-phases %standard-phases
  250. (delete 'configure)
  251. (add-before 'build 'mkdir
  252. (lambda* (#:key outputs #:allow-other-keys)
  253. (let ((out (assoc-ref outputs "out")))
  254. (mkdir-p (string-append out "/share/man"))
  255. (mkdir-p (string-append out "/lib"))
  256. (mkdir-p (string-append out "/bin"))
  257. (mkdir-p (string-append out "/include")))
  258. #t))
  259. (add-before 'build 'chdir
  260. (lambda* (#:key make-flags #:allow-other-keys)
  261. (chdir "src")
  262. #t)))))
  263. (native-inputs
  264. `(("perl" ,perl)
  265. ("which" ,which)))
  266. (synopsis "p2c converts Pascal programs to C programs--which you can then
  267. compile using gcc")
  268. (description "This package provides @command{p2c}, a program to convert
  269. Pascal source code to C source code, and @command{p2cc}, a compiler for
  270. Pascal programs.")
  271. (home-page "http://users.fred.net/tds/lab/p2c/")
  272. (license license:gpl2+)))