Makefile fix to easily make linux, windows, web; DBG flag set correctly

This commit is contained in:
John Alanbrook 2023-09-03 17:50:02 +00:00
parent 3e0dc30645
commit 467f7b29ea
13 changed files with 87 additions and 79 deletions

108
Makefile
View file

@ -5,51 +5,73 @@ UNAME != uname
# Options
# DBG --- build with debugging symbols and logging
# ED --- build with or without editor
# OPT --- Optimize
# Temp to strip long emcc paths to just emcc
CC := $(notdir $(CC))
DBG ?= 1
QFLAGS :=
ifdef DBG
QFLAGS += -O0 -g -DDBG
INFO :=
ifeq ($(DBG),1)
QFLAGS += -g
INFO = dbg
ifeq ($(CC),tcc)
QFLAGS +=
endif
else
QFLAGS += -O2
QFLAGS += -DNDEBUG -s
INFO = rel
CC = clang
endif
ifdef OPT
QFLAGS += -flto
endif
ifdef ED
QFLAGS += -DED
endif
QFLAGS += -DHAVE_CEIL -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF
# Uncomment for smallest binary
# QFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -fno-stack-protector -fomit-frame-pointer -fno-math-errno -fno-unroll-loops -fmerge-all-constants -fno-ident -mfpmath=387 -fsingle-precision-constant -ffast-math
PTYPE != uname -m
LINKER_FLAGS = $(QFLAGS)
ELIBS = engine quickjs
PKGCMD = tar --directory $(BIN) --exclude="./*.a" --exclude="./obj" --exclude="./include" -czf $(DISTDIR)/$(DIST) .
ZIP = .tar.gz
ARCH = x64
ifeq ($(OS), Windows_NT)
QFLAGS += -mwin32
LINKER_FLAGS +=
ELIBS = engine kernel32 user32 shell32 dxgi quickjs gdi32 ws2_32 ole32 winmm setupapi m
LINKER_FLAGS += -mwin32 -static
ELIBS += kernel32 user32 shell32 dxgi gdi32 ws2_32 ole32 winmm setupapi m
EXT = .exe
else ifeq ($(OS), WEB)
PLAT = w64
PKGCMD = zip -r $(DISTDIR)/$(DIST) $(BIN) --exclude "./*.a" --exclude="./obj" --exclude="./include"
ZIP = .zip
else ifeq ($(CC), emcc)
LINKER_FLAGS += -sFULL_ES3
ELIBS = engine pthread quickjs GL c m dl
ELIBS += pthread quickjs GL c m dl
CC = emcc
EXT = .html
PLAT = html5
else
LINKER_FLAGS += -L/usr/local/lib -pthread -rdynamic
ELIBS = engine pthread quickjs GL c m dl X11 Xi Xcursor EGL asound
UNAME != uname -s
ifeq ($(UNAME), Linux)
LINKER_FLAGS += -pthread -rdynamic
ELIBS += GL pthread c m dl X11 Xi Xcursor EGL asound
PLAT = linux-$(ARCH)
endif
ifeq ($(UNAME), Darwin)
ifeq ($(PLATFORM), macosx)
ELIBS = Coca QuartzCore OpenGL
PLAT = mac-$(ARCH)
else ifeq ($(PLATFORM), iphoneos)
ELIBS = Foundation UIKit OpenGLES GLKit
endif
endif
endif
BIN = bin/$(CC)/$(INFO)/
@ -103,7 +125,6 @@ DEPENDS = $(objects:.o=.d)
-include $(DEPENDS)
ENGINE = $(BIN)libengine.a
INCLUDE = $(BIN)include
SCRIPTS = $(shell ls source/scripts/*.js)
@ -111,53 +132,48 @@ LINK = $(LIBPATH) $(LINKER_FLAGS) $(ELIBS)
MYTAG = $(VER)_$(PTYPE)_$(INFO)
DIST = $(NAME)-$(MYTAG).tar.gz
DIST = yugine-$(PLAT)-$(COM)$(ZIP)
DISTDIR = ./dist
yugine: $(BIN)yugine
.DEFAULT_GOAL := all
all: $(DISTDIR)/$(DIST)
$(NAME): $(BIN)$(NAME)
DESTDIR ?= ~/.bin
install: $(DISTDIR)/$(DIST)
@echo Unpacking $(DIST) in $(DESTDIR)
# @unzip $(DISTDIR)/$(DIST) -d $(DESTDIR)
@cp $(DISTDIR)/$(DIST) $(DESTDIR) && tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR) && rm $(DESTDIR)/$(DIST)
$(BIN)$(NAME): $(objprefix)/source/engine/yugine.o $(ENGINE) $(BIN)libquickjs.a
@echo Linking $(NAME)
$(CC) $< $(LINK) -o $(BIN)$(NAME)
@echo Finished build
$(BIN)$(DIST): $(BIN)$(NAME) source/shaders/* $(SCRIPTS) assets/*
$(DISTDIR)/$(DIST): $(BIN)$(NAME) source/shaders/* $(SCRIPTS) assets/*
@echo Creating distribution $(DIST)
@mkdir -p $(BIN)dist
@cp $(BIN)$(NAME) $(BIN)dist
@cp -rf assets/* $(BIN)dist
@cp -rf source/shaders $(BIN)dist
@cp -r source/scripts $(BIN)dist
@tar czf $(DIST) --directory $(BIN)dist .
@mv $(DIST) $(BIN)
@mkdir -p $(DISTDIR)
@cp -rf assets/* $(BIN)
@cp -rf source/shaders $(BIN)
@cp -r source/scripts $(BIN)
@$(PKGCMD)
$(BIN)libquickjs.a:
make -C quickjs clean
make -C quickjs libquickjs.a libquickjs.lto.a CC=$(CC)
cp quickjs/libquickjs.* $(BIN)
dist: $(BIN)$(DIST)
install: $(BIN)$(DIST)
@echo Unpacking $(DIST) in $(DESTDIR)
@cp $(BIN)$(DIST) $(DESTDIR)
@tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR)
@rm $(DESTDIR)/$(DIST)
$(ENGINE): $(eobjects)
@echo Making library engine.a
@ar r $(ENGINE) $(eobjects)
@mkdir -p $(INCLUDE)
@cp -u -r $(ehead) $(INCLUDE)
@llvm-ar r $(ENGINE) $(eobjects)
$(objprefix)/%.o:%.c
@mkdir -p $(@D)
@echo Making C object $@
@echo Making C object $@ OS $(OS)
@$(CC) $(COMPILER_FLAGS)
.PHONY: clean
clean:
@echo Cleaning project
@rm -rf bin/*
@rm -f *.gz
@rm -rf dist/*

View file

@ -31,7 +31,7 @@ char consolelog[CONSOLE_BUF+1] = {'\0'};
void mYughLog(int category, int priority, int line, const char *file, const char *message, ...)
{
#ifdef DBG
#ifndef NDEBUG
if (priority >= logLevel) {
time_t now = time(0);
struct tm *tinfo = localtime(&now);
@ -51,9 +51,6 @@ void mYughLog(int category, int priority, int line, const char *file, const char
snprintf(buffer, ERROR_BUFFER, "%s:%d: %s, %s: %s\n", file, line, logstr[priority], catstr[category], msgbuffer);
log_print(buffer);
// if (category != LOG_SCRIPT && priority >= 2)
// js_stacktrace();
}
#endif
}

View file

@ -19,7 +19,7 @@ extern char lastlog[];
extern char consolelog[];
extern int logLevel;
#ifdef DBG
#ifndef NDEBUG
#define YughLog(cat, pri, msg, ...) mYughLog(cat, pri, __LINE__, __FILE__, msg, ##__VA_ARGS__)
#define YughInfo(msg, ...) mYughLog(0, 0, __LINE__, __FILE__, msg, ##__VA_ARGS__);
#define YughWarn(msg, ...) mYughLog(0, 1, __LINE__, __FILE__, msg, ##__VA_ARGS__);

View file

@ -21,7 +21,7 @@
JSContext *js = NULL;
JSRuntime *rt = NULL;
#ifdef DBG
#ifndef NDEBUG
#define JS_EVAL_FLAGS JS_EVAL_FLAG_STRICT
#else
#define JS_EVAL_FLAGS JS_EVAL_FLAG_STRICT | JS_EVAL_FLAG_STRIP
@ -47,7 +47,7 @@ void script_startup() {
JSValue num_cache[100] = {0};
int js_print_exception(JSValue v) {
#ifdef DBG
#ifndef NDEBUG
if (JS_IsException(v)) {
JSValue exception = JS_GetException(js);
@ -124,7 +124,7 @@ time_t file_mod_secs(const char *file) {
}
void js_stacktrace() {
#ifdef DBG
#ifndef NDEBUG
call_callee(&stacktrace_callee);
#endif
}

View file

@ -9,6 +9,8 @@
#include "time.h"
#include <stdlib.h>
#include "samplerate.h"
#include "stb_ds.h"

View file

@ -88,9 +88,9 @@ struct Texture *texture_pullfromfile(const char *path) {
unsigned char *data;
char *ext = strrchr(path, '.')+1;
char *ext = strrchr(path, '.');
if (!strcmp(ext, "qoi")) {
if (ext && !strcmp(ext, ".qoi")) {
qoi_desc qoi;
data = qoi_read(path, &qoi, 4);
tex->width = qoi.width;

View file

@ -18,6 +18,11 @@
#include <immintrin.h>
#endif
/* Uncomment to enable specific converters */
//#define ENABLE_SINC_BEST_CONVERTER
//#define ENABLE_SINC_FAST_CONVERTER
//#define ENABLE_SINC_MEDIUM_CONVERTER
#include <math.h>
#ifdef HAVE_VISIBILITY

View file

@ -17,13 +17,13 @@
#define CPU_IS_LITTLE_ENDIAN 1
/* Enable sinc best converter. */
#define ENABLE_SINC_BEST_CONVERTER 1
#define ENABLE_SINC_BEST_CONVERTER 0
/* Enable sinc fast converter. */
#define ENABLE_SINC_FAST_CONVERTER 1
#define ENABLE_SINC_FAST_CONVERTER 0
/* Enable sinc balanced converter. */
#define ENABLE_SINC_MEDIUM_CONVERTER 1
#define ENABLE_SINC_MEDIUM_CONVERTER 0
/* Define to 1 if you have the `alarm' function. */
#define HAVE_ALARM 1

View file

@ -6,8 +6,6 @@
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

View file

@ -6,8 +6,6 @@
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

View file

@ -6,8 +6,6 @@
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

View file

@ -6,8 +6,6 @@
** file at : https://github.com/libsndfile/libsamplerate/blob/master/COPYING
*/
#include "config.h"
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>

View file

@ -24,7 +24,7 @@
#include "2dphysics.h"
#ifdef __linux__
#ifdef __GLIBC__
#include <execinfo.h>
#endif
@ -34,13 +34,9 @@
#include "string.h"
#define SOKOL_TRACE_HOOKS
#ifdef DBG
#define SOKOL_DEBUG
#endif
#define SOKOL_IMPL
#if defined __linux__
#if defined __GLIBC__
#define SOKOL_GLCORE33
#elif __EMSCRIPTEN__
#define SOKOL_GLES3
@ -121,7 +117,7 @@ int backtrace(void **buffer, int size) {
#endif
void print_stacktrace() {
#ifdef __linux__
#ifdef __GLIBC__
void *ents[512];
size_t size = backtrace(ents, 512);
@ -138,7 +134,7 @@ void print_stacktrace() {
}
void seghandle(int sig) {
#ifdef __linux__
#ifdef __GLIBC__
if (strsignal(sig))
YughCritical("CRASH! Signal: %s.", strsignal(sig));