Make simulator compile on MacOS

Tested on MacOS Sequoia (Apple Silicon) with the
latest Xcode command line tools, gcc 14
(Homebrew GCC 14.2.0_1) and sdl2 (Homebrew 2.30.9)

Make sure 'gcc' (and 'gcc-ar') is in your PATH
ahead of the Xcode-provided "gcc"(clang). E.g.
by setting up symlinks in /usr/local/bin that
point to gcc-14 and gcc-ar-14.

Notes:
- The appropriate bmp from uisimulator/bitmaps
  has to be manually copied to your build folder
  and renamed to UI256.bmp, if you want the sim
  background to be displayed

Change-Id: I559f33d2165065f913f30c016b85906af380fb81
This commit is contained in:
Christian Soffke 2023-08-12 17:27:43 +02:00 committed by Solomon Peachy
parent f9ae6d6524
commit 1745b74576
13 changed files with 75 additions and 8 deletions

View file

@ -3989,7 +3989,13 @@ size_t audio_get_filebuflen(void)
/* How many tracks exist on the buffer - full or partial */
unsigned int audio_track_count(void)
#ifndef __APPLE__
__attribute__((alias("track_list_count")));
#else
{
return track_list_count();
}
#endif
/* Return total ringbuffer space occupied - ridx to widx */
long audio_filebufused(void)

View file

@ -46,6 +46,17 @@
#undef strncmp
#undef strchr
#undef strtok_r
#ifdef __APPLE__
#undef strncpy
#undef snprintf
#undef strcpy
#undef strcat
#undef memset
#undef memcpy
#undef memmove
#undef vsnprintf
#undef vsprintf
#endif
char* strncpy(char *, const char *, size_t);
void* plugin_get_buffer(size_t *buffer_size);

View file

@ -32,7 +32,7 @@ ifndef APP_TYPE
IMGDEC_OUTLDS = $(IMGVBUILDDIR)/%.link
IMGDEC_OVLFLAGS = -T$(IMGVBUILDDIR)/$*.link -Wl,--gc-sections -Wl,-Map,$(IMGVBUILDDIR)/$*.map
else
IMGDEC_OVLFLAGS = $(PLUGINLDFLAGS) -Wl,-Map,$(IMGVBUILDDIR)/$*.map
IMGDEC_OVLFLAGS = $(PLUGINLDFLAGS) -Wl,$(LDMAP_OPT),$(IMGVBUILDDIR)/$*.map
endif
$(IMGVBUILDDIR)/%.ovl: $(IMGDEC_OUTLDS)

View file

@ -145,7 +145,7 @@ $(BUILDDIR)/apps/plugins/%.o: $(ROOTDIR)/apps/plugins/%.c
$(call PRINTS,CC $(subst $(ROOTDIR)/,,$<))$(CC) -I$(dir $<) $(PLUGINFLAGS) -c $< -o $@
ifdef APP_TYPE
PLUGINLDFLAGS = $(SHARED_LDFLAGS) -Wl,-Map,$*.map
PLUGINLDFLAGS = $(SHARED_LDFLAGS) -Wl,$(LDMAP_OPT),$*.map
PLUGINFLAGS += $(SHARED_CFLAGS) # <-- from Makefile
else
PLUGINLDFLAGS = -T$(PLUGINLINK_LDS) -Wl,--gc-sections -Wl,-Map,$*.map

View file

@ -48,14 +48,14 @@ $(PUZZLES_OBJDIR)/sgt-%.rock: $(PUZZLES_OBJDIR)/src/%.o $(PUZZLES_OBJDIR)/help/%
$(call PRINTS,LD $(@F))$(CC) $(PLUGINFLAGS) -o $(PUZZLES_OBJDIR)/$*.elf \
$(filter %.o, $^) \
$(filter %.a, $+) \
-lgcc $(filter-out -Wl%.map, $(PLUGINLDFLAGS)) -Wl,-Map,$(PUZZLES_OBJDIR)/src/$*.map
-lgcc $(filter-out -Wl%.map, $(PLUGINLDFLAGS)) -Wl,$(LDMAP_OPT),$(PUZZLES_OBJDIR)/src/$*.map
$(SILENT)$(call objcopy,$(PUZZLES_OBJDIR)/$*.elf,$@)
$(PUZZLES_OBJDIR)/sgt-%.rock: $(PUZZLES_OBJDIR)/src/unfinished/%.o $(PUZZLES_SHARED_OBJ) $(TLSFLIB)
$(call PRINTS,LD $(@F))$(CC) $(PLUGINFLAGS) -o $(PUZZLES_OBJDIR)/$*.elf \
$(filter %.o, $^) \
$(filter %.a, $+) \
-lgcc $(filter-out -Wl%.map, $(PLUGINLDFLAGS)) -Wl,-Map,$(PUZZLES_OBJDIR)/src/$*.map
-lgcc $(filter-out -Wl%.map, $(PLUGINLDFLAGS)) -Wl,$(LDMAP_OPT),$(PUZZLES_OBJDIR)/src/$*.map
$(SILENT)$(call objcopy,$(PUZZLES_OBJDIR)/$*.elf,$@)
$(PUZZLES_SRCDIR)/rbcompat.h: $(APPSDIR)/plugin.h \

View file

@ -28,8 +28,12 @@
#endif
#ifndef __MINGW32__
#ifdef __APPLE__
#include <sys/types.h>
#else
#include <endian.h>
#endif
#endif
/* clear these out since we redefine them to be truely constant compatible */
#undef swap16

View file

@ -19,7 +19,12 @@
*
****************************************************************************/
#define RB_FILESYSTEM_OS
#ifdef __APPLE__
#include <sys/param.h>
#include <sys/mount.h>
#else
#include <sys/statfs.h> /* lowest common denominator */
#endif
#include <sys/stat.h>
#include <string.h>
#include <errno.h>
@ -218,6 +223,15 @@ void volume_size(IF_MV(int volume,) sector_t *sizep, sector_t *freep)
if (os_volume_path(IF_MV(volume,) volpath, sizeof (volpath)) >= 0
&& !statfs(volpath, &fs))
{
#ifdef __APPLE__
DEBUGF("statvfs: frsize=%d blocks=%ld bfree=%ld\n",
(int)fs.f_bsize, (long)fs.f_blocks, (long)fs.f_bfree);
if (sizep)
size = (fs.f_blocks / 2) * (fs.f_bsize / 512);
if (freep)
free = (fs.f_bfree / 2) * (fs.f_bsize / 512);
#else
DEBUGF("statvfs: frsize=%d blocks=%ld bfree=%ld\n",
(int)fs.f_frsize, (long)fs.f_blocks, (long)fs.f_bfree);
if (sizep)
@ -225,6 +239,7 @@ void volume_size(IF_MV(int volume,) sector_t *sizep, sector_t *freep)
if (freep)
free = (fs.f_bfree / 2) * (fs.f_frsize / 512);
#endif
}
if (sizep)

View file

@ -24,7 +24,9 @@
#include <sys/time.h>
#if !defined(WIN32)
#include <sys/ioctl.h>
#if !defined(__APPLE__)
#include <linux/rtc.h>
#endif
#include <fcntl.h>
#include <unistd.h>
#include <stdbool.h>
@ -47,7 +49,7 @@ int rtc_read_datetime(struct tm *tm)
int rtc_write_datetime(const struct tm *tm)
{
#if !defined(WIN32)
#if !defined(WIN32) && !defined(__APPLE__)
struct timeval tv;
struct tm *tm_time;

View file

@ -26,7 +26,11 @@ CODECFLAGS := $(CFLAGS) $(RBCODEC_CFLAGS) -fstrict-aliasing \
-I$(RBCODECLIB_DIR)/codecs -I$(RBCODECLIB_DIR)/codecs/lib -DCODEC
ifdef APP_TYPE
CODECLDFLAGS = $(SHARED_LDFLAGS) -Wl,--gc-sections -Wl,-Map,$(CODECDIR)/$*.map
ifeq ($(UNAME), Darwin)
CODECLDFLAGS = $(SHARED_LDFLAGS) -Wl,-map,$(CODECDIR)/$*.map
else
CODECLDFLAGS = $(SHARED_LDFLAGS) -Wl,--gc-sections -Wl,-Map,$(CODECDIR)/$*.map
endif
CODECFLAGS += $(SHARED_CFLAGS) # <-- from Makefile
else
CODECLDFLAGS = -T$(CODECLINK_LDS) -Wl,--gc-sections -Wl,-Map,$(CODECDIR)/$*.map

View file

@ -47,6 +47,13 @@ void* codec_calloc(size_t nmemb, size_t size);
void* codec_realloc(void* ptr, size_t size);
void codec_free(void* ptr);
#ifdef __APPLE__
#undef memcpy
#undef strcat
#undef memset
#undef memmove
#undef strcpy
#endif
void *memcpy(void *dest, const void *src, size_t n);
void *memset(void *s, int c, size_t n);
int memcmp(const void *s1, const void *s2, size_t n);

9
tools/configure vendored
View file

@ -14,6 +14,7 @@ CCOPTS="-W -Wall -Wextra -Wundef -Os -nostdlib -ffreestanding -Wstrict-prototype
LDOPTS=""
# LD options for the core + plugins
GLOBAL_LDOPTS=""
LDMAP_OPT="-Map"
extradefines=""
use_logf="#undef ROCKBOX_HAS_LOGF"
@ -260,6 +261,7 @@ simcc () {
app_type=$1
winbuild=""
macbuild=""
GCCOPTS=`echo $CCOPTS | sed -e s/\ -ffreestanding// -e s/\ -nostdlib// -e s/\ -Wundef//`
if [ "yes" = "$use_debug" ]; then
@ -391,7 +393,9 @@ simcc () {
sigaltstack=`check_sigaltstack`
echo "Darwin host detected"
LDOPTS="$LDOPTS -ldl"
SHARED_LDFLAGS="-dynamiclib -Wl\,-single_module"
SHARED_LDFLAGS="-dynamiclib -Wl,-no_warn_duplicate_libraries"
LDMAP_OPT="-map"
macbuild="yes"
;;
SunOS)
@ -409,7 +413,7 @@ simcc () {
esac
fi
if [ "$winbuild" != "yes" ]; then
if [ "$winbuild" != "yes" ] && [ "$macbuild" != "yes" ]; then
GLOBAL_LDOPTS="$GLOBAL_LDOPTS -Wl,-z,defs"
if [ "`uname -m`" = "i686" ]; then
echo "Enabling MMX support"
@ -4875,6 +4879,7 @@ export SHARED_LDFLAGS=${SHARED_LDFLAGS}
export SHARED_CFLAGS=${SHARED_CFLAGS}
export LDOPTS=${LDOPTS}
export GLOBAL_LDOPTS=${GLOBAL_LDOPTS}
export LDMAP_OPT=${LDMAP_OPT}
export GCCVER=${gccver}
export GCCNUM=${gccnum}
export UNAME=${uname}

View file

@ -25,7 +25,12 @@
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#ifdef __APPLE__
#include <libkern/OSByteOrder.h>
#define htole32(x) OSSwapHostToLittleInt32(x)
#else
#include <endian.h> /* TODO: find portable alternative */
#endif
#define SPL_HEADER_SIZE 512
#define SPL_KEY_SIZE 1536

View file

@ -21,8 +21,12 @@ SIMLIB = $(BUILDDIR)/uisimulator/libuisimulator.a
ifeq (yes,$(APPLICATION))
UIBMP=
else
ifeq ($(UNAME), Darwin)
UIBMP=
else
UIBMP=$(BUILDDIR)/UI256.bmp
endif
endif
.SECONDEXPANSION: # $$(OBJ) is not populated until after this
@ -31,8 +35,12 @@ $(SIMLIB): $$(SIMOBJ) $(UIBMP)
$(call PRINTS,AR $(@F))$(AR) rcs $@ $^ >/dev/null
$(BUILDDIR)/$(BINARY): $$(OBJ) $(FIRMLIB) $(VOICESPEEXLIB) $(CORE_LIBS) $(SIMLIB)
ifeq ($(UNAME), Darwin)
$(call PRINTS,LD $(BINARY))$(CC) -o $@ $^ $(SIMLIB) $(LDOPTS) $(GLOBAL_LDOPTS) -Wl,-map,$(BUILDDIR)/rockbox.map
else
$(call PRINTS,LD $(BINARY))$(CC) -o $@ -Wl,--start-group $^ -Wl,--end-group $(LDOPTS) $(GLOBAL_LDOPTS) \
-Wl,-Map,$(BUILDDIR)/rockbox.map
endif
$(SILENT)$(call objcopy,$@,$@)
$(BUILDDIR)/uisimulator/%.o: $(ROOTDIR)/uisimulator/%.c