-
Notifications
You must be signed in to change notification settings - Fork 4
/
makefile
76 lines (53 loc) · 2.01 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
# client code directory name
CLIENTDIR := cliente
# server code directory name
SERVERDIR := servidor
# common code directory name
COMMONDIR := common
# binary output directory name
OUTPUTDIR := bin
# name for the output(binary) of the client code
CLIENTNAME := client
# name for the output(binary) of the server code
SERVERNAME := server
# libary code directory name
LIBDIR := lib
# add C flags, like: CFLAGS := -Wall -Werror -Wconversion -Wextra
CFLAGS :=
# add load flags, others like -pthread
LDLIB := -lm -lallegro -lallegro_image -lallegro_primitives -lallegro_font -lallegro_ttf -lallegro_audio -lallegro_acodec
CC := gcc -std=c99
RM := rm -f
MK := mkdir -p
EXT := c
INC := -I $(LIBDIR) -I $(COMMONDIR)
CLIENTSOURCES := $(shell find $(CLIENTDIR) -type f -name *.$(EXT))
SERVERSOURCES := $(shell find $(SERVERDIR) -type f -name *.$(EXT))
LIBSOURCES := $(shell find $(LIBDIR) -type f -name *.$(EXT))
COMMONSOURCES := $(shell find $(COMMONDIR) -type f -name *.$(EXT))
CLIENTOBJS := $(subst .$(EXT),.o,$(CLIENTSOURCES))
SERVEROBJS := $(subst .$(EXT),.o,$(SERVERSOURCES))
LIBOBJS := $(subst .$(EXT),.o,$(LIBSOURCES))
COMMONOBJS := $(subst .$(EXT),.o,$(COMMONSOURCES))
all: mkdirs buildServer buildClient clean
server: mkdirs buildServer clean runServer
client: mkdirs buildClient clean runClient
buildClient: $(LIBOBJS) $(CLIENTOBJS) $(COMMONOBJS)
@echo "\n Linking $(CLIENTNAME)..."
$(CC) -o $(OUTPUTDIR)/$(CLIENTNAME) $(LIBOBJS) $(COMMONOBJS) $(CLIENTOBJS) $(LDLIB) $(CFLAGS)
@echo "\n"
buildServer: $(LIBOBJS) $(SERVEROBJS) $(COMMONOBJS)
@echo "\n Linking $(SERVERNAME)..."
$(CC) -o $(OUTPUTDIR)/$(SERVERNAME) $(LIBOBJS) $(COMMONOBJS) $(SERVEROBJS) $(LDLIB) $(CFLAGS)
@echo "\n"
%.o : %.$(EXT)
$(CC) -c $< -o $@ $(INC) $(CFLAGS)
mkdirs:
$(MK) $(OUTPUTDIR)
clean:
@echo " Cleaning..."
$(RM) $(LIBOBJS) $(CLIENTOBJS) $(SERVEROBJS) $(COMMONOBJS)
runClient:
@echo "\n Starting to run $(CLIENTNAME)...\n"; ./$(OUTPUTDIR)/$(CLIENTNAME)
runServer:
@echo "\n Starting to run $(SERVERNAME)...\n"; ./$(OUTPUTDIR)/$(SERVERNAME)