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
|
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
|
|
|
|
# ED --- build with or without editor
|
|
|
|
# OPT --- Optimize
|
2022-12-12 01:35:42 -06:00
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
QFLAGS :=
|
2022-12-12 01:35:42 -06:00
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
ifdef DBG
|
|
|
|
QFLAGS += -O0 -g -DDBG
|
|
|
|
INFO = dbg
|
2023-05-27 10:13:20 -05:00
|
|
|
|
|
|
|
ifeq ($(CC),tcc)
|
|
|
|
QFLAGS +=
|
|
|
|
endif
|
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
else
|
2023-05-24 20:45:50 -05:00
|
|
|
QFLAGS += -O2
|
|
|
|
INFO = rel
|
|
|
|
CC = gcc
|
2022-12-12 10:48:21 -06:00
|
|
|
endif
|
2022-11-24 10:58:36 -06:00
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
ifdef OPT
|
|
|
|
QFLAGS += -flto
|
2021-11-30 21:29:18 -06:00
|
|
|
endif
|
|
|
|
|
2023-05-24 20:45:50 -05:00
|
|
|
ifdef ED
|
|
|
|
QFLAGS += -DED
|
2022-12-12 01:35:42 -06:00
|
|
|
endif
|
2022-11-24 10:58:36 -06:00
|
|
|
|
2023-08-30 18:22:32 -05:00
|
|
|
QFLAGS += -DHAVE_CEIL -DHAVE_FLOOR -DHAVE_FMOD -DHAVE_LRINT -DHAVE_LRINTF
|
|
|
|
|
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
PTYPE != uname -m
|
|
|
|
|
2022-12-15 17:30:17 -06:00
|
|
|
BIN = bin/$(CC)/$(INFO)/
|
2023-08-22 23:34:36 -05:00
|
|
|
|
2022-12-15 17:30:17 -06:00
|
|
|
objprefix = $(BIN)obj
|
2022-02-04 08:38:25 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
define prefix
|
2022-08-06 15:39:29 -05:00
|
|
|
echo $(1) | tr " " "\n" | sed 's/.*/$(2)&$(3)/'
|
2022-02-03 09:16:22 -06:00
|
|
|
endef
|
2022-01-20 11:16:44 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
define rm
|
|
|
|
tmp=$$(mktemp); \
|
|
|
|
echo $(2) | tr " " "\n" > $${tmp}; \
|
|
|
|
echo $(1) | tr " " "\n" | grep -v -f $${tmp}; \
|
|
|
|
rm $${tmp}
|
|
|
|
endef
|
2022-01-20 11:16:44 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
# All other sources
|
2022-11-24 10:58:36 -06:00
|
|
|
edirs != find source -type d -name include
|
2022-12-23 13:48:29 -06:00
|
|
|
subengs = sound 3d
|
|
|
|
|
|
|
|
ifeq ($(DBG), 1)
|
|
|
|
subengs += debug
|
|
|
|
endif
|
|
|
|
|
2022-12-13 12:32:36 -06:00
|
|
|
edirs += source/engine $(addprefix source/engine/, $(subengs)) source/engine/thirdparty/Nuklear
|
2023-06-01 15:58:56 -05:00
|
|
|
ehead != find source/engine source/engine/sound source/engine/debug -maxdepth 1 -type f -name *.h
|
2022-11-24 10:58:36 -06:00
|
|
|
eobjects != find source/engine -type f -name '*.c' | sed -r 's|^(.*)\.c|$(objprefix)/\1.o|' # Gets all .c files and makes .o refs
|
2022-11-03 16:58:03 -05:00
|
|
|
eobjects != $(call rm,$(eobjects),sqlite pl_mpeg_extract_frames pl_mpeg_player yugine nuklear)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-12-23 13:48:29 -06:00
|
|
|
engincs != find source/engine -maxdepth 1 -type d
|
|
|
|
includeflag != find source -type d -name include
|
2022-12-24 13:18:06 -06:00
|
|
|
includeflag += $(engincs) 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-05-30 11:39:22 -05:00
|
|
|
WARNING_FLAGS = -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
|
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-05-30 11:39:22 -05:00
|
|
|
COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -I. -DCP_USE_DOUBLES=0 -DTINYSPLINE_FLOAT_PRECISION -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -c $< -o $@
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-12-14 13:01:42 -06:00
|
|
|
LIBPATH = -L$(BIN)
|
2022-06-28 18:51:21 -05:00
|
|
|
|
2022-12-12 01:35:42 -06:00
|
|
|
ifeq ($(OS), WIN32)
|
2023-08-27 21:57:19 -05:00
|
|
|
LINKER_FLAGS = $(QFLAGS) -static
|
|
|
|
ELIBS = engine glfw3 opengl32 quickjs gdi32 ws2_32 ole32 winmm setupapi m
|
2022-12-12 01:35:42 -06:00
|
|
|
CLIBS =
|
2022-02-03 09:16:22 -06:00
|
|
|
EXT = .exe
|
2021-11-30 21:29:18 -06:00
|
|
|
else
|
2023-05-30 11:39:22 -05:00
|
|
|
LINKER_FLAGS = $(QFLAGS) -L/usr/local/lib -pthread -rdynamic
|
2023-08-29 17:11:36 -05:00
|
|
|
ELIBS = engine pthread quickjs glfw3 asound GL c m dl
|
2022-12-12 01:35:42 -06:00
|
|
|
CLIBS =
|
2021-11-30 21:29:18 -06:00
|
|
|
endif
|
|
|
|
|
2022-12-19 12:16:51 -06:00
|
|
|
NAME = yugine$(EXT)
|
2022-12-12 01:35:42 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
ELIBS != $(call prefix, $(ELIBS), -l)
|
2022-12-15 17:30:22 -06:00
|
|
|
CLIBS != $(call prefix, $(CLIBS), -l);
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-08-06 15:39:29 -05:00
|
|
|
objects = $(eobjects)
|
2022-02-03 11:29:43 -06:00
|
|
|
DEPENDS = $(objects:.o=.d)
|
|
|
|
-include $(DEPENDS)
|
2022-02-03 09:16:22 -06:00
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
ENGINE = $(BIN)libengine.a
|
|
|
|
INCLUDE = $(BIN)include
|
2022-02-04 08:38:25 -06:00
|
|
|
|
2023-04-29 10:07:58 -05:00
|
|
|
SCRIPTS = $(shell ls source/scripts/*.js)
|
|
|
|
|
2022-11-24 10:58:36 -06:00
|
|
|
LINK = $(LIBPATH) $(LINKER_FLAGS) $(ELIBS)
|
2022-11-24 01:54:17 -06:00
|
|
|
|
2022-11-24 10:58:36 -06:00
|
|
|
MYTAG = $(VER)_$(PTYPE)_$(INFO)
|
2022-11-24 01:54:17 -06:00
|
|
|
|
2022-12-15 17:30:17 -06:00
|
|
|
DIST = $(NAME)-$(MYTAG).tar.gz
|
2022-02-03 11:29:43 -06:00
|
|
|
|
2022-12-16 09:07:21 -06:00
|
|
|
yugine: $(BIN)yugine
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-12-15 17:30:17 -06:00
|
|
|
$(NAME): $(BIN)$(NAME)
|
2022-11-23 22:44:42 -06:00
|
|
|
|
2023-04-22 14:07:37 -05:00
|
|
|
$(BIN)$(NAME): $(objprefix)/source/engine/yugine.o $(ENGINE) $(BIN)libquickjs.a
|
2022-12-15 17:30:17 -06:00
|
|
|
@echo Linking $(NAME)
|
|
|
|
$(CC) $< $(LINK) -o $(BIN)$(NAME)
|
2022-11-23 17:29:50 -06:00
|
|
|
@echo Finished build
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2023-04-29 10:07:58 -05:00
|
|
|
$(BIN)$(DIST): $(BIN)$(NAME) source/shaders/* $(SCRIPTS) assets/*
|
2022-12-15 17:30:17 -06:00
|
|
|
@echo Creating distribution $(DIST)
|
2022-12-13 12:32:36 -06:00
|
|
|
@mkdir -p $(BIN)dist
|
2022-12-15 17:30:17 -06:00
|
|
|
@cp $(BIN)$(NAME) $(BIN)dist
|
2023-04-25 14:59:26 -05:00
|
|
|
@cp -rf assets/* $(BIN)dist
|
2022-12-13 12:32:36 -06:00
|
|
|
@cp -rf source/shaders $(BIN)dist
|
2023-04-22 16:44:26 -05:00
|
|
|
@cp -r source/scripts $(BIN)dist
|
2022-12-13 12:32:36 -06:00
|
|
|
@tar czf $(DIST) --directory $(BIN)dist .
|
|
|
|
@mv $(DIST) $(BIN)
|
|
|
|
|
2023-04-22 14:07:37 -05:00
|
|
|
$(BIN)libquickjs.a:
|
|
|
|
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
|
|
|
|
|
|
|
dist: $(BIN)$(DIST)
|
2022-11-23 22:44:42 -06:00
|
|
|
|
2022-12-13 12:32:36 -06:00
|
|
|
install: $(BIN)$(DIST)
|
2022-12-15 17:30:17 -06:00
|
|
|
@echo Unpacking $(DIST) in $(DESTDIR)
|
2022-12-13 12:32:36 -06:00
|
|
|
@cp $(BIN)$(DIST) $(DESTDIR)
|
|
|
|
@tar xzf $(DESTDIR)/$(DIST) -C $(DESTDIR)
|
|
|
|
@rm $(DESTDIR)/$(DIST)
|
2022-08-12 14:03:56 -05:00
|
|
|
|
2022-10-23 17:10:53 -05:00
|
|
|
$(ENGINE): $(eobjects)
|
2022-02-04 08:38:25 -06:00
|
|
|
@echo Making library engine.a
|
2022-06-23 13:16:39 -05:00
|
|
|
@ar r $(ENGINE) $(eobjects)
|
2022-11-20 15:50:14 -06:00
|
|
|
@mkdir -p $(INCLUDE)
|
2022-02-04 11:36:24 -06:00
|
|
|
@cp -u -r $(ehead) $(INCLUDE)
|
2022-02-04 08:38:25 -06:00
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
$(objprefix)/%.o:%.c
|
2022-01-20 11:16:44 -06:00
|
|
|
@mkdir -p $(@D)
|
2022-01-19 16:43:21 -06:00
|
|
|
@echo Making C object $@
|
2022-06-30 10:31:23 -05:00
|
|
|
@$(CC) $(COMPILER_FLAGS)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2023-08-14 17:20:30 -05:00
|
|
|
.PHONY: docs
|
|
|
|
docs:
|
|
|
|
asciidoctor docs/*.adoc
|
|
|
|
|
2022-12-12 01:35:42 -06:00
|
|
|
.PHONY: clean
|
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
|