prosperon/Makefile

153 lines
3.3 KiB
Makefile
Raw Normal View History

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
# Options
# DBG=0,1 --- build with debugging symbols and logging
# ED=0,1 --- build with or without editor
2022-12-23 13:48:29 -06:00
ED ?= 1
DBG ?= 1
ifeq ($(DBG), 1)
2022-12-23 13:48:29 -06:00
LVL = -O0 -g
INFO = dbg
ifeq ($(CC), tcc)
2022-12-23 13:48:29 -06:00
LVL +=
endif
2021-11-30 21:29:18 -06:00
2022-12-23 13:48:29 -06:00
else
LVL = -O2 -DNDEBUG
INFO = rel
endif
2022-12-23 13:48:29 -06:00
QFLAGS = $(LVL) -DDBG=$(DBG) -DED=$(ED)
PTYPE != uname -m
BIN = bin/$(CC)/$(INFO)/
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
edirs != find source -type d -name include
2022-12-23 13:48:29 -06:00
subengs = sound 3d
ifeq ($(ED), 1)
subengs += editor
endif
ifeq ($(DBG), 1)
subengs += debug
endif
edirs += source/engine $(addprefix source/engine/, $(subengs)) source/engine/thirdparty/Nuklear
ehead != find source/engine source/engine/sound source/engine/debug source/engine/editor -maxdepth 1 -type f -name *.h
eobjects != find source/engine -type f -name '*.c' | sed -r 's|^(.*)\.c|$(objprefix)/\1.o|' # Gets all .c files and makes .o refs
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
WARNING_FLAGS = -Wall# -pedantic -Wextra -Wwrite-strings -Wno-incompatible-function-pointer-types -Wno-incompatible-pointer-types -Wno-unused-function
SEM = 0.0.1
COM != git rev-parse --short HEAD
VER = $(SEM)-$(COM)
COMPILER_FLAGS = $(includeflag) $(QFLAGS) -MD $(WARNING_FLAGS) -DVER=\"$(VER)\" -DINFO=\"$(INFO)\" -c $< -o $@
2021-11-30 21:29:18 -06:00
LIBPATH = -L$(BIN)
2022-06-28 18:51:21 -05:00
ifeq ($(OS), WIN32)
LINKER_FLAGS = $(QFLAGS) -static
ELIBS = engine ucrt yughc portaudio glfw3 opengl32 gdi32 ws2_32 ole32 winmm setupapi m
CLIBS =
2022-12-19 12:16:51 -06:00
EXT = .exe
2021-11-30 21:29:18 -06:00
else
LINKER_FLAGS = $(QFLAGS) -L/usr/local/lib
ELIBS = engine pthread yughc portaudio asound glfw3 c m dl samplerate
CLIBS =
2021-11-30 21:29:18 -06:00
endif
2022-12-19 12:16:51 -06:00
NAME = yugine$(EXT)
2022-02-03 09:16:22 -06:00
ELIBS != $(call prefix, $(ELIBS), -l)
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
LINK = $(LIBPATH) $(LINKER_FLAGS) $(ELIBS)
MYTAG = $(VER)_$(PTYPE)_$(INFO)
DIST = $(NAME)-$(MYTAG).tar.gz
2022-12-16 09:07:21 -06:00
yugine: $(BIN)yugine
2022-02-03 11:29:43 -06:00
$(NAME): $(BIN)$(NAME)
$(BIN)$(NAME): $(objprefix)/source/engine/yugine.o $(ENGINE)
@echo Linking $(NAME)
$(CC) $< $(LINK) -o $(BIN)$(NAME)
@echo Finished build
2022-08-12 14:03:56 -05:00
$(BIN)$(DIST): $(BIN)$(NAME) source/shaders/*
@echo Creating distribution $(DIST)
@mkdir -p $(BIN)dist
@cp $(BIN)$(NAME) $(BIN)dist
@cp -rf assets/fonts $(BIN)dist
@cp -rf source/scripts $(BIN)dist
@cp -rf source/shaders $(BIN)dist
@tar czf $(DIST) --directory $(BIN)dist .
@mv $(DIST) $(BIN)
dist: $(BIN)$(DIST)
install: $(BIN)$(DIST)
@echo Unpacking $(DIST) in $(DESTDIR)
@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
.PHONY: clean
2021-11-30 21:29:18 -06:00
clean:
@echo Cleaning project
@rm -rf bin/*
@rm -f *.gz