From 2d5c47d53498976edd7a6f122534422732fd0334 Mon Sep 17 00:00:00 2001 From: Aaron Culliney Date: Sat, 19 Aug 2017 20:05:58 -1000 Subject: [PATCH] Autotools builds on Mac somewhat --- Makefile.am | 1 - configure.ac | 36 ++++++----------------------------- src/audio/soundcore.c | 2 +- src/common.h | 38 +++++++++++++++++++------------------ src/disk.c | 4 ++-- src/interface.c | 15 ++++++++++++--- src/meta/darwin-shim.c | 5 +++++ src/meta/memmngt.h | 2 +- src/meta/trace.h | 2 +- src/misc.c | 8 ++++---- src/test/testcommon.c | 6 +++--- src/test/testcommon.h | 2 +- src/timing.c | 4 ++-- src/video/video.c | 4 ++-- src/video_util/glUtil.h | 2 +- src/video_util/sourceUtil.c | 2 +- 16 files changed, 62 insertions(+), 71 deletions(-) diff --git a/Makefile.am b/Makefile.am index 075371fb..6166831a 100644 --- a/Makefile.am +++ b/Makefile.am @@ -79,7 +79,6 @@ apple2ix_SOURCES = \ apple2ix_CFLAGS = @AM_CFLAGS@ @X_CFLAGS@ apple2ix_CCASFLAGS = $(apple2ix_CFLAGS) -apple2ix_LDFLAGS = -Wl,-z,noexecstack apple2ix_LDADD = @ASM_O@ @VIDEO_O@ @AUDIO_O@ @X_LIBS@ apple2ix_DEPENDENCIES = @ASM_O@ @VIDEO_O@ @AUDIO_O@ diff --git a/configure.ac b/configure.ac index cceb4f62..8fcb9889 100644 --- a/configure.ac +++ b/configure.ac @@ -92,36 +92,6 @@ AC_SUBST(testvm_ASM_O) AC_SUBST([AM_CFLAGS]) -dnl OS Check -AC_EGREP_CPP(unsupported_, [ -#if defined(__ANDROID__) -unsupported_for_now -#elif __APPLE__ -unsupported_for_now - #include "TargetConditionals.h" - #if TARGET_OS_SIMULATOR - #elif TARGET_OS_IPHONE - #elif TARGET_OS_MAC - #else - #endif -#elif __linux -linux -#elif __unix -unix -#elif __posix -posix -#else -unknown -#endif -], [ - AC_MSG_CHECKING([Operating System ]) - AC_MSG_RESULT([unsupported]) - AC_MSG_ERROR([Apparently you have an unsupported OS, build aborted]) -], [ - AC_MSG_CHECKING([Operating System ]) - AC_MSG_RESULT([supported]) -]) - dnl ASM underscore linking test AC_TRY_LINK([asm("_glibc_foobar:");], [glibc_foobar()], [ AC_MSG_NOTICE([Underscores in assembly linkage allowed...]) @@ -133,6 +103,12 @@ AC_TRY_LINK([asm("_glibc_foobar:");], [glibc_foobar()], [ dnl --------------------------------------------------------------------------- +dnl CLI builds extra search areas ... +CPPFLAGS="$CPPFLAGS -I/opt/local/include" +CFLAGS="$CFLAGS -I/opt/local/include" +CXXFLAGS="$CXXFLAGS -I/opt/local/include" +LDFLAGS="$LDFLAGS -L/opt/local/lib" + # Sometimes Flex is installed as Lex, e.g., NetBSD. AC_CHECK_PROG([FLEX], [flex lex], [flex]) # Force the use of `missing' to wrap Flex invocations. diff --git a/src/audio/soundcore.c b/src/audio/soundcore.c index 37ee51d2..5844dd81 100644 --- a/src/audio/soundcore.c +++ b/src/audio/soundcore.c @@ -110,7 +110,7 @@ void audio_shutdown(void) { void audio_pause(void) { // CPU thread owns audio lifecycle (see note above) // Deadlock on Kindle Fire 1st Gen if audio_pause() and audio_resume() happen off CPU thread ... -#ifdef __APPLE__ +#if TARGET_OS_MAC || TARGET_OS_PHONE # warning FIXME TODO : this assert is firing on iOS port ... but the assert is valid ... fix soon #else assert(pthread_self() == cpu_thread_id); diff --git a/src/common.h b/src/common.h index 68a36ae6..a6d505d8 100644 --- a/src/common.h +++ b/src/common.h @@ -16,21 +16,6 @@ # define _GNU_SOURCE 1 #endif -#ifdef __APPLE__ -# warning DEFINING CUSTOM TEMP_FAILURE_RETRY(x) macro -# define TEMP_FAILURE_RETRY(exp) ({ \ - typeof (exp) _rc; \ - do { \ - _rc = (exp); \ - if (_rc == -1 && (errno == EINTR || errno == EAGAIN) ) { \ - usleep(10); \ - } else { \ - break; \ - } \ - } while (1); \ - _rc; }) -#endif - // custom annotations #define INOUT #define INPARM @@ -84,9 +69,11 @@ #include "meta/trace.h" -#ifdef __APPLE__ -#include "darwin-shim.h" -#import +#if __APPLE__ +# include "meta/darwin-shim.h" +# if TARGET_OS_MAC || TARGET_OS_PHONE +# import +# endif #endif #if VIDEO_OPENGL @@ -154,4 +141,19 @@ #define LIKELY(x) __builtin_expect((x), true) #define UNLIKELY(x) __builtin_expect((x), false) +#if !defined(TEMP_FAILURE_RETRY) +# define TEMP_FAILURE_RETRY(exp) ({ \ + typeof (exp) _rc; \ + do { \ + _rc = (exp); \ + if (_rc == -1 && (errno == EINTR || errno == EAGAIN) ) { \ + usleep(10); \ + } else { \ + break; \ + } \ + } while (1); \ + _rc; }) +#endif + + #endif // whole file diff --git a/src/disk.c b/src/disk.c index 65268f26..ab9bad60 100644 --- a/src/disk.c +++ b/src/disk.c @@ -780,7 +780,7 @@ void disk6_init(void) { const char *disk6_eject(int drive) { #if !TESTING -# if __APPLE__ +# if TARGET_OS_MAC || TARGET_OS_PHONE # warning FIXME TODO ... # else assert(cpu_isPaused() && "CPU must be paused for disk ejection"); @@ -877,7 +877,7 @@ const char *disk6_eject(int drive) { const char *disk6_insert(int fd, int drive, const char * const file_name, int readonly) { #if !TESTING -# if __APPLE__ +# if TARGET_OS_MAC || TARGET_OS_PHONE # warning FIXME TODO ... # else assert(cpu_isPaused() && "CPU must be paused for disk insertion"); diff --git a/src/interface.c b/src/interface.c index 9d2ec1af..11a3d537 100644 --- a/src/interface.c +++ b/src/interface.c @@ -1489,7 +1489,11 @@ void c_interface_keyboard_layout() static pthread_mutex_t classic_interface_lock = PTHREAD_MUTEX_INITIALIZER; static pthread_t interface_thread_id = 0; -static void *interface_thread(void *current_key) +typedef struct interface_key_s { + int current_key; +} interface_key_s; + +static void *interface_thread(void *data) { interface_thread_id = pthread_self(); @@ -1504,7 +1508,9 @@ static void *interface_thread(void *current_key) disk_path[PATH_MAX-1] = '\0'; FREE(path); - switch ((__SWORD_TYPE)current_key) { + interface_key_s *interface_key = (interface_key_s *)data; + + switch (interface_key->current_key) { case kF1: c_interface_select_diskette( 0 ); break; @@ -1550,12 +1556,15 @@ static void *interface_thread(void *current_key) void c_interface_begin(int current_key) { + static interface_key_s interface_key = { 0 }; + if (interface_thread_id) { return; } pthread_mutex_lock(&classic_interface_lock); interface_thread_id=1; // interface thread starting ... - pthread_create(&interface_thread_id, NULL, (void *)&interface_thread, (void *)((__SWORD_TYPE)current_key)); + interface_key.current_key = current_key; + pthread_create(&interface_thread_id, NULL, (void *)&interface_thread, &interface_key); pthread_detach(interface_thread_id); } diff --git a/src/meta/darwin-shim.c b/src/meta/darwin-shim.c index 04789c18..2be7d167 100644 --- a/src/meta/darwin-shim.c +++ b/src/meta/darwin-shim.c @@ -9,6 +9,8 @@ * */ +#if __APPLE__ + #include "common.h" #include @@ -40,3 +42,6 @@ int my_clock_gettime(int clk_id, struct timespec *tp) { tp->tv_nsec = diff - (tp->tv_sec * ORWL_GIGA); return 0; } + +#endif + diff --git a/src/meta/memmngt.h b/src/meta/memmngt.h index a2013cf0..6405e4dd 100644 --- a/src/meta/memmngt.h +++ b/src/meta/memmngt.h @@ -66,7 +66,7 @@ int _a2_asprintf(char **strp, const char *fmt, ...); #endif -#ifdef __APPLE__ +#if TARGET_OS_MAC || TARGET_OS_PHONE #define CFRELEASE(x) \ do { \ CFRelease((x)); \ diff --git a/src/meta/trace.h b/src/meta/trace.h index fe05aea5..2be05290 100644 --- a/src/meta/trace.h +++ b/src/meta/trace.h @@ -21,7 +21,7 @@ #define TRACE_TOUCH 0 #if !defined(__linux__) -# warning Linux-specific function call tracing and general profiling not enabled +// TODO FIXME ... implement systrace ... #else extern void _trace_cleanup(void *token); diff --git a/src/misc.c b/src/misc.c index b9b5fa13..daf997e0 100644 --- a/src/misc.c +++ b/src/misc.c @@ -44,7 +44,7 @@ static void _init_common(void) { static __attribute__((constructor)) void __init_common(void) { emulator_registerStartupCallback(CTOR_PRIORITY_FIRST, &_init_common); } -#elif defined(ANDROID) || defined(__APPLE__) +#elif defined(ANDROID) || (TARGET_OS_MAC || TARGET_OS_PHONE) // data_dir is set up elsewhere #else # error "Specify a CONFIG_DATADIR and PACKAGE_NAME" @@ -237,7 +237,7 @@ bool emulator_loadState(int fd, int fdA, int fdB) { } if (UNLIKELY(filePos != fileSiz)) { - LOG("OOPS, state file read: %lu total: %lu", filePos, fileSiz); + LOG("OOPS, state file read: %lu total: %lu", (unsigned long)filePos, (unsigned long)fileSiz); } loaded = true; @@ -375,7 +375,7 @@ void emulator_start(void) { c_keys_set_key(kF8); // show credits before emulation start #endif -#if !defined(__APPLE__) && !defined(ANDROID) +#if !(TARGET_OS_MAC || TARGET_OS_PHONE) && !defined(ANDROID) video_init(); #endif @@ -394,7 +394,7 @@ bool emulator_isShuttingDown(void) { return emulatorShuttingDown; } -#if !defined(__APPLE__) && !defined(ANDROID) +#if !(TARGET_OS_MAC || TARGET_OS_PHONE) && !defined(ANDROID) int main(int _argc, char **_argv) { argc = _argc; argv = _argv; diff --git a/src/test/testcommon.c b/src/test/testcommon.c index 36c73d8f..772defaf 100644 --- a/src/test/testcommon.c +++ b/src/test/testcommon.c @@ -71,7 +71,7 @@ void test_common_init(void) { c_debugger_set_timeout(0); } -#if defined(__APPLE__) +#if (TARGET_OS_MAC || TARGET_OS_PHONE) # define PATHS_COUNT 8 char **_copy_paths_mac(const char *fileName) { const char *fmts[PATHS_COUNT + 1] = { @@ -208,7 +208,7 @@ char **_copy_paths_main(const char *fileName) { #endif char **test_copy_disk_paths(const char *fileName) { -#if defined(__APPLE__) +#if (TARGET_OS_MAC || TARGET_OS_PHONE) return _copy_paths_mac(fileName); #else return _copy_paths_main(fileName); @@ -217,7 +217,7 @@ char **test_copy_disk_paths(const char *fileName) { int test_setup_boot_disk(const char *fileName, int readonly) { -#if defined(__APPLE__) +#if (TARGET_OS_MAC || TARGET_OS_PHONE) char **paths = _copy_paths_mac(fileName); #else char **paths = _copy_paths_main(fileName); diff --git a/src/test/testcommon.h b/src/test/testcommon.h index 0de2d0ec..55dc6e5d 100644 --- a/src/test/testcommon.h +++ b/src/test/testcommon.h @@ -46,7 +46,7 @@ void sha1_to_str(const uint8_t * const md, char *buf); static inline int ASSERT_SHA(const char *SHA_STR) { uint8_t md[SHA_DIGEST_LENGTH]; - uint8_t fb = MALLOC(SCANWIDTH*SCANHEIGHT); + uint8_t *fb = MALLOC(SCANWIDTH*SCANHEIGHT); display_renderStagingFramebuffer(fb); SHA1(fb, SCANWIDTH*SCANHEIGHT, md); FREE(fb); diff --git a/src/timing.c b/src/timing.c index 6e18b5de..45e4c7e0 100644 --- a/src/timing.c +++ b/src/timing.c @@ -172,7 +172,7 @@ void reinitialize(void) { void timing_initialize(void) { #if !TESTING -# ifdef __APPLE__ +# if (TARGET_OS_MAC || TARGET_OS_PHONE) # warning FIXME TODO : this assert is firing on iOS port ... but the assert is valid ... fix soon # else assert(cpu_isPaused() || (pthread_self() == cpu_thread_id)); @@ -284,7 +284,7 @@ static void *cpu_thread(void *dummyptr) { cpu_runloop: do { - LOG("CPUTHREAD %lu LOCKING FOR MAYBE INITIALIZING AUDIO ...", cpu_thread_id); + LOG("CPUTHREAD %lu LOCKING FOR MAYBE INITIALIZING AUDIO ...", (unsigned long)cpu_thread_id); pthread_mutex_lock(&interface_mutex); if (emul_reinitialize_audio) { emul_reinitialize_audio = false; diff --git a/src/video/video.c b/src/video/video.c index ca723351..a5d1bcdf 100644 --- a/src/video/video.c +++ b/src/video/video.c @@ -29,7 +29,7 @@ void video_init(void) { video_initialized = true; assert(pthread_self() != cpu_thread_id); - LOG("(re)setting render_thread_id : %ld -> %ld", render_thread_id, pthread_self()); + LOG("(re)setting render_thread_id : %lu -> %lu", (unsigned long)render_thread_id, (unsigned long)pthread_self()); render_thread_id = pthread_self(); video_clear(); @@ -38,7 +38,7 @@ void video_init(void) { } void _video_setRenderThread(pthread_t id) { - LOG("setting render_thread_id : %ld -> %ld", render_thread_id, id); + LOG("setting render_thread_id : %lu -> %lu", (unsigned long)render_thread_id, (unsigned long)id); render_thread_id = id; } diff --git a/src/video_util/glUtil.h b/src/video_util/glUtil.h index 6f1fbe5a..a673c93e 100644 --- a/src/video_util/glUtil.h +++ b/src/video_util/glUtil.h @@ -16,7 +16,7 @@ #define UNINITIALIZED_GL (-31337) // HACK FIXME TODO : is there an official OpenGL value we can use to signify an uninitialized state? (cannot depend on zero) -#if defined(__APPLE__) +#if (TARGET_OS_MAC || TARGET_OS_PHONE) # define USE_VAO 1 # import # import diff --git a/src/video_util/sourceUtil.c b/src/video_util/sourceUtil.c index 8be3ff95..6a87e644 100644 --- a/src/video_util/sourceUtil.c +++ b/src/video_util/sourceUtil.c @@ -58,7 +58,7 @@ static demoSource *srcLoadSource(const char *filepathname) { demoSource *glshader_createSource(const char *fileName) { demoSource *src = NULL; -#if defined(__APPLE__) +#if (TARGET_OS_MAC || TARGET_OS_PHONE) CFBundleRef mainBundle = CFBundleGetMainBundle(); CFStringRef fileString = CFStringCreateWithCString(/*allocator*/NULL, fileName, CFStringGetSystemEncoding()); CFURLRef fileURL = CFBundleCopyResourceURL(mainBundle, fileString, NULL, NULL);