c99 fix, some linux housekeeping
This commit is contained in:
parent
6ba5217c28
commit
9875198a56
5 changed files with 35 additions and 32 deletions
|
@ -40,7 +40,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
else
|
else
|
||||||
UNAMEOS:=$(shell uname)
|
UNAMEOS:=$(shell uname)
|
||||||
ifeq ($(UNAMEOS),Linux)
|
ifeq ($(UNAMEOS),Linux)
|
||||||
PLATFORM_OS=LINUX
|
PLATFORM_OS=linux
|
||||||
LIBPATH=linux
|
LIBPATH=linux
|
||||||
else
|
else
|
||||||
ifeq ($(UNAMEOS),Darwin)
|
ifeq ($(UNAMEOS),Darwin)
|
||||||
|
@ -73,7 +73,9 @@ endif
|
||||||
ifeq ($(PLATFORM),PLATFORM_RPI)
|
ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
CFLAGS = -O2 -s -Wall -std=gnu99 -fgnu89-inline
|
CFLAGS = -O2 -s -Wall -std=gnu99 -fgnu89-inline
|
||||||
else
|
else
|
||||||
CFLAGS = -O2 -s -Wall -std=c99
|
ifeq ($(PLATFORM_OS),LINUX)
|
||||||
|
CFLAGS = -O2 -s -Wall -std=c99 --D_DEFAULT_SOURCE
|
||||||
|
endif
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources
|
CFLAGS = -O1 -Wall -std=c99 -s USE_GLFW=3 -s ASSERTIONS=1 --preload-file resources
|
||||||
|
@ -88,7 +90,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
RAYLIB_PATH = ../release/win32/mingw32
|
RAYLIB_PATH = ../release/win32/mingw32
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
RAYLIB_PATH = ../release/linux
|
RAYLIB_PATH = ../release/linux
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM_OS),OSX)
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
@ -110,7 +112,7 @@ ifeq ($(PLATFORM),PLATFORM_RPI)
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
# add standard directories for GNU/Linux
|
# add standard directories for GNU/Linux
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
INCLUDES += -I/usr/local/include/raylib/
|
INCLUDES += -I/usr/local/include/raylib/
|
||||||
else ifeq ($(PLATFORM_OS),WINDOWS)
|
else ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
# external libraries headers
|
# external libraries headers
|
||||||
|
@ -141,7 +143,7 @@ endif
|
||||||
# define any libraries to link into executable
|
# define any libraries to link into executable
|
||||||
# if you want to link libraries (libname.so or libname.a), use the -lname
|
# if you want to link libraries (libname.so or libname.a), use the -lname
|
||||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
# libraries for Debian GNU/Linux desktop compiling
|
# libraries for Debian GNU/Linux desktop compiling
|
||||||
# requires the following packages:
|
# requires the following packages:
|
||||||
# libglfw3-dev libopenal-dev libegl1-mesa-dev
|
# libglfw3-dev libopenal-dev libegl1-mesa-dev
|
||||||
|
@ -185,6 +187,11 @@ ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
WINFLAGS = ../src/resources -Wl,--subsystem,windows
|
WINFLAGS = ../src/resources -Wl,--subsystem,windows
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# Linux Fix to timespect from
|
||||||
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
|
CFLAGS += -D_DEFAULT_SOURCE
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(PLATFORM),PLATFORM_WEB)
|
ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
EXT = .html
|
EXT = .html
|
||||||
endif
|
endif
|
||||||
|
@ -207,7 +214,6 @@ EXAMPLES = \
|
||||||
core_3d_camera_first_person \
|
core_3d_camera_first_person \
|
||||||
core_2d_camera \
|
core_2d_camera \
|
||||||
core_world_screen \
|
core_world_screen \
|
||||||
core_oculus_rift \
|
|
||||||
shapes_logo_raylib \
|
shapes_logo_raylib \
|
||||||
shapes_basic_shapes \
|
shapes_basic_shapes \
|
||||||
shapes_colors_palette \
|
shapes_colors_palette \
|
||||||
|
@ -338,8 +344,8 @@ core_world_screen: core_world_screen.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
# compile [core] example - oculus rift
|
# compile [core] example - oculus rift
|
||||||
core_oculus_rift: core_oculus_rift.c
|
#core_oculus_rift: core_oculus_rift.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
# $(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
# compile [shapes] example - raylib logo (with basic shapes)
|
# compile [shapes] example - raylib logo (with basic shapes)
|
||||||
shapes_logo_raylib: shapes_logo_raylib.c
|
shapes_logo_raylib: shapes_logo_raylib.c
|
||||||
|
@ -497,13 +503,6 @@ audio_module_playing: audio_module_playing.c
|
||||||
audio_raw_stream: audio_raw_stream.c
|
audio_raw_stream: audio_raw_stream.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
|
||||||
# Linux Fix to timespect from
|
|
||||||
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
|
||||||
CFLAGS += -D_POSIX_C_SOURCE=199309L
|
|
||||||
endif
|
|
||||||
endif
|
|
||||||
|
|
||||||
# compile [physac] example - physics demo
|
# compile [physac] example - physics demo
|
||||||
physics_demo: physics_demo.c
|
physics_demo: physics_demo.c
|
||||||
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
|
$(CC) -o $@$(EXT) $< $(CFLAGS) $(INCLUDES) $(LFLAGS) $(LIBS) -lpthread -D$(PLATFORM) $(WINFLAGS)
|
||||||
|
@ -537,7 +536,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
find . -type f -perm +ugo+x -delete
|
find . -type f -perm +ugo+x -delete
|
||||||
rm -f *.o
|
rm -f *.o
|
||||||
else
|
else
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -f
|
find -type f -executable | xargs file -i | grep -E 'x-object|x-archive|x-sharedlib|x-executable' | rev | cut -d ':' -f 2- | rev | xargs rm -f
|
||||||
else
|
else
|
||||||
del *.o *.exe
|
del *.o *.exe
|
||||||
|
|
16
src/Makefile
16
src/Makefile
|
@ -60,7 +60,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
else
|
else
|
||||||
UNAMEOS:=$(shell uname)
|
UNAMEOS:=$(shell uname)
|
||||||
ifeq ($(UNAMEOS),Linux)
|
ifeq ($(UNAMEOS),Linux)
|
||||||
PLATFORM_OS=LINUX
|
PLATFORM_OS=linux
|
||||||
else
|
else
|
||||||
ifeq ($(UNAMEOS),Darwin)
|
ifeq ($(UNAMEOS),Darwin)
|
||||||
PLATFORM_OS=OSX
|
PLATFORM_OS=OSX
|
||||||
|
@ -153,12 +153,16 @@ endif
|
||||||
|
|
||||||
# define compiler flags:
|
# define compiler flags:
|
||||||
# -O1 defines optimization level
|
# -O1 defines optimization level
|
||||||
|
# -Og enable debugging
|
||||||
# -Wall turns on most, but not all, compiler warnings
|
# -Wall turns on most, but not all, compiler warnings
|
||||||
# -std=c99 defines C language mode (standard C from 1999 revision)
|
# -std=c99 defines C language mode (standard C from 1999 revision)
|
||||||
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
|
||||||
# -fgnu89-inline declaring inline functions support (GCC optimized)
|
# -fgnu89-inline declaring inline functions support (GCC optimized)
|
||||||
# -Wno-missing-braces ignore invalid warning (GCC bug 53119)
|
# -Wno-missing-braces ignore invalid warning (GCC bug 53119)
|
||||||
CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces
|
# -D_DEFAULT_SOURCE use with -std=c99 on Linux to enable timespec and audio
|
||||||
|
#CFLAGS = -O1 -Wall -std=gnu99 -fgnu89-inline -Wno-missing-braces
|
||||||
|
CFLAGS = -O1 -Wall -std=c99 -D_DEFAULT_SOURCE
|
||||||
|
|
||||||
|
|
||||||
# if shared library required, make sure code is compiled as position independent
|
# if shared library required, make sure code is compiled as position independent
|
||||||
ifeq ($(SHARED),YES)
|
ifeq ($(SHARED),YES)
|
||||||
|
@ -213,7 +217,7 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
|
||||||
ifeq ($(PLATFORM_OS),WINDOWS)
|
ifeq ($(PLATFORM_OS),WINDOWS)
|
||||||
OUTPUT_PATH = ../release/win32/mingw32
|
OUTPUT_PATH = ../release/win32/mingw32
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
OUTPUT_PATH = ../release/linux
|
OUTPUT_PATH = ../release/linux
|
||||||
endif
|
endif
|
||||||
ifeq ($(PLATFORM_OS),OSX)
|
ifeq ($(PLATFORM_OS),OSX)
|
||||||
|
@ -264,7 +268,7 @@ ifeq ($(PLATFORM),PLATFORM_WEB)
|
||||||
@echo "libraylib.bc generated (web version)!"
|
@echo "libraylib.bc generated (web version)!"
|
||||||
else
|
else
|
||||||
ifeq ($(SHARED),YES)
|
ifeq ($(SHARED),YES)
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
# compile raylib to shared library version for GNU/Linux.
|
# compile raylib to shared library version for GNU/Linux.
|
||||||
# WARNING: you should type "make clean" before doing this target
|
# WARNING: you should type "make clean" before doing this target
|
||||||
$(CC) -shared -o $(OUTPUT_PATH)/libraylib.so $(OBJS)
|
$(CC) -shared -o $(OUTPUT_PATH)/libraylib.so $(OBJS)
|
||||||
|
@ -333,7 +337,7 @@ utils.o : utils.c utils.h
|
||||||
# TODO: add other platforms.
|
# TODO: add other platforms.
|
||||||
install :
|
install :
|
||||||
ifeq ($(ROOT),root)
|
ifeq ($(ROOT),root)
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
# On GNU/Linux there are some standard directories that contain
|
# On GNU/Linux there are some standard directories that contain
|
||||||
# libraries and header files. These directory (/usr/local/lib and
|
# libraries and header files. These directory (/usr/local/lib and
|
||||||
# /usr/local/include/) are for libraries that are installed
|
# /usr/local/include/) are for libraries that are installed
|
||||||
|
@ -356,7 +360,7 @@ endif
|
||||||
# TODO: see 'install' target.
|
# TODO: see 'install' target.
|
||||||
unistall :
|
unistall :
|
||||||
ifeq ($(ROOT),root)
|
ifeq ($(ROOT),root)
|
||||||
ifeq ($(PLATFORM_OS),LINUX)
|
ifeq ($(PLATFORM_OS),linux)
|
||||||
rm --force /usr/local/include/raylib.h
|
rm --force /usr/local/include/raylib.h
|
||||||
ifeq ($(SHARED),YES)
|
ifeq ($(SHARED),YES)
|
||||||
rm --force /usr/local/lib/libraylib.so
|
rm --force /usr/local/lib/libraylib.so
|
||||||
|
|
10
src/core.c
10
src/core.c
|
@ -105,7 +105,7 @@
|
||||||
#include <string.h> // Required for: strcmp()
|
#include <string.h> // Required for: strcmp()
|
||||||
//#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
//#include <errno.h> // Macros for reporting and retrieving error conditions through error codes
|
||||||
|
|
||||||
#if defined __linux || defined(PLATFORM_WEB)
|
#if defined __linux__ || defined(PLATFORM_WEB)
|
||||||
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
#include <sys/time.h> // Required for: timespec, nanosleep(), select() - POSIX
|
||||||
#elif defined __APPLE__
|
#elif defined __APPLE__
|
||||||
#include <unistd.h> // Required for: usleep()
|
#include <unistd.h> // Required for: usleep()
|
||||||
|
@ -115,7 +115,7 @@
|
||||||
//#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
|
//#define GLFW_INCLUDE_NONE // Disable the standard OpenGL header inclusion on GLFW3
|
||||||
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
#include <GLFW/glfw3.h> // GLFW3 library: Windows, OpenGL context and Input management
|
||||||
|
|
||||||
#ifdef __linux
|
#ifdef __linux__
|
||||||
#define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting
|
#define GLFW_EXPOSE_NATIVE_X11 // Linux specific definitions for getting
|
||||||
#define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window
|
#define GLFW_EXPOSE_NATIVE_GLX // native functions like glfwGetX11Window
|
||||||
#include <GLFW/glfw3native.h> // which are required for hiding mouse
|
#include <GLFW/glfw3native.h> // which are required for hiding mouse
|
||||||
|
@ -641,7 +641,7 @@ int GetScreenHeight(void)
|
||||||
void ShowCursor()
|
void ShowCursor()
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
#ifdef __linux
|
#ifdef __linux__
|
||||||
XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window));
|
XUndefineCursor(glfwGetX11Display(), glfwGetX11Window(window));
|
||||||
#else
|
#else
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
|
@ -654,7 +654,7 @@ void ShowCursor()
|
||||||
void HideCursor()
|
void HideCursor()
|
||||||
{
|
{
|
||||||
#if defined(PLATFORM_DESKTOP)
|
#if defined(PLATFORM_DESKTOP)
|
||||||
#ifdef __linux
|
#ifdef __linux__
|
||||||
XColor col;
|
XColor col;
|
||||||
const char nil[] = {0};
|
const char nil[] = {0};
|
||||||
|
|
||||||
|
@ -2036,7 +2036,7 @@ static void Wait(float ms)
|
||||||
#else
|
#else
|
||||||
#if defined _WIN32
|
#if defined _WIN32
|
||||||
Sleep(ms);
|
Sleep(ms);
|
||||||
#elif defined __linux || defined(PLATFORM_WEB)
|
#elif defined __linux__ || defined(PLATFORM_WEB)
|
||||||
struct timespec req = { 0 };
|
struct timespec req = { 0 };
|
||||||
time_t sec = (int)(ms/1000.0f);
|
time_t sec = (int)(ms/1000.0f);
|
||||||
ms -= (sec*1000);
|
ms -= (sec*1000);
|
||||||
|
|
|
@ -147,7 +147,7 @@ float GetGesturePinchAngle(void); // Get gesture pinch ang
|
||||||
// Functions required to query time on Windows
|
// Functions required to query time on Windows
|
||||||
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
||||||
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
||||||
#elif defined(__linux)
|
#elif defined(__linux__)
|
||||||
#include <sys/time.h> // Required for: timespec
|
#include <sys/time.h> // Required for: timespec
|
||||||
#include <time.h> // Required for: clock_gettime()
|
#include <time.h> // Required for: clock_gettime()
|
||||||
#endif
|
#endif
|
||||||
|
@ -517,7 +517,7 @@ static double GetCurrentTime(void)
|
||||||
time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds
|
time = (double)currentTime/clockFrequency*1000.0f; // Time in miliseconds
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(__linux)
|
#if defined(__linux__)
|
||||||
// NOTE: Only for Linux-based systems
|
// NOTE: Only for Linux-based systems
|
||||||
struct timespec now;
|
struct timespec now;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &now);
|
clock_gettime(CLOCK_MONOTONIC, &now);
|
||||||
|
|
|
@ -249,7 +249,7 @@ PHYSACDEF void ClosePhysics(void);
|
||||||
// Functions required to query time on Windows
|
// Functions required to query time on Windows
|
||||||
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
int __stdcall QueryPerformanceCounter(unsigned long long int *lpPerformanceCount);
|
||||||
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
int __stdcall QueryPerformanceFrequency(unsigned long long int *lpFrequency);
|
||||||
#elif defined(__linux) || defined(PLATFORM_WEB)
|
#elif defined(__linux__) || defined(PLATFORM_WEB)
|
||||||
#include <sys/time.h> // Required for: timespec
|
#include <sys/time.h> // Required for: timespec
|
||||||
#include <time.h> // Required for: clock_gettime()
|
#include <time.h> // Required for: clock_gettime()
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
@ -277,7 +277,7 @@ PHYSACDEF void ClosePhysics(void);
|
||||||
static unsigned int usedMemory = 0; // Total allocated dynamic memory
|
static unsigned int usedMemory = 0; // Total allocated dynamic memory
|
||||||
static bool physicsThreadEnabled = false; // Physics thread enabled state
|
static bool physicsThreadEnabled = false; // Physics thread enabled state
|
||||||
static double currentTime = 0; // Current time in milliseconds
|
static double currentTime = 0; // Current time in milliseconds
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux__) || defined(PLATFORM_WEB)
|
||||||
static double baseTime = 0; // Android and RPI platforms base time
|
static double baseTime = 0; // Android and RPI platforms base time
|
||||||
#endif
|
#endif
|
||||||
static double startTime = 0; // Start time in milliseconds
|
static double startTime = 0; // Start time in milliseconds
|
||||||
|
@ -1906,7 +1906,7 @@ static double GetCurrentTime(void)
|
||||||
time = (double)((double)currentTime/clockFrequency)*1000;
|
time = (double)((double)currentTime/clockFrequency)*1000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux) || defined(PLATFORM_WEB)
|
#if defined(PLATFORM_ANDROID) || defined(PLATFORM_RPI) || defined(__linux__) || defined(PLATFORM_WEB)
|
||||||
struct timespec ts;
|
struct timespec ts;
|
||||||
clock_gettime(CLOCK_MONOTONIC, &ts);
|
clock_gettime(CLOCK_MONOTONIC, &ts);
|
||||||
uint64_t temp = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
uint64_t temp = (uint64_t)ts.tv_sec*1000000000LLU + (uint64_t)ts.tv_nsec;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue