-
Notifications
You must be signed in to change notification settings - Fork 10
/
connect.gm
215 lines (153 loc) · 5.74 KB
/
connect.gm
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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
#!/usr/bin/make -f
# UNIX platform detection - takes from environment directly
# e.g., SYS=osx make -f connect.gm
UNAME := $(shell uname)
ifeq ($(UNAME),Darwin)
LIBD_EXT := dylib
LIBS_EXT := A.dylib
LIBFLAGS := -dynamiclib
else
LIBD_EXT := so
LIBS_EXT := a
endif
ifeq ($(RELEASE),1)
CFLAGS += -DRELEASE
endif
### general variables section
CDIR := `basename $(PWD)`
STMP := `date +%Y%m%d_%H%M%S`
AR := ar
CFLAGS += -Wall -Wextra -DCNCT_BUILDREV="`bzr revno`"
LIB_DIR = lib
SRC_DIR = src
OUT_DIR = out
OUT_LIB_DIR = $(OUT_DIR)
OUT_BIN_DIR = $(OUT_DIR)
LIB_NAME = connect
BIND_EXT = dyn
BINS_EXT = stat
### library files management section
ifeq ($(SYS),osx)
LIB_SOCKET = $(LIB_DIR)/platform/sys_osx.c
LIB_SOCKET_O = sys_osx.o
CFLAGS += -DSYS_OSX
else ifeq ($(SYS),bsd)
LIB_SOCKET = $(LIB_DIR)/platform/sys_bsd.c
LIB_SOCKET_O = sys_bsd.o
CFLAGS += -DSYS_BSD
else ifeq ($(SYS),qnx)
LIB_SOCKET = $(LIB_DIR)/platform/sys_bsd.c
LIB_SOCKET_O = sys_bsd.o
CFLAGS += -DSYS_BSD -lsocket
else ifeq ($(SYS),nt)
LIB_SOCKET = $(LIB_DIR)/platform/sys_nt.c
LIB_SOCKET_O = sys_nt.o
CFLAGS += -DSYS_NT
else ifeq ($(SYS),linux)
LIB_SOCKET = $(LIB_DIR)/platform/sys_linux.c
LIB_SOCKET_O = sys_linux.o
CFLAGS += -DSYS_LINUX
else
LIB_SOCKET = $(LIB_DIR)/platform/platform.c
LIB_SOCKET_O = platform.o
endif
# library sources
LIB_SOCKET += $(LIB_DIR)/socket.c $(LIB_DIR)/packet.c
LIB_SOCKET_O += socket.o packet.o
# binary sources
BIN_SRC = $(SRC_DIR)/connect_api.c
# binary output for compilation from src/ directory
BIN = connect_api
# binary output for running after compilcation
BIN_OUT = $(OUT_DIR)/connect_api
### basic MINGW cross-compilation support section [compiling NT binaries for running on Windows]
ifeq ($(NT),)
NT_PRFX := i586-mingw32msvc
else
NT_PRFX := $(NT)
endif
NT_CC := $(NT_PRFX)-gcc
NT_LD := $(NT_PRFX)-ld
NT_AR := $(NT_PRFX)-ar
NT_CFLAGS += -lws2_32 -Wall -Wextra -DCNCT_BUILDREV="`bzr revno`"
NT_LFLAGS = -l$(LIB_NAME)
NT_OUT_DIR = $(OUT_DIR)/nt
NT_OUT_LIB_DIR = $(NT_OUT_DIR)
NT_OUT_BIN_DIR = $(NT_OUT_DIR)
### targets section
default: dir build-native-dynamic-lib build-native-dynamic-bin run-native-dynamic
###
all: build run
build: build-native build-cross
run: run-native run-cross
###
run-native: run-native-dynamic run-native-static
build-native: clean dir build-native-dynamic build-native-static
build-native-dynamic: dir build-native-dynamic-lib build-native-dynamic-bin
build-native-static: build-native-static-lib build-native-static-bin
###
run-cross: run-cross-dynamic run-cross-static
build-cross: clean dir build-cross-dynamic build-cross-static
build-cross-dynamic: dir build-cross-dynamic-lib build-cross-dynamic-bin
build-cross-static: build-cross-static-lib build-cross-static-bin
###
dir: clean
@echo "\n ----> making target:" $@ "<----\n"
mkdir $(OUT_DIR)
mkdir $(NT_OUT_DIR)
###
build-native-dynamic-lib: $(LIB_SOCKET)
@echo "\n ----> making target:" $@ "<----\n"
$(CC) $(CFLAGS) $(LDFLAGS) -fPIC -shared $(LIBFLAGS) $(LIB_SOCKET) -o $(OUT_LIB_DIR)/lib$(LIB_NAME).$(LIBD_EXT)
build-native-dynamic-bin: $(BIN_SRC)
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN), $(CC) $(CFLAGS) $(LDFLAGS) -L$(OUT_LIB_DIR) $(SRC_DIR)/$(app).c -o $(OUT_DIR)/$(app) -l$(LIB_NAME);)
build-native-static-lib: $(LIB_SOCKET)
@echo "\n ----> making target:" $@ "<----\n"
$(CC) $(CFLAGS) $(LDFLAGS) -c $(LIB_SOCKET)
$(AR) -scvq $(OUT_LIB_DIR)/lib$(LIB_NAME).$(LIBS_EXT) $(LIB_SOCKET_O)
-rm $(LIB_SOCKET_O)
build-native-static-bin: $(BIN_SRC)
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN), $(CC) $(CFLAGS) $(LDFLAGS) $(SRC_DIR)/$(app).c $(OUT_LIB_DIR)/lib$(LIB_NAME).$(LIBS_EXT) -o $(OUT_DIR)/$(app)_static;)
build-native-fullstatic-bin: $(BIN_SRC)
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN), $(CC) $(CFLAGS) $(LDFLAGS) $(SRC_DIR)/$(app).c $(OUT_LIB_DIR)/lib$(LIB_NAME).$(LIBS_EXT) -static -o $(OUT_DIR)/$(app)_fullstatic;)
run-native-dynamic: $(BIN_OUT)
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN_OUT), LD_LIBRARY_PATH=$(OUT_LIB_DIR):${LD_LIBRARY_PATH} $(app);)
run-native-static: $(BIN_OUT)
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN_OUT), LD_LIBRARY_PATH=$(OUT_LIB_DIR):${LD_LIBRARY_PATH} $(app)_static;)
###
build-cross-dynamic-lib: $(LIB_SOCKET)
@echo "\n ----> making target:" $@ "<----\n"
$(NT_CC) -o $(NT_OUT_LIB_DIR)/$(LIB_NAME).dll -shared $(LIB_SOCKET) $(NT_CFLAGS)
build-cross-static-lib: $(LIB_SOCKET)
@echo "\n ----> making target:" $@ "<----\n"
$(NT_CC) -c $(LIB_SOCKET) $(NT_CFLAGS)
$(NT_AR) -scvq $(NT_OUT_LIB_DIR)/$(LIB_NAME)S.lib $(LIB_SOCKET_O)
-rm $(LIB_SOCKET_O)
build-cross-dynamic-bin: $(BIN_SRC)
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN), $(NT_CC) -L$(NT_OUT_LIB_DIR) $(SRC_DIR)/$(app).c -o $(NT_OUT_BIN_DIR)/$(app).exe $(NT_CFLAGS) $(NT_LFLAGS);)
build-cross-static-bin: $(BIN_SRC)
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN), $(NT_CC) $(SRC_DIR)/$(app).c $(NT_OUT_LIB_DIR)/$(LIB_NAME)S.lib -o $(NT_OUT_BIN_DIR)/$(app)_static.exe $(NT_CFLAGS);)
run-cross-dynamic: $(NT_OUT_BIN_DIR)/$(BIN).exe
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN), wine $(NT_OUT_BIN_DIR)/$(app).exe;)
run-cross-static: $(NT_OUT_BIN_DIR)/$(BIN)_static.exe
@echo "\n ----> making target:" $@ "<----\n"
$(foreach app, $(BIN), wine $(NT_OUT_BIN_DIR)/$(app)_static.exe;)
###
ball: ball-tar ball-zip
ball-tar:
cd .. && tar -czvf $(CDIR)_$(STMP).tar.gz $(CDIR)/connect.* $(CDIR)/lib $(CDIR)/README $(CDIR)/src
ball-zip:
cd .. && zip -r $(CDIR)_$(STMP).zip $(CDIR)/connect.* $(CDIR)/lib $(CDIR)/README $(CDIR)/src
###
clean:
@echo "\n ----> making target:" $@ "<----\n"
-rm -rf $(OUT_DIR)
.PHONY: all