-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
63 lines (55 loc) · 1.78 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
58
59
60
61
62
CC := g++
TARGET := "ImageProcessing"
BUILDDIR := build
BUILDLIBDIR := build/lib
SRCDIR := src
LIBDIR := src/lib
CFLAGS := -std=c++17 -g
SRCEXT := cpp
SOURCES := $(wildcard $(SRCDIR)/*.$(SRCEXT))
LIBSRCS := $(wildcard $(LIBDIR)/*.$(SRCEXT))
OBJECTS := $(patsubst $(SRCDIR)/%, $(BUILDDIR)/%, $(SOURCES:.$(SRCEXT)=.o)) $(patsubst $(LIBDIR)/%, $(BUILDLIBDIR)/%, $(LIBSRCS:.$(SRCEXT)=.o))
$(BUILDLIBDIR)/%.o: $(LIBDIR)/%.$(SRCEXT)
@printf "\e[33m\e[1mBuilding...\e[0m\n";
@mkdir -p $(BUILDLIBDIR)
@echo " $(notdir $@) from $(notdir $<)"
$(CC) $(CFLAGS) -c -o $@ $<
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@printf "\e[33m\e[1mBuilding...\e[0m\n";
@mkdir -p $(BUILDDIR)
@echo " $(notdir $@) from $(notdir $<)"
$(CC) $(CFLAGS) -c -o $@ $<
$(TARGET): $(OBJECTS)
@printf "\e[35m\e[1mLinking...\e[0m\n";
@echo " $(notdir $(OBJECTS))"
$(CC) $(CFLAGS) -o $@ $^
PHONY: clean
clean:
@printf "\e[31m\e[1mCleaning...\e[0m\n"
@echo " /$(BUILDDIR)"
@echo " /$(TARGET)"
@$(RM) -r $(BUILDDIR) $(OBJECTS)
@$(RM) "./$(TARGET)"
PHONY: r
r:
@printf "\e[33m\e[1mRunning $(TARGET)\e[0m\n"
@./$(TARGET)
PHONY: run
run:
@echo $(OBJECTS)
@mkdir -p $(BUILDLIBDIR)
@for source in $(basename $(notdir $(LIBSRCS))); do\
printf "\e[33m\e[1mBuilding Library...\e[0m\n";\
echo " $$source.o from $$source.$(SRCEXT)";\
$(CC) $(CFLAGS) -c -o $(BUILDLIBDIR)/$$source.o $(LIBDIR)/$$source.$(SRCEXT);\
done
@for source in $(basename $(notdir $(SOURCES))); do\
printf "\e[33m\e[1mBuilding...\e[0m\n";\
echo " $$source.o from $$source.$(SRCEXT)";\
$(CC) $(CFLAGS) -c -o $(BUILDDIR)/$$source.o $(SRCDIR)/$$source.$(SRCEXT);\
done
@printf "\e[95m\e[1mLinking...\e[0m\n";
@echo " $(notdir $(OBJECTS))"
@$(CC) $(CFLAGS) -o $(TARGET) $(OBJECTS)
@printf "\e[33m\e[1mRunning $(TARGET)\e[0m\n"
@ ./$(TARGET)