-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
54 lines (39 loc) · 1.15 KB
/
Makefile
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
45
46
47
48
49
50
51
52
53
54
CC := gcc
CFLAGS := -O2 -std=c17 -Wall -Wextra -pedantic -Isrc -MMD -MP
LDFLAGS := $(shell pkg-config --libs ncursesw)
ifeq ($(shell uname -s), Darwin)
LDFLAGS += -framework CoreServices
endif
ifeq ($(DEBUG), 1)
CFLAGS += -g3 -fstack-protector -fsanitize=address,leak,undefined -DDEBUG
endif
BIN_PATH ?= /usr/local/bin
BIN_NAME := sagit
SOURCE_DIR := src
BUILD_DIR := build
OBJECTS_DIR := $(BUILD_DIR)/$(SOURCE_DIR)
SOURCES := $(shell find $(SOURCE_DIR) -type f -name '*.c')
OBJECTS := $(patsubst $(SOURCE_DIR)/%.c, $(OBJECTS_DIR)/%.o, $(SOURCES))
BINARY := $(BUILD_DIR)/$(BIN_NAME)
OBJECTS := $(patsubst $(SOURCE_DIR)/%.c, $(OBJECTS_DIR)/%.o, $(SOURCES))
DEPENDENCIES := $(patsubst %.o, %.d, $(OBJECTS))
.PHONY: all
all: build
.PHONY: build
build: $(BINARY)
.PHONY: clean
clean:
rm -rf $(BUILD_DIR)
.PHONY: install
install: build
mkdir -p $(BIN_PATH)
install -m 755 $(BINARY) $(BIN_PATH)/$(BIN_NAME)
.PHONY: uninstall
uninstall: build
rm $(BIN_PATH)/$(BIN_NAME)
$(BINARY): $(OBJECTS)
$(CC) $(CFLAGS) -o $@ $^ $(LDFLAGS)
$(OBJECTS_DIR)/%.o: $(SOURCE_DIR)/%.c Makefile
@mkdir -p $(@D)
$(CC) $(CFLAGS) -o $@ -c $<
-include $(DEPENDENCIES)