Skip to content

Commit

Permalink
linux: compile with tundra
Browse files Browse the repository at this point in the history
  • Loading branch information
serge-rgb committed Jan 15, 2017
1 parent cbf4c7c commit 5bc0713
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 147 deletions.
60 changes: 2 additions & 58 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,58 +1,2 @@
CC=clang
CXX=clang++

BUILDDIR = build

SHELL = /bin/bash
CFLAGS = -O0 -g

INCLUDES = -I src \
-I third_party \
-I third_party/imgui \
# -I third_party/SDL2-2.0.3/include

SHG_SOURCES = src/shadergen.cc
MLT_SOURCES = src/milton_unity_build.cc

SHG_CFLAGS = $(CFLAGS) \
-std=c++11 \
-Wno-writable-strings


MLT_CFLAGS = $(CFLAGS) \
-std=c++11 \
`pkg-config --cflags sdl2 gtk+-2.0` \
-std=c++11 \
-Wno-missing-braces \
-Wno-unused-function \
-Wno-unused-variable \
-Wno-unused-result \
-Wno-write-strings \
-Wno-c++11-compat-deprecated-writable-strings \
-Wno-null-dereference \
-Wno-format \
-fno-strict-aliasing \
-fno-omit-frame-pointer \
-ldl \
-Werror

# -fsanitize=address\
MLT_LDFLAGS = $(LDFLAGS) -lGL `pkg-config --libs sdl2 gtk+-2.0` -lXi

all: directories shadergen milton

shadergen:
$(CC) $(SHG_CFLAGS) $(SHG_SOURCES) -o $(BUILDDIR)/shadergen

milton:
pushd $(BUILDDIR) && ./shadergen && popd
$(CXX) $(MLT_CFLAGS) $(INCLUDES) $(MLT_SOURCES) $(MLT_LDFLAGS) -o $(BUILDDIR)/milton

directories:
@mkdir -p $(BUILDDIR)

clean:
rm -rf $(BUILDDIR)

.PHONY: all clean directories
all:
tundra/bin/tundra2
2 changes: 1 addition & 1 deletion src/StrokeList.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

#pragma once

#include "Stroke.h"
#include "stroke.h"

#include "memory.h"

Expand Down
1 change: 1 addition & 0 deletions src/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#pragma once

#include <stdint.h>
#include <stddef.h>

typedef int8_t i8;
typedef int16_t i16;
Expand Down
2 changes: 0 additions & 2 deletions src/gl_helpers.cc
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,6 @@ gl_load()
}
#elif defined(__linux__)
#define GETADDRESS(f, e)
// There is no function prototype for the EXT version of this function but there is for GL core one.
#define glBlitFramebufferEXT glBlitFramebuffer

#if 0
#define GETADDRESS(func) \
Expand Down
5 changes: 5 additions & 0 deletions src/gl_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,3 +51,8 @@ bool gl_set_uniform_vec2i(GLuint program, char* name, size_t count, i32* vals);
bool gl_set_uniform_f(GLuint program, char* name, float val);
bool gl_set_uniform_i(GLuint program, char* name, i32 val);
bool gl_set_uniform_vec2i(GLuint program, char* name, i32 x, i32 y);

#if defined(__linux__)
// There is no function prototype for the EXT version of this function but there is for GL core one.
#define glBlitFramebufferEXT glBlitFramebuffer
#endif
13 changes: 2 additions & 11 deletions src/platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,6 @@ enum FileKind
};



#define fopen fopen_error

FILE* fopen_error(const char* fname, const char* mode);
#if !defined(MAX_PATH) && defined(PATH_MAX)
#define MAX_PATH PATH_MAX
#endif
Expand Down Expand Up @@ -186,13 +182,8 @@ void win32_log(char *format, ...);

#if defined(_WIN32)
#include "platform_windows.h"
// TODO: Fix linux/mac compilation...
#elif defined(__linux__)
#include "platform_unix.cc"
#include "platform_linux.cc"
#elif defined(__MACH__)
#include "platform_unix.cc"
#include "platform_mac.cc"
#elif defined(__linux__) || defined(__MACH__)
#include "platform_unix.h"
#endif


Expand Down
10 changes: 5 additions & 5 deletions src/platform_linux.cc
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#include "platform.h"

#include "common.h"
#include "memory.h"

#define IMPL_MISSING mlt_assert(!"IMPLEMENT")

// #define _GNU_SOURCE //temporarily targeting gcc for program_invocation_name
#include <sys/stat.h>
#include <sys/time.h>
#include <errno.h>
#include <time.h>

float
perf_count_to_sec(u64 counter)
Expand Down
64 changes: 5 additions & 59 deletions src/platform_unix.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,12 @@
// License: https://github.com/serge-rgb/milton#license


#ifdef __linux__
#ifndef _GNU_SOURCE
#define _GNU_SOURCE // To get MAP_ANONYMOUS on linux
#endif
#include <gtk/gtk.h>
#define __USE_MISC 1 // MAP_ANONYMOUS and MAP_NORESERVE dont' get defined without this
#include <sys/mman.h>
#undef __USE_MISC
#include <unistd.h>

#include <X11/Xlib.h>
#include <X11/extensions/XInput.h>
#if 0
#include <X11/extensions/XIproto.h>
#include <X11/keysym.h>
#endif

#define BREAKHERE raise(SIGTRAP)

#elif defined(__MACH__)
#include <sys/mman.h>
#include <unistd.h> // getpid
#else
#error "This is not the Unix you're looking for"
#endif

#define HEAP_BEGIN_ADDRESS NULL
#if MILTON_DEBUG
#undef HEAP_BEGIN_ADDRESS
#define HEAP_BEGIN_ADDRESS (void*)(1024LL * 1024 * 1024 * 1024)
#endif

#ifndef MAP_ANONYMOUS

#ifndef MAP_ANON
#error "MAP_ANONYMOUS flag not found!"
#else
#define MAP_ANONYMOUS MAP_ANON
#endif

#endif // MAP_ANONYMOUS


#define PATH_STRLEN strlen
#define PATH_TOLOWER tolower
#define PATH_STRCMP strcmp
#define PATH_STRNCPY strncpy
#define PATH_STRCPY strcpy
//#define PATH_STRCAT strcat
#define PATH_STRNCAT strncat
#define PATH_SNPRINTF snprintf
#define platform_milton_log printf

#if defined(__MACH__)
// Include header for our SDL hook.
#include "platform_OSX_SDL_hooks.h"
#endif
#include "platform.h"
#include "platform_unix.h"

// Define this function before we substitute fopen in Milton with a macro.
FILE* fopen_unix(const char* fname, const char* mode)
FILE*
fopen_unix(const char* fname, const char* mode)
{
FILE* fd = fopen(fname, mode);
return fd;
Expand Down Expand Up @@ -98,7 +44,7 @@ typedef struct UnixMemoryHeader_s
void*
platform_allocate(size_t size)
{
u8* ptr = (u8*)mmap(HEAP_BEGIN_ADDRESS, size + sizeof(UnixMemoryHeader),
u8* ptr = (u8*)mmap(NULL, size + sizeof(UnixMemoryHeader),
PROT_WRITE | PROT_READ,
/*MAP_NORESERVE |*/ MAP_PRIVATE | MAP_ANONYMOUS,
-1, 0);
Expand Down
60 changes: 60 additions & 0 deletions src/platform_unix.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@

#ifdef __linux__
#ifndef _GNU_SOURCE
#define _GNU_SOURCE // To get MAP_ANONYMOUS on linux
#endif
#include <gtk/gtk.h>
#define __USE_MISC 1 // MAP_ANONYMOUS and MAP_NORESERVE dont' get defined without this
#include <sys/mman.h>
#undef __USE_MISC
#include <unistd.h>

#include <X11/Xlib.h>
#include <X11/extensions/XInput.h>
#if 0
#include <X11/extensions/XIproto.h>
#include <X11/keysym.h>
#endif
// #define _GNU_SOURCE //temporarily targeting gcc for program_invocation_name
#include <sys/stat.h>
#include <sys/time.h>
#include <errno.h>
#include <time.h>
#include <ctype.h>

#define BREAKHERE raise(SIGTRAP)

#elif defined(__MACH__)
#include <sys/mman.h>
#include <unistd.h> // getpid
#else
#error "This is not the Unix you're looking for"
#endif

#ifndef MAP_ANONYMOUS

#ifndef MAP_ANON
#error "MAP_ANONYMOUS flag not found!"
#else
#define MAP_ANONYMOUS MAP_ANON
#endif

#endif // MAP_ANONYMOUS


#define PATH_STRLEN strlen
#define PATH_TOLOWER tolower
#define PATH_STRCMP strcmp
#define PATH_STRNCPY strncpy
#define PATH_STRCPY strcpy
//#define PATH_STRCAT strcat
#define PATH_STRNCAT strncat
#define PATH_SNPRINTF snprintf
#define platform_milton_log printf

#if defined(__MACH__)
// Include header for our SDL hook.
#include "platform_OSX_SDL_hooks.h"
#endif

FILE* fopen_unix(const char* fname, const char* mode);
7 changes: 0 additions & 7 deletions src/sdl_milton.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,6 @@
#include "persist.h"


FILE*
fopen_error(const char* fname, const char* mode)
{
INVALID_CODE_PATH; // Use platform_fopen
return NULL;
}

static void
cursor_set_and_show(SDL_Cursor* cursor)
{
Expand Down
53 changes: 49 additions & 4 deletions tundra.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

Build {
Env = {
CPPPATH = { "third_party", "third_party/imgui", "third_party/SDL2-2.0.3/include" },
CPPPATH = { "third_party",
"third_party/imgui",
{"third_party/SDL2-2.0.3/include"; Config = "win*"},
"src"
},
CXXOPTS = { }
},

Expand All @@ -16,8 +20,11 @@ Build {
},
DefRule {
Name = "ShaderGen",
Command = "pushd $(OBJECTROOT)$(SEP)$(BUILD_ID) && shadergen.exe",
ImplicitInputs = { "$(OBJECTROOT)$(SEP)$(BUILD_ID)$(SEP)shadergen.exe" },
-- Command = "pushd $(OBJECTROOT)$(SEP)$(BUILD_ID) && shadergen.exe",
-- ImplicitInputs = { "$(OBJECTROOT)$(SEP)$(BUILD_ID)$(SEP)shadergen.exe" },
Command = "cd $(OBJECTROOT)$(SEP)$(BUILD_ID) && ./shadergen",
ImplicitInputs = { "$(OBJECTROOT)$(SEP)$(BUILD_ID)$(SEP)shadergen" },

Pass = "CodeGeneration",
Blueprint = {
Input = { Type = "string", Required = true },
Expand Down Expand Up @@ -63,7 +70,9 @@ Build {
"src/vector.cc",
"src/sdl_milton.cc",
"src/StrokeList.cc",
"src/platform_windows.cc",
{"src/platform_windows.cc"; Config = { "win*" }},
{"src/platform_unix.cc"; Config = { "linux-*" }},
{"src/platform_linux.cc"; Config = { "linux-*" }},
"src/third_party_libs.cc",

-- ResourceFile { Input="Milton.rc" },
Expand All @@ -79,6 +88,12 @@ Build {
{ "ole32.lib"; Config = { "win*" } },
{ "oleAut32.lib"; Config = { "win*" } },
{ "third_party/bin/SDL2.lib"; Config = { "win*" } },

{ "GL"; Config = "linux-*-*"},
--, "Xi", "m", "c"
{ "m"; Config = "linux-*-*"},
{ "Xi"; Config = "linux-*-*"},
{ "stdc++"; Config = "linux-*-*"},
},
}

Expand Down Expand Up @@ -115,6 +130,36 @@ Build {
ReplaceEnv = {
OBJECTROOT = "build",
},
},
Config {
Name = "linux-clang",
DefaultOnHost = "linux",
Tools = { "clang" },
Env = {
CXXOPTS = {
"-std=c++11",
"`pkg-config --cflags sdl2 gtk+-2.0`",
"-Wno-missing-braces",
"-Wno-unused-function",
"-Wno-unused-variable",
"-Wno-unused-result",
"-Wno-write-strings",
"-Wno-c++11-compat-deprecated-writable-strings",
"-Wno-null-dereference",
"-Wno-format",
"-fno-strict-aliasing",
"-fno-omit-frame-pointer",
"-Werror",
"-O0",
"-g",
},
PROGOPTS = {
"`pkg-config --libs sdl2 gtk+-2.0`",
},
},
ReplaceEnv = {
OBJECTROOT = "build",
},
}
},
}
Binary file added tundra/bin/t2-inspect
Binary file not shown.
Binary file added tundra/bin/t2-lua
Binary file not shown.
Binary file added tundra/bin/tundra2
Binary file not shown.

0 comments on commit 5bc0713

Please sign in to comment.