-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
76 lines (58 loc) · 1.71 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# Program settings
INCLUDES := include
LIBRARIES :=
SOURCES := source
TARGET := bin/nds_iconconverter
# Language settings
CFLAGS := -Wall -O2 -std=c++17
BUILD := build
CXX := g++
CC := gcc
########################################################################################
CFILES := $(foreach dir,$(SOURCES), \
$(wildcard $(dir)/*.c))
CCFILES := $(foreach dir,$(SOURCES), \
$(wildcard $(dir)/*.cc))
OFILES := $(patsubst %.cc,%.o,$(CCFILES))
OFILES += $(patsubst %.c,%.o,$(CFILES))
INCLUDES := $(addprefix -I,$(INCLUDES))
OBJMAKE = -c $(<) -o $(@)
LDMAKE = -o $(TARGET) $(^)
############################################################
ifeq ($(strip $(CCFILES)),)
LD := $(CC)
else
LD := $(CXX)
endif
ifeq ($(OS),Windows_NT)
CFLAGS += -D__windows__
endif
############################################################
.PHONY: all
all: $(TARGET)
@echo "🎉 All done"
.PHONY: clean
clean:
@echo "🧹 Cleaning ... "
@rm -rf $(foreach dir,$(SOURCES), \
$(wildcard $(dir)/*.o)) \
$(foreach dir,$(SOURCES), \
$(wildcard $(dir)/*.d)) \
$(TARGET) $(BUILD)
###########################################################
DEPS := $(addprefix $(BUILD)/,$(patsubst %.o,%.d,$(OFILES)))
DEPFLAG = -MMD -MF $(BUILD)/$(@:.o=.d)
-include $(DEPS)
###########################################################
$(TARGET): $(OFILES)
@mkdir -p bin
@echo "🔗 Linking $(@) ... "
@$(LD) $(LDMAKE) $(CFLAGS) $(LIBRARIES)
%.o: %.c
@echo "🚧 Compiling C object $(<) -> $(@) ... "
@mkdir -p $(dir $(BUILD)/$(@))
@$(CC) $(OBJMAKE) $(INCLUDES) $(CFLAGS) $(DEPFLAG)
%.o: %.cc
@echo "🚧 Compiling CXX object $(<) -> $(@) ... "
@mkdir -p $(dir $(BUILD)/$(@))
@$(CXX) $(OBJMAKE) $(INCLUDES) $(CFLAGS) $(DEPFLAG)