-
Notifications
You must be signed in to change notification settings - Fork 0
/
makefile
52 lines (41 loc) · 1.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
#detecta se o sistema é de 32 ou 64 bits
BITS_OPTION = -m64
#### define o compilador
CPPC = g++
#############################
### opcoes de compilacao e includes
CCOPT = $(BITS_OPTION) -O3 -fPIC -fexceptions -DNDEBUG -DIL_STD -std=c++0x -msse2
CONCERTINCDIR = $(CONCERTDIR)/include
#############################
#### flags do linker
#############################
#### diretorios com os source files e com os objs files
SRCDIR = src
OBJDIR = obj
#############################
#### lista de todos os srcs e todos os objs
SRCS = $(wildcard $(SRCDIR)/*.cpp)
OBJS = $(patsubst $(SRCDIR)/%.cpp, $(OBJDIR)/%.o, $(SRCS))
#############################
#### regra principal, gera o executavel
tsp: $(OBJS)
@echo "\033[31m \nLinking all objects files: \033[0m"
$(CPPC) $(BITS_OPTION) $(OBJS) -o $@ $(CPPFLAGS) $(CCOPT) -g
############################
#inclui os arquivos de dependencias
-include $(OBJS:.o=.d)
#regra para cada arquivo objeto: compila e gera o arquivo de dependencias do arquivo objeto
#cada arquivo objeto depende do .c e dos headers (informacao dos header esta no arquivo de dependencias gerado pelo compiler)
$(OBJDIR)/%.o: $(SRCDIR)/%.cpp
@echo "\033[31m \nCompiling $<: \033[0m"
$(CPPC) $(CPPFLAGS) $(CCOPT) -c $< -o $@ -g
@echo "\033[32m \ncreating $< dependency file: \033[0m"
$(CPPC) -std=c++0x -MM $< > $(basename $@).d
@mv -f $(basename $@).d $(basename $@).d.tmp #proximas tres linhas colocam o diretorio no arquivo de dependencias (g++ nao coloca, surprisingly!)
@sed -e 's|.*:|$(basename $@).o:|' < $(basename $@).d.tmp > $(basename $@).d
@rm -f $(basename $@).d.tmp
#delete objetos e arquivos de dependencia
clean:
@echo "\033[31mcleaning obj directory \033[0m"
@rm tsp -f $(OBJDIR)/*.o $(OBJDIR)/*.d
rebuild: clean tsp