-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
123 lines (94 loc) · 2.73 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
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
# Includes the config.mk igurations
include config.mk
#
# Validating project variables defined in config.mk
#
ifndef PROJECT_NAME
$(error Missing PROJECT_NAME. Put variables at config.mk file)
endif
ifndef BINARY
$(error Missing BINARY. Put variables at config.mk file)
endif
ifndef PROJECT_PATH
$(error Missing PROJECT_PATH. Put variables at config.mk file)
endif
# Gets the Operating system name
OS = $(shell uname -s)
# Default shell
SHELL = bash
# Color prefix for Linux distributions
COLOR_PREFIX = e
ifeq ($(OS),Darwin)
COLOR_PREFIX = 033
endif
# Color definition for print purpose
BROWN=\$(COLOR_PREFIX)[0;33m
BLUE=\$(COLOR_PREFIX)[1;34m
END_COLOR=\$(COLOR_PREFIX)[0m
# Source code directory structure
BINDIR = bin
SRCDIR = src
LOGDIR = log
LIBDIR = lib
TESTDIR = test
# Source code file extension
SRCEXT = c
# Defines the C Compiler
CC = gcc
# Defines the language standards for GCC
STD = -std=c11 # See man gcc for more options
# Protection for stack-smashing attack
# STACK = -fstack-protector-all -Wstack-protector
# Specifies to GCC the required warnings
WARNS = -Wall -Wextra -pedantic
# Flags for compiling
CFLAGS = -O3 $(STD) $(STACK) $(WARNS)
# Debug options
DEBUG = -g3 -DDEBUG=1
# Dependency libraries
LIBS = -lm -lncurses
# %.o file names
NAMES = $(notdir $(basename $(wildcard $(SRCDIR)/*.$(SRCEXT))))
OBJECTS =$(patsubst %,$(LIBDIR)/%.o,$(NAMES))
#
# COMPILATION RULES
#
default: all
# Rule for link and generate the binary file
all: $(OBJECTS)
@echo -en "$(BROWN)LD $(END_COLOR)";
$(CC) -o $(BINDIR)/$(BINARY) $+ $(DEBUG) $(CFLAGS) $(LIBS)
@echo -en "\n--\nBinary file placed at" \
"$(BROWN)$(BINDIR)/$(BINARY)$(END_COLOR)\n";
# Rule for object binaries compilation
$(LIBDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@echo -en "$(BROWN)CC $(END_COLOR)";
$(CC) -c $^ -o $@ $(DEBUG) $(CFLAGS) $(LIBS)
# Run
FILES = $(filter-out $@,$(MAKECMDGOALS))
run:
$(BINDIR)/$(BINARY) $(FILES)
# Clean
clean:
@rm -rvf $(BINDIR)/* $(LIBDIR)/* $(LOGDIR)/*;
# Install
install: all
mkdir -p ${DESTDIR}${PREFIX}/bin
cp -f $(BINDIR)/$(BINARY) ${DESTDIR}${PREFIX}/bin/$(PROJECT_NAME)
chmod 755 ${DESTDIR}${PREFIX}/bin/$(PROJECT_NAME)
@echo -en "$(BROWN)-- YAH! VITI HAS BEEN INSTALLED! --$(END_COLOR)\n"
# Uninstall
uninstall:
rm -f ${DESTDIR}${PREFIX}/bin/$(PROJECT_NAME)
@echo -en "$(BROWN)-- UNINSTALLED VITI! --$(END_COLOR)\n"
# Help
help:
@echo "VITI TEXTEDITOR"
@echo
@echo "Target rules:"
@echo " all - Compiles and generates binary file"
@echo " install - Compiles and install binary file"
@echo " uninstall - uninstall binary file"
@echo " run - run binary file"
@echo " clean - Clean the project by removing binaries"
@echo " help - Prints a help message with target rules"