-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
83 lines (64 loc) · 1.68 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
## VARIABLES
CXX=g++
CXXFLAGS=-O3 -std=c++17 -Wall -pthread
LDFLAGS=-static-libstdc++ -static-libgcc
DIRSRC = src
DIROBJ = obj
DIRBIN = bin
DIRDEP = dep
PROGRAM=Audio-DFT
LDLIBS=-lX11 -lGL -lpthread -lasound
## LOGICA
#detectamos el sistema operativo
ifeq ($(OS),Windows_NT)
OS_NAME := Windows
else
OS_NAME := $(shell uname)
endif
$(info OS_NAME = $(OS_NAME))
#definimos la s condiciones de compilacion dependiendo del sistema operativo
ifeq ($(OS_NAME),Linux)
PROGRAM:=$(addsuffix .elf,$(PROGRAM))
define MKDIR_OS
-mkdir -p $(1)
endef
define RM_OS
rm -rf $(1)
endef
else
$(error Sistema operativo no valido)
endif
FILE_BIN=$(DIRBIN)/$(PROGRAM)
$(info LDLIBS = $(LDLIBS))
$(info FILE_BIN = $(FILE_BIN))
#listamos los archivos de codigo
SRCS = $(wildcard $(DIRSRC)/*.cpp $(DIRSRC)/*/*.cpp)
$(info SRCS sin prorizar = $(SRCS))
#optenemos los objetos
OBJS = $(SRCS:$(DIRSRC)/%.cpp=$(DIROBJ)/%.o)
$(info OBJS = $(OBJS))
#optenemos las dependencias
DEPS = $(SRCS:$(DIRSRC)/%.cpp=$(DIRDEP)/%.d)
$(info DEPS = $(DEPS))
## TARGETS
#targets que no son archivos
.PHONY: all clean
#inicio del make
all: $(FILE_BIN)
#archivos a linkar
$(FILE_BIN): $(OBJS)
$(call MKDIR_OS,$(@D))
$(CXX) $^ -o $@ $(LDLIBS) $(LDFLAGS)
#incluimos las dependencias
-include $(DEPS)
#patron de objetos a compilar
$(DIROBJ)/%.o: $(DIRSRC)/%.cpp
# creamos los subdirectorios y generamos los archivos de dependencias
$(call MKDIR_OS,$(@D:$(DIROBJ)%=$(DIRDEP)%))
$(CXX) -MM $< > $(@:$(DIROBJ)/%.o=$(DIRDEP)/%.d)
# creamos los subdirectorios y compilamos los objetos
$(call MKDIR_OS,$(@D))
$(CXX) -o $@ -c $< $(CXXFLAGS) -I$(DIRSRC)
#limpiamos los archivos antiguos
clean:
$(call RM_OS,$(DIROBJ) $(DIRDEP) $(FILE_BIN))