summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Soffke <christian.soffke@gmail.com>2023-08-12 17:27:43 +0200
committerSolomon Peachy <pizza@shaftnet.org>2024-11-30 22:19:02 -0500
commit1745b745765605c2f3a353a413f5cc66c73bc3cb (patch)
treef5a85dc20889d4a7bc233c3080d647588815c96d
parentf9ae6d65244448a8ad652824e9343d16ba6549d7 (diff)
downloadrockbox-1745b74576.tar.gz
rockbox-1745b74576.zip
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
-rw-r--r--apps/playback.c6
-rw-r--r--apps/plugin.h11
-rw-r--r--apps/plugins/imageviewer/imageviewer.make2
-rw-r--r--apps/plugins/plugins.make2
-rw-r--r--apps/plugins/puzzles/puzzles.make4
-rw-r--r--firmware/include/rbendian.h4
-rw-r--r--firmware/target/hosted/filesystem-unix.c15
-rw-r--r--firmware/target/hosted/rtc.c4
-rw-r--r--lib/rbcodec/codecs/codecs.make6
-rw-r--r--lib/rbcodec/codecs/lib/codeclib.h7
-rwxr-xr-xtools/configure9
-rw-r--r--tools/mkspl-x1000.c5
-rw-r--r--uisimulator/uisimulator.make8
13 files changed, 75 insertions, 8 deletions
diff --git a/apps/playback.c b/apps/playback.c
index 567a7bb2da..3f535ebd9f 100644
--- a/apps/playback.c
+++ b/apps/playback.c
@@ -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)
diff --git a/apps/plugin.h b/apps/plugin.h
index d54f1ae951..0997b73a08 100644
--- a/apps/plugin.h
+++ b/apps/plugin.h
@@ -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);
diff --git a/apps/plugins/imageviewer/imageviewer.make b/apps/plugins/imageviewer/imageviewer.make
index 97af1e98a7..3179685089 100644
--- a/apps/plugins/imageviewer/imageviewer.make
+++ b/apps/plugins/imageviewer/imageviewer.make
@@ -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)
diff --git a/apps/plugins/plugins.make b/apps/plugins/plugins.make
index 4dd55134c9..74d6fb7db7 100644
--- a/apps/plugins/plugins.make
+++ b/apps/plugins/plugins.make
@@ -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
diff --git a/apps/plugins/puzzles/puzzles.make b/apps/plugins/puzzles/puzzles.make
index 8c5bc1de40..7136254bb4 100644
--- a/apps/plugins/puzzles/puzzles.make
+++ b/apps/plugins/puzzles/puzzles.make
@@ -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 \
diff --git a/firmware/include/rbendian.h b/firmware/include/rbendian.h
index 8a6bb43a05..16888335fe 100644
--- a/firmware/include/rbendian.h
+++ b/firmware/include/rbendian.h
@@ -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
diff --git a/firmware/target/hosted/filesystem-unix.c b/firmware/target/hosted/filesystem-unix.c
index 4869d07263..14e977abc0 100644
--- a/firmware/target/hosted/filesystem-unix.c
+++ b/firmware/target/hosted/filesystem-unix.c
@@ -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)
diff --git a/firmware/target/hosted/rtc.c b/firmware/target/hosted/rtc.c
index 05c8f75ef7..b41862f977 100644
--- a/firmware/target/hosted/rtc.c
+++ b/firmware/target/hosted/rtc.c
@@ -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;
diff --git a/lib/rbcodec/codecs/codecs.make b/lib/rbcodec/codecs/codecs.make
index fbb71f11a8..c9077ae890 100644
--- a/lib/rbcodec/codecs/codecs.make
+++ b/lib/rbcodec/codecs/codecs.make
@@ -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
diff --git a/lib/rbcodec/codecs/lib/codeclib.h b/lib/rbcodec/codecs/lib/codeclib.h
index 6a18870898..daaa21f423 100644
--- a/lib/rbcodec/codecs/lib/codeclib.h
+++ b/lib/rbcodec/codecs/lib/codeclib.h
@@ -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);
diff --git a/tools/configure b/tools/configure
index aa905a3203..d37a62903c 100755
--- a/tools/configure
+++ b/tools/configure
@@ -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}
diff --git a/tools/mkspl-x1000.c b/tools/mkspl-x1000.c
index 1754681d41..ed481a0149 100644
--- a/tools/mkspl-x1000.c
+++ b/tools/mkspl-x1000.c
@@ -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
diff --git a/uisimulator/uisimulator.make b/uisimulator/uisimulator.make
index 2641353bc9..091bdd1c43 100644
--- a/uisimulator/uisimulator.make
+++ b/uisimulator/uisimulator.make
@@ -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