-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·146 lines (106 loc) · 3.07 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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
# Structurally sane Makefile for a C project.
# Author: Diego Sáinz de Medrano
# directories
BUILDDIR = build
BUILDLIBDIR = lib/build
DEPSDIR = includes
LIBSDIR = lib
SRCDIR = src
SRCLIBDIR = srclib
# auxiliary modules
CONFIG = config
SCRIPT = cgi
DUPER = remap-pipe-fds
FINDER = finder
HEADERS = headers
HTTP = http
# test main programs
TESTCGI = testcgi
TESTCONF = testconfig
TESTSCRIPTS = testscripts
# main programs
ECHOS = echo
FILES = file
SERVER = server
# core target of the makefile
# change this variable to produce one of the targets
# listed as main or test main
TARGET = $(SERVER)
# cleaning targets
CLEAN = ./$(TESTCGI) ./$(TESTCONF) ./$(TESTSCRIPTS)
CLEAN += ./$(ECHOS) ./$(FILES) ./$(SERVER)
# library list of modules
LIBS = libdaemon libconcurrent libtcp libserver picohttpparser
# library name
_LIB = redes2
LIB = $(patsubst %,$(LIBSDIR)/lib%.a, $(_LIB))
# tooling
CC = gcc
AR = ar
# flags
# v debug v includes
CFLAGS = -g -I$(DEPSDIR)
LDFLAGS = -L$(LIBSDIR) -l$(_LIB) -lpthread
# ^ libs ^ our lib ^ threads
.PHONY: all clean clean_libs verbose
all: before lib $(TARGET)
# phony target to prepare the directories
before:
@[ -d $(BUILDDIR) ] || mkdir $(BUILDDIR)
@[ -d $(BUILDLIBDIR) ] || mkdir -p $(BUILDLIBDIR)
#
## linking targets
#
# echo: echo(main) server
$(ECHOS): $(BUILDDIR)/$(ECHOS).o
@echo "Enlazando $(notdir $@): $(notdir $^)"
$(CC) -o $@ $^ $(LDFLAGS)
# file: file(main) server
$(FILES): $(BUILDDIR)/$(FILES).o
@echo "Enlazando $(notdir $@): $(notdir $^)"
$(CC) -o $@ $^ $(LDFLAGS)
# http: http(main) parser
$(SERVER): $(BUILDDIR)/$(SERVER).o $(BUILDDIR)/$(HTTP).o $(BUILDDIR)/$(CONFIG).o $(BUILDDIR)/$(FINDER).o $(BUILDDIR)/$(HEADERS).o $(BUILDDIR)/$(DUPER).o $(BUILDDIR)/$(SCRIPT).o
@echo "Enlazando $(notdir $@): $(notdir $^)"
$(CC) -o $@ $^ $(LDFLAGS)
#
## test programs
#
$(TESTCGI): $(BUILDDIR)/$(TESTCGI).o $(BUILDDIR)/$(DUPER).o $(BUILDDIR)/$(SCRIPT).o $(BUILDDIR)/$(FINDER).o
@echo "Enlazando $(notdir $@): $(notdir $^)"
$(CC) -o $@ $^ $(LDFLAGS)
$(TESTCONF): $(BUILDDIR)/$(TESTCONF).o $(BUILDDIR)/$(CONFIG).o
@echo "Enlazando $(notdir $@): $(notdir $^)"
$(CC) -o $@ $^ $(LDFLAGS)
$(TESTSCRIPTS): $(BUILDDIR)/$(TESTSCRIPTS).o $(BUILDDIR)/$(DUPER).o $(BUILDDIR)/$(SCRIPT).o $(BUILDDIR)/$(FINDER).o
@echo "Enlazando $(notdir $@): $(notdir $^)"
$(CC) -o $@ $^ $(LDFLAGS)
#
## compile targets
#
# every requested src/%.c file gets compiled into build/%.o
$(BUILDDIR)/%.o: $(SRCDIR)/%.c
@echo "Compilando $(notdir $@): $(notdir $^)"
$(CC) -o $@ -c $^ $(CFLAGS)
#
## library targets
#
# lib: name for `make lib`
lib: $(LIB)
# compile all targets in $(LIBS) and archive into $(LIB)
$(LIB): $(patsubst %, $(BUILDLIBDIR)/%.o, $(LIBS))
@echo "Archivando objetos en la librería"
$(AR) r $@ $^
# every requested srclib/%.c file gets compiled into lib/build/%.o
$(BUILDLIBDIR)/%.o: $(SRCLIBDIR)/%.c
@echo "Compilando librerías"
$(CC) -o $@ -c $^ $(CFLAGS)
#
## clean targets
#
clean:
@echo "Limpiando objetos y ejecutables"
@rm -f ./$(BUILDDIR)/* ./$(CLEAN)
clean_libs:
@echo "Limpiando librerías"
@rm -f ./$(BUILDLIBDIR)/*