-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
68 lines (54 loc) · 1.52 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
##
# Server
#
# @file Makefile
# @version 1.0
##
EDIR := .
SDIR := src
IDIR := include
ODIR := obj
SLDIR := srclib
LDIR := lib
NAME := server
C_NAMES := main.c http.c # Archivos en src
L_NAMES := picohttpparser.c tpool.c iniparser.c socket.c # Archivos en srclib
CC := gcc
CFLAGS := -g -I$(IDIR) -pedantic -Wall -Wextra
LFLAGS := -L$(LDIR) -liniparser -lpicohttpparser -ltpool -lpthread -lsocket
SFILES := c
OFILES := o
LFILES := a
SOURCES := $(foreach sname, $(C_NAMES), $(SDIR)/$(sname))
LSOURCES := $(foreach sname, $(L_NAMES), $(SLDIR)/$(sname))
OBJECTS := $(patsubst $(SDIR)/%.$(SFILES), $(ODIR)/%.$(OFILES), $(SOURCES))
LOBJECTS := $(patsubst $(SLDIR)/%.$(SFILES), $(ODIR)/%.$(OFILES), $(LSOURCES))
LIBRARIES := $(patsubst $(SLDIR)/%.$(SFILES), $(LDIR)/lib%.$(LFILES), $(LSOURCES))
EXE := $(EDIR)/$(NAME)
all: exe
exe: $(LIBRARIES) $(EXE)
$(EXE): $(OBJECTS) # Compilacion del ejecutable
$(CC) $^ -o $@ $(LFLAGS)
$(LDIR)/lib%$(LFILES): $(ODIR)/%$(OFILES) # Compilacion de las librerias
@mkdir -p lib
ar rcs $@ $<
$(ODIR)/%$(OFILES): */%$(SFILES) # Compilacion de los objetos
@mkdir -p obj
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: clean
clean:
rm -fv $(EXE) $(DEPEND_FILES)
rm -rfv $(ODIR) $(LDIR)
.PHONY: run
run:
@echo "> Ejecutando servidor..."
./server
.PHONY: runv
runv:
@echo "> Ejecutando servidor con valgrind..."
valgrind -s --leak-check=full --track-origins=yes --show-leak-kinds=all ./server
# Deteccion de dependencias automatica
CFLAGS += -MMD
DEPEND_FILES := $(wildcard $(ODIR)/*.d)
-include $(DEPEND_FILES)
# end