-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
60 lines (50 loc) · 1.22 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
# All credits to ARMANGAU Etienne
# sudo make
# VARIABLES TO MODIFY
# sources folder (*.cpp)
SRC := sources
# headers folder (*.h)
INC := include
# main.cpp (your main cpp source code)
MAIN := main.cpp
# name of the generated executable
EXEC := prog
# the main file can be alone or within the sources folder
ifneq ("$(wildcard $(MAIN))","")
sources := $(MAIN) $(wildcard $(SRC)/*.cpp)
else
sources := $(wildcard $(SRC)/*.cpp)
endif
# objects files list
objects := $(sources:.cpp=.o)
# dependacies files list
deps := $(objects:.o=.d)
# compilator's choice
CXX := g++
CPPFLAGS := -I $(INC) -MMD -MP
# compilator's options (you may add some options here)
CXXFLAGS := -std=c++17 -g -Wall -pedantic
# OS name
UNAME := $(shell uname -s)
ifeq ($(UNAME), Linux)
LDFLAGS := -L/usr/lib/x86_64-linux-gnu
LDLIBS := -lcurl
else
# if it's Darwin
CXXFLAGS += -D OSX
LDFLAGS := -stdlib=libstdc++
endif
# linking
$(EXEC) : $(objects)
$(CXX) $(LDFLAGS) $^ $(LDLIBS) -o $@
$(RM) $(objects) $(deps)
@echo "Compilation done !"
# compilation from source files
$(SRC)/%.o: $(SRC)/%.cpp
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c $^ -o $@
# subroutine to remove exec
.PHONY: clean
clean:
$(RM) $(EXEC)
# dependancies between files
-include $(deps)