Skip to content

Commit

Permalink
Make build info **actually** be build info
Browse files Browse the repository at this point in the history
Before, instead of showing build computer's host name, it would show user's host name. Now fixed by adding some code that executes and generates a temporary header file with app title #defined:  compile_time_code.c
TL;DR gethostname() is now executed compile time so user knows who compiled their build (no longer just shows user's computer name).
  • Loading branch information
ilia3101 authored Jul 17, 2017
1 parent a752502 commit 95c636c
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 7 deletions.
7 changes: 6 additions & 1 deletion platform/cocoa/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
38 changes: 38 additions & 0 deletions platform/cocoa/compile_time_code.c
Original file line number Diff line number Diff line change
@@ -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 <stdio.h>
#include <stdlib.h>
#include <string.h>
/* Host name */
#include <unistd.h>

#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);
}
11 changes: 5 additions & 6 deletions platform/cocoa/main.m
Original file line number Diff line number Diff line change
Expand Up @@ -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 */

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 95c636c

Please sign in to comment.