moved linux over to build.c system

This commit is contained in:
Allen Webster 2016-09-04 16:41:48 -04:00
parent 7b046c477b
commit a01957a3fc
8 changed files with 3766 additions and 3543 deletions

BIN
4coder_custom.so Executable file

Binary file not shown.

BIN
4ed_app Executable file

Binary file not shown.

View File

@ -0,0 +1,19 @@
CPP_FILES := $(wildcard *.cpp) $(wildcard **/*.cpp)
C_FILES := $(wildcard *.c) $(wildcard **/*.c)
H_FILES := $(wildcard *.h) $(wildcard **/*.h)
WARNINGS := -Wno-write-strings
FLAGS := -D_GNU_SOURCE -fPIC
debug: FLAGS += -DDEV_BUILD
debug: ../build/build
../build/build: $(CPP_FILES) $(C_FILES) $(H_FILES)
gcc $(WARNINGS) $(FLAGS) build.c -g -o $@
../build/build
clean:
$(RM) ../build/build ../build/fsmgen ../build/metagen ../build/4ed_app.so ../build/4ed

316
build.c
View File

@ -4,19 +4,17 @@
// TOP
#include <stdio.h>
#include <stdio.h> // include system for windows
#include <stdlib.h> // include system for linux (YAY!)
#include <stdint.h>
#include <assert.h>
#include <string.h>
//
// reusable
//
#define CL_OPTS \
"/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 " \
"/wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX " \
"/GR- /EHa- /nologo /FC"
// NOTE(allen): Compiler OS cracking.
#if defined(_MSC_VER)
#define IS_CL
@ -25,6 +23,18 @@
#if defined(_WIN32)
# define IS_WINDOWS
# pragma comment(lib, "Kernel32.lib")
#else
# error This compiler/platform combo is not supported yet
#endif
#elif defined(__GNUC__) || defined(__GNUG__)
#define IS_GCC
#if defined(__gnu_linux__)
# define IS_LINUX
#else
# error This compiler/platform combo is not supported yet
#endif
#else
@ -41,6 +51,11 @@ static int32_t error_state = 0;
}while(0)
static void init_time_system();
static uint64_t get_time();
static int32_t get_current_directory(char *buffer, int32_t max);
static void execute(char *dir, char *str);
#if defined(IS_WINDOWS)
typedef uint32_t DWORD;
@ -101,6 +116,69 @@ execute(char *dir, char *str){
}
}
#elif defined(IS_LINUX)
#include <time.h>
#include <unistd.h>
typedef struct Temp_Dir{
char dir[512];
} Temp_Dir;
static Temp_Dir
linux_pushd(char *dir){
Temp_Dir temp;
char *result = getcwd(temp.dir, sizeof(temp.dir));
int32_t chresult = chdir(dir);
if (result == 0 || chresult != 0){
printf("trying pushd %s\n", dir);
assert(result != 0);
assert(chresult == 0);
}
return(temp);
}
static void
linux_popd(Temp_Dir temp){
chdir(temp.dir);
}
static void
init_time_system(){
// NOTE(allen): do nothing
}
static uint64_t
get_time(){
struct timespec spec;
uint64_t result;
clock_gettime(CLOCK_MONOTONIC, &spec);
result = (spec.tv_sec * (uint64_t)(1000000)) + (spec.tv_nsec / (uint64_t)(1000));
return(result);
}
static int32_t
get_current_directory(char *buffer, int32_t max){
int32_t result = 0;
char *d = getcwd(buffer, max);
if (d == buffer){
result = strlen(buffer);
}
return(result);
}
static void
execute(char *dir, char *str){
if (dir){
Temp_Dir temp = linux_pushd(dir);
systemf("%s", str);
linux_popd(temp);
}
else{
systemf("%s", str);
}
}
#else
#error This OS is not supported yet
#endif
@ -112,19 +190,11 @@ execute(char *dir, char *str){
// 4coder specific
//
#define CL_INCLUDES \
"/I..\\foreign /I..\\foreign\\freetype2"
#define CL_LIBS \
"user32.lib winmm.lib gdi32.lib opengl32.lib ..\\foreign\\freetype.lib"
#define CL_ICON \
"..\\foreign\\freetype.lib"
static void
swap_ptr(void **A, void **B){
void *a = *A;
void *b = *B;
swap_ptr(char **A, char **B){
char *a = *A;
char *b = *B;
*A = b;
*B = a;
}
@ -150,6 +220,62 @@ enum{
};
#define BUILD_LINE_MAX 4096
typedef struct Build_Line{
char build_optionsA[BUILD_LINE_MAX];
char build_optionsB[BUILD_LINE_MAX];
char *build_options;
char *build_options_prev;
int32_t build_max;
} Build_Line;
static void
init_build_line(Build_Line *line){
line->build_options = line->build_optionsA;
line->build_options_prev = line->build_optionsB;
line->build_optionsA[0] = 0;
line->build_optionsB[0] = 0;
line->build_max = BUILD_LINE_MAX;
}
#if defined(IS_CL)
#define build_ap(line, str, ...) do{ \
snprintf(line.build_options, \
line.build_max, "%s "str, \
line.build_options_prev, __VA_ARGS__); \
swap_ptr(&line.build_options, \
&line.build_options_prev); \
}while(0)
#elif defined(IS_GCC)
#define build_ap(line, str, ...) do{ \
snprintf(line.build_options, \
line.build_max, "%s "str, \
line.build_options_prev, ##__VA_ARGS__);\
swap_ptr(&line.build_options, \
&line.build_options_prev); \
}while(0)
#endif
#define CL_OPTS \
"/W4 /wd4310 /wd4100 /wd4201 /wd4505 /wd4996 " \
"/wd4127 /wd4510 /wd4512 /wd4610 /wd4390 /WX " \
"/GR- /EHa- /nologo /FC"
#define CL_INCLUDES \
"/I..\\foreign /I..\\foreign\\freetype2"
#define CL_LIBS \
"user32.lib winmm.lib gdi32.lib opengl32.lib " \
"..\\foreign\\freetype.lib"
#define CL_ICON \
"..\\foreign\\freetype.lib"
static void
build_cl(uint32_t flags,
char *code_path, char *code_file,
@ -158,6 +284,51 @@ build_cl(uint32_t flags,
win32_slash_fix(out_path);
win32_slash_fix(code_path);
Build_Line line;
init_build_line(&line);
if (flags & OPTS){
build_ap(line, CL_OPTS);
}
if (flags & INCLUDES){
build_ap(line, CL_INCLUDES);
}
if (flags & LIBS){
build_ap(line, CL_LIBS);
}
if (flags & ICON){
build_ap(line, CL_ICON);
}
if (flags & DEBUG_INFO){
build_ap(line, "/Zi");
}
if (flags & OPTIMIZATION){
build_ap(line, "/O2");
}
if (flags & SHARED_CODE){
build_ap(line, "/LD");
}
if (flags & SUPER){
build_ap(line, "/DFRED_SUPER");
}
if (flags & INTERNAL){
build_ap(line, "/DFRED_INTERNAL");
}
if (flags & KEEP_ASSERT){
build_ap(line, "/DFRED_KEEP_ASSERT");
}
swap_ptr(&line.build_options, &line.build_options_prev);
char link_options[1024];
if (flags & SHARED_CODE){
assert(exports);
@ -167,69 +338,84 @@ build_cl(uint32_t flags,
snprintf(link_options, sizeof(link_options), "/NODEFAULTLIB:library");
}
char build_optionsA[4096];
char build_optionsB[4096];
char *build_options = build_optionsA;
char *build_options_prev = build_optionsB;
int32_t build_max = sizeof(build_optionsA);
systemf("pushd %s & cl %s %s\\%s /Fe%s /link /DEBUG /INCREMENTAL:NO %s",
out_path, line.build_options, code_path, code_file, out_file, link_options);
}
build_optionsA[0] = 0;
build_optionsB[0] = 0;
#define GCC_OPTS \
"-Wno-write-strings -D_GNU_SOURCE -fPIC " \
"-fno-threadsafe-statics -pthread"
#define GCC_INCLUDES \
"-I../foreign"
#define GCC_LIBS \
"-L/usr/local/lib -lX11 -lpthread -lm -lrt " \
"-lGL -ldl -lXfixes -lfreetype -lfontconfig"
static void
build_gcc(uint32_t flags,
char *code_path, char *code_file,
char *out_path, char *out_file,
char *exports){
Build_Line line;
init_build_line(&line);
if (flags & OPTS){
snprintf(build_options, build_max, "%s "CL_OPTS, build_options_prev);
swap_ptr(&build_options, &build_options_prev);
build_ap(line, GCC_OPTS);
}
if (flags & INCLUDES){
snprintf(build_options, build_max, "%s "CL_INCLUDES, build_options_prev);
swap_ptr(&build_options, &build_options_prev);
int32_t size = 0;
char freetype_include[512];
FILE *file = popen("pkg-config --cflags freetype2", "r");
if (file != 0){
fgets(freetype_include, sizeof(freetype_include), file);
size = strlen(freetype_include);
freetype_include[size-1] = 0;
pclose(file);
}
if (flags & LIBS){
snprintf(build_options, build_max, "%s "CL_LIBS, build_options_prev);
swap_ptr(&build_options, &build_options_prev);
}
if (flags & ICON){
snprintf(build_options, build_max, "%s "CL_ICON, build_options_prev);
swap_ptr(&build_options, &build_options_prev);
build_ap(line, GCC_INCLUDES" %s", freetype_include);
}
if (flags & DEBUG_INFO){
snprintf(build_options, build_max, "%s /Zi", build_options_prev);
swap_ptr(&build_options, &build_options_prev);
build_ap(line, "-g -O0");
}
if (flags & OPTIMIZATION){
snprintf(build_options, build_max, "%s /O2", build_options_prev);
swap_ptr(&build_options, &build_options_prev);
build_ap(line, "-O3");
}
if (flags & SHARED_CODE){
snprintf(build_options, build_max, "%s /LD", build_options_prev);
swap_ptr(&build_options, &build_options_prev);
build_ap(line, "-shared");
}
if (flags & SUPER){
snprintf(build_options, build_max, "%s /DFRED_SUPER", build_options_prev);
swap_ptr(&build_options, &build_options_prev);
build_ap(line, "-DFRED_SUPER");
}
if (flags & INTERNAL){
snprintf(build_options, build_max, "%s /DFRED_INTERNAL", build_options_prev);
swap_ptr(&build_options, &build_options_prev);
build_ap(line, "-DFRED_INTERNAL");
}
if (flags & KEEP_ASSERT){
snprintf(build_options, build_max, "%s /DFRED_KEEP_ASSERT", build_options_prev);
swap_ptr(&build_options, &build_options_prev);
build_ap(line, "-DFRED_KEEP_ASSERT");
}
swap_ptr(&build_options, &build_options_prev);
build_ap(line, "%s/%s", code_path, code_file);
systemf("pushd %s & cl %s %s\\%s /Fe%s /link /DEBUG /INCREMENTAL:NO %s",
out_path, build_options, code_path, code_file, out_file, link_options);
if (flags & LIBS){
build_ap(line, GCC_LIBS);
}
swap_ptr(&line.build_options, &line.build_options_prev);
Temp_Dir temp = linux_pushd(out_path);
systemf("g++ %s -o %s", line.build_options, out_file);
linux_popd(temp);
}
static void
@ -239,6 +425,8 @@ build(uint32_t flags,
char *exports){
#if defined(IS_CL)
build_cl(flags, code_path, code_file, out_path, out_file, exports);
#elif defined(IS_GCC)
build_gcc(flags, code_path, code_file, out_path, out_file, exports);
#else
#error The build rule for this compiler is not ready
#endif
@ -254,6 +442,15 @@ buildsuper(char *code_path, char *out_path, char *filename){
systemf("pushd %s & call \"%s\\buildsuper.bat\" %s",
out_path, code_path, filename);
#elif defined(IS_GCC)
Temp_Dir temp = linux_pushd(out_path);
systemf("\"%s/buildsuper.sh\" %s",
code_path, filename);
linux_popd(temp);
#else
#error The build rule for this compiler is not ready
#endif
@ -262,6 +459,14 @@ buildsuper(char *code_path, char *out_path, char *filename){
#define META_DIR "../meta"
#define BUILD_DIR "../build"
#if defined(IS_WINDOWS)
#define PLAT_LAYER "win32_4ed.cpp"
#elif defined(IS_LINUX)
#define PLAT_LAYER "linux_4ed.cpp"
#else
#error No platform layer defined for this OS.
#endif
static void
standard_build(char *cdir, uint32_t flags){
#if 1
@ -298,7 +503,11 @@ standard_build(char *cdir, uint32_t flags){
{
BEGIN_TIME_SECTION();
//buildsuper(cdir, BUILD_DIR, "../code/4coder_default_bindings.cpp");
#if IS_WINDOWS
buildsuper(cdir, BUILD_DIR, "../code/internal_4coder_tests.cpp");
#else
buildsuper(cdir, BUILD_DIR, "../code/power/4coder_experiments.cpp");
#endif
//buildsuper(cdir, BUILD_DIR, "../code/power/4coder_casey.cpp");
//buildsuper(cdir, BUILD_DIR, "../4vim/4coder_chronal.cpp");
END_TIME_SECTION("build custom");
@ -315,16 +524,17 @@ standard_build(char *cdir, uint32_t flags){
{
BEGIN_TIME_SECTION();
build(OPTS | INCLUDES | LIBS | ICON | flags, cdir, "win32_4ed.cpp",
build(OPTS | INCLUDES | LIBS | ICON | flags, cdir, PLAT_LAYER,
BUILD_DIR, "4ed", 0);
END_TIME_SECTION("build 4ed");
}
#endif
}
#if defined(DEV_BUILD)
#if defined(DEV_BUILD)
int main(int argc, char **argv){
init_time_system();

BIN
fsmgen Executable file

Binary file not shown.

View File

@ -128,12 +128,6 @@ struct Application_Links;
#define static_assert(x, ...)
#endif
#if defined(_BSD_SOURCE) || defined(_SVID_SOURCE) || _POSIX_C_SOURCE >= 200809L || _XOPEN_SOURCE >= 700
#define OLD_STAT_NANO_TIME 0
#else
#define OLD_STAT_NANO_TIME 1
#endif
#define SUPPORT_DPI 1
#define LINUX_FONTS 1
@ -3433,7 +3427,7 @@ main(int argc, char **argv)
linuxvars.input.clipboard = linuxvars.clipboard_contents;
linuxvars.new_clipboard = 0;
} else {
linuxvars.input.clipboard = string_zero();
linuxvars.input.clipboard = null_string;
}
linuxvars.app.step(

BIN
metagen Executable file

Binary file not shown.

View File

@ -8,7 +8,7 @@ FLAGS := -D_GNU_SOURCE -fPIC -fno-threadsafe-statics -pthread -I../foreign
# main stuff
debug: FLAGS += -DFRED_INTERNAL=1 -DFRED_SUPER=1 -g -O0
debug: ../metagen ../4ed_app.so ../4ed
debug: ../4ed_app.so ../4ed
../metagen: $(CPP_FILES) $(C_FILES) $(H_FILES)
g++ $(WARNINGS) $(FLAGS) 4ed_metagen.cpp -iquoteforeign -o $@
@ -42,8 +42,8 @@ super32: alpha32
PACKAGE_FILES := ../4ed ../4ed_app.so README.txt TODO.txt
../4coder_super.zip: PACKAGE_FILES += 4coder_*.h 4coder_*.cpp buildsuper.sh SUPERREADME.txt
../4coder_super32.zip: PACKAGE_FILES += 4coder_*.h 4coder_*.cpp buildsuper.sh SUPERREADME.txt
../4coder_super.zip: PACKAGE_FILES += 4coder_*.h 4coder_*.cpp buildsuper.sh
../4coder_super32.zip: PACKAGE_FILES += 4coder_*.h 4coder_*.cpp buildsuper.sh
../4coder_%.zip: %
zip -j $@ $(PACKAGE_FILES)