aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile69
1 files changed, 52 insertions, 17 deletions
diff --git a/Makefile b/Makefile
index 7da1156..d25d150 100644
--- a/Makefile
+++ b/Makefile
@@ -1,15 +1,48 @@
PKGS=libtiff-4 libpng
-#PKGS+=raylib
-EXE=prog
+DEFINES=
BUILD_DIR=build/
-OBJ_DIR=$(BUILD_DIR)obj/
-SRC_DIR=src/
INC_DIR=include/
-SRCS=$(shell find $(SRC_DIR) -iname \*.c)
-OBJS_sub=$(subst $(SRC_DIR),$(OBJ_DIR),$(SRCS))
-OBJS=$(OBJS_sub:.c=.o)
-OBJ_DIRS_sub=$(shell find $(SRC_DIR) -type d)
-OBJ_DIRS=$(subst $(SRC_DIR),$(OBJ_DIR),$(OBJ_DIRS_sub))
+
+# Source files
+SRC_DIR=src/
+SRC_OBJ_DIR=$(BUILD_DIR)obj/$(SRC_DIR)
+SRC_SRCS=$(shell find $(SRC_DIR) -iname \*.c)
+SRC_OBJS_sub=$(subst $(SRC_DIR),$(SRC_OBJ_DIR),$(SRC_SRCS))
+SRC_OBJS=$(SRC_OBJS_sub:.c=.o)
+SRC_OBJ_DIRS_sub=$(shell find $(SRC_DIR) -type d)
+SRC_OBJ_DIRS=$(subst $(SRC_DIR),$(SRC_OBJ_DIR),$(SRC_OBJ_DIRS_sub))
+
+# Library files
+LIB_DIR=lib/
+LIB_OBJ_DIR=$(BUILD_DIR)obj/$(LIB_DIR)
+LIB_SRCS=$(shell find $(LIB_DIR) -iname \*.c)
+LIB_OBJS_sub=$(subst $(LIB_DIR),$(LIB_OBJ_DIR),$(LIB_SRCS))
+LIB_OBJS=$(LIB_OBJS_sub:.c=.o)
+LIB_OBJ_DIRS_sub=$(shell find $(LIB_DIR) -type d)
+LIB_OBJ_DIRS=$(subst $(LIB_DIR),$(LIB_OBJ_DIR),$(LIB_OBJ_DIRS_sub))
+
+# Programs
+PROG_DIR=
+PROG_OUT_DIR=$(BUILD_DIR)$(PROG_DIR)
+PROG_SRCS=$(shell find $(SRC_DIR) -iname \*.c)
+PROG_OBJS=$(PROG_SRCS:.c=.o)
+PROG_DIRS_sub=$(shell find $(SRC_DIR) -type d)
+PROG_DIRS=$(subst $(SRC_DIR),$(PROG_OUT_DIR),$(PROG_DIRS_sub))
+PROGS_sub=$(subst $(SRC_DIR),$(PROG_OUT_DIR),$(PROG_SRCS))
+PROGS=$(PROGS_sub:.c=)
+
+# Include raylib if we want a visual experience
+ifdef RAYLIB
+$(info Visual Experience Selected)
+PKGS+=raylib
+DEFINES+=-DVISUAL
+endif
+
+# Dump AVL tree info?
+ifdef AVL_INFO
+$(info Including AVL Dump)
+DEFINES+=-DAVL_INFO
+endif
ifeq ($(shell uname -s),Linux)
PKGCONF=pkgconf
@@ -21,6 +54,8 @@ endif
CFLAGS=
CFLAGS+=$(shell $(PKGCONF) --cflags $(PKGS))
CFLAGS+=-I$(INC_DIR)
+CFLAGS+=$(DEFINES)
+CFLAGS+=-Wall
LDFLAGS=
LDFLAGS+=$(shell $(PKGCONF) --libs $(PKGS))
@@ -29,21 +64,21 @@ default: clean build
.PHONY: clean build run
-build: $(BUILD_DIR)$(EXE)
+build: $(PROGS)
-$(BUILD_DIR)$(EXE): $(OBJS)
+$(BUILD_DIR)$(PROG_DIR)%: $(SRC_OBJ_DIR)%.o $(LIB_OBJS)
@echo LD --\> $@
@gcc -o $@ $(LDFLAGS) $^
-$(OBJ_DIR)%.o: $(SRC_DIR)%.c
+$(SRC_OBJ_DIR)%.o: $(SRC_DIR)%.c
+ @echo CC $< --\> $@
+ @gcc -o $@ $(CFLAGS) -c $<
+
+$(LIB_OBJ_DIR)%.o: $(LIB_DIR)%.c
@echo CC $< --\> $@
@gcc -o $@ $(CFLAGS) -c $<
clean:
@echo Cleaning build files...
@-rm -rf $(OBJ_DIR) $(BUILD_DIR)
- @mkdir -p $(OBJ_DIR) $(BUILD_DIR) $(OBJ_DIRS)
-
-run: $(BUILD_DIR)$(EXE)
- @echo Executing...
- @./$(BUILD_DIR)$(EXE)
+ @mkdir -p $(BUILD_DIR) $(SRC_OBJ_DIRS) $(LIB_OBJ_DIRS) $(PROG_DIRS)