-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
59 lines (45 loc) · 1.34 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
55
56
57
PROJECT_NAME := example-project
CC := g++
SRCDIR := src
HEADERDIR := include
BUILDDIR := build
BINDIR := bin
TARGET := $(BINDIR)/$(PROJECT_NAME)
SOURCES := $(shell find $(SRCDIR) -type f -name *.c*)
HEDEARS := $(shell find $(HEADERDIR) -type f -name *.h*)
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(addsuffix .o,$(basename $(SOURCES))))
DEPS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(addsuffix .d,$(basename $(SOURCES))))
CFLAGS := -Wall -Werror -Wextra
LIB :=
INC := -I include -I src
all: debug
debug: CFLAGS += -g
debug: $(TARGET)
release: $(TARGET)
release: CFLAGS += -O3
GREEN=`tput setaf 2`
RESET=`tput sgr0`
define print_green
@echo "$(GREEN)$(1)$(RESET)"
endef
all: $(TARGET)
clean:
rm $(BUILDDIR) $(BINDIR) -rf
$(TARGET): $(BINDIR) $(BUILDDIR) $(OBJECTS)
$(call print_green,"Linking object files...")
@$(CC) $(OBJECTS) -o $(TARGET) $(LIB)
$(call print_green,"$(TARGET) has been created!")
$(BUILDDIR) :
mkdir $(BUILDDIR)
$(BINDIR):
mkdir $(BINDIR)
$(BUILDDIR)/%.o: $(SRCDIR)/%.c*
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
@$(CC) $(CFLAGS) $(INC) -M $< -MT $@ > $(@:.o=.td)
@cp $(@:.o=.td) $(@:.o=.d);
@sed -e 's/#.*//' -e 's/^[^:]*: *//' -e 's/ *\\$$//' \
-e '/^$$/ d' -e 's/$$/ :/' < $(@:.o=.td) >> $(@:.o=.d);
@rm -f $(@:.o=.td)
-include $(DEPS)
.PHONY: clean all