-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
51 lines (41 loc) · 1.78 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
## Makefile to compile a typical, simple C++14 project.
## Author : Bart Groeneveld
## License : GPLv3
## Latest update: Saturday, May 21st, 2016
## You are probably only interested in the first line of this Makefile.
# Libraries on which TARGET depends
LIBS = \
-lpthread \
-lntl -lgmp -lm
# Name of the executable
TARGET = $(shell basename "$$PWD")
# Place to store all generated files
BUILD_DIR = build
# All source files. Header files are detected automatically
# SRCS = $(shell find . -path ./$(BUILD_DIR) -prune -o -name '*.cpp' -ls | awk '{$$1=$$2=$$3=$$4=$$5=$$6=$$7=$$8=$$9=$$10=""; print $0}' | sed 's/^\s*//' | grep -v -e '.zip\|.tar')
SRCS=./main.cpp
# Compiler. On non-gnu systems you may want to change this
CC = g++ -I/usr/local/include/
# C++ version
EXTRAFLAGS = -std=c++11
SHELL = /bin/bash
DEPENDENCY_LIST = $(BUILD_DIR)/depend
OBJS = $(addprefix $(BUILD_DIR)/, $(SRCS:.cpp=.o))
.PHONY: all clean
all: $(BUILD_DIR) $(DEPENDENCY_LIST) $(TARGET)
$(BUILD_DIR):
mkdir $(BUILD_DIR)
$(TARGET): $(OBJS)
$(CC) $(EXTRAFLAGS) -o $(TARGET) $(OBJS) $(LIBS)
# Every .o file will be matched here, and will be compiled from a .cpp file. Other dependencies are listed with '-include $(DEPENDENCY_LIST)'.
$(BUILD_DIR)/%.o: %.cpp
$(CC) $(EXTRAFLAGS) -c $< -o $@
# -MM outputs Makefile style dependencies of a source file
$(DEPENDENCY_LIST): $(SRCS) | $(BUILD_DIR)
$(RM) $(DEPENDENCY_LIST)
$(CC) $(EXTRAFLAGS) -MM $^ | awk '{print "$(BUILD_DIR)/./" $$0;}' >> $(DEPENDENCY_LIST)
# '-' prevents warning on first build or build after clean because dependencies files does not exist
-include $(DEPENDENCY_LIST)
# A note for maintainers of this Makefile: DO NOT REMOVE WHOLE BUILD_DIR! (would be a disaster if BUILD_DIR equals '.')
clean:
$(RM) $(BUILD_DIR)/*.o *~ $(TARGET) $(DEPENDENCY_LIST)