diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5dca275 --- /dev/null +++ b/Makefile @@ -0,0 +1,34 @@ +TARGET := dns-keeper +SRC_DIR := src +BUILD_DIR := build + +CC := gcc +CFLAGS := -O2 -Wall -Wextra -ffunction-sections -fdata-sections -flto +CFLAGS += $(shell pkg-config --cflags libcurl) + +ifeq ($(STATIC),1) +LDFLAGS := -Wl,--gc-sections -Wl,-s -flto -static \ + $(shell pkg-config --static --libs libcurl) -lcjson -lpthread +else +LDFLAGS := -Wl,--gc-sections -Wl,-s -flto \ + $(shell pkg-config --libs libcurl) -lcjson -lpthread +endif + +SRCS := $(wildcard $(SRC_DIR)/*.c) +OBJS := $(patsubst $(SRC_DIR)/%.c, $(BUILD_DIR)/%.o, $(SRCS)) + +.PHONY: all clean + +all: $(BUILD_DIR)/$(TARGET) + +$(BUILD_DIR)/$(TARGET): $(OBJS) + $(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS) + +$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR) + $(CC) $(CFLAGS) -c $< -o $@ + +$(BUILD_DIR): + mkdir -p $(BUILD_DIR) + +clean: + rm -rf $(BUILD_DIR)