summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 2d6d5b24f66c1d09e55112a00a8e859737194d32 (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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# Maintainer: Pavel Dobiáš <git at paveldobias dot eu>

pkgname=floating-sandbox
pkgver=1.21.0
pkgrel=1
pkgdesc="Mass-spring network in C++, simulating physical bodies floating in water and sinking"
arch=('x86_64')
url="https://github.com/GabrieleGiuseppini/Floating-Sandbox"
license=('CC-BY-4.0')

install=$pkgname.install

depends=(
    'gtk3'
    'libx11'
    'openal'
    'libvorbis'
    'libsm'
    'flac'
    'libpng'
    'libnotify'
    'libjpeg-turbo'
)

makedepends=(
    'cmake'
    'git'
    'make'
    'gcc'
)

source=(
    "floating-sandbox.sh"
    "floating-sandbox.desktop"
    "custom-ships-dir.patch"
    "${pkgname}-${pkgver}.tar.gz::${url}/archive/refs/tags/v${pkgver}.tar.gz"
    "git+https://github.com/wxWidgets/wxWidgets.git#tag=v3.1.4"
    "git+https://github.com/google/googletest.git#tag=v1.12.0"
    "git+https://github.com/kazuho/picojson.git#tag=v1.3.0"
    "git+https://github.com/SFML/SFML.git#tag=2.6.2"
)

sha256sums=(
    'aa3800b629de788d5df30777d41a16ce3f46b218c8252086722dfa849a43a597'
    '15cc756fd0abb38d62058744422e60fce08d02377f34394d814ec72f08c8fbcb'
    '7f2d22ac951fd72fd6dbfd5ffad94abf32db82e4e4d907dbd1af7380ac06a657'
    '8dd20c9553f09df9ac283db1ba51f99a62f585dce47007f4517e523dffbefd28'
    'SKIP'
    'SKIP'
    'SKIP'
    'SKIP'
)

prepare() {
    mkdir -p "${srcdir}/libs"

    cd "${srcdir}/wxWidgets"
    git submodule update --init --recursive

    cd "${srcdir}/Floating-Sandbox-${pkgver}"
    # Patches support for custom ships directory using env var
    patch -Np1 -i "${srcdir}/custom-ships-dir.patch"

    # Create custom UserSettings.cmake to setup correct build environment
    cat <<EOF >UserSettings.cmake
set(FS_USE_STATIC_LIBS ON)

set(SDK_ROOT "${srcdir}/libs")
set(REPOS_ROOT "${srcdir}")

set(BENCHMARK_ROOT_DIR "\${SDK_ROOT}/benchmark")
set(wxWidgets_ROOT "\${SDK_ROOT}/wxWidgets")
set(wxWidgets_CONFIG_EXECUTABLE "\${SDK_ROOT}/wxWidgets/bin/wx-config")
set(SFML_ROOT "\${SDK_ROOT}/sfml")
set(SFML_STATIC_LIBRARIES ON)
set(GTEST_DIR "\${REPOS_ROOT}/googletest")
set(PICOJSON_DIR "\${REPOS_ROOT}/picojson")

# Fix SFML 2.6 static target naming issue for OpenAL
find_package(OpenAL REQUIRED)
if(TARGET OpenAL::OpenAL AND NOT TARGET OpenAL)
    add_library(OpenAL UNKNOWN IMPORTED)
    if(OPENAL_LIBRARY)
        set_target_properties(OpenAL PROPERTIES IMPORTED_LOCATION "\${OPENAL_LIBRARY}")
    endif()
    if(OPENAL_INCLUDE_DIR)
        set_target_properties(OpenAL PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "\${OPENAL_INCLUDE_DIR}")
    endif()
endif()

# Define macro that creates post-install actions
macro(DefineUserPostInstall)
endmacro()
EOF
}

build() {
    export LC_ALL=C.UTF-8

    export CFLAGS="${CFLAGS} -ffile-prefix-map=${srcdir}=."
    export CXXFLAGS="${CXXFLAGS} -ffile-prefix-map=${srcdir}=."

    msg2 "Building static wxWidgets..."
    cd "${srcdir}/wxWidgets"
    mkdir -p wx_build
    cd wx_build
    ../configure \
        --disable-shared \
        --with-gtk=3 \
        --with-libpng \
        --with-libxpm \
        --with-libjpeg \
        --without-libtiff \
        --without-expat \
        --disable-pnm \
        --disable-gif \
        --disable-pcx \
        --disable-iff \
        --with-opengl \
        --prefix="${srcdir}/libs/wxWidgets" \
        --exec_prefix="${srcdir}/libs/wxWidgets" \
        --disable-tests \
        --disable-rpath

    make install -j$(nproc)

    msg2 "Building static SFML..."
    cmake -B "${srcdir}/libs/sfml" -S "${srcdir}/SFML" \
        -DCMAKE_BUILD_TYPE=Release \
        -DBUILD_SHARED_LIBS=OFF \
        -DSFML_BUILD_EXAMPLES=OFF \
        -DSFML_BUILD_DOC=OFF
    cmake --build "${srcdir}/libs/sfml" -j$(nproc)

    msg2 "Building Floating Sandbox..."
    cd "${srcdir}/Floating-Sandbox-${pkgver}"

    cmake -B build -S . \
        -DCMAKE_BUILD_TYPE=Release \
        -DFS_BUILD_BENCHMARKS=OFF \
        -DFS_USE_STATIC_LIBS=ON \
        -DSFML_ROOT="${srcdir}/libs/sfml" \
        -DSFML_DIR="${srcdir}/libs/sfml" \
        -DSFML_STATIC_LIBRARIES=ON \
        -DwxWidgets_USE_DEBUG=OFF \
        -DwxWidgets_USE_UNICODE=ON \
        -DFS_INSTALL_DIRECTORY="${pkgdir}/opt/floating-sandbox"

    cmake --build build -j$(nproc)
}

package() {
    # Directories
    install -dm755 "${pkgdir}/opt"
    install -dm755 "${pkgdir}/usr/bin"
    install -dm755 "${pkgdir}/usr/share/applications"
    install -dm755 "${pkgdir}/usr/share/pixmaps"

    # Install the game
    cd "${srcdir}/Floating-Sandbox-${pkgver}"
    cmake --install build

    # Prevents a crash when loading ships from these directories
    chmod 1777 "${pkgdir}/opt/floating-sandbox/Ships"
    chmod 1777 "${pkgdir}/opt/floating-sandbox/Data/Built-in Ships"

    # Symlink regional English variants to 'en' only if they don't already exist, prevents language default to be broken
    local lang_dir="${pkgdir}/opt/floating-sandbox/Data/Languages"
    if [ -d "${lang_dir}/en" ]; then
        for lang in en_GB en_US en_AU en_CA; do
            if [ ! -e "${lang_dir}/${lang}" ]; then
                ln -s "en" "${lang_dir}/${lang}"
            fi
        done
    fi

    # Launcher script
    install -m755 "$srcdir/floating-sandbox.sh" \
        "$pkgdir/usr/bin/floating-sandbox"

    # Desktop integration
    install -m644 "${srcdir}/floating-sandbox.desktop" \
        "${pkgdir}/usr/share/applications/floating-sandbox.desktop"

    install -m644 "${pkgdir}/opt/floating-sandbox/Data/Built-in Ships/fs_logo_texture.png.dat" \
        "${pkgdir}/usr/share/pixmaps/floating-sandbox.png"
}