- Fix the clean and deepclean rules to actually make sense: clean removes the intermediary, deepclean removes the outputs - Change the intermediary directory from `out/` to `build/` to better reflect how it is used
63 lines
1.1 KiB
Makefile
63 lines
1.1 KiB
Makefile
# PROGRAMS
|
|
CC = clang
|
|
CXX = clang++
|
|
LD = clang
|
|
AR = ar
|
|
RM = rm -f
|
|
TYPST = typst
|
|
|
|
# COMPILATION FLAGS
|
|
LIBS = raylib
|
|
ifdef DEBUG
|
|
CFLAGS += -Og -g -DDEBUG
|
|
else
|
|
CFLAGS += -O2
|
|
endif
|
|
CFLAGS += -Wall -Wextra -pedantic -std=gnu23 -Iinclude -Werror=return-type $(shell pkg-config --cflags $(LIBS))
|
|
LDFLAGS += $(shell pkg-config --libs $(LIBS))
|
|
|
|
# FILES
|
|
SRCS=$(wildcard src/*.c)
|
|
DEPS=$(patsubst src/%.c, build/%.d, $(SRCS))
|
|
OBJS=$(patsubst src/%.c, build/%.o, $(SRCS))
|
|
|
|
DOCSRC=$(wildcard docs/*.typ)
|
|
DOCS=$(patsubst docs/%.typ, docs/%.pdf, $(DOCSRC))
|
|
|
|
PROGRAM=ain48
|
|
|
|
.PHONY: all build docs clean deepclean
|
|
all: build docs
|
|
|
|
build: $(PROGRAM)
|
|
|
|
docs: $(DOCS)
|
|
|
|
docs/%.pdf: docs/%.typ
|
|
$(TYPST) c $< $@
|
|
|
|
clean:
|
|
$(RM) $(OBJS)
|
|
$(RM) $(DEPS)
|
|
$(RM) compile_commands.json
|
|
deepclean: clean
|
|
$(RM) $(PROGRAM)
|
|
$(RM) $(DOCS)
|
|
|
|
$(PROGRAM): $(OBJS)
|
|
$(LD) $(LDFLAGS) $(OBJS) -o $@
|
|
|
|
build/%.d: src/%.c
|
|
@mkdir -p $(@D)
|
|
@set -e ; $(RM) $@; \
|
|
$(CC) -M $(CFLAGS) $< > $@.$$$$; \
|
|
sed 's,\($*\)\.o[ :]*,build/\1.o $@ : ,g' < $@.$$$$ > $@; \
|
|
$(RM) $@.$$$$
|
|
|
|
build/%.o: src/%.c
|
|
@mkdir -p $(@D)
|
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
|
|
include $(DEPS)
|
|
|