root/rpcs3.scm

(define-module (hidamari-blue rpcs3)
  #:use-module (guix packages)
  #:use-module (guix utils)
  #:use-module (guix download)
  #:use-module (guix git-download)
  #:use-module (guix build-system gnu)
  #:use-module (guix build-system cmake)
  #:use-module ((guix licenses) #:renamer (symbol-prefix-proc 'license:))
  #:use-module (gnu packages)
  #:use-module (gnu packages pkg-config)
  #:use-module (gnu packages ncurses)
  #:use-module (gnu packages base)
  #:use-module (gnu packages sdl)
  #:use-module (gnu packages gl)
  #:use-module (gnu packages bison)
  #:use-module (gnu packages flex)
  #:use-module (gnu packages databases)
  #:use-module (gnu packages compression)
  #:use-module (gnu packages fontutils)
  #:use-module (gnu packages fonts)
  #:use-module (gnu packages image)
  #:use-module (gnu packages games)
  #:use-module (gnu packages audio)
  #:use-module (gnu packages video)
  #:use-module (gnu packages mp3)
  #:use-module (gnu packages xiph)
  #:use-module (gnu packages gtk)
  #:use-module (gnu packages qt)
  #:use-module (gnu packages xorg)
  #:use-module (gnu packages xml)
  #:use-module (gnu packages llvm)
  #:use-module (gnu packages boost)
  #:use-module (gnu packages version-control)
  #:use-module (gnu packages serialization)
  #:use-module (gnu packages autotools)
  #:use-module (gnu packages linux)
  #:use-module (gnu packages libusb)
  #:use-module (gnu packages perl))

;;; status: - compiles, but linking of unbundled libraries fails
;;;         - most libraries should be unbundled
;;;         - the original repo uses git submodules of projects that don't have proper releases
;;;           or are fixed to old versions (guidelines-support-library).
;;;           Some of the linked versions might be wrong and incompatible with the rpcs3 release.
;;;         - All of the metadata field should be filled out
;;;         - llvm 4 should be packaged since building without llvm is not recommended.

(define-public asmjit
  (let ((commit "673dcefaa048c5f5a2bf8b85daf8f7b9978d018a"))
    (package
     (name "asmjit")
     (version commit)
     (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/asmjit/asmjit")
                    (commit commit)))
              (sha256 (base32 "1r0xivh7sc5xfyf5zzymik8vpy2ni6zd5yrw2083ddfyp94vdrf1"))))
     (arguments '(;; too lazy to package them
                  #:tests?
                  #f
                  #:configure-flags (list "-DASMJIT_BUILD_TEST=FALSE")))
     (build-system cmake-build-system)
     (description "")
     (synopsis "")
     (home-page "")
     (license license:zlib))))

(define-public guidelines-support-library      ;gsl
  ;; outdated commit required where the header is still named gsl.h
  ;; in the latest version it's just #include <gsl>
  (let ((commit "fc5fce4f4f8d64fbda523d1b0d55115f5ca68774"))
    (package
     ;; Not to be confused with gnu-scientific-library
     ;; this one even is by microsoft
     (name "guidelines-support-library")
     (version commit)
     (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/Microsoft/GSL")
                    (commit commit)))
              (sha256 (base32 "0c5wh5n1cl16firw5s8rf9mzyzxcpbpq4na48dkiidwffx8c2rba"))))

     (arguments '(#:phases
                  (modify-phases %standard-phases
                                 (delete 'check)
                                 (add-after 'unpack 'remove-tests
                                            (lambda _
                                              ;; needs further local git cloning
                                              ;; unconvinient to package and I'm too lazy rn
                                              (substitute* "CMakeLists.txt"
                                                           (("enable_testing\\(\\)")
                                                            ""))
                                              (substitute* "CMakeLists.txt"
                                                           (("add_subdirectory\\(tests\\)")
                                                            ""))))
                                 (replace 'install
                                          (lambda* (#:key outputs #:allow-other-keys)
                                            (let ((out (assoc-ref outputs "out")))
                                              (mkdir-p (string-append out "/include"))
                                              ;; (mkdir-p (string-append out "/lib"))
                                              (copy-recursively "../source/include"
                                                                (string-append out "/include"))
                                              ;; (copy-recursively "lib"
                                              ;;                   (string-append out "/lib"))
                                              ))))))
     (build-system cmake-build-system)
     (description "")
     (synopsis "")
     (home-page "")
     (license license:expat))))

(define-public hidapi
  (let ((commit "ca39ce8939e490ffcadb38ff978447aac1c17662"))
    (package
     (name "hidapi")
     (version commit)
     (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/RPCS3/hidapi")
                    (commit commit)))
              (sha256 (base32 "0qr3chakvbxgph1v87m7qvd02lsl541fpymvz9l7m7xiyb0ch9kl"))))
     (arguments '(;; too lazy to package them
                  #:tests?
                  #f
                  #:phases (modify-phases %standard-phases
                                          (add-before 'configure 'bootstrap
                                                      (lambda _
                                                        (zero? (system* "./bootstrap")))))))
     (build-system gnu-build-system)
     (inputs `(("eudev" ,eudev)
               ("libusb" ,libusb)))
     (native-inputs `(("autoconf" ,autoconf)
                      ("automake" ,automake)
                      ("libtool" ,libtool)
                      ("pkg-config" ,pkg-config)))
     (description "")
     (synopsis "")
     (home-page "")
     (license (list license:gpl3+
                    ;; also possible to be used under bsd license
                    ;; probably for compatability with rpcs3 which is gpl2
                    )))))

(define-public optional-cpp
  (let ((commit "f27e79084a9176672ed1eae50b3397fa8035d50d"))
    (package
     (name "optional-cpp")
     (version commit)
     (source (origin
              (method git-fetch)
              (uri (git-reference
                    (url "https://github.com/akrzemi1/Optional")
                    (commit commit)))
              (sha256 (base32 "0wf57ns22qmdsxgv4w60pjm1ap42p7l3q20rw61ghdy47l738f8j"))))
     (build-system cmake-build-system)
     (description "")
     (synopsis "")
     (home-page "")
     (license license:zlib))))

(define-public rpcs3
  (package
   (name "rpcs3")
   (version "0.0.4")
   (source
    (origin
     (method url-fetch)
     (uri (string-append "https://github.com/RPCS3/rpcs3/archive/v"
                         version ".tar.gz"))
     (sha256 (base32 "0qqp8fpymyzhdqaji57xh0xxwhp899h2n1a045cggdcxr523dlzs"))))
   (build-system cmake-build-system)
   (arguments
    `(#:tests?
      #f
      #:configure-flags
      (list "-DUSE_SYSTEM_LIBPNG=ON"
            "-DUSE_SYSTEM_FFMPEG=ON"
            "-DWITHOUT_LLVM=ON"         ;TODO package llvm4
            ;; "-DUSE_VULKAN=OFF"
            )
      #:phases
      (modify-phases %standard-phases
                     (add-after 'unpack 'remove-3rd-party
                                (lambda _
                                  ;; don't build bundled hidapi
                                  (substitute* "CMakeLists.txt"
                                               (("include_directories\\(3rdparty/hidapi/hidapi\\)")
                                                ""))
                                  (substitute* "CMakeLists.txt"
                                               (("add_subdirectory\\(3rdparty/hidapi/linux\\)")
                                                ""))

                                  ;; lazy as insert of some define we need
                                  (substitute* "rpcs3/CMakeLists.txt"
                                               (("add_definitions\\(-DGLX_GLXEXT_PROTOTYPES\\)")

                                                "add_definitions(-DGLX_GLXEXT_PROTOTYPES)
add_definitions(-DPUGIXML_SOURCE=1)"))

                                  ;; use system asmjit
                                  (substitute* "rpcs3/CMakeLists.txt"
                                               (("\\$\\{RPCS3_SRC_DIR\\}/\\.\\./asmjit/src/asmjit")
                                                (string-append (assoc-ref %build-inputs "asmjit") "/include/asmjit")))
                                  ;; don't compile bundled asmjit
                                  (substitute* "rpcs3/CMakeLists.txt"
                                               (("\\\"\\$\\{RPCS3_SRC_DIR\\}/\\.\\./asmjit/src/asmjit/\\*\\.cpp\\\"")
                                                ""))
                                  ;; use system optional-cpp
                                  (substitute* "rpcs3/CMakeLists.txt"
                                               (("\\$\\{RPCS3_SRC_DIR\\}/\\.\\./3rdparty/Optional")
                                                (string-append (assoc-ref %build-inputs "optional-cpp") "/include/akrzemi1")))
                                  ;; use system hidapi
                                  (substitute* "rpcs3/CMakeLists.txt"
                                               (("\\$\\{RPCS3_SRC_DIR\\}/\\.\\./3rdparty/hidapi/hidapi")
                                                (string-append (assoc-ref %build-inputs "hidapi") "/include/hidapi")))

                                  ;; lazy ass insert of unbundled libraries link instructions
                                  (substitute* "rpcs3/CMakeLists.txt"
                                               (("target_link_libraries\\(rpcs3 libavformat\\.so libavcodec\\.so libavutil\\.so libswscale\\.so\\)")
                                                "
target_link_libraries(rpcs3 libasmjit.so libyaml-cpp.so libpugixml.a)
target_link_libraries(rpcs3 libavformat.so libavcodec.so libavutil.so libswscale.so)"))

                                  #t)))))
   (inputs `(("asmjit" ,asmjit)
             ("boost" ,boost)
             ("cereal" ,cereal)
             ("eudev" ,eudev)
             ("ffmpeg" ,ffmpeg)
             ("glew" ,glew)
             ("guidelines-support-library" ,guidelines-support-library)
             ("hidapi" ,hidapi)
             ;; ("llvm" ,llvm) ; upgrade to llvm-4
             ("libpng" ,libpng)
             ("libusb" ,libusb)
             ("libvorbis" ,libvorbis)
             ("mesa" ,mesa)
             ("openal" ,openal)
             ("optional-cpp" ,optional-cpp)
             ("pugixml" ,pugixml)
             ("qt" ,qt)
             ("yaml-cpp" ,yaml-cpp)
             ("zlib" ,zlib)))
   (native-inputs `(("pkg-config" ,pkg-config)))
   (synopsis "")
   (description "")
   (home-page "")
   (license license:gpl2+)))