-
Notifications
You must be signed in to change notification settings - Fork 8
/
Makefile
87 lines (65 loc) · 1.53 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
#!/bin/bash
#
# Folder structure
# project/ - Project folder
# project/src - All .cpp files (sub folders also included)
# project/inc - All .h files
#
# make clean - to delete all output files
# make build - to build only
# make all - to compile and link
# make run - to compile, link and run
#
# This is the main compiler
CC := g++
# Source file directory
SRCDIR := src
# Include directories
# Don't remove -I
INC := -I inc
# Build directory - to store object files
BUILDDIR := build
# Output directory
OUTPUT = bin
# Target or Executible file
TARGET := $(OUTPUT)/sandbox
# Source file extension
SRCEXT := cpp
# Compiler flags
CFLAGS := #-g -g3 -O2 -ggdb -m64 -Wall #-D debug=1
# Include libraries
LIB :=
# Creating list of cpp files
SOURCES := $(shell find $(SRCDIR) -type f -name "*.$(SRCEXT)")
# Creating list of files to be built
OBJECTS := $(patsubst $(SRCDIR)/%,$(BUILDDIR)/%,$(SOURCES:.$(SRCEXT)=.o))
# Default task
all: build link
$(TARGET): $(OBJECTS)
@echo "\n# Linking"
@mkdir -p $(OUTPUT)
$(CC) $^ -o $(TARGET) $(LIB)
@echo "\n# Executable Binary: $(TARGET)"
$(BUILDDIR)/%.o: $(SRCDIR)/%.$(SRCEXT)
@if [ ! -f $@ ]; then mkdir -p $@; rm -r $@; fi
$(CC) $(CFLAGS) $(INC) -c -o $@ $<
# Cleaning all files
clean:
@echo "# Cleaning";
@$(RM) -r -v $(BUILDDIR) $(OUTPUT)
@echo ""
# Building
build: .print $(OBJECTS)
@echo ""
# Linking
link: $(TARGET)
# Build and run
run: all
@echo "# Running"
@./$(TARGET)
@echo ""
.PHONY: clean
.print:
@echo "# Building"
help:
@echo 'make <all, clean, build, link, run>'