manifest.scm 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. (use-modules (guix gexp)
  2. ((guix licenses) #:select (bsd-3))
  3. (guix packages)
  4. (guix profiles)
  5. (gnu packages base)
  6. (gnu packages commencement)
  7. (gnu packages pkg-config)
  8. (gnu packages scheme))
  9. (define scheme48-prescheme
  10. (package
  11. (inherit scheme48)
  12. (name "scheme48-prescheme")
  13. (arguments
  14. (list #:tests? #f ; tests only cover scheme48
  15. #:modules '((guix build gnu-build-system)
  16. (guix build utils)
  17. (ice-9 popen)
  18. (srfi srfi-1))
  19. #:phases
  20. #~(modify-phases %standard-phases
  21. (add-after 'configure 'patch-prescheme-version
  22. (lambda _
  23. ;; Ensure the Pre-Scheme version matches the package version
  24. (call-with-output-file "ps-compiler/minor-version-number"
  25. (lambda (port)
  26. (let* ((version #$(package-version this-package))
  27. (vparts (string-split version #\.))
  28. (vminor (string-join (drop vparts 1) ".")))
  29. (write vminor port))))))
  30. (add-after 'configure 'patch-prescheme-headers
  31. (lambda _
  32. ;; Rename "io.h" to play nicely with others
  33. (copy-file "c/io.h" "c/prescheme-io.h")
  34. (substitute* "c/prescheme.h"
  35. (("^#include \"io\\.h\"")
  36. "#include \"prescheme-io.h\""))))
  37. (add-after 'configure 'generate-pkg-config
  38. (lambda _
  39. ;; Generate a pkg-config file
  40. (call-with-output-file "prescheme.pc"
  41. (lambda (port)
  42. (let ((s48-version #$(package-version scheme48))
  43. (version #$(package-version this-package)))
  44. (format port (string-join
  45. '("prefix=~a"
  46. "exec_prefix=${prefix}"
  47. "libdir=${prefix}/lib/scheme48-~a"
  48. "includedir=${prefix}/include"
  49. ""
  50. "Name: Pre-Scheme (Scheme 48)"
  51. "Description: Pre-Scheme C runtime"
  52. "Version: ~a"
  53. "Libs: -L${libdir} -lprescheme"
  54. "Cflags: -I${includedir}")
  55. "\n" 'suffix)
  56. #$output s48-version version))))))
  57. (add-after 'configure 'generate-prescheme-wrapper
  58. (lambda _
  59. ;; Generate a wrapper to load and run ps-compiler.image
  60. (call-with-output-file "prescheme"
  61. (lambda (port)
  62. (let ((s48-version #$(package-version scheme48)))
  63. (format port (string-join
  64. '("#!/bin/sh"
  65. "scheme48=~a/lib/scheme48-~a"
  66. "prescheme=~a/lib/scheme48-~a"
  67. "exec ${scheme48}/scheme48vm -i ${prescheme}/prescheme.image \"$@\"")
  68. "\n" 'suffix)
  69. #$scheme48 s48-version #$output s48-version))))
  70. (chmod "prescheme" #o755)))
  71. (replace 'build
  72. (lambda _
  73. ;; Build libscheme48.a and rename it to libprescheme.a
  74. ;; TODO: trim this down to only prescheme-related objs
  75. (invoke "make" "c/libscheme48.a")
  76. (rename-file "c/libscheme48.a" "c/libprescheme.a")
  77. ;; Dump a Scheme 48 image with both the Pre-Scheme compatibility
  78. ;; library and compiler pre-loaded, courtesy of Taylor Campbell's
  79. ;; Pre-Scheme Manual:
  80. ;; https://groups.scheme.org/prescheme/1.3/#Invoking-the-Pre_002dScheme-compiler
  81. (with-directory-excursion "ps-compiler"
  82. (let ((version #$(package-version this-package))
  83. (port (open-pipe* OPEN_WRITE "scheme48")))
  84. (format port (string-join
  85. '(",batch"
  86. ",config ,load ../scheme/prescheme/interface.scm"
  87. ",config ,load ../scheme/prescheme/package-defs.scm"
  88. ",exec ,load load-ps-compiler.scm"
  89. ",in prescheme-compiler prescheme-compiler"
  90. ",user (define prescheme-compiler ##)"
  91. ",dump ../prescheme.image \"(Pre-Scheme ~a)\""
  92. ",exit")
  93. "\n" 'suffix)
  94. version)
  95. (close-pipe port)))))
  96. (replace 'install
  97. (lambda _
  98. (let* ((s48-version #$(package-version scheme48))
  99. (bin-dir (string-append #$output "/bin"))
  100. (lib-dir (string-append #$output "/lib/scheme48-" s48-version))
  101. (pkgconf-dir (string-append #$output "/lib/pkgconfig"))
  102. (share-dir (string-append #$output "/share/scheme48-" s48-version))
  103. (include-dir (string-append #$output "/include")))
  104. ;; Install Pre-Scheme compiler image
  105. (install-file "prescheme" bin-dir)
  106. (install-file "prescheme.image" lib-dir)
  107. ;; Install Pre-Scheme config, headers, and lib
  108. (install-file "prescheme.pc" pkgconf-dir)
  109. (install-file "c/prescheme.h" include-dir)
  110. (install-file "c/prescheme-io.h" include-dir)
  111. (install-file "c/libprescheme.a" lib-dir)
  112. ;; Install Pre-Scheme sources
  113. (copy-recursively "scheme/prescheme" (string-append share-dir "/prescheme"))
  114. (copy-recursively "ps-compiler" (string-append share-dir "/ps-compiler"))
  115. ;; Remove files specific to building the Scheme 48 VM
  116. (for-each (lambda (file)
  117. (delete-file (string-append share-dir "/" file)))
  118. '("ps-compiler/compile-bibop-gc-32.scm"
  119. "ps-compiler/compile-bibop-gc-64.scm"
  120. "ps-compiler/compile-gc.scm"
  121. "ps-compiler/compile-twospace-gc-32.scm"
  122. "ps-compiler/compile-twospace-gc-64.scm"
  123. "ps-compiler/compile-vm-no-gc-32.scm"
  124. "ps-compiler/compile-vm-no-gc-64.scm"))))))))
  125. (propagated-inputs (list scheme48))
  126. (home-page "http://s48.org/")
  127. (synopsis "Pre-Scheme compiler from Scheme 48")
  128. (description
  129. "Pre-Scheme is a statically compilable dialect of Scheme, used to implement the
  130. Scheme 48 virtual machine. Scheme 48 ships with a Pre-Scheme to C compiler written
  131. in Scheme, and a runtime library which allows Pre-Scheme code to run as Scheme.")
  132. (license bsd-3)))
  133. (packages->manifest
  134. (list scheme48-prescheme
  135. gcc-toolchain
  136. gnu-make
  137. pkg-config))