Skip to content

Commit ae32abf

Browse files
gunnarbeutnerlinusg
authored andcommitted
Ports: Add openttd
1 parent 4b33365 commit ae32abf

File tree

8 files changed

+244
-0
lines changed

8 files changed

+244
-0
lines changed

Ports/AvailablePorts.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ Please make sure to keep this list up to date when adding and updating ports. :^
8181
| [`nyancat`](nyancat/) | Nyancat | | https://github.com/klange/nyancat |
8282
| [`openssh`](openssh/) | OpenSSH | 8.3-9ca7e9c | https://github.com/openssh/openssh-portable |
8383
| [`openssl`](openssl/) | OpenSSL | 1.0.2t | https://www.openssl.org/ |
84+
| [`openttd`](openttd/) | OpenTTD | 1.11.0 | https://www.openttd.org/ |
85+
| [`openttd-opengfx`](openttd-opengfx/) | OpenGFX graphics for OpenTTD | 0.6.1 | https://www.openttd.org/ |
86+
| [`openttd-opensfx`](openttd-opensfx/) | OpenSFX audio files for OpenTTD | 1.0.1 | https://www.openttd.org/ |
8487
| [`oksh`](oksh/) | oksh | 6.8.1 | https://github.com/ibara/oksh |
8588
| [`patch`](patch/) | patch (OpenBSD) | 6.6 | https://github.com/ibara/libpuffy |
8689
| [`pcre`](pcre/) | Perl-compatible Regular Expressions (PCRE) | 8.44 | https://www.pcre.org/ |

Ports/openttd-opengfx/package.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env -S bash ../.port_include.sh
2+
port=openttd-opengfx
3+
version=0.6.1
4+
workdir=.
5+
files="https://cdn.openttd.org/opengfx-releases/${version}/opengfx-${version}-all.zip opengfx-${version}-all.zip c694a112cd508d9c8fdad1b92bde05e7c48b14d66bad0c3999e443367437e37e"
6+
auth_type=sha256
7+
8+
build() {
9+
# The ZIP file we downloaded contains a tarball.
10+
run_nocd tar xf opengfx-${version}.tar
11+
}
12+
13+
install() {
14+
run_nocd mkdir -p ${SERENITY_INSTALL_ROOT}/usr/local/share/games/openttd/baseset/
15+
run_nocd cp -a opengfx-${version}/* ${SERENITY_INSTALL_ROOT}/usr/local/share/games/openttd/baseset/
16+
}

Ports/openttd-opensfx/package.sh

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env -S bash ../.port_include.sh
2+
port=openttd-opensfx
3+
version=1.0.1
4+
workdir=.
5+
files="https://cdn.openttd.org/opensfx-releases/${version}/opensfx-${version}-all.zip opensfx-${version}-all.zip 37b825426f1d690960313414423342733520d08916f512f30f7aaf30910a36c5"
6+
auth_type=sha256
7+
8+
build() {
9+
# The ZIP file we downloaded contains a tarball.
10+
run_nocd tar xf opensfx-${version}.tar
11+
}
12+
13+
install() {
14+
run_nocd mkdir -p ${SERENITY_INSTALL_ROOT}/usr/local/share/games/openttd/baseset/
15+
run_nocd cp -a opensfx-${version}/* ${SERENITY_INSTALL_ROOT}/usr/local/share/games/openttd/baseset/
16+
}

Ports/openttd/package.sh

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
#!/usr/bin/env -S bash ../.port_include.sh
2+
port=openttd
3+
version=1.11.0
4+
auth_type=sha256
5+
depends="SDL2 libpng zlib xz"
6+
files="https://cdn.openttd.org/openttd-releases/${version}/openttd-${version}-source.tar.xz openttd-${version}.tar.xz 5e65184e07368ba1afa62dbb3e35abaee6c4da6730ff4bc9eb4447d53363c7a8"
7+
useconfigure=true
8+
configopts="-DCMAKE_TOOLCHAIN_FILE=$SERENITY_ROOT/Toolchain/CMake/CMakeToolchain.txt"
9+
10+
configure() {
11+
host_env
12+
mkdir -p $workdir/host-build
13+
(
14+
cd $workdir/host-build
15+
cmake .. -DOPTION_TOOLS_ONLY=1
16+
)
17+
18+
target_env
19+
mkdir -p $workdir/build
20+
(
21+
cd $workdir/build
22+
cmake .. $configopts -DHOST_BINARY_DIR=$(pwd)/../host-build
23+
)
24+
}
25+
26+
build() {
27+
host_env
28+
(
29+
cd $workdir/host-build
30+
make $makeopts
31+
)
32+
33+
target_env
34+
(
35+
cd $workdir/build
36+
make $makeopts
37+
)
38+
}
39+
40+
install() {
41+
(
42+
cd $workdir/build
43+
make install
44+
)
45+
46+
ln -sf /usr/local/games/openttd $DESTDIR/usr/local/bin/openttd
47+
}
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
diff -Naur openttd-1.11.0/cmake/CompileFlags.cmake openttd-1.11.0.serenity/cmake/CompileFlags.cmake
2+
--- openttd-1.11.0/cmake/CompileFlags.cmake 2021-04-01 14:33:44.000000000 +0200
3+
+++ openttd-1.11.0.serenity/cmake/CompileFlags.cmake 2021-04-19 19:30:33.457232215 +0200
4+
@@ -154,7 +154,7 @@
5+
message(FATAL_ERROR "No warning flags are set for this compiler yet; please consider creating a Pull Request to add support for this compiler.")
6+
endif()
7+
8+
- if(NOT WIN32)
9+
+ if(NOT WIN32 AND NOT SERENITYOS)
10+
# rdynamic is used to get useful stack traces from crash reports.
11+
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -rdynamic")
12+
endif()
13+
diff -Naur openttd-1.11.0/src/network/core/address.cpp openttd-1.11.0.serenity/src/network/core/address.cpp
14+
--- openttd-1.11.0/src/network/core/address.cpp 2021-04-01 14:33:44.000000000 +0200
15+
+++ openttd-1.11.0.serenity/src/network/core/address.cpp 2021-04-19 19:30:33.457232215 +0200
16+
@@ -372,7 +372,7 @@
17+
DEBUG(net, 3, "[%s] could not set reusable %s sockets for port %s: %s", type, family, address, strerror(errno));
18+
}
19+
20+
-#ifndef __OS2__
21+
+#if !defined(__OS2__) && !defined(__serenity__)
22+
if (runp->ai_family == AF_INET6 &&
23+
setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&on, sizeof(on)) == -1) {
24+
DEBUG(net, 3, "[%s] could not disable IPv4 over IPv6 on port %s: %s", type, address, strerror(errno));
25+
diff -Naur openttd-1.11.0/src/network/core/host.cpp openttd-1.11.0.serenity/src/network/core/host.cpp
26+
--- openttd-1.11.0/src/network/core/host.cpp 2021-04-01 14:33:44.000000000 +0200
27+
+++ openttd-1.11.0.serenity/src/network/core/host.cpp 2021-04-19 19:30:33.457232215 +0200
28+
@@ -147,6 +147,7 @@
29+
30+
static void NetworkFindBroadcastIPsInternal(NetworkAddressList *broadcast) // !GETIFADDRS implementation
31+
{
32+
+#ifndef __serenity__
33+
SOCKET sock = socket(AF_INET, SOCK_DGRAM, 0);
34+
if (sock == INVALID_SOCKET) return;
35+
36+
@@ -183,6 +184,7 @@
37+
}
38+
39+
closesocket(sock);
40+
+#endif
41+
}
42+
#endif /* all NetworkFindBroadcastIPsInternals */
43+
44+
diff -Naur openttd-1.11.0/src/network/core/os_abstraction.h openttd-1.11.0.serenity/src/network/core/os_abstraction.h
45+
--- openttd-1.11.0/src/network/core/os_abstraction.h 2021-04-01 14:33:44.000000000 +0200
46+
+++ openttd-1.11.0.serenity/src/network/core/os_abstraction.h 2021-04-19 19:30:33.457232215 +0200
47+
@@ -59,13 +59,14 @@
48+
# include <unistd.h>
49+
# include <sys/ioctl.h>
50+
# include <sys/socket.h>
51+
+# include <sys/select.h>
52+
# include <netinet/in.h>
53+
# include <netinet/tcp.h>
54+
# include <arpa/inet.h>
55+
# include <net/if.h>
56+
/* According to glibc/NEWS, <ifaddrs.h> appeared in glibc-2.3. */
57+
# if !defined(__sgi__) && !defined(SUNOS) && !defined(__INNOTEK_LIBC__) \
58+
- && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX)
59+
+ && !(defined(__GLIBC__) && (__GLIBC__ <= 2) && (__GLIBC_MINOR__ <= 2)) && !defined(__dietlibc__) && !defined(HPUX) && !defined(__serenity__)
60+
/* If for any reason ifaddrs.h does not exist on your system, comment out
61+
* the following two lines and an alternative way will be used to fetch
62+
* the list of IPs from the system. */
63+
diff -Naur openttd-1.11.0/src/os/unix/unix.cpp openttd-1.11.0.serenity/src/os/unix/unix.cpp
64+
--- openttd-1.11.0/src/os/unix/unix.cpp 2021-04-01 14:33:44.000000000 +0200
65+
+++ openttd-1.11.0.serenity/src/os/unix/unix.cpp 2021-04-19 19:30:33.457232215 +0200
66+
@@ -42,9 +42,11 @@
67+
# define HAS_SYSCTL
68+
#endif
69+
70+
+#ifndef __serenity__
71+
#ifdef HAS_STATVFS
72+
#include <sys/statvfs.h>
73+
#endif
74+
+#endif
75+
76+
#ifdef HAS_SYSCTL
77+
#include <sys/sysctl.h>
78+
@@ -84,7 +86,7 @@
79+
80+
if (statfs(path, &s) != 0) return false;
81+
free = (uint64)s.f_bsize * s.f_bavail;
82+
-#elif defined(HAS_STATVFS)
83+
+#elif defined(HAS_STATVFS) && !defined(__serenity__)
84+
struct statvfs s;
85+
86+
if (statvfs(path, &s) != 0) return false;
87+
diff -Naur openttd-1.11.0/src/stdafx.h openttd-1.11.0.serenity/src/stdafx.h
88+
--- openttd-1.11.0/src/stdafx.h 2021-04-01 14:33:44.000000000 +0200
89+
+++ openttd-1.11.0.serenity/src/stdafx.h 2021-04-19 20:08:30.758187723 +0200
90+
@@ -28,7 +28,7 @@
91+
# define TROUBLED_INTS
92+
#endif
93+
94+
-#if defined(__HAIKU__) || defined(__CYGWIN__)
95+
+#if defined(__HAIKU__) || defined(__CYGWIN__) || defined(__serenity__)
96+
# include <strings.h> /* strncasecmp */
97+
#endif
98+
99+
@@ -107,7 +107,7 @@
100+
# define strcasecmp stricmp
101+
#endif
102+
103+
-#if defined(SUNOS) || defined(HPUX) || defined(__CYGWIN__)
104+
+#if defined(SUNOS) || defined(HPUX) || defined(__CYGWIN__) || defined(__serenity__)
105+
# include <alloca.h>
106+
#endif
107+
108+
@@ -307,7 +307,7 @@
109+
typedef unsigned char byte;
110+
111+
/* This is already defined in unix, but not in QNX Neutrino (6.x) or Cygwin. */
112+
-#if (!defined(UNIX) && !defined(__HAIKU__)) || defined(__QNXNTO__) || defined(__CYGWIN__)
113+
+#if (!defined(UNIX) && !defined(__HAIKU__)) || defined(__QNXNTO__) || defined(__CYGWIN__) || defined(__serenity__)
114+
typedef unsigned int uint;
115+
#endif
116+

Ports/openttd/patches/memory.patch

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
diff -Naur openttd-1.11.0/src/spritecache.cpp openttd-1.11.0.serenity/src/spritecache.cpp
2+
--- openttd-1.11.0/src/spritecache.cpp 2021-04-01 14:33:44.000000000 +0200
3+
+++ openttd-1.11.0.serenity/src/spritecache.cpp 2021-04-18 21:03:15.916430052 +0200
4+
@@ -915,6 +915,7 @@
5+
/* Remember 'target_size' from the previous allocation attempt, so we do not try to reach the target_size multiple times in case of failure. */
6+
static uint last_alloc_attempt = 0;
7+
8+
+#ifndef __serenity__
9+
if (_spritecache_ptr == nullptr || (_allocated_sprite_cache_size != target_size && target_size != last_alloc_attempt)) {
10+
delete[] reinterpret_cast<byte *>(_spritecache_ptr);
11+
12+
@@ -950,6 +951,10 @@
13+
ScheduleErrorMessage(msg);
14+
}
15+
}
16+
+#else
17+
+ _allocated_sprite_cache_size = target_size / 5;
18+
+ _spritecache_ptr = reinterpret_cast<MemBlock *>(new byte[_allocated_sprite_cache_size]);
19+
+#endif
20+
21+
/* A big free block */
22+
_spritecache_ptr->size = (_allocated_sprite_cache_size - sizeof(MemBlock)) | S_FREE_MASK;

Ports/openttd/patches/rdtsc.patch

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff -Naur openttd-1.11.0/src/cpu.cpp openttd-1.11.0.serenity/src/cpu.cpp
2+
--- openttd-1.11.0/src/cpu.cpp 2021-04-22 01:14:21.038920133 +0200
3+
+++ openttd-1.11.0.serenity/src/cpu.cpp 2021-04-22 01:13:56.638440518 +0200
4+
@@ -40,7 +40,7 @@
5+
#endif
6+
7+
/* rdtsc for all other *nix-en (hopefully). Use GCC syntax */
8+
-#if (defined(__i386__) || defined(__x86_64__)) && !defined(RDTSC_AVAILABLE)
9+
+#if (defined(__i386__) || defined(__x86_64__)) && !defined(__serenity__) && !defined(RDTSC_AVAILABLE)
10+
uint64 ottd_rdtsc()
11+
{
12+
uint32 high, low;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
diff -Naur openttd-1.11.0/src/os/unix/crashlog_unix.cpp openttd-1.11.0.serenity/src/os/unix/crashlog_unix.cpp
2+
--- openttd-1.11.0/src/os/unix/crashlog_unix.cpp 2021-04-01 14:33:44.000000000 +0200
3+
+++ openttd-1.11.0.serenity/src/os/unix/crashlog_unix.cpp 2021-04-18 21:40:06.426298674 +0200
4+
@@ -178,7 +178,7 @@
5+
/* static */ void CrashLog::InitialiseCrashLog()
6+
{
7+
for (const int *i = _signals_to_handle; i != endof(_signals_to_handle); i++) {
8+
- signal(*i, HandleCrash);
9+
+ //signal(*i, HandleCrash);
10+
}
11+
}
12+

0 commit comments

Comments
 (0)