A modern Music Player Daemon based on Rockbox open source high quality audio player
libadwaita
audio
rust
zig
deno
mpris
rockbox
mpd
1#!/bin/sh
2# Usage: resync.sh PUZZLES_PATH
3#
4# Automatic resync tool. Removes the current source snapshot in src/
5# and copies just the source files we need from the puzzles source
6# tree. Handles help generation as well. Stages changes in git.
7#
8# Expects a modified Halibut (https://github.com/built1n/halibut) to
9# be installed in $PATH. Also requires host CC and lz4 library to be
10# available
11
12
13if [ $# -ne 1 ]
14then
15 echo -e "Usage: $0 PUZZLES_PATH\n"
16 echo "Automatically resync with upstream."
17 echo "PUZZLES_PATH is the path to a puzzles source tree."
18 exit
19fi
20
21echo "Resyncing to upstream sources $1"
22echo "This script assumes you have gcc, lz4, and a custom halibut (https://github.com/built1n/halibut) installed!"
23
24echo "=== POTENTIALLY DANGEROUS OPERATION ==="
25echo "Are you sure you want to remove all files in src/ and help/?"
26echo -n "If so, type \"yes\" in all caps: "
27read ans
28if [ "YES" == $ans ]
29then
30 pushd "$(dirname "$0")" > /dev/null
31 ROOT="$PWD"
32
33 echo "[1/6] Removing current src/ directory"
34 rm -rf src
35
36 echo "[2/6] Copying new sources"
37 mkdir -p src/unfinished
38 cp -r "$1"/{*.h,puzzles.but,LICENCE,README,CMakeLists.txt,unfinished} src
39
40 echo "[3/6] Generating SOURCES, SOURCES.games"
41
42 cat <<EOF | tee SOURCES SOURCES.games >/dev/null
43/* !!! DO NOT MODIFY THIS FILE !!! */
44
45/*
46 *
47 * This file is automatically generated by resync.sh. Any manual
48 * changes here will be overwritten by future resyncs.
49 *
50 * If you wish to change anything in this file, instead edit resync.sh
51 * to accomplish what you want. You have been warned.
52 */
53
54/* !!! DO NOT MODIFY THIS FILE !!! */
55
56EOF
57
58 # Parse out definitions of core, core_obj, and common from the
59 # upstream CMakeLists.txt. Extract the .c filenames, except
60 # malloc.c and ps.c, and store in SOURCES.core.
61 EXCLUDE_CORE_REGEX="malloc|ps"
62
63 cat src/CMakeLists.txt |
64 awk '/add_library\(/{p=1} p{printf $0" "} /\)/{if(p) print; p=0}' | # parse out add_library(...)
65 grep -E "core|common" |
66 grep -Po "[a-z0-9\-]*?\.c" |
67 sort -n |
68 grep -vE "$EXCLUDE_CORE_REGEX" |
69 awk '{print "src/"$0}' |
70 uniq > SOURCES.core
71
72 # printing.c is pulled in via platforms/*.cmake. We don't have
73 # that, so must add it ourselves.
74 echo "src/printing.c" >> SOURCES.core
75
76 # Parse out puzzle definitions to build SOURCES.games, but exclude
77 # nullgame, and also #ifdef also memory-intensive games on
78 # low-memory targets.
79 EXCLUDE_GAMES_ALWAYS="nullgame|separate"
80
81 cat src/CMakeLists.txt |
82 awk '/puzzle\(/{p=1} p{print} /\)/{p=0}' | # parse out puzzle(...)
83 grep -Eo "\(.*$" | # parse out only the first argument - this is brittle.
84 tr -dc "a-z\n" |
85 grep -vE "$EXCLUDE_GAMES_ALWAYS" | # exclude nullgame
86 awk '{print "src/"$0".c"}' > SOURCES.games
87
88 SRC="$(cat SOURCES.games SOURCES.core | sed 's/src\///' | tr '\n' ' ' | head -c-1)"
89 echo "Detected sources:" $SRC
90 pushd "$1" > /dev/null
91 cp -r $SRC "$ROOT"/src
92 popd > /dev/null
93
94 EXCLUDE_GAMES_LOW_MEMORY="loopy|pearl|solo"
95
96 # Linking on win32 (i.e. for sim/app builds) blows up with
97 # un-overridden weak symbols, which are used by nullhelp.c to
98 # provide fallback help text variables for the unfinished
99 # plugins. A possible fix to support those games on win32 would be
100 # to compile two versions of rockbox.o with a preprocessor flag to
101 # prevent referencing the help variables in unfinished builds.
102 #
103 # But for now, we just disable the unfinished plugins on win32.
104 EXCLUDE_GAMES_WIN32="unfinished"
105
106 cat src/unfinished/CMakeLists.txt |
107 awk '/puzzle\(/{p=1} p{print} /\)/{p=0}' |
108 grep -Eo "\(.*$" |
109 tr -dc "a-z\n" |
110 awk '{print "src/unfinished/"$0".c"}' |
111 grep -Ev "$EXCLUDE_GAMES_ALWAYS" >> SOURCES.games
112
113 # Edit SOURCES.games in-place to conditionally compile games due
114 # to either low-memory (EXCLUDE_GAMES_LOW_MEMORY), or win32
115 # incompatibility (EXCLUDE_GAMES_WIN32).
116 awk -i inplace '{
117 if ($0 ~ /'"$EXCLUDE_GAMES_WIN32"'/) {
118 print "#ifndef WIN32"; print $0; print "#endif";
119 }
120 else if ($0 ~ /'"$EXCLUDE_GAMES_LOW_MEMORY"'/) {
121 print "#if PLUGIN_BUFFER_SIZE > 0x14000"; print $0; print "#endif";
122 }
123 else {
124 print
125 }
126}' SOURCES.games
127
128 cat <<EOF >> SOURCES
129/* rockbox frontend sources, from SOURCES.rockbox */
130EOF
131 cat SOURCES.rockbox | cpp | grep -vE "^#" | sed '/^$/d' >> SOURCES
132
133 cat <<EOF >> SOURCES
134
135/* puzzles core sources, from src/CMakeLists.txt */
136EOF
137
138 cat SOURCES.core >> SOURCES
139 rm SOURCES.core
140
141 echo "[4/6] Generating help"
142 rm -rf help
143 ./genhelp.sh
144
145 echo "[5/6] Staging for commit"
146 git add src help
147 echo "[6/6] Successfully resynced with upstream"
148
149 popd > /dev/null
150else
151 echo "Did nothing."
152fi