2022-11-24 10:58:36 -06:00
|
|
|
PROCS != nproc
|
|
|
|
MAKEFLAGS = --jobs=$(PROCS)
|
2022-02-04 08:38:25 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
UNAME != uname
|
2023-09-04 01:20:55 -05:00
|
|
|
MAKEDIR != pwd
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-12-12 01:35:42 -06:00
|
|
|
# Options
|
2023-05-24 20:45:50 -05:00
|
|
|
# DBG --- build with debugging symbols and logging
|
2023-09-03 12:50:02 -05:00
|
|
|
|
|
|
|
# Temp to strip long emcc paths to just emcc
|
|
|
|
CC := $(notdir $(CC))
|
|
|
|
|
|
|
|
DBG ?= 1
|
2023-09-04 09:48:44 -05:00
|
|
|
OPT ?= 0
|
2022-12-12 01:35:42 -06:00
|
|
|
|
2023-09-03 12:50:02 -05:00
|
|
|
INFO :=
|
|
|
|
|
|
|
|
ifeq ($(DBG),1)
|
2023-09-04 16:27:30 -05:00
|
|
|
CFLAGS += -g
|
|
|
|
INFO += dbg
|
2022-12-23 13:48:29 -06:00
|
|
|
else
|
2023-09-04 16:27:30 -05:00
|
|
|
CFLAGS += -DNDEBUG
|
|
|
|
LDFLAGS += -s
|
|
|
|
INFO += rel
|
2022-12-12 01:35:42 -06:00
|
|
|
endif
|
2022-11-24 10:58:36 -06:00
|
|
|
|
2023-09-04 16:27:30 -05:00
|
|
|
ifeq ($(OPT),small)
|
|
|
|
CFLAGS += -Os
|
|
|
|
AR = ar
|
|
|
|
INFO := $(addsuffix _small,$(INFO))
|
2023-09-04 09:48:44 -05:00
|
|
|
else
|
2023-09-04 16:27:30 -05:00
|
|
|
ifeq ($(OPT), 1)
|
|
|
|
CFLAGS += -O2 -flto
|
|
|
|
AR = llvm-ar
|
|
|
|
INFO := $(addsuffix _opt,$(INFO))
|
|
|
|
else
|
|
|
|
CFLAGS += -O0
|
|
|
|
endif
|
2023-09-04 09:48:44 -05:00
|
|
|
endif
|
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
PTYPE != uname -m
|
|
|
|
|
2023-09-04 16:27:30 -05:00
|
|
|
CFLAGS += -DHAVE_CEIL -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF $(includeflag) -MD $(WARNING_FLAGS) -I. -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DVER=\"$(VER)\" -DINFO=\"$(INFO)\"
|
2023-09-02 06:53:52 -05:00
|
|
|
|
2023-09-04 16:27:30 -05:00
|
|
|
PKGCMD = tar --directory $(BIN) --exclude="./*.a" --exclude="./obj" -czf $(DISTDIR)/$(DIST) .
|
2023-09-03 12:50:02 -05:00
|
|
|
ZIP = .tar.gz
|
2023-09-04 01:20:55 -05:00
|
|
|
UNZIP = cp $(DISTDIR)/$(DIST) $(DESTDIR) && tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR) && rm $(DESTDIR)/$(DIST)
|
2023-09-03 12:50:02 -05:00
|
|
|
|
|
|
|
ARCH = x64
|
|
|
|
|
2023-09-02 06:53:52 -05:00
|
|
|
ifeq ($(OS), Windows_NT)
|
2023-09-04 16:27:30 -05:00
|
|
|
LDFLAGS += -mwin32 -static
|
|
|
|
CFLAGS += -mwin32
|
|
|
|
LDLIBS += mingw32 kernel32 user32 shell32 dxgi gdi32 ws2_32 ole32 winmm setupapi m
|
2023-09-03 12:50:02 -05:00
|
|
|
EXT = .exe
|
|
|
|
PLAT = w64
|
2023-09-04 01:20:55 -05:00
|
|
|
PKGCMD = cd $(BIN); zip -q -r $(MAKEDIR)/$(DISTDIR)/$(DIST) . -x \*.a ./obj/\*
|
2023-09-03 12:50:02 -05:00
|
|
|
ZIP = .zip
|
2023-09-04 01:20:55 -05:00
|
|
|
UNZIP = unzip -o -q $(DISTDIR)/$(DIST) -d $(DESTDIR)
|
2023-09-03 12:50:02 -05:00
|
|
|
else ifeq ($(CC), emcc)
|
2023-09-04 16:27:30 -05:00
|
|
|
LDFLAGS += -sMIN_WEBGL_VERSION=2 -sMAX_WEBGL_VERSION=2 -pthread -s ALLOW_MEMORY_GROWTH=1
|
|
|
|
CFLAGS += -pthread
|
|
|
|
LDLIBS += pthread quickjs GL openal c m dl
|
2023-09-03 12:50:02 -05:00
|
|
|
CC = emcc
|
|
|
|
EXT = .html
|
|
|
|
PLAT = html5
|
2023-08-31 17:23:24 -05:00
|
|
|
else
|
2023-09-03 12:50:02 -05:00
|
|
|
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
|
2023-09-03 12:50:02 -05:00
|
|
|
PLAT = linux-$(ARCH)
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifeq ($(UNAME), Darwin)
|
|
|
|
ifeq ($(PLATFORM), macosx)
|
2023-09-04 16:27:30 -05:00
|
|
|
LDLIBS += Coca QuartzCore OpenGL
|
2023-09-03 12:50:02 -05:00
|
|
|
PLAT = mac-$(ARCH)
|
|
|
|
else ifeq ($(PLATFORM), iphoneos)
|
2023-09-04 16:27:30 -05:00
|
|
|
LDLIBS += Foundation UIKit OpenGLES GLKit
|
2023-09-03 12:50:02 -05:00
|
|
|
endif
|
|
|
|
endif
|
2023-08-31 17:23:24 -05:00
|
|
|
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
|
2023-09-04 16:27:30 -05:00
|
|
|
includeflag += $(engineincs) source/engine/thirdparty/Nuklear
|
2022-12-23 13:48:29 -06:00
|
|
|
includeflag := $(addprefix -I, $(includeflag))
|
2022-06-23 13:16:39 -05:00
|
|
|
|
2023-09-04 01:20:55 -05:00
|
|
|
WARNING_FLAGS = -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types #-Wall -Wno-incompatible-function-pointer-types -Wno-unused-function# -pedantic -Wextra -Wwrite-strings -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function -Wno-int-conversion
|
2022-11-24 01:54:17 -06:00
|
|
|
|
2023-09-04 16:27:30 -05:00
|
|
|
NAME = yugine$(EXT)
|
2022-11-24 01:54:17 -06:00
|
|
|
SEM = 0.0.1
|
2023-08-22 07:29:53 -05:00
|
|
|
COM != fossil describe
|
2022-11-24 01:54:17 -06:00
|
|
|
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
|
|
|
|
2023-04-29 10:07:58 -05:00
|
|
|
SCRIPTS = $(shell ls source/scripts/*.js)
|
|
|
|
|
2022-11-24 10:58:36 -06:00
|
|
|
MYTAG = $(VER)_$(PTYPE)_$(INFO)
|
2022-11-24 01:54:17 -06:00
|
|
|
|
2023-09-03 12:50:02 -05:00
|
|
|
DIST = yugine-$(PLAT)-$(COM)$(ZIP)
|
|
|
|
DISTDIR = ./dist
|
2022-02-03 11:29:43 -06:00
|
|
|
|
2023-09-03 12:50:02 -05:00
|
|
|
.DEFAULT_GOAL := all
|
|
|
|
all: $(DISTDIR)/$(DIST)
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2023-09-03 12:50:02 -05:00
|
|
|
DESTDIR ?= ~/.bin
|
|
|
|
|
|
|
|
install: $(DISTDIR)/$(DIST)
|
|
|
|
@echo Unpacking $(DIST) in $(DESTDIR)
|
|
|
|
# @unzip $(DISTDIR)/$(DIST) -d $(DESTDIR)
|
2023-09-04 01:20:55 -05:00
|
|
|
@$(UNZIP)
|
2022-11-23 22:44:42 -06:00
|
|
|
|
2023-09-04 16:27:30 -05:00
|
|
|
$(BIN)/$(NAME): $(BIN)/libengine.a $(BIN)/libquickjs.a
|
2022-12-15 17:30:17 -06:00
|
|
|
@echo Linking $(NAME)
|
2023-09-04 16:27:30 -05:00
|
|
|
$(CC) $^ $(LDFLAGS) $(LDLIBS) -o $@
|
2022-11-23 17:29:50 -06:00
|
|
|
@echo Finished build
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2023-09-04 16:27:30 -05:00
|
|
|
$(DISTDIR)/$(DIST): $(BIN)/$(NAME) source/shaders/* $(SCRIPTS) assets/*
|
2022-12-15 17:30:17 -06:00
|
|
|
@echo Creating distribution $(DIST)
|
2023-09-03 12:50:02 -05:00
|
|
|
@mkdir -p $(DISTDIR)
|
|
|
|
@cp -rf assets/* $(BIN)
|
|
|
|
@cp -rf source/shaders $(BIN)
|
|
|
|
@cp -r source/scripts $(BIN)
|
|
|
|
@$(PKGCMD)
|
2022-12-13 12:32:36 -06:00
|
|
|
|
2023-09-04 16:27:30 -05:00
|
|
|
$(BIN)/libengine.a: $(OBJS)
|
|
|
|
@$(AR) r $@ $^
|
|
|
|
|
|
|
|
$(BIN)/libquickjs.a:
|
2023-04-22 14:07:37 -05:00
|
|
|
make -C quickjs clean
|
|
|
|
make -C quickjs libquickjs.a libquickjs.lto.a CC=$(CC)
|
|
|
|
cp quickjs/libquickjs.* $(BIN)
|
2022-12-13 12:32:36 -06:00
|
|
|
|
2023-09-04 16:27:30 -05:00
|
|
|
$(OBJDIR)/%.o:%.c
|
2022-01-20 11:16:44 -06:00
|
|
|
@mkdir -p $(@D)
|
2023-09-04 09:48:44 -05:00
|
|
|
@echo Making C object $@
|
2023-09-04 16:27:30 -05:00
|
|
|
@$(CC) $(CFLAGS) -c $^ -o $@
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
clean:
|
|
|
|
@echo Cleaning project
|
2022-12-14 13:01:42 -06:00
|
|
|
@rm -rf bin/*
|
2022-12-13 12:32:36 -06:00
|
|
|
@rm -f *.gz
|
2023-09-03 12:50:02 -05:00
|
|
|
@rm -rf dist/*
|