add tooling to prepare and ease compilation on Linux

This commit is contained in:
Gwenhael Le Moine 2024-10-29 21:36:04 +01:00
parent 03d5beeeed
commit f8a728884e
No known key found for this signature in database
GPG key ID: FDFE3669426707A7
7 changed files with 291 additions and 0 deletions

59
.clang-format Normal file
View file

@ -0,0 +1,59 @@
---
Language: Cpp
ColumnLimit: 140
IndentWidth: 4
PPIndentWidth: 2
UseTab: Never
AlignArrayOfStructures: Left
IndentCaseBlocks: true
IndentCaseLabels: true
IndentGotoLabels: false
IndentPPDirectives: AfterHash
IndentWrappedFunctionNames: true
InsertBraces: false
InsertNewlineAtEOF: true
MaxEmptyLinesToKeep: 1
PointerAlignment: Left
ReferenceAlignment: Left
QualifierAlignment: Left
SortIncludes: false
SpaceBeforeAssignmentOperators: true
SpaceBeforeParens: ControlStatements
SpaceBeforeRangeBasedForLoopColon: true
SpaceInEmptyParentheses: false
SpacesInAngles: true
SpacesInCStyleCastParentheses: true
SpacesInContainerLiterals: true
SpacesInParentheses: true
SpacesInSquareBrackets: true
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
BreakBeforeBraces: Custom
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterExternBlock: false
AfterFunction: true
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
...

41
Makefile Normal file
View file

@ -0,0 +1,41 @@
.PHONY: release release-with-assets debug debug-with-assets clean mrproper pull-emu48plus pull-assets keystore linux-compatible undo-linux-compatible
release:
./gradlew assembleRelease assembleReleaseUnitTest
find . -name \*.apk
debug:
./gradlew assembleDebug assembleDebugUnitTest
find . -name \*.apk
clean:
./gradlew clean
-rm -fr ./app/src/main/cpp/emu48plus.bkp
-rm -fr ./app/src/main/assets/calculators.bkp
mrproper: clean
-rm -fr ./app/src/main/assets/calculators/*
linux-compatible:
zsh ./make-linux-compatible.sh
undo-linux-compatible:
git reset --hard HEAD
rm -f app/src/main/cpp/core/emu48.c
rm -f app/src/main/cpp/core/emu48.h
rm -f app/src/main/cpp/core/opcodes.h
keystore:
bash ./gen-keystore.sh
# These are leftovers from a previous iteration,
# neither necessary not up-to-date but ncie to keep around for reference
release-with-assets: pull-assets release
debug-with-assets: pull-assets debug
pull-emu48plus:
zsh ./pull-emu48plus-sources.sh
pull-assets:
bash ./pull-KMLs-and-ROMs.sh

21
gen-keystore.sh Executable file
View file

@ -0,0 +1,21 @@
#!/bin/bash
cd "$(dirname "$0")" || exit 1
KEYSTORE_FILE=${KEYSTORE_FILE:-./keystore.jks}
ALIAS=key-emu48
echo "Generating $KEYSTORE_FILE"
keytool -genkey -keystore "$KEYSTORE_FILE" -keyalg RSA -validity 9125 -alias $ALIAS
echo -n "Type again the password (will not echo): "
read -s password
echo
echo "Generating ./keystore.properties…"
cat <<EOF > ./keystore.properties
storeFile=$KEYSTORE_FILE
storePassword=$password
keyAlias=$ALIAS
keyPassword=$password
EOF

8
local.properties.sample Normal file
View file

@ -0,0 +1,8 @@
## This file must *NOT* be checked into Version Control Systems,
# as it contains information specific to your local configuration.
#
# Location of the SDK. This is only used by Gradle.
# For customization when using a Version Control System, please read the
# header note.
#Mon Apr 01 18:38:15 CEST 2024
sdk.dir=/home/gwh/Android/Sdk

68
make-linux-compatible.sh Executable file
View file

@ -0,0 +1,68 @@
#!/bin/zsh
# This script depends on:
# - fd
# - sed
# - grep
# - dos2unix
# - clang-format
set -eu
cd "$(dirname "$0")" || exit 1
CWD=$(pwd)
cd ./app/src/main/cpp/core/ || exit 1
echo "> Correct filenames' case"
for f in ./*; do
dos2unix "$f" >/dev/null 2>&1
echo "$f" | grep -q "[A-Z]" && mv "$f" "$(echo "$f" | tr '[:upper:]' '[:lower:]')"
done
cd "$CWD" || exit 1
echo "> fix includes for lowercase filenames"
sed -i 's|Emu48\.h|emu48.h|g' $(grep -l "Emu48\.h[^t]" * -r)
sed -i 's|Emu48Dll\.h|emu48dll.h|g' $(grep -l "Emu48Dll\.h" * -r)
sed -i 's|Opcodes\.h|opcodes.h|g' $(grep -l "Opcodes\.h" * -r)
sed -i 's|Ops\.h|ops.h|g' $(grep -l "Ops\.h" * -r)
echo "> make gradlew executable"
chmod +x ./gradlew
echo "> gitignore secrets"
echo "keystore.properties" >> .gitignore
echo "keystore.kjs" >> .gitignore
echo "> patch app/build.gradle to add custom suffix to build"
SUFFIX=${SUFFIX:-gwh}
BUILD_SUFFIXES=" versionNameSuffix \"-${SUFFIX}\"\n versionName"
ESCAPED_BUILD_SUFFIXES="$(echo "${BUILD_SUFFIXES}" | sed ':a;N;$!ba;s/\n/\\n/g' | sed 's/\$/\\$/g')"
sed -i 's/ versionName/'"${ESCAPED_BUILD_SUFFIXES}"'/' app/build.gradle
sed -i 's/Emu48-v$versionName/$applicationId-v$versionName$versionNameSuffix/' app/build.gradle
# not necessary but it makes code readable
echo "> translitterate windows-encoded ß to 'ss'"
sed -i 's/'$(echo "\0337")'/ss/g' ./app/src/main/cpp/core/*
echo "> remove those ugly ^M characters"
fd -e c \
-e h \
-e C \
-e H \
-e java \
-e kml \
-e KML \
-e kmi \
-e htm \
-e pro \
-e xml \
-e txt \
-e gradle \
-e properties \
-x sed -i 's| ||g'
echo "> prettify all C code"
clang-format -i $(fd -e c -e h)

61
pull-KMLs-and-ROMs.sh Executable file
View file

@ -0,0 +1,61 @@
#!/bin/bash
set -eu
cd "$(dirname "$0")" || exit 1
cd ./app/src/main/assets/ || exit 1
[ -d ./calculators.bkp ] && rm -fr ./calculators.bkp
cp -a ./calculators ./calculators.bkp
cd ./calculators || exit 1
rm -fr ./realcalcs* ./rom.* ./gxrom* ./sxrom* ./*.ico ./*.kml ./*.png ./*.kmi ./readme-rom.49g.txt
echo "Pulling Eric Rechlin's Real Calcs KML Scripts for Emu48 and Emu48+"
wget -c "https://www.hpcalc.org/hp48/pc/emulators/realcalcs.zip"
unzip realcalcs.zip
rm realcalcs.zip
mv ./docs ./realcalcs-docs
mv ./skins/* ./
rm -fr ./skins
wget -c "https://www.hpcalc.org/hp49/pc/emulators/realcalcsplus.zip"
unzip realcalcsplus.zip
rm realcalcsplus.zip
mv ./docs ./realcalcsplus-docs
mv ./skins/* ./
rm -fr ./skins
echo " …removing the medium versions"
rm ./*-m.kml ./*-m.png ./*-mc.kml ./*-mc.png ./*-muc.kml ./*-muc.png
echo "Pulling ROM for 38g"
curl "https://www.hpcalc.org/hp38/pc/38grom.zip" --output - | funzip > "rom.38g"
echo "Pulling ROM for 39g"
curl "https://www.hpcalc.org/hp39/pc/rom3940.zip" --output - | funzip > "rom.39g"
echo "Pulling ROM for 48S(X)"
curl "https://www.hpcalc.org/hp48/pc/emulators/sxrom-a.zip" --output - | funzip > "sxrom-a"
curl "https://www.hpcalc.org/hp48/pc/emulators/sxrom-b.zip" --output - | funzip > "sxrom-b"
curl "https://www.hpcalc.org/hp48/pc/emulators/sxrom-c.zip" --output - | funzip > "sxrom-c"
curl "https://www.hpcalc.org/hp48/pc/emulators/sxrom-d.zip" --output - | funzip > "sxrom-d"
curl "https://www.hpcalc.org/hp48/pc/emulators/sxrom-e.zip" --output - | funzip > "sxrom-e"
curl "https://www.hpcalc.org/hp48/pc/emulators/sxrom-j.zip" --output - | funzip > "sxrom-j"
echo "Pulling ROM for 48G(X)"
curl "https://www.hpcalc.org/hp48/pc/emulators/gxrom-l.zip" --output - | funzip > "gxrom-l"
curl "https://www.hpcalc.org/hp48/pc/emulators/gxrom-m.zip" --output - | funzip > "gxrom-m"
curl "https://www.hpcalc.org/hp48/pc/emulators/gxrom-p.zip" --output - | funzip > "gxrom-p"
curl "https://www.hpcalc.org/hp48/pc/emulators/gxrom-r.zip" --output - | funzip > "gxrom-r"
cp sxrom-j rom.48s
cp gxrom-r rom.48g
echo "Pulling ROM for 49G(+) / 50g"
wget -c "https://www.hpcalc.org/hp49/pc/rom/hp4950emurom.zip"
unzip hp4950emurom.zip
rm hp4950emurom.zip
mv ./readme.txt ./readme-rom.49g.txt

33
pull-emu48plus-sources.sh Executable file
View file

@ -0,0 +1,33 @@
#!/bin/zsh
set -eu
cd "$(dirname "$0")" || exit 1
cd ./app/src/main/cpp/ || exit 1
[ -d ./emu48plus.bkp ] && rm -fr ./emu48plus.bkp
[ -d ./emu48plus ] && mv ./emu48plus ./emu48plus.bkp
echo "Pulling Emu48+ sources"
wget -c "https://www.hpcalc.org/hp48/pc/emulators/e48sp65plus.zip"
unzip e48sp65plus.zip source.zip
unzip -d emu48plus source.zip
rm e48sp65plus.zip source.zip
echo "Correct filenames' case"
cd emu48plus || exit 1
sed -i 's/'$(echo "\0337")'/ss/g' ./*
for f in ./*; do
dos2unix "$f"
echo "$f" | grep -q "[A-Z]" && mv "$f" "$(echo "$f" | tr '[:upper:]' '[:lower:]')"
done
sed -i 's|Emu48\.h|emu48.h|g' ./*
sed -i 's|Emu48Dll\.h|emu48dll.h|g' ./*
sed -i 's|Opcodes\.h|opcodes.h|g' ./*
sed -i 's|Ops\.h|ops.h|g' ./*
clang-format -i ./*.c ./*.h