prosperon/Makefile

330 lines
7.4 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
CXX:=$(CC)
ifeq ($(CXX), tcc)
CXX=clang
endif
2023-11-20 07:49:14 -06:00
ifeq ($(CC),cc)
CC=clang
endif
# 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)
2023-11-20 07:49:14 -06:00
#ifeq ($(CC), clang)
# AR = llvm-ar
#endif
2023-09-25 08:21:02 -05:00
ifeq ($(CC), x86_64-w64-mingw32-gcc)
AR = x86_64-w64-mingw32-ar
endif
ifdef NEDITOR
CPPFLAGS += -DNO_EDITOR
endif
ifdef NFLAC
CPPFLAGS += -DNFLAC
endif
ifdef NMP3
CPPFLAGS += -DNMP3
endif
ifdef NSVG
CPPFLAGS += -DNSVG
endif
ifdef NQOA
CPPFLAGS += -DNQOA
endif
CPPFLAGS += -ffast-math
ifeq ($(DBG),1)
2023-12-24 09:14:46 -06:00
CPPFLAGS += -g #-fsanitize=address
INFO += _dbg
2022-12-23 13:48:29 -06:00
else
CPPFLAGS += -DNDEBUG
2023-09-04 16:27:30 -05:00
LDFLAGS += -s
endif
2023-09-04 16:27:30 -05:00
ifeq ($(OPT),small)
CPPFLAGS += -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)
CPPFLAGS += -O2 -flto
2023-09-04 16:27:30 -05:00
INFO := $(addsuffix _opt,$(INFO))
else
CPPFLAGS += -O0
2023-09-04 16:27:30 -05:00
endif
endif
2023-12-24 09:14:46 -06:00
CPPFLAGS += -DHAVE_CEIL -DCP_USE_CGTYPES=0 -DCP_USE_DOUBLES=0 -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" #-DENABLE_SINC_MEDIUM_CONVERTER -DENABLE_SINC_FAST_CONVERTER -DCP_COLLISION_TYPE_TYPE=uintptr_t -DCP_BITMASK_TYPE=uintptr_t
2023-11-28 22:48:32 -06:00
# ENABLE_SINC_[BEST|FAST|MEDIUM]_CONVERTER
# default, fast and medium available in game at runtime; best available in editor
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)
ifeq ($(ARCH),)
ARCH != uname -m
endif
STEAMPATH = steam/sdk/redistributable_bin
DISCORDPATH = discord/lib
ifdef DISCORD
LDPATHS += $(DISCORDPATH)/$(ARCH)
LDLIBS += discord_game_sdk
CPPFLAGS += -DDISCORD
endif
ifdef STEAM
LDLIBS += steam_api
LDPATHS += $(STEAMPATH)/$(ARCH)
endif
ifeq ($(OS), Windows_NT)
LDFLAGS += -mwin32 -static
CPPFLAGS += -mwin32
LDLIBS += mingw32 kernel32 d3d11 user32 shell32 dxgi gdi32 ws2_32 ole32 winmm setupapi m
EXT = .exe
ARCH := x86_64
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)
OS := Web
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -sTOTAL_MEMORY=450MB
CPPFLAGS += -pthread
2023-09-04 16:27:30 -05:00
LDLIBS += pthread quickjs GL openal c m dl
CC = emcc
EXT = .html
2023-11-20 07:49:14 -06:00
else
UNAME != uname -s
ifeq ($(UNAME), Linux)
OS := Linux
2023-09-04 16:27:30 -05:00
LDFLAGS += -pthread -rdynamic
LDLIBS += GL pthread c m dl X11 Xi Xcursor EGL asound
endif
ifeq ($(UNAME), Darwin)
OS := macos
CPPFLAGS += -arch $(ARCH)
CFLAGS += -x objective-c
CXXFLAGS += -std=c++11
LDFLAGS += -framework Cocoa -framework QuartzCore -framework AudioToolbox -framework Metal -framework MetalKit
endif
endif
BIN = bin/$(OS)/$(ARCH)$(INFO)
2023-08-22 23:34:36 -05:00
ifdef STEAM
BIN := $(addsuffix /steam, $(BIN))
endif
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 += $(shell find source/engine -type f -name '*.cpp')
2023-11-20 07:49:14 -06:00
OBJS += $(shell find source/engine -type f -name '*.m')
OBJS := $(patsubst %.cpp, %.o, $(OBJS))
2023-09-04 16:27:30 -05:00
OBJS := $(patsubst %.c, %.o,$(OBJS))
2023-11-20 07:49:14 -06:00
OBJS := $(patsubst %.m, %.o, $(OBJS))
2023-09-04 16:27:30 -05:00
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/tinycdb source/shaders
2022-12-23 13:48:29 -06:00
includeflag := $(addprefix -I, $(includeflag))
2022-06-23 13:16:39 -05:00
2023-11-20 07:49:14 -06:00
# Adding different SDKs
ifdef STEAM
includeflag += -Isteam/sdk/public
CPPFLAGS += -DSTEAM
# BIN += /steam
2023-11-20 07:49:14 -06:00
endif
WARNING_FLAGS = -Wno-incompatible-function-pointer-types
NAME = primum$(EXT)
SEM = 0.0.1
COM != fossil describe
VER = $(SEM)-$(COM)
2023-09-04 16:27:30 -05:00
LDLIBS := $(addprefix -l, $(LDLIBS))
2023-11-20 07:49:14 -06:00
LDPATHS := $(addprefix -L, $(LDPATHS))
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
DIST = yugine-$(OS)$(ARCH)$(INFO)-$(COM)$(ZIP)
DISTDIR = ./dist
2022-02-03 11:29:43 -06:00
.DEFAULT_GOAL := all
all: $(BIN)/$(NAME)
cp $(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 -f $(BIN)/$(NAME) $(DESTDIR)
2023-09-25 08:21:02 -05:00
$(BIN)/$(NAME): $(BIN)/libengine.a $(BIN)/libquickjs.a
@echo Linking $(NAME)
$(LD) $^ $(CPPFLAGS) $(LDFLAGS) -L$(BIN) $(LDPATHS) $(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: source/engine/core.cdb.h $(OBJS)
@$(AR) rcs $@ $(OBJS)
2023-09-04 16:27:30 -05:00
$(BIN)/libcdb.a:
mkdir -p $(BIN)
rm -f $(CDB)/libcdb.a
2023-09-25 08:21:02 -05:00
make -C $(CDB) CC=$(CC) AR=$(AR) libcdb.a
cp $(CDB)/libcdb.a $(BIN)
tools/libcdb.a:
make -C $(CDB) libcdb.a
mv $(CDB)/libcdb.a tools
DOCOS = Sound gameobject Game Window physics Profile Time Player Mouse IO Log ColorMap sprite SpriteAnim Render Geometry
DOCHTML := $(addsuffix .api.html, $(DOCOS))
DOCMD := $(addsuffix .api.md, $(DOCOS))
api.md: $(DOCMD)
@(echo "# API"; cat $^) > $@
@rm $^
2023-10-26 11:48:02 -05:00
INPUT = editor DebugControls component.sprite component.polygon2d component.edge2d component.circle2d
INPUTMD := $(addsuffix .input.md, $(INPUT))
input.md: $(INPUTMD)
@(echo "# Input"; cat $^) > $@
@rm $^
%.input.md: primum $(SCRIPTS)
@echo Printing controls for $*
@./primum -e $* > $@
%.api.md: primum $(SCRIPTS)
@echo Printing api for $*
@./primum -d $* > $@
2023-11-20 07:49:14 -06:00
$(BIN)/libquickjs.a: $(QUICKJS_O)
2023-04-22 14:07:37 -05:00
make -C quickjs clean
2023-11-20 07:49:14 -06:00
make -C quickjs SYSRT=$(SYSRT) TTARGET=$(TTARGET) ARCH=$(ARCH) DBG=$(DBG) OPT=$(OPT) AR=$(AR) OS=$(OS) libquickjs.a libquickjs.lto.a HOST_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) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
2021-11-30 21:29:18 -06:00
2023-11-20 07:49:14 -06:00
$(OBJDIR)/%.o: %.cpp
@mkdir -p $(@D)
@echo Making C++ object $@ with $(CXX)
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
2023-11-20 07:49:14 -06:00
$(OBJDIR)/%.o: %.m
@mkdir -p $(@D)
@echo Making Objective-C object $@
@$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
2023-11-20 07:49:14 -06:00
shaders: $(SHADERS)
@echo Making shaders
%.sglsl.h:%.sglsl
@echo Creating shader $^
@./sokol-shdc --ifdef -i $^ --slang=glsl330:hlsl5:metal_macos:metal_ios:metal_sim:glsl300es -o $@
cdb: tools/cdb.c tools/libcdb.a
cc $^ -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
CDB_C != find $(CDB) -name *.c
packer: tools/packer.c tools/libcdb.a
cc $^ -I$(CDB) -o packer
jso: tools/jso.c tools/libquickjs.a
$(CC) $^ -lm -Iquickjs -o $@
tools/libquickjs.a:
make -C quickjs clean
make -C quickjs OPT=$(OPT) AR=$(AR) libquickjs.a
cp -f quickjs/libquickjs.a tools
%.jso: %.js jso
@echo Making $@ from $<
./jso $< > $@
WINCC = x86_64-w64-mingw32-gcc
#WINCC = i686-w64-mingw32-g++
.PHONY: crosswin
crosswin:
make CC=$(WINCC) OS=Windows_NT
crossmac:
make ARCH=arm64
mv primum primum_arm64
make ARCH=x86_64
mv primum primum_x86_64
lipo primum_arm64 primum_x86_64 -create -output primum
2021-11-30 21:29:18 -06:00
clean:
@echo Cleaning project
@rm -rf bin dist
2023-11-07 12:45:52 -06:00
@rm -f shaders/*.sglsl.h shaders/*.metal core.cdb jso cdb packer scripts/*.jso
@make -C quickjs clean
TAGINC != find . -name "*.[chj]"
tags: $(TAGINC)
@echo Making tags.
@etags $(TAGINC)