Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Easier build on M1 #577

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 33 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@

LBITS := $(shell getconf LONG_BIT)
MARCH ?= $(LBITS)
ARCH ?= $(shell uname -m)

PREFIX ?= /usr/local
INSTALL_DIR ?= $(PREFIX)
INSTALL_BIN_DIR ?= $(PREFIX)/bin
Expand All @@ -9,7 +11,7 @@ INSTALL_INCLUDE_DIR ?= $(PREFIX)/include

LIBS=fmt sdl ssl openal ui uv mysql sqlite

CFLAGS = -Wall -O3 -I src -msse2 -mfpmath=sse -std=c11 -D LIBHL_EXPORTS
CFLAGS = -Wall -O3 -I src -std=c11 -D LIBHL_EXPORTS
LFLAGS = -L. -lhl
EXTRA_LFLAGS ?=
LIBFLAGS =
Expand Down Expand Up @@ -81,26 +83,48 @@ else ifeq ($(UNAME),Darwin)

# Mac
LIBEXT=dylib
CFLAGS += -m$(MARCH) -I include -I /usr/local/include -I /usr/local/opt/libjpeg-turbo/include \
-I /usr/local/opt/jpeg-turbo/include -I /usr/local/opt/sdl2/include -I /usr/local/opt/libvorbis/include \
-I /usr/local/opt/openal-soft/include -Dopenal_soft -DGL_SILENCE_DEPRECATION
LFLAGS += -Wl,-export_dynamic -L/usr/local/lib

BPREFIX := $(shell brew --prefix)

BREW_LIBJPEG := $(shell brew --prefix libjpeg)
BREW_SDL2 := $(shell brew --prefix sdl2)
BREW_JPEGTURBO := $(shell brew --prefix jpeg-turbo)
BREW_VORBIS := $(shell brew --prefix libvorbis)
BREW_OPENAL := $(shell brew --prefix openal-soft)
BREW_MBEDTLS := $(shell brew --prefix mbedtls@2)
BREW_LIBPNG := $(shell brew --prefix libpng)
BREW_LIBOGG := $(shell brew --prefix libogg)
BREW_LIBUV := $(shell brew --prefix libuv)

CFLAGS += -m$(MARCH) -I include -I $(BREW_LIBJPEG)/include \
-I $(BREW_JPEGTURBO)/include -I $(BREW_SDL2)/include -I $(BREW_VORBIS)/include \
-I $(BREW_MBEDTLS)/include -I $(BREW_LIBPNG)/include -I $(BREW_LIBOGG)/include \
-I $(BREW_LIBUV)/include \
-I $(BREW_OPENAL)/include -Dopenal_soft -DGL_SILENCE_DEPRECATION
LFLAGS += -Wl,-export_dynamic

ifdef OSX_SDK
ISYSROOT = $(shell xcrun --sdk macosx$(OSX_SDK) --show-sdk-path)
CFLAGS += -isysroot $(ISYSROOT)
LFLAGS += -isysroot $(ISYSROOT)
endif

LIBFLAGS += -L/usr/local/opt/libjpeg-turbo/lib -L/usr/local/opt/jpeg-turbo/lib -L/usr/local/lib -L/usr/local/opt/libvorbis/lib -L/usr/local/opt/openal-soft/lib
LIBFLAGS += -L$(BREW_LIBJPEG)/lib -L$(BREW_SDL2)/lib -L$(BREW_JPEGTURBO)/lib \
-L$(BREW_VORBIS)/lib -L$(BREW_OPENAL)/lib -L$(BREW_MBEDTLS)/lib \
-L$(BREW_LIBPNG)/lib -L$(BREW_LIBOGG)/lib -L$(BREW_LIBUV)/lib
LIBOPENGL = -framework OpenGL
LIBOPENAL = -lopenal
LIBSSL = -framework Security -framework CoreFoundation
RELEASE_NAME = osx

# Mac native debug
ifneq ($(ARCH),arm64)
HL_DEBUG = include/mdbg/mdbg.o include/mdbg/mach_excServer.o include/mdbg/mach_excUser.o
LIB += ${HL_DEBUG}
endif

CFLAGS += -arch $(ARCH)
LFLAGS += -arch $(ARCH)

else

Expand Down Expand Up @@ -155,7 +179,7 @@ src/std/regexp.o: src/std/regexp.c
${CC} ${CFLAGS} -o $@ -c $< ${PCRE_FLAGS}

libhl: ${LIB}
${CC} -o libhl.$(LIBEXT) -m${MARCH} ${LIBFLAGS} -shared ${LIB} -lpthread -lm
${CC} ${CFLAGS} -o libhl.$(LIBEXT) -m${MARCH} ${LIBFLAGS} -shared ${LIB} -lpthread -lm

hlc: ${BOOT}
${CC} ${CFLAGS} -o hlc ${BOOT} ${LFLAGS} ${EXTRA_LFLAGS}
Expand Down Expand Up @@ -211,8 +235,8 @@ release_haxelib_package:
mkdir $(HLIB)_release
(cd libs/$(HLIB) && cp -R $(HLPACK) *.h *.c* haxelib.json ../../$(HLIB)_release | true)
zip -r $(HLIB).zip $(HLIB)_release
haxelib submit $(HLIB).zip
rm -rf $(HLIB)_release
#haxelib submit $(HLIB).zip
#rm -rf $(HLIB)_release

BUILD_DIR ?= .
PACKAGE_NAME := hashlink-$(shell $(BUILD_DIR)/hl --version)-$(RELEASE_NAME)
Expand Down
5 changes: 5 additions & 0 deletions include/mdbg/mach_excServer.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

/* Module mach_exc */

#ifdef __x86_64__

#define __MIG_check__Request__mach_exc_subsystem__ 1

#include <string.h>
Expand Down Expand Up @@ -803,3 +805,6 @@ mig_external mig_routine_t mach_exc_server_routine

return catch_mach_exc_subsystem.routine[msgh_id].stub_routine;
}

#endif

6 changes: 6 additions & 0 deletions include/mdbg/mach_excUser.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
* with a MiG generated by bootstrap_cmds-116
* OPTIONS:
*/

#ifdef __x86_64__

#define __MIG_check__Reply__mach_exc_subsystem__ 1

#include "mach_exc.h"
Expand Down Expand Up @@ -808,3 +811,6 @@ mig_external kern_return_t mach_exception_raise_state_identity

return KERN_SUCCESS;
}

#endif

5 changes: 5 additions & 0 deletions include/mdbg/mdbg.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
* DEALINGS IN THE SOFTWARE.
*/

#ifdef __x86_64__

#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
Expand Down Expand Up @@ -882,3 +884,6 @@ void* MDBG_API(read_register)( pid_t pid, int thread, int reg, bool is64 ) {
status_t MDBG_API(write_register)( pid_t pid, int thread, int reg, void *value, bool is64 ) {
return write_register( get_task(pid), thread, reg, value, is64 ) == KERN_SUCCESS;
}

#endif

8 changes: 3 additions & 5 deletions libs/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,9 @@ endif()

# add_subdirectory(mesa)

if(WIN32)
option(WITH_OPENAL "Build openal.hdll." ON)
if(WITH_OPENAL)
add_subdirectory(openal)
endif()
option(WITH_OPENAL "Build openal.hdll." ON)
if(WITH_OPENAL)
add_subdirectory(openal)
endif()

option(WITH_SDL "Build sdl.hdll." ON)
Expand Down
39 changes: 26 additions & 13 deletions libs/openal/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,31 +1,44 @@
add_library(openal.hdll SHARED openal.c)

if(WIN32)
if(MSVC)
set(CMAKE_SHARED_LINKER_FLAGS "${CMAKE_SHARED_LINKER_FLAGS} /SAFESEH:NO")
endif()

if(CMAKE_SIZEOF_VOID_P EQUAL 8)
find_library(OpenAL_LIBRARY OpenAL32 PATHS ${INCLUDES_BASE_DIR}/openal/libs/Win64)
find_library(OPENAL_LIBRARY OpenAL32 PATHS ${INCLUDES_BASE_DIR}/openal/libs/Win64)
else()
find_library(OpenAL_LIBRARY OpenAL32 PATHS ${INCLUDES_BASE_DIR}/openal/libs/Win32)
find_library(OPENAL_LIBRARY OpenAL32 PATHS ${INCLUDES_BASE_DIR}/openal/libs/Win32)
endif()

add_library(openal.hdll SHARED openal.c)

set_as_hdll(openal)

target_include_directories(openal.hdll
PRIVATE
${INCLUDES_BASE_DIR}/openal/include
)

target_link_libraries(openal.hdll
libhl
${OpenAL_LIBRARY}
)

install(
TARGETS
openal.hdll
DESTINATION ${HDLL_DESTINATION}
)
else()
find_package(OpenAL)
target_compile_definitions(openal.hdll
PRIVATE
CMAKE_BUILD
)
target_include_directories(openal.hdll
PRIVATE
${OPENAL_INCLUDE_DIR}
)
endif()

set_as_hdll(openal)
target_link_libraries(openal.hdll
libhl
${OPENAL_LIBRARY}
)

install(
TARGETS
openal.hdll
DESTINATION ${HDLL_DESTINATION}
)
8 changes: 6 additions & 2 deletions libs/openal/openal.c
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
#define HL_NAME(n) openal_##n
#include <hl.h>

#if defined(__APPLE__) && !defined(openal_soft)
#if defined(CMAKE_BUILD)
#include "al.h"
#include "alc.h"
#include "alext.h"
#elif defined(__APPLE__) && !defined(openal_soft)
#include <OpenAL/al.h>
#include <OpenAL/alc.h>
#else
Expand Down Expand Up @@ -1041,4 +1045,4 @@ DEFINE_PRIM(_I32, al_get_auxiliary_effect_sloti, _I32 _I32);
DEFINE_PRIM(_VOID, al_get_auxiliary_effect_slotiv, _I32 _I32 _BYTES);
DEFINE_PRIM(_F32, al_get_auxiliary_effect_slotf, _I32 _I32);
DEFINE_PRIM(_VOID, al_get_auxiliary_effect_slotfv, _I32 _I32 _BYTES);
#endif
#endif
25 changes: 13 additions & 12 deletions src/std/debug.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@
# define USE_PTRACE
#endif

#ifdef HL_MAC
#if defined(HL_MAC) && defined(__x86_64__)
# include <mdbg/mdbg.h>
# define MAC_DEBUG
#endif

#if defined(HL_WIN)
Expand Down Expand Up @@ -66,7 +67,7 @@ HL_API bool hl_debug_start( int pid ) {
# if defined(HL_WIN)
last_pid = -1;
return (bool)DebugActiveProcess(pid);
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_session_attach(pid);
# elif defined(USE_PTRACE)
return ptrace(PTRACE_ATTACH,pid,0,0) >= 0;
Expand All @@ -80,7 +81,7 @@ HL_API bool hl_debug_stop( int pid ) {
BOOL b = DebugActiveProcessStop(pid);
CleanHandles();
return (bool)b;
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_session_detach(pid);
# elif defined(USE_PTRACE)
return ptrace(PTRACE_DETACH,pid,0,0) >= 0;
Expand All @@ -92,7 +93,7 @@ HL_API bool hl_debug_stop( int pid ) {
HL_API bool hl_debug_breakpoint( int pid ) {
# if defined(HL_WIN)
return (bool)DebugBreakProcess(OpenPID(pid));
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_session_pause(pid);
# elif defined(USE_PTRACE)
return kill(pid,SIGTRAP) == 0;
Expand All @@ -104,7 +105,7 @@ HL_API bool hl_debug_breakpoint( int pid ) {
HL_API bool hl_debug_read( int pid, vbyte *addr, vbyte *buffer, int size ) {
# if defined(HL_WIN)
return (bool)ReadProcessMemory(OpenPID(pid),addr,buffer,size,NULL);
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_read_memory(pid, addr, buffer, size);
# elif defined(USE_PTRACE)
while( size ) {
Expand All @@ -128,7 +129,7 @@ HL_API bool hl_debug_read( int pid, vbyte *addr, vbyte *buffer, int size ) {
HL_API bool hl_debug_write( int pid, vbyte *addr, vbyte *buffer, int size ) {
# if defined(HL_WIN)
return (bool)WriteProcessMemory(OpenPID(pid),addr,buffer,size,NULL);
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_write_memory(pid, addr, buffer, size);
# elif defined(USE_PTRACE)
while( size ) {
Expand All @@ -153,7 +154,7 @@ HL_API bool hl_debug_write( int pid, vbyte *addr, vbyte *buffer, int size ) {
HL_API bool hl_debug_flush( int pid, vbyte *addr, int size ) {
# if defined(HL_WIN)
return (bool)FlushInstructionCache(OpenPID(pid),addr,size);
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return true;
# elif defined(USE_PTRACE)
return true;
Expand All @@ -162,7 +163,7 @@ HL_API bool hl_debug_flush( int pid, vbyte *addr, int size ) {
# endif
}

#ifdef HL_MAC
#if defined(MAC_DEBUG)
static int get_reg( int r ) {
switch( r ) {
case 0: return REG_RSP;
Expand Down Expand Up @@ -243,7 +244,7 @@ HL_API int hl_debug_wait( int pid, int *thread, int timeout ) {
break;
}
return 4;
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_session_wait(pid, thread, timeout);
# elif defined(USE_PTRACE)
int status;
Expand All @@ -268,7 +269,7 @@ HL_API int hl_debug_wait( int pid, int *thread, int timeout ) {
HL_API bool hl_debug_resume( int pid, int thread ) {
# if defined(HL_WIN)
return (bool)ContinueDebugEvent(pid, thread, DBG_CONTINUE);
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_session_resume(pid);
# elif defined(USE_PTRACE)
return ptrace(PTRACE_CONT,pid,0,0) >= 0;
Expand Down Expand Up @@ -340,7 +341,7 @@ HL_API void *hl_debug_read_register( int pid, int thread, int reg, bool is64 ) {
return (void*)*(int_val*)&c.ExtendedRegisters[10*16];
#endif
return (void*)*GetContextReg(&c,reg);
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_read_register(pid, thread, get_reg(reg), is64);
# elif defined(USE_PTRACE)
void *r = get_reg(reg);
Expand Down Expand Up @@ -391,7 +392,7 @@ HL_API bool hl_debug_write_register( int pid, int thread, int reg, void *value,
else
*GetContextReg(&c,reg) = (REGDATA)value;
return (bool)SetThreadContext(OpenTID(thread),&c);
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return mdbg_write_register(pid, thread, get_reg(reg), value, is64);
# elif defined(USE_PTRACE)
return ptrace(PTRACE_POKEUSER,thread,get_reg(reg),value) >= 0;
Expand Down
5 changes: 3 additions & 2 deletions src/std/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -223,8 +223,9 @@ static void _sigtrap_handler(int signum) {
}
#endif

#ifdef HL_MAC
#if defined(HL_MAC) && defined(__x86_64__)
extern bool is_debugger_attached(void);
# define MAC_DEBUG
#endif

HL_PRIM bool hl_detect_debugger() {
Expand All @@ -237,7 +238,7 @@ HL_PRIM bool hl_detect_debugger() {
raise(SIGTRAP);
}
return (bool)debugger_present;
# elif defined(HL_MAC)
# elif defined(MAC_DEBUG)
return is_debugger_attached();
# else
return false;
Expand Down