prosperon/Makefile

304 lines
8.2 KiB
Makefile
Raw Normal View History

MAKEFLAGS = --jobs=4
2022-02-03 09:16:22 -06:00
UNAME != uname
MAKEDIR != pwd
# Options
2024-03-19 14:39:19 -05:00
# NDEBUG --- build with debugging symbols and logging
CXX:=$(CC)
# Temp to strip long emcc paths to just emcc
CC := $(notdir $(CC))
OPT ?= 0
INFO :=
2023-09-04 21:35:05 -05:00
LD = $(CC)
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
ifeq ($(CC), emcc)
2024-03-23 09:56:38 -05:00
LDFLAGS += #--closure 1 --emrun
CPPFLAGS += -O0
OPT = 0
2024-03-19 14:39:19 -05:00
NDEBUG = 1
AR = emar
endif
ifdef NDEBUG
CPPFLAGS += -DNDEBUG
else
2024-03-23 09:56:38 -05:00
CPPFLAGS += -g -DDUMP
INFO :=$(INFO)_dbg
endif
ifdef LEAK
2024-03-23 09:56:38 -05:00
CPPFLAGS += -fsanitize=address -fsanitize=undefined -fno-omit-frame-pointer -DLEAK
endif
2024-02-23 16:05:30 -06:00
2023-09-04 16:27:30 -05:00
ifeq ($(OPT),small)
2024-03-23 09:56:38 -05:00
CPPFLAGS += -Oz -flto -fno-ident -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections
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
2024-03-23 09:56:38 -05:00
INFO :=$(INFO)_small
else ifeq ($(OPT), 1)
CPPFLAGS += -O2 -flto
INFO :=$(INFO)_opt
else
2024-03-23 09:56:38 -05:00
CPPFLAGS += -O2
endif
2024-03-23 09:56:38 -05: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=\"$(SEM)\" -DCOM=\"$(COM)\" -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
2024-03-09 18:22:06 -06:00
CPPFLAGS += -D_FILE_OFFSET_BITS=64 # for tinycdb
2024-03-23 09:56:38 -05:00
CPPFLAGS += -DCONFIG_VERSION=\"2024-02-14\" -DCONFIG_BIGNUM #for quickjs
2024-03-09 18:22:06 -06:00
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
2024-03-23 09:56:38 -05:00
PKGCMD = tar --directory --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
2024-03-23 09:56:38 -05:00
INFO :=$(INFO)_$(ARCH)
2024-03-23 09:56:38 -05:00
ifeq ($(OS), Windows_NT) # then WINDOWS
DEPS += resource.o
LDFLAGS += -mwin32 -static
CPPFLAGS += -mwin32
2024-03-09 18:22:06 -06:00
LDLIBS += mingw32 kernel32 d3d11 user32 shell32 dxgi gdi32 ws2_32 ole32 winmm setupapi m pthread
EXT = .exe
2024-03-23 09:56:38 -05:00
PKGCMD = zip -q -r $(MAKEDIR)/$(DISTDIR)/$(DIST) . -x \*.a ./obj/\*
ZIP = .zip
UNZIP = unzip -o -q $(DISTDIR)/$(DIST) -d $(DESTDIR)
2024-03-23 09:56:38 -05:00
INFO :=$(INFO)_win
else ifeq ($(OS), IOS)
CC = /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang
SDK = iphoneos
SDK_PATH = /Applications/Xcode.app/Contents/Developer/Platforms/$(SDK).platform/Developer/SDKs/$(SDK).sdk
CFLAGS += -isysroot $(SDK_PATH) -miphoneos-version-min=13.0
LDFLAGS += -isysroot $(SDK_PATH) -miphoneos-version-min=13.0
LDFLAGS += -framework Foundation -framework UIKit -framework AudioToolbox -framework Metal -framework MetalKit -framework AVFoundation
CXXFLAGS += -std=c++11
CFLAGS += -x objective-c
INFO :=$(INFO)_ios
else ifeq ($(CC), emcc) # Then WEB
OS := Web
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -sTOTAL_MEMORY=128MB
CPPFLAGS += -pthread
2023-09-04 16:27:30 -05:00
LDLIBS += pthread quickjs GL openal c m dl
EXT = .html
else
UNAME != uname -s
2024-03-23 09:56:38 -05:00
ifeq ($(UNAME), Linux) # then 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
2024-03-23 09:56:38 -05:00
INFO :=$(INFO)_linux
endif
ifeq ($(UNAME), Darwin)
OS := macos
CPPFLAGS += -arch $(ARCH)
2024-01-14 10:24:31 -06:00
CFLAGS += -x objective-c
CXXFLAGS += -std=c++11
2024-01-14 10:24:31 -06:00
LDFLAGS += -framework Cocoa -framework QuartzCore -framework AudioToolbox -framework Metal -framework MetalKit
2024-03-23 09:56:38 -05:00
INFO :=$(INFO)_macos
endif
endif
2022-02-03 09:16:22 -06:00
# All other sources
OBJS != find source/engine -type f -name '*.c' | grep -vE 'test|tool|example|fuzz|main' | grep -vE 'quickjs'
2024-03-09 18:22:06 -06:00
CPPOBJS != find source/engine -type f -name '*.cpp' | grep -vE 'test|tool|example|fuzz|main'
2024-03-03 16:58:59 -06:00
OBJS += $(CPPOBJS)
2023-11-20 07:49:14 -06:00
OBJS += $(shell find source/engine -type f -name '*.m')
2024-03-23 09:56:38 -05:00
OBJS := $(patsubst %.cpp, %$(INFO).o, $(OBJS))
OBJS := $(patsubst %.c, %$(INFO).o,$(OBJS))
OBJS := $(patsubst %.m, %$(INFO).o, $(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 source/engine/thirdparty/sokol source/engine/thirdparty/stb source/engine/thirdparty/cgltf source/engine/thirdparty/TinySoundFont source/engine/thirdparty/dr_libs
2022-12-23 13:48:29 -06:00
includeflag := $(addprefix -I, $(includeflag))
2022-06-23 13:16:39 -05:00
2024-03-11 22:23:02 -05:00
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types
2024-03-23 09:56:38 -05:00
APP = prosperon
NAME = $(APP)$(INFO)$(EXT)
2024-03-18 08:16:25 -05:00
SEM != git describe --tags --abbrev=0
COM != git rev-parse --short HEAD
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
.DEFAULT_GOAL := all
2024-03-23 09:56:38 -05:00
all: $(NAME)
cp -f $(NAME) $(APP)$(EXT)
SHADERS = $(shell ls source/shaders/*.sglsl)
SHADERS := $(patsubst %.sglsl, %.sglsl.h, $(SHADERS))
DESTDIR ?= ~/.bin
2024-03-23 09:56:38 -05:00
install: $(NAME)
cp -f $(NAME) $(DESTDIR)/$(APP)
$(NAME): libengine$(INFO).a libquickjs$(INFO).a $(DEPS)
@echo Linking $(NAME)
2024-03-23 09:56:38 -05:00
$(LD) $^ $(CPPFLAGS) $(LDFLAGS) -L. $(LDPATHS) $(LDLIBS) -o $@
@echo Finished build
2022-08-12 14:03:56 -05:00
2024-03-23 09:56:38 -05:00
libengine$(INFO).a: $(OBJS)
$(AR) rcs $@ $(OBJS)
QUICKJS := source/engine/thirdparty/quickjs
2024-03-23 09:56:38 -05:00
libquickjs$(INFO).a: $(QUICKJS)/libregexp$(INFO).o $(QUICKJS)/quickjs$(INFO).o $(QUICKJS)/libunicode$(INFO).o $(QUICKJS)/cutils$(INFO).o $(QUICKJS)/libbf$(INFO).o
$(AR) rcs $@ $^
%$(INFO).o: %.c $(SHADERS) source/engine/core.cdb.h
@echo Making C object $@
2024-03-23 09:56:38 -05:00
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
2021-11-30 21:29:18 -06:00
2024-03-23 09:56:38 -05:00
%$(INFO).o: %.cpp
2024-03-09 18:22:06 -06:00
@echo Making C++ object $@
2024-03-23 09:56:38 -05:00
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $< -o $@
2023-11-20 07:49:14 -06:00
2024-03-23 09:56:38 -05:00
%$(INFO).o: %.m
2023-11-20 07:49:14 -06:00
@echo Making Objective-C object $@
2024-03-23 09:56:38 -05:00
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
2023-11-20 07:49:14 -06:00
shaders: $(SHADERS)
@echo Making shaders
%.sglsl.h:%.sglsl
@echo Creating shader $^
2024-03-23 09:56:38 -05:00
./sokol-shdc --ifdef -i $^ --slang=glsl330:hlsl5:metal_macos:metal_ios:metal_sim:glsl300es -o $@
CDB = source/engine/thirdparty/tinycdb
CDB_C != find $(CDB) -name *.c
CDB_O := $(patsubst %.c, %.o, $(CDB_C))
CDB_O := $(notdir $(CDB_O))
tools/libcdb.a: $(CDB_C)
cc -c $^
$(AR) rcs $@ $(CDB_O)
cdb: tools/cdb.c tools/libcdb.a
2024-03-23 09:56:38 -05:00
@echo Making cdb
cc $^ -I$(CDB) -o cdb
2024-03-23 09:56:38 -05:00
packer: tools/packer.c tools/libcdb.a
@echo Making packer
cc $^ -I$(CDB) -o packer
core.cdb: packer $(CORE)
./packer $(CORE)
chmod 644 out.cdb
mv out.cdb core.cdb
source/engine/core.cdb.h: core.cdb
2024-03-23 09:56:38 -05:00
@echo Packing core.cdb.h
xxd -i $< > $@
SCRIPTS := $(shell ls scripts/*.js*)
SCRIPT_O := $(addsuffix o, $(SCRIPTS))
CORE != (ls icons/* fonts/*)
CORE := $(CORE) $(SCRIPTS)
jsc: tools/jso.c tools/libquickjs.a
$(CC) $^ -lm -Iquickjs -o $@
2024-03-09 18:22:06 -06:00
tools/libquickjs.a: $(BIN)/libquickjs.a
cp -f $(BIN)/libquickjs.a tools
ICNSIZE = 16 32 128 256 512 1024
ICNNAME := $(addsuffix .png, $(ICNSIZE))
ICON = icons/moon.gif
icon.ico: $(ICON)
for i in $(ICNSIZE); do convert $^ -thumbnail $${i}x$${i} $${i}.png; done
convert $(ICNNAME) icon.ico
rm $(ICNNAME)
resource.o: resource.rc resource.manifest icon.ico
x86_64-w64-mingw32-windres -i $< -o $@
WINCC = x86_64-w64-mingw32-gcc
crosswin: packer resource.o
2024-03-23 09:56:38 -05:00
make CC=$(WINCC) OS=Windows_NT ARCH=x86_64 DEBUG=$(DEBUG) OPT=$(OPT)
crossios:
make OS=IOS ARCH=arm64 DEBUG=$(DEBUG) OPT=$(OPT)
Prosperon.icns: $(ICON)
2024-03-23 09:56:38 -05:00
mkdir -p Prosperon.iconset
for i in $(ICNSIZE); do magick $^ -size $${i}x$${i} Prosperon.iconset/icon_$${i}x$${i}.png; done
2024-03-23 09:56:38 -05:00
iconutil -c icns Prosperon.iconset
crossmac: Prosperon.icns
make ARCH=arm64 DEBUG=$(DEBUG) OPT=$(OPT)
mv $(APP) mac_arm64
make ARCH=x86_64 DEBUG=$(DEBUG) OPT=$(OPT)
mv $(APP) mac_x86_64
lipo mac_arm64 mac_x86_64 -create -output $(APP)_mac
rm mac_arm64 mac_x86_64
rm -rf Prosperon.app
mkdir Prosperon.app
mkdir Prosperon.app/Contents
mkdir Prosperon.app/Contents/MacOS
mkdir Prosperon.app/Contents/Resources
mv $(NAME) Prosperon.app/Contents/MacOS/Prosperon
cp Info.plist Prosperon.app/Contents
cp Prosperon.icns Prosperon.app/Contents/Resources
2024-03-09 18:22:06 -06:00
crossweb:
make CC=emcc
2024-03-23 09:56:38 -05:00
playweb:
make crossweb
emrun $(NAME).html
2024-03-09 18:22:06 -06:00
2021-11-30 21:29:18 -06:00
clean:
@echo Cleaning project
rm -f source/shaders/*.h core.cdb jso cdb packer TAGS source/engine/core.cdb.h tools/libcdb.a **.a **.o **.d $(APP)* *.icns *.ico
2024-03-23 09:56:38 -05:00
rm -rf Prosperon.app
2024-02-21 03:45:26 -06:00
docs: doc/prosperon.org
make -C doc
mv doc/html .
2024-02-19 20:31:26 -06:00
TAGINC != find . -name "*.[chj]"
tags: $(TAGINC)
@echo Making tags.
@etags $(TAGINC)