Skip to content

Commit

Permalink
Add custom build-emulatorjs.sh
Browse files Browse the repository at this point in the history
  • Loading branch information
ethanaobrien committed Mar 7, 2024
1 parent e3006dd commit 85f46ec
Show file tree
Hide file tree
Showing 3 changed files with 167 additions and 139 deletions.
8 changes: 1 addition & 7 deletions Makefile.emscripten
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,6 @@ GL_DEBUG ?= 0 # help diagnose GLSL problems (can cause errors in normal operatio
GENERATE_SOURCEMAP ?= 0
FS_DEBUG = 0

MEMORY_PADDING ?= 0

# default value: 5242880 (5 MiB)
STACK_MEMORY ?= 8388608
# default value: 16777216 (16 MiB)
Expand Down Expand Up @@ -129,10 +127,6 @@ LDFLAGS := -L. --no-heap-copy $(LIBS) -s TOTAL_STACK=$(STACK_MEMORY) -s TOTAL_ME

# -s MODULARIZE=1 -s EXPORT_ES6=1

ifneq ($(MEMORY_PADDING), 0)
LDFLAGS += -s GLOBAL_BASE=$(MEMORY_PADDING)mb
endif


ifeq ($(HAVE_RWEBAUDIO), 1)
LDFLAGS += --js-library emscripten/library_rwebaudio.js
Expand Down Expand Up @@ -253,7 +247,7 @@ $(OBJDIR)/%.o: %.cpp
$(Q)$(CXX) $(CXXFLAGS) $(DEFINES) $(EOPTS) -c -o $@ $<

clean:
#rm -rf $(OBJDIR)
rm -rf $(OBJDIR)
rm -f $(TARGET)

.PHONY: all clean
158 changes: 158 additions & 0 deletions dist-scripts/build-emulatorjs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#!/bin/sh

. ../version.all
PLATFORM=$1
CLEAN=$2
PTHREADS=$3
LEGACY=$4
SALAMANDER=no
MAKEFILE_GRIFFIN=no

clean=no
if [ "$CLEAN" = "clean" ] ; then
clean=yes
fi
threads=0
if [ "$PTHREADS" = "yes" ] ; then
threads=8
fi

platform=emscripten
EXT=bc

if [ -z "$EMSCRIPTEN" ] ; then
echo "run this script with emmake. Ex: emmake $0"
exit 1
fi

# Cleanup existing core if it exists
if [ $clean = "yes" ]; then
make -C ../ -f Makefile.${platform} clean || exit 1
fi

COUNTER=0

lastPthreads=0
lastGles=0

#for f in *_${platform}.${EXT} ; do
for f in `ls -v *_${platform}.${EXT}`; do

echo Buildbot: building ${name} for ${platform}
name=`echo "$f" | sed "s/\(_libretro_${platform}\|\).${EXT}$//"`
async=1
pthread="$threads"
wasm=1

gles3=0
stack_mem=8388608
heap_mem=268435456

if [ $name = "mupen64plus_next" ] ; then
gles3=1
async=1
stack_mem=268435456
heap_mem=536870912
if [ $wasm = 0 ]; then
continue;
fi
elif [ $name = "picodrive" ] ; then
heap_mem=536870912
elif [ $name = "pcsx_rearmed" ] || [ $name = "genesis_plus_gx" ]; then
heap_mem=536870912
elif [ $name = "mednafen_psx" ] || [ $name = "mednafen_psx_hw" ]; then
gles3=1
heap_mem=536870912
elif [ $name = "parallel_n64" ] ; then
gles3=1
heap_mem=536870912
elif [ $name = "ppsspp" ] ; then
gles3=0
pthread=12
heap_mem=536870912
fi
echo "-- Building core: $name --"
cp -f "$f" ../libretro_${platform}.a

if [ "$LEGACY" = "yes" ]; then
gles3=0
elif [ "$LEGACY" = "no" ]; then
gles3=1
fi
echo NAME: $name
echo ASYNC: $async
echo PTHREAD: $pthread
echo WASM: $wasm
echo GLES3: $gles3
echo STACK_MEMORY: $stack_mem
echo HEAP_MEMORY: $heap_mem

if [ $clean = "yes" ]; then
if [ $lastPthreads != $pthread ] ; then
make -C ../ -f Makefile.${platform} clean || exit 1
fi
if [ $lastGles != $gles3 ] ; then
make -C ../ -f Makefile.${platform} clean || exit 1
fi
fi

lastPthreads=$pthread
lastGles=$gles3

# Compile core
echo "BUILD COMMAND: make -C ../ -f Makefile.emscripten $OPTS PTHREAD=$pthread ASYNC=$async WASM=$wasm HAVE_OPENGLES3=$gles3 STACK_MEMORY=$stack_mem HEAP_MEMORY=$heap_mem -j7 TARGET=${name}_libretro.js"
make -C ../ -f Makefile.emscripten $OPTS PTHREAD=$pthread ASYNC=$async WASM=$wasm HAVE_OPENGLES3=$gles3 STACK_MEMORY=$stack_mem HEAP_MEMORY=$heap_mem -j$(nproc) TARGET=${name}_libretro.js || exit 1

# Move executable files
mkdir -p ../pkg/emscripten/

out_dir="../../EmulatorJS/data/cores"
out_name=""

mkdir -p $out_dir

core=""
if [ $name = "mednafen_vb" ]; then
core="beetle_vb"
else
core=${name}
fi

if [ "$LEGACY" = "yes" ]; then
if [ $pthread != 0 ] ; then
out_name=${core}-thread-legacy-wasm.data
else
if [ $wasm = 0 ]; then
out_name=${core}-legacy-asmjs.data
else
out_name=${core}-legacy-wasm.data
fi
fi
else
if [ $pthread != 0 ] ; then
out_name=${core}-thread-wasm.data
else
if [ $wasm = 0 ]; then
out_name=${core}-asmjs.data
else
out_name=${core}-wasm.data
fi
fi
fi

if [ $pthread != 0 ] ; then
7z a ${out_dir}/${out_name} ../${name}_libretro.wasm ../${name}_libretro.js ../${name}_libretro.worker.js
else
if [ $wasm = 0 ]; then
7z a ${out_dir}/${out_name} ../${name}_libretro.js.mem ../${name}_libretro.js
rm ../${name}_libretro.js.mem
else
7z a ${out_dir}/${out_name} ../${name}_libretro.wasm ../${name}_libretro.js
rm ../${name}_libretro.wasm
fi
fi
rm ../${name}_libretro.js

# Remove executable files
rm -f ../${name}_libretro.js
done
140 changes: 8 additions & 132 deletions dist-scripts/dist-cores.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,9 @@

. ../version.all
PLATFORM=$1
CLEAN=$2
PTHREADS=$3
LEGACY=$4
SALAMANDER=no
MAKEFILE_GRIFFIN=no

clean=no
if [ "$CLEAN" = "clean" ] ; then
clean=yes
fi
threads=0
if [ "$PTHREADS" = "yes" ] ; then
threads=8
fi

# PSP
if [ $PLATFORM = "unix" ] ; then
platform=unix
Expand Down Expand Up @@ -206,28 +194,16 @@ if [ $PLATFORM = "libnx" ]; then
make -C ../ -f Makefile.${platform} clean || exit 1
fi

if [ $clean = "yes" ]; then
rm -rf ../obj-emscripten
fi
lastPthreads=0
lastGles=0

#for f in *_${platform}.${EXT} ; do
for f in `ls -v *_${platform}.${EXT}`; do

echo Buildbot: building ${name} for ${platform}
name=`echo "$f" | sed "s/\(_libretro_${platform}\|\).${EXT}$//"`
async=0
pthread="$threads"
wasm=1
pthread=${pthread:-0}
lto=0
whole_archive=
big_stack=
memory_padding=0

gles3=0
stack_mem=8388608
heap_mem=268435456

if [ $PLATFORM = "emscripten" ]; then
async=1 #emscripten needs async to sleep
Expand All @@ -239,76 +215,27 @@ for f in `ls -v *_${platform}.${EXT}`; do
echo "Applying big stack..."
lto=0
big_stack="BIG_STACK=1"
elif [ $name = "mupen64plus_next" ] ; then
gles3=1
async=1
stack_mem=268435456
heap_mem=536870912
if [ $wasm = 0 ]; then
continue;
fi
elif [ $name = "picodrive" ] ; then
heap_mem=536870912
elif [ $name = "pcsx_rearmed" ] || [ $name = "genesis_plus_gx" ]; then
heap_mem=536870912
elif [ $name = "mednafen_psx" ] || [ $name = "mednafen_psx_hw" ]; then
gles3=1
heap_mem=536870912
elif [ $name = "parallel_n64" ] ; then
gles3=1
async=1
heap_mem=536870912
elif [ $name = "ppsspp" ] ; then
gles3=0
pthread=12
heap_mem=536870912
elif [ $name = "scummvm" ] ; then
elif [ $name = "mupen64plus" ] ; then
async=1
elif [ $name = "dosbox" ] ; then
async=0
fi
echo "-- Building core: $name --"
if [ $PLATFORM = "unix" ]; then
cp -f "$f" ../libretro.${EXT}
elif [ $PLATFORM = "emscripten" ]; then
cp -f "$f" ../libretro_${platform}.a
else
cp -f "$f" ../libretro_${platform}.${EXT}
fi

if [ "$LEGACY" = "yes" ]; then
gles3=0
elif [ "$LEGACY" = "no" ]; then
gles3=1
fi
echo NAME: $name
echo ASYNC: $async
echo PTHREAD: $pthread
echo LTO: $lto
echo WASM: $wasm
echo GLES3: $gles3
echo STACK_MEMORY: $stack_mem
echo HEAP_MEMORY: $heap_mem
echo MEMORY_PADDING: $memory_padding

if [ $clean = "yes" ]; then
if [ $lastPthreads != $pthread ] ; then
rm -rf ../obj-emscripten
fi
if [ $lastGles != $gles3 ] ; then
rm -rf ../obj-emscripten
fi
fi

lastPthreads=$pthread
lastGles=$gles3

# Do cleanup if this is a big stack core
if [ "$big_stack" = "BIG_STACK=1" ] ; then
if [ $MAKEFILE_GRIFFIN = "yes" ]; then
make -C ../ -f Makefile.griffin platform=${platform} clean || exit 1
elif [ $PLATFORM = "emscripten" ]; then
make -C ../ -f Makefile.emscripten PTHREAD=$pthread ASYNC=$async LTO=$lto WASM=$wasm -j$(nproc) clean || exit 1
make -C ../ -f Makefile.emscripten PTHREAD=$pthread ASYNC=$async LTO=$lto -j7 clean || exit 1
elif [ $PLATFORM = "unix" ]; then
make -C ../ -f Makefile LINK=g++ LTO=$lto -j7 clean || exit 1
else
Expand All @@ -320,8 +247,8 @@ for f in `ls -v *_${platform}.${EXT}`; do
if [ $MAKEFILE_GRIFFIN = "yes" ]; then
make -C ../ -f Makefile.griffin $OPTS platform=${platform} $whole_archive $big_stack -j3 || exit 1
elif [ $PLATFORM = "emscripten" ]; then
echo "BUILD COMMAND: make -C ../ -f Makefile.emscripten $OPTS PTHREAD=$pthread ASYNC=$async WASM=$wasm LTO=$lto HAVE_OPENGLES3=$gles3 STACK_MEMORY=$stack_mem HEAP_MEMORY=$heap_mem MEMORY_PADDING=$memory_padding -j7 TARGET=${name}_libretro.js"
make -C ../ -f Makefile.emscripten $OPTS PTHREAD=$pthread ASYNC=$async WASM=$wasm LTO=$lto HAVE_OPENGLES3=$gles3 STACK_MEMORY=$stack_mem HEAP_MEMORY=$heap_mem -j$(nproc) TARGET=${name}_libretro.js || exit 1
echo "BUILD COMMAND: make -C ../ -f Makefile.emscripten PTHREAD=$pthread ASYNC=$async LTO=$lto -j7 LIBRETRO=${name} TARGET=${name}_libretro.js"
make -C ../ -f Makefile.emscripten $OPTS PTHREAD=$pthread ASYNC=$async LTO=$lto -j7 LIBRETRO=${name} TARGET=${name}_libretro.js || exit 1
elif [ $PLATFORM = "unix" ]; then
make -C ../ -f Makefile LINK=g++ $whole_archive $big_stack -j3 || exit 1
elif [ $PLATFORM = "ctr" ]; then
Expand Down Expand Up @@ -386,62 +313,11 @@ for f in `ls -v *_${platform}.${EXT}`; do
mv -f ../retrodos.exe ../pkg/${platform}/cores/${name}.exe
elif [ $PLATFORM = "emscripten" ] ; then
mkdir -p ../pkg/emscripten/

out_dir="../../EmulatorJS/data/cores"
out_name=""

mkdir -p $out_dir

core=""
if [ $name = "mednafen_vb" ]; then
core="beetle_vb"
else
core=${name}
fi

if [ "$LEGACY" = "yes" ]; then
if [ $pthread != 0 ] ; then
out_name=${core}-thread-legacy-wasm.data
else
if [ $wasm = 0 ]; then
out_name=${core}-legacy-asmjs.data
else
out_name=${core}-legacy-wasm.data
fi
fi
else
if [ $pthread != 0 ] ; then
out_name=${core}-thread-wasm.data
else
if [ $wasm = 0 ]; then
out_name=${core}-asmjs.data
else
out_name=${core}-wasm.data
fi
fi
fi

mv -f ../${name}_libretro.js ../pkg/emscripten/${name}_libretro.js
mv -f ../${name}_libretro.wasm ../pkg/emscripten/${name}_libretro.wasm
if [ $pthread != 0 ] ; then
7z a ${out_dir}/${out_name} ../${name}_libretro.wasm ../${name}_libretro.js ../${name}_libretro.worker.js
else
if [ $wasm = 0 ]; then
7z a ${out_dir}/${out_name} ../${name}_libretro.js.mem ../${name}_libretro.js
rm ../${name}_libretro.js.mem
else
7z a ${out_dir}/${out_name} ../${name}_libretro.wasm ../${name}_libretro.js
rm ../${name}_libretro.wasm
fi
mv -f ../${name}_libretro.worker.js ../pkg/emscripten/${name}_libretro.worker.js
fi
rm ../${name}_libretro.js


# mv -f ../${name}_libretro.js ../pkg/emscripten/${name}_libretro.js
# mv -f ../${name}_libretro.wasm ../pkg/emscripten/${name}_libretro.wasm
# if [ $pthread != 0 ] ; then
# mv -f ../${name}_libretro.worker.js ../pkg/emscripten/${name}_libretro.worker.js
# fi


fi

# Do manual executable step
Expand Down

0 comments on commit 85f46ec

Please sign in to comment.