From: kub Date: Thu, 9 Jul 2020 21:51:39 +0000 (+0200) Subject: libretro, build fixes X-Git-Tag: v2.00~717 X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03718e6276272f3508b2c76ece1901744434b7db;p=picodrive.git libretro, build fixes --- diff --git a/Makefile b/Makefile index f80a9ec7..a06b8189 100644 --- a/Makefile +++ b/Makefile @@ -280,6 +280,9 @@ endif pico/carthw_cfg.c: pico/carthw.cfg tools/make_carthw_c $< $@ +# preprocessed asm files most probably include the offsets file +$(filter %.S,$(SRCS_COMMON)): pico/pico_int_offs.h + # random deps pico/carthw/svp/compiler.o : cpu/drc/emit_arm.c cpu/sh2/compiler.o : cpu/drc/emit_arm.c cpu/drc/emit_arm64.c cpu/drc/emit_ppc.c diff --git a/Makefile.libretro b/Makefile.libretro index 309d3f72..b227f17f 100644 --- a/Makefile.libretro +++ b/Makefile.libretro @@ -364,6 +364,10 @@ else ifeq ($(platform), emscripten) STATIC_LINKING = 1 DONT_COMPILE_IN_ZLIB = 1 + use_cyclone = 0 + use_fame = 1 + use_drz80 = 0 + use_cz80 = 1 # GCW0 else ifeq ($(platform), gcw0) TARGET := $(TARGET_NAME)_libretro.so diff --git a/platform/common/common.mak b/platform/common/common.mak index 024ff75f..599f246f 100644 --- a/platform/common/common.mak +++ b/platform/common/common.mak @@ -76,7 +76,7 @@ SRCS_COMMON += $(R)pico/32x/draw_arm.S endif ifeq "$(asm_32xmemory)" "1" DEFINES += _ASM_32X_MEMORY_C -SRCS_COMMON += $(R)pico/32x/memory_arm.s +SRCS_COMMON += $(R)pico/32x/memory_arm.S endif ifeq "$(asm_mix)" "1" SRCS_COMMON += $(R)pico/sound/mix_arm.S diff --git a/tools/Makefile b/tools/Makefile index 752cd6b2..41c4d3d6 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -2,7 +2,7 @@ TARGETS = amalgamate textfilter OBJS = $(addsuffix .o,$(TARGETS)) all: $(TARGETS) - CC="$(XCC)" CFLAGS="$(XCFLAGS)" ./mkoffsets.sh ../pico + CC="$(XCC)" CFLAGS="$(XCFLAGS)" sh ./mkoffsets.sh ../pico clean: $(RM) $(TARGETS) $(OBJS) diff --git a/tools/mkoffsets.sh b/tools/mkoffsets.sh index 6b086a93..0aa8e96e 100755 --- a/tools/mkoffsets.sh +++ b/tools/mkoffsets.sh @@ -8,30 +8,80 @@ CC=${CC:-gcc} # endianess of target (automagically determined below) ENDIAN= -# don't do this if ELF format isn't used. it doesn't matter since offsets are -# only needed for the asm parts (currently mips/arm32) and those have ELF -check_elf () +# check which object format to dissect +READELF= +OBJDUMP= +check_obj () { + # prepare an object file; as side effect dtermine the endianess + CROSS=$(echo $CC | sed 's/gcc.*//') echo '#include ' >/tmp/getoffs.c echo "const int32_t val = 1;" >>/tmp/getoffs.c $CC $CFLAGS -I .. -c /tmp/getoffs.c -o /tmp/getoffs.o || exit 1 - if ! command -v readelf >/dev/null || ! file /tmp/getoffs.o | grep -q ELF; then - echo "/* mkoffset.sh: no readelf or not ELF, offset table not created */" >$fn - echo "WARNING: no readelf or not ELF, offset table not created" - exit + + # check for readelf; readelf is the only toolchain tool not using bfd, + # hence it works with ELF files for every target + if file /tmp/getoffs.o | grep -q ELF; then + if command -v readelf >/dev/null; then + READELF=readelf + elif command -v ${CROSS}readelf >/dev/null; then + READELF=${CROSS}readelf + fi + fi + if [ -n "$READELF" ]; then + # find the the .rodata section (in case -fdata-sections is used) + rosect=$($READELF -S /tmp/getoffs.o | grep '\.rodata\|\.sdata' | + sed 's/^[^.]*././;s/ .*//') + # read .rodata section as hex string (should be only 4 bytes) + ro=$($READELF -x $rosect /tmp/getoffs.o | grep '0x' | cut -c14-48 | + tr -d ' \n' | cut -c1-8) + # if no output could be read readelf isn't working + if [ -z "$ro" ]; then + READELF= + fi + fi + # if there is no working readelf try using objdump + if [ -z "$READELF" ]; then + # objdump is using bfd; try using the toolchain objdump first + # since this is likely working with the toolchain objects + if command -v ${CROSS}objdump >/dev/null; then + OBJDUMP=${CROSS}objdump + elif command -v objdump >/dev/null; then + OBJDUMP=objdump + fi + # find the start line of the .rodata section; read the next line + ro=$($OBJDUMP -s /tmp/getoffs.o | awk '\ + /Contents of section.*(__const|.rodata|.sdata)/ {o=1; next} \ + {if(o) { gsub(/ .*/,""); $1=""; gsub(/ /,""); print; o=0}}') + # no working tool for extracting the ro data; stop here + if [ -z "$ro" ]; then + echo "/* mkoffset.sh: no readelf or not ELF, offset table not created */" >$fn + echo "WARNING: no readelf or not ELF, offset table not created" + exit + fi fi + # extract decimal value from ro + rodata=$(printf "%d" 0x$ro) + ENDIAN=$(if [ "$rodata" -eq 1 ]; then echo be; else echo le; fi) } # compile with target C compiler and extract value from .rodata section compile_rodata () { $CC $CFLAGS -I .. -c /tmp/getoffs.c -o /tmp/getoffs.o || exit 1 - # find the name of the .rodata section (in case -fdata-sections is used) - rosect=$(readelf -S /tmp/getoffs.o | grep '\.rodata\|\.sdata' | + if [ -n "$READELF" ]; then + # find the .rodata section (in case -fdata-sections is used) + rosect=$(readelf -S /tmp/getoffs.o | grep '\.rodata\|\.sdata' | sed 's/^[^.]*././;s/ .*//') - # read out .rodata section as hex string (should be only 4 bytes) - ro=$(readelf -x $rosect /tmp/getoffs.o | grep '0x' | cut -c14-48 | + # read .rodata section as hex string (should be only 4 bytes) + ro=$(readelf -x $rosect /tmp/getoffs.o | grep '0x' | cut -c14-48 | tr -d ' \n' | cut -c1-8) + elif [ -n "$OBJDUMP" ]; then + # find the start line of the .rodata section; read the next line + ro=$($OBJDUMP -s /tmp/getoffs.o | awk '\ + /Contents of section.*(__const|.rodata|.sdata)/ {o=1; next} \ + {if(o) { gsub(/ .*/,""); $1=""; gsub(/ /,""); print; o=0}}') + fi if [ "$ENDIAN" = "le" ]; then # swap needed for le target hex="" @@ -63,12 +113,7 @@ get_define () # prefix struct member member... fn="${1:-.}/pico_int_offs.h" if echo $CFLAGS | grep -qe -flto; then CFLAGS="$CFLAGS -fno-lto"; fi -check_elf -# determine endianess -echo '#include ' >/tmp/getoffs.c -echo "const int32_t val = 1;" >>/tmp/getoffs.c -compile_rodata -ENDIAN=$(if [ "$rodata" -eq 1 ]; then echo be; else echo le; fi) +check_obj # output header echo "/* autogenerated by mkoffset.sh, do not edit */" >$fn echo "/* target endianess: $ENDIAN, compiled with: $CC $CFLAGS */" >>$fn