2022-02-04 08:38:25 -06:00
|
|
|
procs != nproc
|
|
|
|
MAKEFLAGS = --jobs=$(procs)
|
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
UNAME != uname
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
ifeq ($(OS),Windows_NT)
|
2022-02-03 09:16:22 -06:00
|
|
|
UNAME = Windows_NT
|
2021-11-30 21:29:18 -06:00
|
|
|
endif
|
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
UNAME_P != uname -m
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
#CC specifies which compiler we're using
|
2022-06-22 23:04:35 -05:00
|
|
|
CC = tcc -std=c99
|
|
|
|
|
|
|
|
MUSL = /usr/local/musl/include
|
2022-06-21 12:48:19 -05:00
|
|
|
|
2021-11-30 21:29:18 -06:00
|
|
|
ifeq ($(DEBUG), 1)
|
|
|
|
DEFFALGS += -DDEBUG
|
|
|
|
INFO = dbg
|
|
|
|
endif
|
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
BIN = ./bin/
|
|
|
|
objprefix = $(BIN)obj
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
DIRS = engine pinball editor brainstorm
|
|
|
|
ETP = ./source/engine/thirdparty/
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
define make_objs
|
2022-06-22 15:20:29 -05:00
|
|
|
find $(1) -type f -name '*.c' | sed 's|\.c.*|.o|' | sed 's|\.|$(objprefix)|1'
|
2022-02-04 08:38:25 -06:00
|
|
|
endef
|
|
|
|
|
|
|
|
define make_obj
|
|
|
|
echo $(1) | tr " " "\n" | sed 's|\.c.*|.o|' | sed 's|\.|$(objprefix)|1'
|
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 find_include
|
2022-02-03 11:29:43 -06:00
|
|
|
find $(1) -type f -name '*.h' | sed 's|\/[^\/]*\.h$$||' | sort | uniq
|
2022-02-03 09:16:22 -06:00
|
|
|
endef
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
define prefix
|
|
|
|
echo $(1) | tr " " "\n" | sed 's|.*|$(2)&$(3)|'
|
|
|
|
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-04 08:38:25 -06:00
|
|
|
define findindir
|
2022-02-04 11:36:24 -06:00
|
|
|
find $(1) -maxdepth 1 -type f -name '$(2)'
|
2022-02-04 08:38:25 -06:00
|
|
|
endef
|
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
# All other sources
|
2022-02-04 08:38:25 -06:00
|
|
|
edirs != find ./source/engine -type d -name include
|
|
|
|
edirs += ./source/engine
|
|
|
|
ehead != $(call findindir,./source/engine,*.h)
|
2022-02-03 09:16:22 -06:00
|
|
|
eobjects != $(call make_objs, ./source/engine)
|
2022-02-04 11:36:24 -06:00
|
|
|
eobjects != $(call rm,$(eobjects),sqlite pl_mpeg_extract_frames pl_mpeg_player yugine.c yugine.c)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
eddirs != find ./source/editor -type d
|
2022-02-04 08:38:25 -06:00
|
|
|
eddirs += ./source/editor
|
|
|
|
edhead != $(call findindir,./source/editor,*.h)
|
2022-06-22 15:20:29 -05:00
|
|
|
edobjects != find ./source/editor -maxdepth 1 -type f -name '*.c'
|
2022-02-04 08:38:25 -06:00
|
|
|
edobjects != $(call make_obj,$(edobjects))
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
bsdirs != find ./source/brainstorm -type d
|
|
|
|
bsobjects != $(call make_objs, ./source/brainstorm)
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
pindirs != find ./source/pinball -type d
|
|
|
|
pinobjects != $(call make_objs, ./source/pinball);
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
edirs += ./source/engine/thirdparty/Chipmunk2D/include ./source/engine/thirdparty/enet/include
|
|
|
|
includeflag != $(call prefix,$(edirs) $(eddirs) $(pindirs) $(bsdirs),-I)
|
2022-02-04 11:36:24 -06:00
|
|
|
COMPINCLUDE = $(edirs) $(eddirs) $(pindirs) $(bsdirs)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
#COMPILER_FLAGS specifies the additional compilation options we're using
|
2022-02-07 08:50:34 -06:00
|
|
|
WARNING_FLAGS = #-Wall -Wextra -Wwrite-strings -Wno-unused-parameter -Wno-unused-function -Wno-missing-braces -Wno-incompatible-function-pointer-types -Wno-gnu-statement-expression -Wno-complex-component-init -pedantic
|
2022-06-21 12:48:19 -05:00
|
|
|
#COMPILER_FLAGS = $(includeflag) -g -O0 $(WARNING_FLAGS) -DGLEW_STATIC -D_GLFW_X11 -D_POSIX_C_SOURCE=1993809L -c -MMD -MP $< -o $@
|
2022-06-21 15:21:00 -05:00
|
|
|
COMPILER_FLAGS = $(includeflag) -I/usr/local/include -g -O0 $(WARNING_FLAGS) -DGLEW_STATIC -D_GLFW_X11 -D_POSIX_C_SOURCE=1993809L -c $< -o $@
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-06-22 23:04:35 -05:00
|
|
|
LIBPATH = -L./bin -L/usr/local/lib -L/usr/local/lib/tcc
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
ifeq ($(UNAME), Windows_NT)
|
2022-02-03 09:16:22 -06:00
|
|
|
LINKER_FLAGS = -static -DSDL_MAIN_HANDLED
|
2022-02-04 11:36:24 -06:00
|
|
|
ELIBS = engine editor mingw32 SDL2main SDL2 m dinput8 dxguid dxerr8 user32 gdi32 winmm imm32 ole32 oleaut32 shell32 version uuid setupapi opengl32 stdc++ winpthread
|
2022-02-03 09:16:22 -06:00
|
|
|
ELIBS += SDL2_mixer FLAC vorbis vorbisenc vorbisfile mpg123 out123 syn123 opus opusurl opusfile ogg ssp shlwapi
|
|
|
|
CLIBS = glew32
|
|
|
|
EXT = .exe
|
2021-11-30 21:29:18 -06:00
|
|
|
else
|
2022-06-22 23:04:35 -05:00
|
|
|
LINKER_FLAGS = -fPIC -rdynamic
|
|
|
|
ELIBS = editor engine glfw3 m c tcc tcc1
|
2022-06-22 20:39:18 -05:00
|
|
|
CLIBS =
|
2022-02-03 09:16:22 -06:00
|
|
|
EXT =
|
2021-11-30 21:29:18 -06:00
|
|
|
endif
|
|
|
|
|
2022-02-03 09:16:22 -06:00
|
|
|
ELIBS != $(call prefix, $(ELIBS), -l)
|
2022-06-22 23:04:35 -05:00
|
|
|
#CLIBS != $(call prefix, $(CLIBS), -l)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-06-22 20:39:18 -05:00
|
|
|
#LELIBS = -Wl,-Bstatic $(ELIBS)# -Wl,-Bdynamic $(CLIBS)
|
2022-06-22 23:04:35 -05:00
|
|
|
LELIBS = $(ELIBS) $(CLIBS)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-03 11:29:43 -06:00
|
|
|
objects = $(bsobjects) $(eobjects) $(pinobjects)
|
|
|
|
DEPENDS = $(objects:.o=.d)
|
|
|
|
-include $(DEPENDS)
|
2022-02-03 09:16:22 -06:00
|
|
|
|
|
|
|
yuginec = ./source/engine/yugine.c
|
2022-01-19 16:43:21 -06:00
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
ENGINE = $(BIN)libengine.a
|
|
|
|
EDITOR = $(BIN)libeditor.a
|
|
|
|
INCLUDE = $(BIN)include
|
2022-02-04 08:38:25 -06:00
|
|
|
|
2022-06-21 15:21:00 -05:00
|
|
|
linkinclude = $(BIN)include
|
2022-02-04 11:36:24 -06:00
|
|
|
|
|
|
|
LINK = $(LIBPATH) $(LINKER_FLAGS) $(LELIBS) -o $@
|
|
|
|
|
|
|
|
engine: $(yuginec:.%.c=$(objprefix)%.o) $(ENGINE)
|
2022-02-04 08:38:25 -06:00
|
|
|
@echo Linking engine
|
2022-06-21 15:21:00 -05:00
|
|
|
@$(CC) $< $(LINK)
|
2022-02-06 10:14:57 -06:00
|
|
|
@echo Finished build
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
editor: $(yuginec:.%.c=$(objprefix)%.o) $(EDITOR) $(ENGINE)
|
2022-02-04 08:38:25 -06:00
|
|
|
@echo Linking editor
|
2022-06-21 15:21:00 -05:00
|
|
|
$(CC) $< $(LINK)
|
2022-02-06 10:14:57 -06:00
|
|
|
@echo Finished build
|
2022-02-03 11:29:43 -06:00
|
|
|
|
2022-06-22 20:39:18 -05:00
|
|
|
$(ENGINE): $(eobjects) bin/libglfw3.a
|
2022-02-04 08:38:25 -06:00
|
|
|
@echo Making library engine.a
|
2022-02-04 11:36:24 -06:00
|
|
|
@ar -r $(ENGINE) $(eobjects)
|
|
|
|
@cp -u -r $(ehead) $(INCLUDE)
|
2022-02-04 08:38:25 -06:00
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
$(EDITOR): $(edobjects)
|
2022-02-04 08:38:25 -06:00
|
|
|
@echo Making editor library
|
2022-02-04 11:36:24 -06:00
|
|
|
@ar -r $(EDITOR) $(edobjects)
|
|
|
|
@cp -u -r $(edhead) $(INCLUDE)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
xbrainstorm: $(ENGINE) $(bsobjects)
|
2022-01-19 16:43:21 -06:00
|
|
|
@echo Making brainstorm
|
2022-06-21 12:48:19 -05:00
|
|
|
@$(CC) $(bsobjects) $(LINK) -o $@
|
2022-02-04 11:36:24 -06:00
|
|
|
@mv xbrainstorm brainstorm/brainstorm$(EXT)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
2022-02-04 11:36:24 -06:00
|
|
|
pinball: $(ENGINE) $(pinobjects)
|
2022-02-03 09:16:22 -06:00
|
|
|
@echo Making pinball
|
2022-06-21 12:48:19 -05:00
|
|
|
@$(CC) $(pinobjects) $(LINK) -o $@
|
2022-02-04 11:36:24 -06:00
|
|
|
@mv pinball paladin/pinball
|
2022-02-03 09:16:22 -06:00
|
|
|
|
2022-06-22 20:39:18 -05:00
|
|
|
bin/libglfw3.a:
|
|
|
|
@echo Making GLFW
|
|
|
|
make glfw/build
|
|
|
|
cp glfw/build/src/libglfw3.a bin/libglfw3.a
|
|
|
|
|
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-02-06 10:14:57 -06:00
|
|
|
-@$(CC) $(COMPILER_FLAGS)
|
2021-11-30 21:29:18 -06:00
|
|
|
|
|
|
|
clean:
|
|
|
|
@echo Cleaning project
|
2022-02-04 11:36:24 -06:00
|
|
|
@find $(BIN) -type f -delete
|