prosperon/Makefile

222 lines
5 KiB
Makefile
Raw Normal View History

MAKEFLAGS = --jobs=4
2022-02-03 09:16:22 -06:00
UNAME != uname
MAKEDIR != pwd
2021-11-30 21:29:18 -06:00
# Options
2023-05-24 20:45:50 -05:00
# DBG --- build with debugging symbols and logging
# Temp to strip long emcc paths to just emcc
CC := $(notdir $(CC))
DBG ?= 1
OPT ?= 0
INFO :=
2023-09-04 21:35:05 -05:00
LD = $(CC)
ifeq ($(CC), clang)
AR = llvm-ar
endif
ifdef NEDITOR
CFLAGS += -DNO_EDITOR
endif
ifdef NFLAC
CFLAGS += -DNFLAC
endif
ifdef NMP3
CFLAGS += -DNMP3
endif
ifeq ($(DBG),1)
2023-09-04 16:27:30 -05:00
CFLAGS += -g
INFO += _dbg
LDFLAGS += -g
2022-12-23 13:48:29 -06:00
else
2023-09-04 16:27:30 -05:00
CFLAGS += -DNDEBUG
LDFLAGS += -s
endif
2023-09-04 16:27:30 -05:00
ifeq ($(OPT),small)
CFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables
2023-09-04 21:35:05 -05:00
LDFLAGS += -flto
2023-09-05 09:38:52 -05:00
ifeq ($(CC), emcc)
LDFLAGS += --closure 1
endif
2023-09-04 16:27:30 -05:00
INFO := $(addsuffix _small,$(INFO))
else
2023-09-04 16:27:30 -05:00
ifeq ($(OPT), 1)
CFLAGS += -O2 -flto
2023-09-04 21:35:05 -05:00
LDFLAGS += -flto
2023-09-04 16:27:30 -05:00
INFO := $(addsuffix _opt,$(INFO))
else
CFLAGS += -O0
endif
endif
2022-12-23 13:48:29 -06:00
PTYPE != uname -m
CFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DVER=\"$(VER)\" -DINFO=\"$(INFO)\"
2023-09-04 16:27:30 -05:00
PKGCMD = tar --directory $(BIN) --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(DIST) .
ZIP = .tar.gz
UNZIP = cp $(DISTDIR)/$(DIST) $(DESTDIR) && tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR) && rm $(DESTDIR)/$(DIST)
ARCH = x64
ifeq ($(OS), Windows_NT)
2023-09-04 16:27:30 -05:00
LDFLAGS += -mwin32 -static
CFLAGS += -mwin32
LDLIBS += mingw32 kernel32 opengl32 user32 shell32 dxgi gdi32 ws2_32 ole32 winmm setupapi m
EXT = .exe
PLAT = w64
PKGCMD = cd $(BIN); zip -q -r $(MAKEDIR)/$(DISTDIR)/$(DIST) . -x \*.a ./obj/\*
ZIP = .zip
UNZIP = unzip -o -q $(DISTDIR)/$(DIST) -d $(DESTDIR)
else ifeq ($(CC), emcc)
2023-09-11 02:46:12 -05:00
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -sALLOW_MEMORY_GROWTH -sTOTAL_MEMORY=450MB --embed-file $(BIN)@
2023-09-04 16:27:30 -05:00
CFLAGS += -pthread
LDLIBS += pthread quickjs GL openal c m dl
CC = emcc
EXT = .html
PLAT = html5
else
UNAME != uname -s
ifeq ($(UNAME), Linux)
2023-09-04 16:27:30 -05:00
LDFLAGS += -pthread -rdynamic
LDLIBS += GL pthread c m dl X11 Xi Xcursor EGL asound
PLAT = linux-$(ARCH)$(INFO)
endif
ifeq ($(UNAME), Darwin)
CFLAGS += -x objective-c
LDFLAGS += -framework Cocoa -framework QuartzCore -framework AudioToolbox
# LDFLAGS += -framework Metal -framework MetalKit
LDFLAGS += -framework OpenGL
PLAT = osx-$(ARCH)$(INFO)
endif
endif
2023-09-04 16:27:30 -05:00
BIN = bin/$(CC)/$(INFO)
2023-08-22 23:34:36 -05:00
2023-09-04 16:27:30 -05:00
OBJDIR = $(BIN)/obj
2022-01-20 11:16:44 -06:00
2022-02-03 09:16:22 -06:00
# All other sources
2023-09-04 16:27:30 -05:00
OBJS != find source/engine -type f -name '*.c'
OBJS := $(patsubst %.c, %.o,$(OBJS))
OBJS := $(addprefix $(BIN)/obj/, $(OBJS))
2021-11-30 21:29:18 -06:00
2023-09-04 16:27:30 -05:00
engineincs != find source/engine -maxdepth 1 -type d
2022-12-23 13:48:29 -06:00
includeflag != find source -type d -name include
includeflag += $(engineincs) source/engine/thirdparty/Nuklear source/engine/thirdparty/tinycdb source/shaders
2022-12-23 13:48:29 -06:00
includeflag := $(addprefix -I, $(includeflag))
2022-06-23 13:16:39 -05:00
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function -Wno-unused-const-variable
2023-09-04 16:27:30 -05:00
NAME = yugine$(EXT)
SEM = 0.0.1
COM != fossil describe
VER = $(SEM)-$(COM)
2023-09-04 16:27:30 -05:00
LDLIBS := $(addprefix -l, $(LDLIBS))
2021-11-30 21:29:18 -06:00
2023-09-04 16:27:30 -05:00
DEPENDS = $(OBJS:.o=.d)
2022-02-03 11:29:43 -06:00
-include $(DEPENDS)
2022-02-03 09:16:22 -06:00
MYTAG = $(VER)_$(PTYPE)_$(INFO)
DIST = yugine-$(PLAT)-$(COM)$(ZIP)
DISTDIR = ./dist
2022-02-03 11:29:43 -06:00
.DEFAULT_GOAL := all
all: $(BIN)/$(NAME)
2022-08-12 14:03:56 -05:00
DESTDIR ?= ~/.bin
CDB = source/engine/thirdparty/tinycdb
SHADERS = $(shell ls source/shaders/*.sglsl)
SHADERS := $(patsubst %.sglsl, %.sglsl.h, $(SHADERS))
install: $(BIN)/$(NAME)
cp $(BIN)/$(NAME) $(DESTDIR)
$(BIN)/$(NAME): $(BIN)/libengine.a $(BIN)/libquickjs.a $(BIN)/libcdb.a
@echo Linking $(NAME)
$(LD) $^ $(LDFLAGS) -L$(BIN) $(LDLIBS) -o $@
@echo Finished build
2022-08-12 14:03:56 -05:00
$(DISTDIR)/$(DIST): $(BIN)/$(NAME)
@echo Creating distribution $(DIST)
@mkdir -p $(DISTDIR)
@$(PKGCMD)
$(BIN)/libengine.a: $(SHADERS) source/engine/core.cdb.h .WAIT $(OBJS)
@$(AR) rcs $@ $(OBJS)
2023-09-04 16:27:30 -05:00
$(BIN)/libcdb.a:
mkdir -p $(BIN)
rm -f $(CDB)/libcdb.a
make -C $(CDB) libcdb.a
cp $(CDB)/libcdb.a $(BIN)
$(BIN)/libquickjs.a:
2023-04-22 14:07:37 -05:00
make -C quickjs clean
make -C quickjs OPT=$(OPT) HOST_CC=$(CC) libquickjs.a libquickjs.lto.a CC=$(CC)
@mkdir -p $(BIN)
cp -rf quickjs/libquickjs.* $(BIN)
$(OBJDIR)/%.o: %.c
2022-01-20 11:16:44 -06:00
@mkdir -p $(@D)
@echo Making C object $@
@$(CC) $(CFLAGS) -c $< -o $@
2021-11-30 21:29:18 -06:00
shaders: $(SHADERS)
@echo Making shaders
%.sglsl.h:%.sglsl
@echo Creating shader $^
@./sokol-shdc --ifdef -i $^ --slang=glsl330:hlsl5:metal_macos -o $@
cdb: tools/cdb.c $(BIN)/libcdb.a
$(CC) $< -lcdb -L$(BIN) -I$(CDB) -o cdb
source/engine/core.cdb.h: core.cdb
xxd -i $< > $@
SCRIPTS := $(shell ls scripts/*.js)
SCRIPT_O := $(addsuffix o, $(SCRIPTS))
CORE != (ls icons/* fonts/*)
CORE := $(CORE) $(SCRIPTS)
core.cdb: packer $(CORE)
./packer $(CORE)
chmod 644 out.cdb
mv out.cdb core.cdb
packer: tools/packer.c $(BIN)/libcdb.a
cc $^ -Isource/engine/thirdparty/tinycdb -o packer
jso: tools/jso.c $(BIN)/libquickjs.a
$(CC) $< -lquickjs -lm -L$(BIN) -Iquickjs -o $@
%.jso: %.js jso
@echo Making $@ from $<
./jso $< > $@
2021-11-30 21:29:18 -06:00
clean:
@echo Cleaning project
@rm -rf bin dist
@rm -f shaders/*.sglsl.h shaders/*.metal core.cdb jso cdb packer TAGS
@make -C $(CDB) clean
@make -C quickjs clean
TAGINC != find . -name "*.[chj]"
tags: $(TAGINC)
@echo Making tags.
@etags $(TAGINC)