diff --git a/platform/cocoa/Makefile b/platform/cocoa/Makefile index 581d59c8..e328fd1d 100644 --- a/platform/cocoa/Makefile +++ b/platform/cocoa/Makefile @@ -15,8 +15,13 @@ linkflags = $(mainflags) -mmacosx-version-min=10.6 -lm -pthread cflags := $(mainflags) -c -mmacosx-version-min=10.6 # Link all objects with main flags +# Running some cheeky compiletime code to generate window title with hostname main : $(objects) - $(CC) $(mainflags) $(objects) -o $(appname) -framework Cocoa + $(CC) compile_time_code.c -o compile_time_code; \ + ./compile_time_code; \ + $(CC) $(mainflags) $(objects) -o $(appname) -framework Cocoa; \ + rm compile_time_code; \ + rm app_window_title.h; # Making all objects... main.o : main.m diff --git a/platform/cocoa/compile_time_code.c b/platform/cocoa/compile_time_code.c new file mode 100644 index 00000000..5e53cb20 --- /dev/null +++ b/platform/cocoa/compile_time_code.c @@ -0,0 +1,38 @@ +/* Kind of like a makefile within a makefile, Currently used + * to put build PC's hostname within app title as a constant... + * before it would show the users hotname! not builder's. doh. */ + +#include +#include +#include +/* Host name */ +#include + +#include "gui_stuff/style_config.h" + + +int main(int argc, char * argv[]) +{ + /* Generate App title with build info in a temporary .h file */ + char * app_name = malloc(1024); + char * host_name = malloc(1024); + + gethostname(host_name, 1023); + + snprintf(app_name, 1023, APP_NAME " (" __DATE__ " " __TIME__ " @%s)", host_name); + + printf("Initial app name: %s\n", app_name); + + FILE * app_name_header = fopen("app_window_title.h", "wb"); + + /* Here's our beautiful header file */ + fprintf(app_name_header, "#ifndef _app_window_title_h_\n"); + fprintf(app_name_header, "#define _app_window_title_h_\n\n"); + fprintf(app_name_header, "#define APP_WINDOW_TITLE \"%s\"\n\n", app_name); + fprintf(app_name_header, "%s\n", "#endif"); + + fclose(app_name_header); + + free(host_name); + free(app_name); +} diff --git a/platform/cocoa/main.m b/platform/cocoa/main.m index bc626d0a..1d75799e 100644 --- a/platform/cocoa/main.m +++ b/platform/cocoa/main.m @@ -28,6 +28,9 @@ /* Important stuff */ #include "background_thread.h" +/* This file is generated temorarily during compile time */ +#include "app_window_title.h" + /* Here comes some very global variables */ @@ -103,12 +106,8 @@ int NSApplicationMain(int argc, const char * argv[]) [window setMinSize: NSMakeSize(WINDOW_WIDTH_MINIMUM, WINDOW_HEIGHT_MINIMUM)]; - /* App title with build info */ - { - char host_name[1024]; - gethostname(host_name, 1023); /* Computer's name */ - [window setTitle: [NSString stringWithFormat: @ APP_NAME " (" __DATE__ " " __TIME__ " @%s)", host_name]]; - } + /* App title with build info - a generated macro during compilation */ + [window setTitle: @APP_WINDOW_TITLE]; /* If DARK_STYLE is true set window to dark theme