Working on Makefiles...

This commit is contained in:
Ray San
2017-10-02 14:12:03 +02:00
parent 1288d6a5df
commit b2789949ee
4 changed files with 307 additions and 248 deletions

View File

@ -44,19 +44,16 @@
# possible platforms: PLATFORM_DESKTOP PLATFORM_ANDROID PLATFORM_RPI PLATFORM_WEB
PLATFORM ?= PLATFORM_DESKTOP
# define raylib default path, required to look for emsdk and android-toolchain
RAYLIB_PATH ?= C:/raylib
# define raylib library type: STATIC (.a) or SHARED (.so/.dll)
RAYLIB_LIBTYPE ?= STATIC
# define YES if you want shared/dynamic version of library instead of static (default)
SHARED_RAYLIB ?= NO
# use OpenAL Soft as shared library (.so / .dll)
# NOTE: If defined NO, static OpenAL Soft library should be provided
SHARED_OPENAL ?= NO
# define OpenAL Soft library type: STATIC (.a) or SHARED (.so/.dll)
# NOTE: OpenAL Soft library should be provided in the selected form
OPENAL_LIBTYPE ?= STATIC
# on PLATFORM_WEB force OpenAL Soft shared library
ifeq ($(PLATFORM),PLATFORM_WEB)
SHARED_OPENAL = YES
OPENAL_LIBTYPE = SHARED
endif
# determine if the file has root access (only for installing raylib)
@ -82,9 +79,14 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
endif
endif
ifeq ($(PLATFORM),PLATFORM_RPI)
# RPI cross-compiler
RPI_CROSS_COMPILE ?= NO
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
# Emscripten required variables
EMSDK_PATH = $(RAYLIB_PATH)/emsdk
EMSDK_PATH = C:/emsdk
EMSCRIPTEN_VERSION = 1.37.9
CLANG_VERSION=e1.37.9_64bit
PYTHON_VERSION=2.7.5.3_64bit
@ -100,15 +102,6 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Android architecture: ARM or ARM64
ANDROID_ARCH ?= ARM
# Android compiler: gcc or clang
# NOTE: Define YES to use clang instead of gcc
ANDROID_LLVM ?= NO
endif
ifeq ($(PLATFORM),PLATFORM_RPI)
# RPI cross-compiler
CROSS_COMPILE ?= NO
endif
# define raylib graphics api depending on selected platform
@ -118,14 +111,17 @@ ifeq ($(PLATFORM),PLATFORM_DESKTOP)
#GRAPHICS = GRAPHICS_API_OPENGL_11 # Uncomment to use OpenGL 1.1
#GRAPHICS = GRAPHICS_API_OPENGL_21 # Uncomment to use OpenGL 2.1
endif
ifeq ($(PLATFORM),PLATFORM_RPI)
# on RPI OpenGL ES 2.0 must be used
GRAPHICS = GRAPHICS_API_OPENGL_ES2
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
# on HTML5 OpenGL ES 2.0 is used, emscripten translates it to WebGL 1.0
GRAPHICS = GRAPHICS_API_OPENGL_ES2
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
# by default use OpenGL ES 2.0 on Android
GRAPHICS = GRAPHICS_API_OPENGL_ES2
@ -134,52 +130,41 @@ endif
# NOTE: makefiles targets require tab indentation
# NOTE: define compiler: gcc for C program, define as g++ for C++
# default gcc compiler
# default C compiler: gcc
CC = gcc
# For OS X
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
ifeq ($(PLATFORM_OS),OSX)
CC = clang
# OSX default compiler
CC = clang
endif
endif
# Android toolchain compiler
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(ANDROID_ARCH),ARM)
ifeq ($(ANDROID_LLVM),YES)
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
else
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-gcc
endif
endif
ifeq ($(ANDROID_ARCH),ARM64)
ifeq ($(ANDROID_LLVM),YES)
CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-clang
else
CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-gcc
endif
endif
endif
# RPI cross-compiler
ifeq ($(PLATFORM),PLATFORM_RPI)
ifeq ($(CROSS_COMPILE),YES)
# rpi compiler
ifeq ($(RPI_CROSS_COMPILE),YES)
# RPI cross-compiler
CC = armv6j-hardfloat-linux-gnueabi-gcc
endif
endif
# HTML5 emscripten compiler
ifeq ($(PLATFORM),PLATFORM_WEB)
# HTML5 emscripten compiler
CC = emcc
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Android toolchain (must be provided for desired architecture and compiler)
# NOTE: gcc compiler is being deprecated at Android NDK r16
ifeq ($(ANDROID_ARCH),ARM)
CC = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-clang
endif
ifeq ($(ANDROID_ARCH),ARM64)
CC = $(ANDROID_TOOLCHAIN)/bin/aarch64-linux-android-clang
endif
endif
# default archiver program to pack libraries
AR = ar
# Android archiver
# Android archiver (also depends on desired architecture)
ifeq ($(PLATFORM),PLATFORM_ANDROID)
ifeq ($(ANDROID_ARCH),ARM)
AR = $(ANDROID_TOOLCHAIN)/bin/arm-linux-androideabi-ar
@ -192,6 +177,7 @@ endif
# define compiler flags:
# -O1 defines optimization level
# -Og enable debugging
# -s strip unnecessary data from build
# -Wall turns on most, but not all, compiler warnings
# -std=c99 defines C language mode (standard C from 1999 revision)
# -std=gnu99 defines C language mode (GNU C from 1999 revision)
@ -200,15 +186,16 @@ endif
# -D_DEFAULT_SOURCE use with -std=c99
CFLAGS += -O1 -s -Wall -std=c99 -D_DEFAULT_SOURCE -fgnu89-inline -Wno-missing-braces
# additional flags for compiler (if desired)
#CFLAGS += -Wextra -Wmissing-prototypes -Wstrict-prototypes
ifeq ($(PLATFORM),PLATFORM_WEB)
CFLAGS += -s USE_GLFW=3 -s ASSERTIONS=1 --profiling --preload-file resources
# -O2 # if used, also set --memory-init-file 0
# --memory-init-file 0 # to avoid an external memory initialization code file (.mem)
# -s ALLOW_MEMORY_GROWTH=1 # to allow memory resizing
# -s TOTAL_MEMORY=16777216 # to specify heap memory size (default = 16MB)
# -s USE_PTHREADS=1 # multithreading support
CFLAGS += -s USE_GLFW=3 -s ASSERTIONS=1 --profiling
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Compiler flags for arquitecture
CFLAGS += -march=armv7-a -mfloat-abi=softfp -mfpu=vfpv3-d16
@ -220,54 +207,51 @@ ifeq ($(PLATFORM),PLATFORM_ANDROID)
CFLAGS += -DANDROID -DPLATFORM_ANDROID -D__ANDROID_API__=16
endif
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
# if shared library required, make sure code is compiled as position independent
ifeq ($(SHARED_RAYLIB),YES)
CFLAGS += -fPIC
SHAREDFLAG = BUILDING_DLL
else
SHAREDFLAG = BUILDING_STATIC
# define raylib libtype required compilation flags
ifeq ($(RAYLIB_LIBTYPE),SHARED)
# make sure code is compiled as position independent
# BE CAREFUL: It seems that for gcc -fpic si not the same as -fPIC
# MinGW32 just doesn't need -fPIC, it shows warnings
CFLAGS += -fPIC -DBUILD_LIBTYPE_SHARED
endif
# if static OpenAL Soft required, define the corresponding flags
ifeq ($(SHARED_OPENAL),NO)
SHAREDLIBS += -lopenal32 -lwinmm
SHAREDOPENALFLAG = AL_LIBTYPE_STATIC
# NOTE: ALLIBS flag only required for raylib Win32 SHARED library building
ifeq ($(OPENAL_LIBTYPE),STATIC)
ALLIBS = -lopenal32 -lwinmm
ALFLAGS = AL_LIBTYPE_STATIC
else
SHAREDLIBS += -lopenal32dll
SHAREDOPENALFLAG = SHARED_OPENAL
ALLIBS = -lopenal32dll
endif
#CFLAGSEXTRA = -Wextra -Wmissing-prototypes -Wstrict-prototypes
# define include paths for required headers
# external required libraries (stb and others)
INCLUDES = -I. -Iexternal
INCLUDE_PATHS = -I. -Iexternal
# OpenAL Soft library
INCLUDES += -Iexternal/openal_soft/include
INCLUDE_PATHS += -Iexternal/openal_soft/include
# define any directories containing required header files
ifeq ($(PLATFORM),PLATFORM_DESKTOP)
# GLFW3 library
INCLUDES += -Iexternal/glfw3/include
INCLUDE_PATHS += -Iexternal/glfw3/include
endif
ifeq ($(PLATFORM),PLATFORM_RPI)
# RPI requried libraries
INCLUDES += -I/opt/vc/include
INCLUDES += -I/opt/vc/include/interface/vmcs_host/linux
INCLUDES += -I/opt/vc/include/interface/vcos/pthreads
INCLUDE_PATHS += -I/opt/vc/include
INCLUDE_PATHS += -I/opt/vc/include/interface/vmcs_host/linux
INCLUDE_PATHS += -I/opt/vc/include/interface/vcos/pthreads
endif
ifeq ($(PLATFORM),PLATFORM_WEB)
# GLFW3 library
INCLUDES += -Iexternal/glfw3/include
INCLUDE_PATHS += -Iexternal/glfw3/include
endif
ifeq ($(PLATFORM),PLATFORM_ANDROID)
# Android required libraries
INCLUDES += -I$(ANDROID_TOOLCHAIN)/sysroot/usr/include
INCLUDE_PATHS += -I$(ANDROID_TOOLCHAIN)/sysroot/usr/include
# Include android_native_app_glue.h
INCLUDES += -Iexternal/android/native_app_glue
#INCLUDES += -I$(ANDROID_NDK)/sources/android/native_app_glue
INCLUDE_PATHS += -Iexternal/android/native_app_glue
#INCLUDE_PATHS += -I$(ANDROID_NDK)/sources/android/native_app_glue
endif
# define output directory for compiled library
@ -301,7 +285,7 @@ endif
# The wildcard takes all files that finish with ".c", then it replaces the
# extentions with ".o", that are the object files.
OBJS = $(patsubst %.c, %.o, $(wildcard *.c))
OBJS += external/stb_vorbis.o
OBJS += stb_vorbis.o
# typing 'make' will invoke the default target entry called 'all',
# in this case, the 'default' target entry is raylib
@ -324,12 +308,12 @@ raylib: $(OBJS)
ifeq ($(PLATFORM),PLATFORM_WEB)
# compile raylib for web.
emcc -O1 $(OBJS) -o $(OUTPUT_PATH)/libraylib.bc
@echo "libraylib.bc generated (web version)!"
@echo "raylib library generated (libraylib.bc)!"
else
ifeq ($(SHARED_RAYLIB),YES)
ifeq ($(RAYLIB_LIBTYPE),SHARED)
# NOTE: If using OpenAL Soft as static library, all its dependencies must be also linked in the shared library
ifeq ($(PLATFORM_OS),WINDOWS)
$(CC) -shared -o $(OUTPUT_PATH)/raylib.dll $(OBJS) $(SHAREDLIBS) -Lexternal/glfw3/lib/win32 -Lexternal/openal_soft/lib/win32 -lglfw3 -lgdi32 -Wl,--out-implib,$(OUTPUT_PATH)/libraylibdll.a
$(CC) -shared -o $(OUTPUT_PATH)/raylib.dll $(OBJS) $(ALLIBS) -Lexternal/glfw3/lib/win32 -Lexternal/openal_soft/lib/win32 -lglfw3 -lgdi32 -Wl,--out-implib,$(OUTPUT_PATH)/libraylibdll.a
@echo "raylib dynamic library (raylib.dll) and import library (libraylibdll.a) generated!"
endif
ifeq ($(PLATFORM_OS),LINUX)
@ -351,7 +335,7 @@ else
# compile raylib static library.
$(AR) rcs $(OUTPUT_PATH)/libraylib.a $(OBJS)
@echo "raylib static library generated (libraylib.a)!"
ifeq ($(SHARED_OPENAL),NO)
ifeq ($(OPENAL_LIBTYPE),STATIC)
@echo "expected OpenAL Soft static library linking"
else
@echo "expected OpenAL Soft shared library linking"
@ -363,39 +347,39 @@ endif
# compile core module
core.o : core.c raylib.h rlgl.h utils.h raymath.h gestures.h
$(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
# compile rlgl module
rlgl.o : rlgl.c rlgl.h raymath.h
$(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(GRAPHICS)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
# compile shapes module
shapes.o : shapes.c raylib.h rlgl.h
$(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(SHAREDFLAG)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
# compile textures module
textures.o : textures.c rlgl.h utils.h
$(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(GRAPHICS) -D$(SHAREDFLAG)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
# compile text module
text.o : text.c raylib.h utils.h
$(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(SHAREDFLAG)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
# compile models module
models.o : models.c raylib.h rlgl.h raymath.h
$(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(GRAPHICS)
# compile audio module
audio.o : audio.c raylib.h
$(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG) -D$(SHAREDOPENALFLAG)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM) -D$(ALFLAGS)
# compile stb_vorbis library
external/stb_vorbis.o: external/stb_vorbis.c external/stb_vorbis.h
$(CC) -c -o $@ $< -O1 $(CFLAGS) $(INCLUDES) -D$(PLATFORM)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
# compile utils module
utils.o : utils.c utils.h
$(CC) -c $< $(CFLAGS) $(INCLUDES) -D$(PLATFORM) -D$(SHAREDFLAG)
$(CC) -c $< $(CFLAGS) $(INCLUDE_PATHS) -D$(PLATFORM)
# It installs generated and needed files to compile projects using raylib.
# The installation works manually.
@ -407,7 +391,7 @@ ifeq ($(ROOT),root)
# libraries and header files. These directory (/usr/local/lib and
# /usr/local/include/) are for libraries that are installed
# manually (without a package manager).
ifeq ($(SHARED_RAYLIB),YES)
ifeq ($(RAYLIB_LIBTYPE),SHARED)
cp --update $(OUTPUT_PATH)/libraylib.so /usr/local/lib/libraylib.so
else
cp --update raylib.h /usr/local/include/raylib.h
@ -427,14 +411,14 @@ uninstall :
ifeq ($(ROOT),root)
ifeq ($(PLATFORM_OS),LINUX)
rm --force /usr/local/include/raylib.h
ifeq ($(SHARED_RAYLIB),YES)
ifeq ($(RAYLIB_LIBTYPE),SHARED)
rm --force /usr/local/lib/libraylib.so
else
rm --force /usr/local/lib/libraylib.a
endif
@echo "raylib dev files removed!"
@echo "raylib development files removed!"
else
@echo "This function works only on GNU/Linux systems"
@echo "This function works only on GNU/Linux systems"
endif
else
@echo "Error: no root permissions"

View File

@ -74,14 +74,17 @@
//#define PLATFORM_WEB // HTML5 (emscripten, asm.js)
// Security check in case no PLATFORM_* defined
#if !defined(PLATFORM_DESKTOP) && !defined(PLATFORM_ANDROID) && !defined(PLATFORM_RPI) && !defined(PLATFORM_WEB)
#define PLATFORM_DESKTOP
#if !defined(PLATFORM_DESKTOP) && \
!defined(PLATFORM_ANDROID) && \
!defined(PLATFORM_RPI) && \
!defined(PLATFORM_WEB)
#define PLATFORM_DESKTOP
#endif
#if defined(_WIN32) && defined(BUILDING_DLL)
#define RLAPI __declspec(dllexport) // We are building raylib as a Win32 DLL
#elif defined(_WIN32) && defined(RAYLIB_DLL)
#define RLAPI __declspec(dllimport) // We are using raylib as a Win32 DLL
#if defined(_WIN32) && defined(BUILD_LIBTYPE_SHARED)
#define RLAPI __declspec(dllexport) // We are building raylib as a Win32 shared library (.dll)
#elif defined(_WIN32) && defined(USE_LIBTYPE_SHARED)
#define RLAPI __declspec(dllimport) // We are using raylib as a Win32 shared library (.dll)
#else
#define RLAPI // We are building or using raylib as a static library (or Linux shared library)
#endif