From 921a68e765ca951b14b06c28d57be6c0eacbb259 Mon Sep 17 00:00:00 2001 From: Yuval Dolev Date: Tue, 24 Dec 2019 01:22:56 +0200 Subject: [PATCH] Created separate build files for macOS. --- bin/4ed_build.cpp | 3 +- bin/build-mac.sh | 43 ++++++++++++++++++++++++++ bin/build.sh | 5 ++- bin/build_x86-mac.sh | 5 +++ custom/bin/buildsuper_x64-mac.sh | 30 ++++++++++++++++++ custom/bin/buildsuper_x64.sh | 5 ++- custom/bin/buildsuper_x86-mac.sh | 53 ++++++++++++++++++++++++++++++++ custom/bin/buildsuper_x86.sh | 3 +- platform_mac/mac_4ed.mm | 39 +++++++++++++++-------- platform_mac/mac_4ed_old.m | 16 ++++++---- 10 files changed, 175 insertions(+), 27 deletions(-) create mode 100755 bin/build-mac.sh create mode 100644 bin/build_x86-mac.sh create mode 100755 custom/bin/buildsuper_x64-mac.sh create mode 100755 custom/bin/buildsuper_x86-mac.sh diff --git a/bin/4ed_build.cpp b/bin/4ed_build.cpp index 235e2813..90a1e350 100644 --- a/bin/4ed_build.cpp +++ b/bin/4ed_build.cpp @@ -90,7 +90,7 @@ char *includes[] = { "custom", FOREIGN "/freetype2", 0, }; char *windows_platform_layer[] = { "platform_win32/win32_4ed.cpp", 0 }; char *linux_platform_layer[] = { "platform_linux/linux_4ed.cpp", 0 }; -char *mac_platform_layer[] = { "platform_mac/mac_4ed.m", "platform_mac/mac_4ed.cpp", 0 }; +char *mac_platform_layer[] = { "platform_mac/mac_4ed_old.m", 0 }; char **platform_layers[Platform_COUNT] = { windows_platform_layer, @@ -387,6 +387,7 @@ build(Arena *arena, u32 flags, u32 arch, char *code_path, char **code_files, cha fm_finish_build_line(&line); Temp_Dir temp = fm_pushdir(out_path); + printf("Build: g++ %s -o %s\n", line.build_options, out_file); systemf("g++ %s -o %s", line.build_options, out_file); fm_popdir(temp); } diff --git a/bin/build-mac.sh b/bin/build-mac.sh new file mode 100755 index 00000000..9d77d2e9 --- /dev/null +++ b/bin/build-mac.sh @@ -0,0 +1,43 @@ +#!/bin/bash + +# If any command errors, stop the script +set -e + +# Set up directories (mirrors build.bat) +# NOTE(yuval): Replaced readlink with realpath which works for both macOS and Linux +ME="$(realpath "$0")" +LOCATION="$(dirname "$ME")" +SRC_ROOT="$(dirname "$LOCATION")" +PROJECT_ROOT="$(dirname "$SRC_ROOT")" +if [ ! -d "$PROJECT_ROOT/build" ]; then +mkdir "$PROJECT_ROOT/build" +fi +BUILD_ROOT="$PROJECT_ROOT/build" +BIN_ROOT="$SRC_ROOT/bin" +CUSTOM_ROOT="$SRC_ROOT/custom" +CUSTOM_BIN="$CUSTOM_ROOT/bin" + +# Get the build mode +BUILD_MODE="$1" +if [ -z "$BUILD_MODE" ]; then + BUILD_MODE="-DDEV_BUILD" +fi + +# Get the OS specific flags +chmod +rx "$BIN_ROOT/detect_os.sh" +os=$("$BIN_ROOT/detect_os.sh") + +if [[ "$os" == "linux" ]]; then +WARNINGS="-Wno-write-strings -Wno-comment" +elif [[ "$os" == "mac" ]]; then +WARNINGS="-Wno-write-strings -Wno-comment -Wno-null-dereference -Wno-switch" +fi + +FLAGS="-D_GNU_SOURCE -fPIC -fpermissive $BUILD_MODE" +INCLUDES="-I$SRC_ROOT -I$CUSTOM_ROOT" + +# Execute +clang++ $WARNINGS $FLAGS $INCLUDES "$BIN_ROOT/4ed_build.cpp" -g -o "$BUILD_ROOT/build" +pushd "$SRC_ROOT" +"$BUILD_ROOT/build" +popd diff --git a/bin/build.sh b/bin/build.sh index 90b1fa46..0d01ab2d 100755 --- a/bin/build.sh +++ b/bin/build.sh @@ -4,8 +4,7 @@ set -e # Set up directories (mirrors build.bat) -# NOTE(yuval): Replaced readlink with realpath which works for both macOS and Linux -ME="$(realpath "$0")" +ME="$(readlink -f "$0")" LOCATION="$(dirname "$ME")" SRC_ROOT="$(dirname "$LOCATION")" PROJECT_ROOT="$(dirname "$SRC_ROOT")" @@ -30,7 +29,7 @@ os=$("$BIN_ROOT/detect_os.sh") if [[ "$os" == "linux" ]]; then WARNINGS="-Wno-write-strings -Wno-comment" elif [[ "$os" == "mac" ]]; then -WARNINGS="-Wno-write-strings -Wno-comment -Wno-null-dereference -Wno-switch" +WARNINGS="-Wno-write-strings -Wno-comment -Wno-logical-op-parentheses -Wno-null-dereference -Wno-switch" fi FLAGS="-D_GNU_SOURCE -fPIC -fpermissive $BUILD_MODE" diff --git a/bin/build_x86-mac.sh b/bin/build_x86-mac.sh new file mode 100644 index 00000000..3642eddf --- /dev/null +++ b/bin/build_x86-mac.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +./build.sh -DDEV_BUILD_X86 + + diff --git a/custom/bin/buildsuper_x64-mac.sh b/custom/bin/buildsuper_x64-mac.sh new file mode 100755 index 00000000..e04e79cf --- /dev/null +++ b/custom/bin/buildsuper_x64-mac.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +# If any command errors, stop the script +set -e + +# Store the real CWD +ME="$(realpath "$0")" +LOCATION="$(dirname "$ME")" +CODE_HOME="$(dirname "$LOCATION")" + +# Find the most reasonable candidate build file +SOURCE="$1" +if [ -z "$SOURCE" ]; then + SOURCE="$(readlink -f "$CODE_HOME/4coder_default_bindings.cpp")" +fi + +# NOTE(yuval): Removed -Wno-writable-strings as it is the same as -Wno-write-strings +opts="-Wno-write-strings -Wno-null-dereference -Wno-comment -Wno-switch -g" +arch=-m64 + +preproc_file=4coder_command_metadata.i +meta_macros="-DMETA_PASS" +g++ -I"$CODE_HOME" $meta_macros $arch $opts $debug -std=gnu++0x "$SOURCE" -E -o $preproc_file +g++ -I"$CODE_HOME" $opts $debug -std=gnu++0x "$CODE_HOME/4coder_metadata_generator.cpp" -o "$CODE_HOME/metadata_generator" +"$CODE_HOME/metadata_generator" -R "$CODE_HOME" "$PWD/$preproc_file" + +g++ -I"$CODE_HOME" $arch $opts $debug -std=gnu++0x "$SOURCE" -shared -o custom_4coder.so -fPIC + +rm "$CODE_HOME/metadata_generator" +rm $preproc_file diff --git a/custom/bin/buildsuper_x64.sh b/custom/bin/buildsuper_x64.sh index e04e79cf..6b49d4ab 100755 --- a/custom/bin/buildsuper_x64.sh +++ b/custom/bin/buildsuper_x64.sh @@ -4,7 +4,7 @@ set -e # Store the real CWD -ME="$(realpath "$0")" +ME="$(readlink -f "$0")" LOCATION="$(dirname "$ME")" CODE_HOME="$(dirname "$LOCATION")" @@ -14,8 +14,7 @@ if [ -z "$SOURCE" ]; then SOURCE="$(readlink -f "$CODE_HOME/4coder_default_bindings.cpp")" fi -# NOTE(yuval): Removed -Wno-writable-strings as it is the same as -Wno-write-strings -opts="-Wno-write-strings -Wno-null-dereference -Wno-comment -Wno-switch -g" +opts="-Wno-write-strings -Wno-null-dereference -Wno-comment -Wno-switch -Wno-writable-strings -g" arch=-m64 preproc_file=4coder_command_metadata.i diff --git a/custom/bin/buildsuper_x86-mac.sh b/custom/bin/buildsuper_x86-mac.sh new file mode 100755 index 00000000..e3dde9b0 --- /dev/null +++ b/custom/bin/buildsuper_x86-mac.sh @@ -0,0 +1,53 @@ +#!/bin/bash + +# Store the real CWD +REAL_PWD="$PWD" + +# Find the code home folder +TARGET_FILE="$0" +cd `dirname $TARGET_FILE` +TARGET_FILE=`basename $TARGET_FILE` +while [ -L "$TARGET_FILE" ] +do + TARGET_FILE=`readlink $TARGET_FILE` + cd `dirname $TARGET_FILE` + TARGET_FILE=`basename $TARGET_FILE` +done +PHYS_DIR=`pwd -P` +SCRIPT_FILE=$PHYS_DIR/$TARGET_FILE +code_home=$(dirname "$SCRIPT_FILE") + +# Find the most reasonable candidate build file +SOURCE="$1" +if [ -z "$SOURCE" ]; then + SOURCE="$code_home/4coder_default_bindings.cpp" +fi + +TARGET_FILE="$SOURCE" +cd `dirname $TARGET_FILE` +TARGET_FILE=`basename $TARGET_FILE` +while [ -L "$TARGET_FILE" ] +do + TARGET_FILE=`readlink $TARGET_FILE` + cd `dirname $TARGET_FILE` + TARGET_FILE=`basename $TARGET_FILE` +done +PHYS_DIR=`pwd -P` +SOURCE=$PHYS_DIR/$TARGET_FILE + +# NOTE(yuval): Removed -Wno-writable-strings as it is the same as -Wno-write-strings +opts="-Wno-write-strings -Wno-null-dereference -Wno-comment -Wno-switch -g" +arch=-m32 + +cd "$REAL_PWD" +preproc_file=4coder_command_metadata.i +meta_macros="-DMETA_PASS" +g++ -I"$code_home" $meta_macros $arch $opts $debug -std=gnu++0x "$SOURCE" -E -o $preproc_file +g++ -I"$code_home" $opts $debug -std=gnu++0x "$code_home/4coder_metadata_generator.cpp" -o metadata_generator +./metadata_generator -R "$code_home" "$PWD/$preproc_file" + +g++ -I"$code_home" $arch $opts $debug -std=gnu++0x "$SOURCE" -shared -o custom_4coder.so -fPIC + +rm metadata_generator +rm $preproc_file + diff --git a/custom/bin/buildsuper_x86.sh b/custom/bin/buildsuper_x86.sh index e3dde9b0..46d0ab6e 100755 --- a/custom/bin/buildsuper_x86.sh +++ b/custom/bin/buildsuper_x86.sh @@ -35,8 +35,7 @@ done PHYS_DIR=`pwd -P` SOURCE=$PHYS_DIR/$TARGET_FILE -# NOTE(yuval): Removed -Wno-writable-strings as it is the same as -Wno-write-strings -opts="-Wno-write-strings -Wno-null-dereference -Wno-comment -Wno-switch -g" +opts="-Wno-write-strings -Wno-null-dereference -Wno-comment -Wno-switch -Wno-writable-strings -g" arch=-m32 cd "$REAL_PWD" diff --git a/platform_mac/mac_4ed.mm b/platform_mac/mac_4ed.mm index e5993845..8182c122 100644 --- a/platform_mac/mac_4ed.mm +++ b/platform_mac/mac_4ed.mm @@ -1,16 +1,31 @@ +// #include + int main(int arg_count, char **args){ - Thread_Context _tctx = {}; - thread_ctx_init(&_tctx, ThreadKind_Main, - get_base_allocator_system(), - get_base_allocator_system()); - - block_zero_struct(&global_mac_vars); - global_mac_vars.tctx = &_tctx; - - // NOTE(yuval): Application Core Update - Application_Step_Result result = {}; - if (app.step != 0){ - result = app.step(mac_vars.tctx, &target, base_ptr, &input); + @autoreleasepool{ + // NOTE(yuval): NSApplication & Delegate Creation + NSApplication* app = [NSApplication sharedApplication]; + [NSApp setActivationPolicy:NSApplicationActivationPolicyRegular]; + + App_Delegate* app_delegate = [[App_Delegate alloc] init]; + [app setDelegate:app_delegate]; + + [NSApp finishLaunching]; + +#if 0 + Thread_Context _tctx = {}; + thread_ctx_init(&_tctx, ThreadKind_Main, + get_base_allocator_system(), + get_base_allocator_system()); + + block_zero_struct(&global_mac_vars); + global_mac_vars.tctx = &_tctx; + + // NOTE(yuval): Application Core Update + Application_Step_Result result = {}; + if (app.step != 0){ + result = app.step(mac_vars.tctx, &target, base_ptr, &input); + } +#endif } } \ No newline at end of file diff --git a/platform_mac/mac_4ed_old.m b/platform_mac/mac_4ed_old.m index ebadc1ca..098da2fe 100644 --- a/platform_mac/mac_4ed_old.m +++ b/platform_mac/mac_4ed_old.m @@ -9,6 +9,7 @@ // TOP +#if 0 #define IS_OBJC_LAYER #include "4coder_base_types.h" @@ -23,6 +24,8 @@ #define external #include "osx_objective_c_to_cpp_links.h" +#endif + #include #import @@ -30,7 +33,7 @@ #import #import #import - +#if 0 #include #include #include @@ -814,9 +817,9 @@ osx_list_loadable_fonts(void){ NSString *font_n = fonts[i]; char *font_n_c = (char*)[font_n UTF8String]; NSFont *font = [font_manager - fontWithFamily:font_n - traits:NSUnboldFontMask|NSUnitalicFontMask - weight:5 + fontWithFamily:font_n + traits:NSUnboldFontMask|NSUnitalicFontMask + weight:5 size:12]; NSString *path = get_font_path(font); char *path_c = 0; @@ -840,9 +843,10 @@ OSX_Keyboard_Modifiers osx_get_modifiers(void){ return(osx_mods_nsevent_to_struct([NSEvent modifierFlags])); } - +#endif int main(int argc, char **argv){ +#if 0 memset(&osx_objc, 0, sizeof(osx_objc)); u32 clipboard_size = KB(16); @@ -887,7 +891,7 @@ main(int argc, char **argv){ [NSApp run]; } - +#endif return(0); }