This repository has been archived by the owner on Sep 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmakefile
63 lines (47 loc) · 1.48 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
# Defines the C compiler
CC := gcc
# Protection for stack-smashing attack
STACK := -fstack-protector-all -Wstack-protector
# Specifies to GCC the required warnings
WARNS := -Wall -Wextra -pedantic # -pedantic warns on language standards
# Debug flags (add to CFLAGS if you wish to compile the program for debug porpuses)
DEBUG := -g -fsanitize=address
# Flags for compiling
CFLAGS := -O3 $(STACK) $(WARNS)
# Color prefix for Linux distributions
COLOR_PREFIX := e
# 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
LIBDIR := lib
# Source code file extension
SRCEXT := c
# Binary name
BINARY := ooc
# %.o file names
NAMES := $(notdir $(basename $(wildcard $(SRCDIR)/*.$(SRCEXT))))
OBJECTS :=$(patsubst %,$(LIBDIR)/%.o,$(NAMES))
#
# Compilation Rules
#
default: all
# Help message
help:
@echo "Object-oriented C"
@echo " all - Compiles and generates binary files"
@echo " clean - Clean the project by removing binaries"
@echo " help - Prints a help message with target rules"
all: $(OBJECTS)
@echo -en "$(BROWN)LD $(END_COLOR)"
$(CC) -o $(BINDIR)/$(BINARY) $+ $(CFLAGS) $(LIBS)
@echo -en "\n--\nBinary file placed at $(BROWN)$(BINDIR)/$(BINARY)$(END_COLOR)\n"
$(LIBDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@echo -en "$(BROWN)CC $(END_COLOR)";
$(CC) -c $^ -o $@ $(CFLAGS) $(LIBS)
# Rule for cleaning the project
clean:
@rm -rvf $(BINDIR)/* $(LIBDIR)/*;