This repository has been archived by the owner on Sep 24, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile
71 lines (66 loc) · 1.65 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
# OS specific part
# -----------------
ifeq ($(OS),Windows_NT)
CLEAR = cls
LS = dir
TOUCH =>>
RM = del /F /Q
CPF = copy /y
RMDIR = -RMDIR /S /Q
MKDIR = -mkdir
CMDSEP = &
ERRIGNORE = 2>NUL || (exit 0)
GO_PATH = $(subst \,/,${GOPATH})
SEP=\\
else
CLEAR = clear
GO_PATH = ${GOPATH}
LS = ls
TOUCH = touch
CPF = cp -f
RM = rm -rf
RMDIR = rm -rf
CMDSEP = ;
MKDIR = mkdir -p
ERRIGNORE = 2>/dev/null
SEP=/
endif
# recursive wildcard
rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))
PSEP = $(strip $(SEP))
nullstring :=
space := $(nullstring)
SERVER_IP = 127.0.0.1
SERVER_PORT = 8080
LIBRARIES = $(filter-out $(wildcard ./cmd/*/*.c), $(call rwildcard,./,*.c))
TARGET = $(notdir $(patsubst %/,%,$(dir $(wildcard ./cmd/*/.))))
.PHONY: dep client run-client server run-server clean
client: clean
- $(MKDIR) ./bin
- $(RM) ./bin/client
- gcc -o ./bin/client ${LIBRARIES} ./cmd/client/main.c -std=c99 -lpthread -Wall -lnsl
run-client: client
- $(CLEAR)
- ./bin/client ${SERVER_IP} ${SERVER_PORT}
server: clean
- $(CLEAR)
- $(MKDIR) ./bin
- $(RM) ./bin/server
- gcc -o ./bin/server ${LIBRARIES} ./cmd/server/main.c -std=c99 -lpthread -Wall -lnsl
run-server: server
- $(CLEAR)
- ./bin/server ${SERVER_PORT}
build: clean
- $(MKDIR) ./bin
for target in $(TARGET); do \
gcc -o .$(PSEP)bin$(PSEP)$$target ${LIBRARIES} .$(PSEP)cmd$(PSEP)$$target$(PSEP)main.c -std=c99 -lpthread -Wall -lnsl; \
done
clean:
- $(RM) ./bin
- $(RM) ./core.*
dep:
- $(info Installing clang-format from npm)
- npm install -g clang-format
print:
- $(CLEAR)
- @echo $(space) $(DIRS)