Repository navigation
Expand file tree
/
Copy pathMakefile
More file actions
executable file
·140 lines (115 loc) · 4.43 KB
/
Copy pathMakefile
File metadata and controls
executable file
·140 lines (115 loc) · 4.43 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
###############################################################################
# Project structure
###############################################################################
BIN_DIR= bin/
OBJ_DIR= obj/
###############################################################################
# Toolchain
###############################################################################
BINPATH=
PREFIX=
CC= $(BINPATH)$(PREFIX)gcc
AS= $(BINPATH)$(PREFIX)gcc -x assembler-with-cpp
CP= $(BINPATH)$(PREFIX)objcopy
AR= $(BINPATH)$(PREFIX)ar
SZ= $(BINPATH)$(PREFIX)size
HEX= $(CP) -O ihex
BIN= $(CP) -O binary -S
CFLAGS= -Isrc\
-W -Wall -Werror\
-fdata-sections -ffunction-sections
LFLAGS= -lm\
-Wl,--gc-sections
###############################################################################
# Utilities
###############################################################################
# TERMINAL COLORS
RED := $(shell tput -Txterm setaf 1)
GREEN := $(shell tput -Txterm setaf 2)
WHITE := $(shell tput -Txterm setaf 7)
YELLOW := $(shell tput -Txterm setaf 3)
RESET := $(shell tput -Txterm sgr0)
# Add the following 'help' target to your Makefile
# And add help text after each target name starting with '\#\#'
# A category can be added with @category
# Credits to: https://gist.github.com/prwhite/8168133
HELP_FUNC = \
%help; \
while(<>) { \
if(/^([a-z0-9_-]+):.*\#\#(?:@(\w+))?\s(.*)$$/) { \
push(@{$$help{$$2}}, [$$1, $$3]); \
} \
}; \
print "Usage: make ${YELLOW}[target]${RESET}\n\n"; \
for ( sort keys %help ) { \
print "${WHITE}$$_:${RESET}\n"; \
printf(" ${YELLOW}%-20s${RESET} ${GREEN}%s${RESET}\n", $$_->[0], $$_->[1]) for @{$$help{$$_}}; \
print "\n"; \
}
PASS := @tput bold && tput -Txterm setaf 2 && echo "OK" && tput -Txterm sgr0
BUILD_OK := @tput bold && tput -Txterm setaf 2 && echo "Build successfully!" && tput -Txterm sgr0
COMP_MSG := @tput bold && tput -Txterm setaf 3 && echo -n "Compiling " && tput -Txterm sgr0
MAKE_DIR := @tput bold && tput -Txterm setaf 6 && echo -n "Created " && tput -Txterm sgr0
###############################################################################
# Phony rules
###############################################################################
.PHONY: all
all: ##@options Build everything
all: static_linked_list inheritance_in_c bubble_sort
@echo
$(BUILD_OK)
@echo
.PHONY: clean
clean: ##@options Clean generated files and folders
clean:
@echo -n "Cleaning $(TARGET_NAME) project\t"
@rm -fR $(OBJ_DIR)
@rm -fR $(BIN_DIR)
$(PASS)
@echo
.PHONY: help
help: ##@options Shows a list of all available make options.
@perl -e '$(HELP_FUNC)' $(MAKEFILE_LIST)
###############################################################################
# static_linked_list
###############################################################################
.PHONY: static_linked_list
static_linked_list: ##@C_examples Build linked list with static memory allocation.
static_linked_list: src/static_linked_list/main.c | $(BIN_DIR)
$(COMP_MSG)
@echo -n "$@ \t"
@$(CC) -o $(BIN_DIR)$@ $^ $(CFLAGS) $(LDFLAGS)
$(PASS)
###############################################################################
# inheritance-in-C
###############################################################################
INHERITANCE_IN_C_SRC = src/inheritance_in_c/main.c \
src/inheritance_in_c/AbstractProduct.c \
src/inheritance_in_c/Book.c \
src/inheritance_in_c/Product.c \
src/inheritance_in_c/TravelGuide.c
.PHONY: inheritance_in_c
inheritance_in_c: ##@C_examples Implements inheritance with a primitive way in C!!! (needs -fms-extensions or -std=c11 compiler flag)
inheritance_in_c: $(INHERITANCE_IN_C_SRC) | $(BIN_DIR)
$(COMP_MSG)
@echo -n "$@ \t"
@$(CC) -o $(BIN_DIR)$@ $^ -fms-extensions $(CFLAGS) $(LDFLAGS) -Isrc/inheritance-in-C/
$(PASS)
###############################################################################
# bubble_sort
###############################################################################
.PHONY: bubble_sort
bubble_sort: ##@C_examples Classic bubble sort algorithm.
bubble_sort: src/bubble_sort/main.c | $(BIN_DIR)
$(COMP_MSG)
@echo -n "$@ \t"
@$(CC) -o $(BIN_DIR)$@ $^ $(CFLAGS) $(LDFLAGS)
$(PASS)
###############################################################################
# Create bin directory
###############################################################################
$(BIN_DIR):
$(MAKE_DIR)
@echo -n "$@ \t"
@mkdir -p $@
$(PASS)