-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
93 lines (75 loc) · 2.46 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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
########################################################################
####################### Makefile Template ##############################
########################################################################
# Compiler settings - Can be customized.
CC = gcc
CXXFLAGS = -std=c11 -Wall -lm -D COMPILER=\"$(CC)\"
LDFLAGS =
# Makefile settings - Can be customized.
APPNAME = casm
EXT = .c
SRCDIR = src
HEADERDIR = include
BINDIR = bin
OBJDIR = $(BINDIR)/obj
############## Do not change anything from here downwards! #############
SRC = $(wildcard $(SRCDIR)/*$(EXT))
OBJ = $(SRC:$(SRCDIR)/%$(EXT)=$(OBJDIR)/%.o)
APP = $(BINDIR)/$(APPNAME)
DEP = $(OBJ:$(OBJDIR)/%.o=%.d)
DEBUGFLAGS = -D DEBUG_TRACE_EXECUTION -D DEBUG_PRINT_CODE
# count stuff
OBJCOUNT_NOPAD = $(shell v=`echo $(OBJ) | wc -w`; echo `seq 1 $$(expr $$v)`)
OBJCOUNT = $(foreach v,$(OBJCOUNT_NOPAD),$(shell printf '%02d' $(v)))
# UNIX-based OS variables & settings
RM = rm
MKDIR = mkdir
DELOBJ = $(OBJ)
########################################################################
####################### Targets beginning here #########################
########################################################################
.MAIN: $(APP)
all: $(APP)
# Builds the app
$(APP): $(OBJ) | makedirs
@printf "[final] compiling final product $(notdir $@)..."
@$(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
@#cp $(APP) "."
@printf "\b\b done!\n"
# Building rule for .o files and its .c/.cpp in combination with all .h
# $(OBJDIR)/%.o: $(SRCDIR)/%$(EXT) | makedirs
$(OBJDIR)/%.o: $(SRCDIR)/%$(EXT) | makedirs
@printf "[$(word 1,$(OBJCOUNT))/$(words $(OBJ))] compiling $(notdir $<) into $(notdir $@)..."
@$(CC) $(CXXFLAGS) -I $(HEADERDIR) -o $@ -c $<
@printf "\b\b done!\n"
$(eval OBJCOUNT = $(filter-out $(word 1,$(OBJCOUNT)),$(OBJCOUNT)))
################### Cleaning rules for Unix-based OS ###################
# Cleans complete project
.PHONY: clean
clean:
@# $(RM) $(DELOBJ) $(DEP) $(APP)
@$(RM) -rf $(OBJDIR)
@$(RM) -rf $(BINDIR)
.PHONY: run
run: $(APP)
@printf "============ Running \"$(APP)\" with args \"$(args)\" ============\n\n"
@$(APP) $(args)
.PHONY: routine
routine: $(APP) run clean
.PHONY: makedirs
makedirs:
@$(MKDIR) -p $(BINDIR)
@$(MKDIR) -p $(OBJDIR)
.PHONY: remake
remake: clean $(APP)
.PHONY: printdebug
printdebug:
@printf "debug mode set!\n"
# .PHONY: debug
debug: CXXFLAGS += $(DEBUGFLAGS)
debug: printdebug
debug: all
.PHONY: test
test: all
@printf "\n\n\n"
@$(APP) test/test.instr test/test.asm $(args)