Bläddra i källkod

[Makefile] Making it much more complex

Vinicius Teshima 1 år sedan
förälder
incheckning
b5a6e02e19
1 ändrade filer med 27 tillägg och 5 borttagningar
  1. 27 5
      Makefile

+ 27 - 5
Makefile

@@ -1,18 +1,40 @@
 SRCS=$(shell find ./src -name '*.c' -type f)
+DEPS=$(patsubst %.c, %.d, ${SRCS})
 HDRS=$(shell find ./src -name '*.h' -type f)
 
-CFLAGS=-ansi -m64 -Og -fsanitize=address -ggdb \
+CFLAGS+=-ansi -m64 -Og -ggdb \
 -pedantic -Wall -Wextra -Wshadow \
 -Wcast-align -Wunused -Wconversion -Wmisleading-indentation \
 -Wdouble-promotion -Wformat=2 -Wbad-function-cast \
 -Wmissing-declarations \
 -Wmissing-prototypes -Wnested-externs -Werror
 
-sdl3: src/sdl3.c ${HDRS}
-	gcc $(shell pkg-config --cflags sdl3) $(shell pkg-config --libs sdl3) -ggdb ${CFLAGS} $^ -o $@
+LDFLAGS+= -fsanitize=address
 
-cint: src/cint.c ${HDRS}
-	gcc -ggdb ${CFLAGS} $^ -o $@
+ifneq ($(findstring -static, ${LDFLAGS}), )
+	LDFLAGS:=$(filter-out -fsanitize=address, ${LDFLAGS})
+	_PKGT_STATIC:=--static
+endif
+
+BIN := $(subst src/,,$(patsubst %.c, %, ${SRCS}))
+
+_CFLAGS_sdl3:=$(shell pkg-config ${_PKG_STATIC} --cflags sdl3)
+_LDFLAGS_sdl3:=$(shell pkg-config ${_PKG_STATIC} --libs sdl3)
+
+_CFLAGS_raylib:=$(shell pkg-config ${_PKG_STATIC} --cflags raylib)
+_LDFLAGS_raylib:=$(shell pkg-config ${_PKG_STATIC} --libs raylib)
+
+${BIN}: %: src/%.o
+	gcc ${LDFLAGS} ${_LDFLAGS_$@} $^ -o $@
+
+
+%.o: %.c
+	gcc ${CFLAGS} ${_CFLAGS_${@:src/%.o=%}} $^ -c -o $@
+
+%.d: %.c
+	gcc ${CFLAGS} -MM $^ > $@
+
+include ${DEPS}
 
 tags: ${SRCS} ${HDRS}
 	ctags --kinds-all=* --totals=yes $^