summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: df9bf35ada3bac2d649ed20bb0038679676d0d88 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
# Maintainer: Amro Emad <korialo001 at gmail dot com>

pkgbase=seanime-git
pkgname=('seanime-server-git' 'seanime-denshi-git')
_pkgname=seanime
_electronver=42
pkgver=v3.10.3.r0.g2da73d9
pkgrel=1
pkgdesc="Open-source media server with a web interface and desktop app for anime and manga."
arch=('x86_64' 'aarch64')
options=('!debug')
url="https://seanime.app"
license=('GPL-3.0-only')
depends=(
    'glibc'
    'libgcc'
    'libstdc++')
makedepends=(
    'git'
    'make'
    'npm'
    'go>=1.27.1'
    "electron$_electronver")
source=(
    "git+https://github.com/5rahim/seanime.git"
    "app.seanime.seanime_denshi.desktop"
    "seanime-denshi.sh.in")
sha256sums=(
    'SKIP'
    'a95400bc0f4cc9a8fb15feb243ed2a05a5b1d93aa3e0522bd2bac1095b821d1e'
    '7f36f983c1313bba1b5d718865fe6115764429ffad3886a6863ec309f78cbb0c')

pkgver() {
    cd "${_pkgname}"
    # Cutting off 'foo-' prefix that presents in the git tag
    git describe --long --tags --abbrev=7 | sed 's/^foo-//;s/\([^-]*-g\)/r\1/;s/-/./g'
}

prepare() {
    
    # Add the electron version for denshi
    
    sed "s/@ELECTRON@/electron$_electronver/" ${_pkgname}-denshi.sh.in > ${_pkgname}-denshi.sh
}

build() {
    
    cd "${_pkgname}/seanime-web"

    # Mirror the workflow, build order webapp > server > denshi, start with webapp below

    npm ci
    make build-all

    # Prepare for the server binary (go)

    cd "${srcdir}/${_pkgname}"

    mkdir -p binaries

    # Server: We can build for both (x64/arm64 or aarch64) try to conform with upstream

    if [ "$CARCH" = aarch64 ]; then
    export GOARCH=arm64
    export _Arch=${GOARCH}
    else
    export GOARCH=amd64
    export _Arch=x64
    fi

    # https://wiki.archlinux.org/title/Go_package_guidelines#Flags_and_build_options
    # (cgo) is required for linking and its enabled by default, let's be verbose
    # TODO: debug symbols for GO

    # Fail if we have to downlaod (go) compiler from the internet
    export GOTOOLCHAIN=path
    export CGO_CPPFLAGS="${CPPFLAGS}"
    export CGO_CFLAGS="${CFLAGS}"
    export CGO_CXXFLAGS="${CXXFLAGS}"
    go build \
    -trimpath \
    -buildmode=pie \
    -mod=readonly \
    -modcacherw \
    -ldflags "-linkmode external -extldflags \"${LDFLAGS}\"" \
    -o ./binaries/seanime-server-linux-${GOARCH} \
    .	
    
    # Denshi app

    cd "seanime-denshi/"
    
    # Prepare for the binary

    mkdir -p binaries

    cp "${srcdir}/${_pkgname}/binaries/seanime-server-linux-${GOARCH}" ./binaries/

    # Prepare for system electron to be used after build

    electronDist=/usr/lib/electron$_electronver
    electronVer=$(electron$_electronver --version | tail -c +2)

    export ELECTRON_SKIP_BINARY_DOWNLOAD=1
    npm ci
    npm run build:main
    npm run sync:mpv-prism -- linux-${_Arch}
    npm exec -- electron-builder build --linux --${_Arch} --dir -c.electronDist=$electronDist -c.electronVersion=$electronVer
}

package_seanime-server-git() {

    install -Dm644 "${_pkgname}/LICENSE" -t "${pkgdir}/usr/share/licenses/${_pkgname}-server"
    install -Dm644 "${_pkgname}/"*.md -t "${pkgdir}/usr/share/doc/${_pkgname}-server"  

    cd "${_pkgname}"
    
    install -Dm755 "binaries/seanime-server-linux-${GOARCH}" "${pkgdir}/usr/bin/${_pkgname}-server"
}

package_seanime-denshi-git() {
    depends=(
	'gtk3'
        'hicolor-icon-theme' 
        "electron$_electronver")

    # TODO: debug symbols nag from mpv-prism

    install -Dm644 "app.seanime.seanime_denshi.desktop" -t "${pkgdir}/usr/share/applications"
    install -Dm755 "seanime-denshi.sh" "${pkgdir}/usr/bin/${_pkgname}-denshi"
    install -Dm644 "${_pkgname}/LICENSE" -t "${pkgdir}/usr/share/licenses/${_pkgname}-denshi"
    install -Dm644 "${_pkgname}/"*.md -t "${pkgdir}/usr/share/doc/${_pkgname}-denshi"

    cd "${_pkgname}/seanime-denshi"

    install -Dm644 "dist/linux-unpacked/resources/app.asar" -t "${pkgdir}/usr/lib/${_pkgname}-denshi"
    install -Dm755 "dist/linux-unpacked/resources/binaries/seanime-server-linux-${GOARCH}" -t "${pkgdir}/usr/lib/electron$_electronver/resources/binaries"
    cp -r "dist/linux-unpacked/resources/native-builds" "${pkgdir}/usr/lib/electron$_electronver/resources/"

    for icon in $(find assets -regex '.*/[0-9]+x[0-9]+\.png' | sort -n); do
    size=$(basename -s .png "$icon")
    install -Dm644 "assets/$size.png" "${pkgdir}/usr/share/icons/hicolor/${size}/apps/${_pkgname}-denshi.png"
    done
}