aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 5f129e45f70f3192c4c3d2f48ae821592daee7fc (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
CC?=cc

BIN_EXT =
MKDIR = mkdir -p $(OUT_DIR) $(dir $@)
RM = rm -rf

CFLAGS=-Wall -Wpedantic

LIBFLAGS=$(shell pkg-config --cflags --libs lua5.5) $(shell pkg-config --cflags --libs libarchive) $(shell pkg-config --cflags --libs libcurl) $(shell pkg-config --cflags --libs libb2)
DEBUG_CFLAGS=-g -fsanitize=leak

SRC_DIR=src
OUT_DIR=out
TARGET=pow
CFLAGS+=$(LIBFLAGS)

ifeq ($(wildcard $(SRC_DIR)),)
$(error Source directory '$(SRC_DIR)' not found. Please specify the source directory using 'make SRC_DIR=path/to/source' or edit the makefile)
endif

SRC_FILES := $(wildcard $(SRC_DIR)/**/*.c) $(wildcard $(SRC_DIR)/*.c)

OBJ_FILES := $(patsubst $(SRC_DIR)/%.c,$(OUT_DIR)/%.o,$(SRC_FILES))

DEP_FILES := $(OBJ_FILES:.o=.d)

$(OUT_DIR)/%.o: $(SRC_DIR)/%.c
	$(MKDIR)
	$(CC) -c -o $@ $< $(CFLAGS)

-include $(DEP_FILES)

all: $(TARGET)

debug: CFLAGS += $(DEBUG_CFLAGS)
debug: $(TARGET)

$(TARGET): $(OBJ_FILES)
	$(CC) -o $@$(BIN_EXT) $^ $(CFLAGS)

.PHONY: clean

clean:
	$(RM) $(OUT_DIR) $(TARGET)$(BIN_EXT)