aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian C <cc@localhost>2025-03-07 22:07:25 -0800
committerChristian C <cc@localhost>2025-03-07 22:07:25 -0800
commit7ed69a0373ea170a164bf0557d61096100a7bba0 (patch)
tree70e27a991289e8f67df5ed765fda847d6cf14eeb
parent0d1f5979dd1d6062af118fae3a1aa1863ea596f2 (diff)
Modularize programs
-rw-r--r--Makefile20
-rw-r--r--src/prog.c (renamed from src/main.c)0
2 files changed, 9 insertions, 11 deletions
diff --git a/Makefile b/Makefile
index 238fb87..380a016 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,5 @@
PKGS=libtiff-4 libpng
DEFINES=
-EXE=prog
BUILD_DIR=build/
INC_DIR=include/
@@ -22,10 +21,13 @@ 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))
-$(info $(LIB_SRCS))
-$(info $(LIB_OBJ_DIR))
-$(info $(LIB_OBJ_DIRS))
-$(info $(LIB_OBJS))
+# 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=$(subst $(SRC_DIR),$(PROG_OUT_DIR),$(PROG_SRCS))
+PROGS=$(PROG_DIRS_sub:.c=)
# Include raylib if we want a visual experience
ifdef RAYLIB
@@ -60,9 +62,9 @@ default: clean build
.PHONY: clean build run
-build: $(BUILD_DIR)$(EXE)
+build: $(PROGS)
-$(BUILD_DIR)$(EXE): $(SRC_OBJS) $(LIB_OBJS)
+$(BUILD_DIR)$(PROG_DIR)%: $(SRC_OBJ_DIR)%.o $(LIB_OBJS)
@echo LD --\> $@
@gcc -o $@ $(LDFLAGS) $^
@@ -78,7 +80,3 @@ clean:
@echo Cleaning build files...
@-rm -rf $(OBJ_DIR) $(BUILD_DIR)
@mkdir -p $(BUILD_DIR) $(SRC_OBJ_DIRS) $(LIB_OBJ_DIRS)
-
-run: $(BUILD_DIR)$(EXE)
- @echo Executing...
- @./$(BUILD_DIR)$(EXE)
diff --git a/src/main.c b/src/prog.c
index 5350797..5350797 100644
--- a/src/main.c
+++ b/src/prog.c