-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
52 lines (39 loc) · 1.2 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
.POSIX:
CC = clang
CPPFLAGS := -MMD -MP -DSYNTH_LIB_ALONE
CFLAGS := -Wall -Wextra -std=c99 -pedantic -Ofast
LDFLAGS = -s
# LDLIBS =
# PREFIX = /usr/local
LIB_DIR := lib
BUILD_DIR := build
SRC_DIR := resynthesizer
SRCS := $(shell find $(SRC_DIR) -name '*.c')
OBJS := $(SRCS:%=$(BUILD_DIR)/%.o)
DEPS := $(OBJS:.o=.d)
INC_DIRS := $(shell find $(SRC_DIR) -type d)
INC_FLAGS := $(addprefix -I,$(INC_DIRS))
TARGET_LIB := $(LIB_DIR)/libresynthesizer.a
EXAMPLE_DIR := examples
EXAMPLE_SRCS := $(shell find $(EXAMPLE_DIR) -name '*.c')
EXAMPLES := $(basename $(EXAMPLE_SRCS))
# -g -Wall -Wextra -Werror -std=c99 -pedantic-errors
# TODO: Try both -Werror and -pedantic-errors after all the chores are done.
all: $(EXAMPLES)
@echo "\033[1;92mDone!\033[0m"
$(EXAMPLES): $(TARGET_LIB) $(EXAMPLE_SRCS)
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
$(CC) $(CFLAGS) -o $@ $@.c $(LDFLAGS) $(INC_FLAGS) $(TARGET_LIB)
$(TARGET_LIB): $(OBJS)
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
ar rvs $@ $^
$(BUILD_DIR)/%.c.o: %.c
@echo "\033[1;92mBuilding $@\033[0m"
mkdir -p $(dir $@)
$(CC) $(CPPFLAGS) $(CFLAGS) -c $< -o $@
.PHONY: clean
clean:
$(RM) -r $(BUILD_DIR) $(LIB_DIR) $(EXAMPLES)
-include $(DEPS)