aboutsummaryrefslogtreecommitdiff
path: root/Makefile
blob: 8523cf6e5fd971dfde8d3fd1e0d8f147ec77bff7 (plain) (blame)
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
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
# Makefile for HaxIRCd
#
# Written by: Test_User <hax@runxiyu.org>
#
# This is free and unencumbered software released into the public
# domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

ORIGINAL_CFLAGS := $(CFLAGS)
ORIGINAL_LDFLAGS := $(LDFLAGS)

INCLUDEFLAGS =

LDFLAGS = -lpthread

.makeopts:
	> .makeopts
	printf '%s\n' 'LAST_CLIENT = $(CLIENT)' >> .makeopts
	printf '%s\n' 'LAST_SERVER = $(SERVER)' >> .makeopts
	printf '%s\n' 'LAST_PLAINTEXT_NETWORK = $(PLAINTEXT_NETWORK)' >> .makeopts
	printf '%s\n' 'LAST_GNUTLS_NETWORK = $(GNUTLS_NETWORK)' >> .makeopts
	printf '%s\n' 'LAST_OPENSSL_NETWORK = $(OPENSSL_NETWORK)' >> .makeopts
	printf '%s\n' 'LAST_PLAINTEXT_BUFFERED_NETWORK = $(PLAINTEXT_BUFFERED_NETWORK)' >> .makeopts
	printf '%s\n' 'LAST_GNUTLS_BUFFERED_NETWORK = $(GNUTLS_BUFFERED_NETWORK)' >> .makeopts
	printf '%s\n' 'LAST_OPENSSL_BUFFERED_NETWORK = $(OPENSSL_BUFFERED_NETWORK)' >> .makeopts
	printf '%s\n' 'LAST_INSPIRCD2_PROTOCOL = $(INSPIRCD2_PROTOCOL)' >> .makeopts
	printf '%s\n' 'LAST_INSPIRCD3_PROTOCOL = $(INSPIRCD3_PROTOCOL)' >> .makeopts
	printf '%s\n' 'LAST_INSPIRCD4_PROTOCOL = $(INSPIRCD4_PROTOCOL)' >> .makeopts
	printf '%s\n' 'LAST_HAXSERV_PSEUDOCLIENT = $(HAXSERV_PSEUDOCLIENT)' >> .makeopts
	printf '%s\n' 'LAST_SERVICES_PSEUDOCLIENT = $(SERVICES_PSEUDOCLIENT)' >> .makeopts
	printf '%s\n' 'LAST_SAFE_STACK = $(SAFE_STACK)' >> .makeopts
	printf '%s\n' 'LAST_FUTEX = $(FUTEX)' >> .makeopts
	printf '%s\n' 'LAST_MISERABLE_SPINLOCKS = $(MISERABLE_SPINLOCKS)' >> .makeopts
	printf '%s\n' 'LAST_ATOMICS = $(ATOMICS)' >> .makeopts
	printf '%s\n' 'LAST_IPv4 = $(IPv4)' >> .makeopts
	printf '%s\n' 'LAST_IPv6 = $(IPv6)' >> .makeopts
	printf '%s\n' 'LAST_HAX_STRING_PATH = $(HAX_STRING_PATH)' >> .makeopts
	printf '%s\n' 'LAST_HAX_TABLE_PATH = $(HAX_TABLE_PATH)' >> .makeopts
	printf '%s\n' 'LAST_CFLAGS = $(ORIGINAL_CFLAGS)' >> .makeopts
	printf '%s\n' 'LAST_LDFLAGS = $(ORIGINAL_LDFLAGS)' >> .makeopts
	printf '%s\n' 'LAST_CC = $(CC)' >> .makeopts

$(shell [ -e .makeopts ] || > .makeopts)

include .makeopts

rebuild = 0

# tabs not allowed :(
ifneq ($(CLIENT),)
ifneq ($(CLIENT),$(LAST_CLIENT))
rebuild = 1
endif
else
CLIENT := $(LAST_CLIENT)
endif

ifneq ($(SERVER),)
ifneq ($(SERVER),$(LAST_SERVER))
rebuild = 1
endif
else
SERVER := $(LAST_SERVER)
endif

ifneq ($(PLAINTEXT_NETWORK),)
ifneq ($(PLAINTEXT_NETWORK),$(LAST_PLAINTEXT_NETWORK))
rebuild = 1
endif
else
PLAINTEXT_NETWORK := $(LAST_PLAINTEXT_NETWORK)
endif

ifneq ($(GNUTLS_NETWORK),)
ifneq ($(GNUTLS_NETWORK),$(LAST_GNUTLS_NETWORK))
rebuild = 1
endif
else
GNUTLS_NETWORK := $(LAST_GNUTLS_NETWORK)
endif

ifneq ($(OPENSSL_NETWORK),)
ifneq ($(OPENSSL_NETWORK),$(LAST_OPENSSL_NETWORK))
rebuild = 1
endif
else
OPENSSL_NETWORK := $(LAST_OPENSSL_NETWORK)
endif

ifneq ($(PLAINTEXT_BUFFERED_NETWORK),)
ifneq ($(PLAINTEXT_BUFFERED_NETWORK),$(LAST_PLAINTEXT_BUFFERED_NETWORK))
rebuild = 1
endif
else
PLAINTEXT_BUFFERED_NETWORK := $(LAST_PLAINTEXT_BUFFERED_NETWORK)
endif

ifneq ($(GNUTLS_BUFFERED_NETWORK),)
ifneq ($(GNUTLS_BUFFERED_NETWORK),$(LAST_GNUTLS_BUFFERED_NETWORK))
rebuild = 1
endif
else
GNUTLS_BUFFERED_NETWORK := $(LAST_GNUTLS_BUFFERED_NETWORK)
endif

ifneq ($(OPENSSL_BUFFERED_NETWORK),)
ifneq ($(OPENSSL_BUFFERED_NETWORK),$(LAST_OPENSSL_BUFFERED_NETWORK))
rebuild = 1
endif
else
OPENSSL_BUFFERED_NETWORK := $(LAST_OPENSSL_BUFFERED_NETWORK)
endif

ifneq ($(INSPIRCD2_PROTOCOL),)
ifneq ($(INSPIRCD2_PROTOCOL),$(LAST_INSPIRCD2_PROTOCOL))
rebuild = 1
endif
else
INSPIRCD2_PROTOCOL := $(LAST_INSPIRCD2_PROTOCOL)
endif

ifneq ($(INSPIRCD3_PROTOCOL),)
ifneq ($(INSPIRCD3_PROTOCOL),$(LAST_INSPIRCD3_PROTOCOL))
rebuild = 1
endif
else
INSPIRCD3_PROTOCOL := $(LAST_INSPIRCD3_PROTOCOL)
endif

ifneq ($(INSPIRCD4_PROTOCOL),)
ifneq ($(INSPIRCD4_PROTOCOL),$(LAST_INSPIRCD4_PROTOCOL))
rebuild = 1
endif
else
INSPIRCD4_PROTOCOL := $(LAST_INSPIRCD4_PROTOCOL)
endif

ifneq ($(HAXSERV_PSEUDOCLIENT),)
ifneq ($(HAXSERV_PSEUDOCLIENT),$(LAST_HAXSERV_PSEUDOCLIENT))
rebuild = 1
endif
else
HAXSERV_PSEUDOCLIENT := $(LAST_HAXSERV_PSEUDOCLIENT)
endif

ifneq ($(SERVICES_PSEUDOCLIENT),)
ifneq ($(SERVICES_PSEUDOCLIENT),$(LAST_SERVICES_PSEUDOCLIENT))
rebuild = 1
endif
else
SERVICES_PSEUDOCLIENT := $(LAST_SERVICES_PSEUDOCLIENT)
endif

ifneq ($(SAFE_STACK),)
ifneq ($(SAFE_STACK),$(LAST_SAFE_STACK))
rebuild = 1
endif
else
SAFE_STACK := $(LAST_SAFE_STACK)
endif

ifneq ($(ORIGINAL_CFLAGS),)
ifneq ($(ORIGINAL_CFLAGS),$(LAST_CFLAGS))
rebuild = 1
endif
else
ORIGINAL_CFLAGS := $(LAST_CFLAGS)
CFLAGS += $(LAST_CFLAGS)
endif

ifneq ($(HAX_STRING_PATH),)
ifneq ($(HAX_STRING_PATH),$(LAST_HAX_STRING_PATH))
rebuild = 1
endif
else
HAX_STRING_PATH += $(LAST_HAX_STRING_PATH)
endif

ifneq ($(HAX_TABLE_PATH),)
ifneq ($(HAX_TABLE_PATH),$(LAST_HAX_TABLE_PATH))
rebuild = 1
endif
else
HAX_TABLE_PATH += $(LAST_HAX_TABLE_PATH)
endif

ifneq ($(ORIGINAL_LDFLAGS),)
ifneq ($(ORIGINAL_LDFLAGS),$(LAST_LDFLAGS))
rebuild = 1
endif
else
ORIGINAL_LDFLAGS := $(LAST_LDFLAGS)
LDFLAGS += $(LAST_LDFLAGS)
endif

ifneq ($(CC),)
ifneq ($(CC),$(LAST_CC))
rebuild = 1
endif
else
CC := $(LAST_CC)
endif

ifneq ($(FUTEX),)
ifneq ($(FUTEX),$(LAST_FUTEX))
rebuild = 1
endif
else
FUTEX := $(LAST_FUTEX)
endif

ifneq ($(MISERABLE_SPINLOCKS),)
ifneq ($(MISERABLE_SPINLOCKS),$(LAST_MISERABLE_SPINLOCKS))
rebuild = 1
endif
else
MISERABLE_SPINLOCKS := $(LAST_MISERABLE_SPINLOCKS)
endif

ifneq ($(ATOMICS),)
ifneq ($(ATOMICS),$(LAST_ATOMICS))
rebuild = 1
endif
else
ATOMICS := $(LAST_ATOMICS)
endif

ifneq ($(IPv4),)
ifneq ($(IPv4),$(LAST_IPv4))
rebuild = 1
endif
else
IPv4 := $(LAST_IPv4)
endif

ifneq ($(IPv6),)
ifneq ($(IPv6),$(LAST_IPv6))
rebuild = 1
endif
else
IPv6 := $(LAST_IPv6)
endif

ifeq ($(rebuild),1)
.PHONY: .makeopts
endif

CFLAGS += $(INCLUDEFLAGS) -fPIC -fno-plt -D_REENTRANT -ggdb3 -Wall -Wextra -Wsign-conversion -Wno-unknown-warning-option -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-alloc-size -std=gnu99

ifneq ($(HAX_STRING_PATH),)
CFLAGS += -I$(HAX_STRING_PATH)
endif
ifneq ($(HAX_TABLE_PATH),)
CFLAGS += -I$(HAX_TABLE_PATH)
endif

LDFLAGS += -lhax_string_utils -lhax_table

ifneq ($(HAX_STRING_PATH),)
LDFLAGS += -L$(HAX_STRING_PATH)
endif
ifneq ($(HAX_TABLE_PATH),)
LDFLAGS += -L$(HAX_TABLE_PATH)
endif

USE_PLAINTEXT = 0
USE_CLIENT = 0
USE_GNUTLS = 0
USE_SERVER = 0

OFILES = config.o general_network.o real_main.o mutex.o
SOFILES = HaxIRCd.so

USE_IRCD := 0
ifeq ($(CLIENT),1)
OFILES += client_network.o
CFLAGS += -DUSE_CLIENT
USE_IRCD := 1
USE_CLIENT := 1
endif

ifeq ($(SERVER),1)
OFILES += server_network.o
CFLAGS += -DUSE_SERVER
USE_IRCD := 1
USE_SERVER := 1
endif

ifneq ($(USE_IRCD),1)
$(error Well, you neither want clients nor servers, so... int main(void) {return 0;}, your IRCd is complete)
endif


USE_NETWORK := 0
ifeq ($(PLAINTEXT_NETWORK),1)
OFILES += networks/plaintext.o
CFLAGS += -DUSE_PLAINTEXT_NETWORK
USE_NETWORK := 1
USE_PLAINTEXT_NETWORK := 1
endif

ifeq ($(GNUTLS_NETWORK),1)
OFILES += networks/gnutls.o
CFLAGS += -DUSE_GNUTLS_NETWORK $(shell pkg-config gnutls --cflags)
LDFLAGS += $(shell pkg-config gnutls --libs)
USE_NETWORK := 1
USE_GNUTLS_NETWORK := 1
endif

ifeq ($(OPENSSL_NETWORK),1)
OFILES += networks/openssl.o
CFLAGS += -DUSE_OPENSSL_NETWORK $(shell pkg-config openssl --cflags)
LDFLAGS += $(shell pkg-config openssl --libs)
USE_NETWORK := 1
USE_OPENSSL_NETWORK := 1
endif

ifeq ($(PLAINTEXT_BUFFERED_NETWORK),1)
OFILES += networks/plaintext_buffered.o
CFLAGS += -DUSE_PLAINTEXT_BUFFERED_NETWORK
USE_NETWORK := 1
USE_PLAINTEXT_BUFFERED_NETWORK := 1
endif

ifeq ($(GNUTLS_BUFFERED_NETWORK),1)
OFILES += networks/gnutls_buffered.o
CFLAGS += -DUSE_GNUTLS_BUFFERED_NETWORK $(shell pkg-config gnutls --cflags)
LDFLAGS += $(shell pkg-config gnutls --libs)
USE_NETWORK := 1
USE_GNUTLS_BUFFERED_NETWORK := 1
endif

ifeq ($(OPENSSL_BUFFERED_NETWORK),1)
OFILES += networks/openssl_buffered.o
CFLAGS += -DUSE_OPENSSL_BUFFERED_NETWORK $(shell pkg-config openssl --cflags)
LDFLAGS += $(shell pkg-config openssl --libs)
USE_NETWORK := 1
USE_OPENSSL_BUFFERED_NETWORK := 1
endif

ifneq ($(USE_NETWORK),1)
$(error How would you like to communicate with these clients or servers? You need to enable at least one network transport)
endif


ifeq ($(INSPIRCD2_PROTOCOL),1)
OFILES += protocols/inspircd2.o
CFLAGS += -DUSE_INSPIRCD2_PROTOCOL
USE_PROTOCOLS = 1
endif

ifeq ($(INSPIRCD3_PROTOCOL),1)
OFILES += protocols/inspircd3.o
CFLAGS += -DUSE_INSPIRCD3_PROTOCOL
USE_PROTOCOLS = 1
endif

ifeq ($(INSPIRCD4_PROTOCOL),1)
OFILES += protocols/inspircd4.o
CFLAGS += -DUSE_INSPIRCD4_PROTOCOL
USE_PROTOCOLS = 1
endif

ifeq ($(USE_SERVER),1)
ifneq ($(USE_PROTOCOLS),1)
$(error You must enable at least one s2s protocol if you want to link servers)
endif
endif



ifeq ($(HAXSERV_PSEUDOCLIENT),1)
SOFILES += pseudoclients/haxserv.so
CFLAGS += -DUSE_HAXSERV_PSEUDOCLIENT
USE_PSEUDOCLIENTS = 1
endif

ifeq ($(SERVICES_PSEUDOCLIENT),1)
SOFILES += pseudoclients/services.so
CFLAGS += -DUSE_SERVICES_PSEUDOCLIENT $(shell pkg-config --cflags lmdb)
LDFLAGS += $(shell pkg-config --libs lmdb)
USE_PSEUDOCLIENTS = 1
endif



ifeq ($(USE_PLAINTEXT_BUFFERED),1)
OFILES += networks/plaintext_buffered.o
CFLAGS += -DUSE_PLAINTEXT_BUFFERED
endif

ifeq ($(USE_GNUTLS_BUFFERED),1)
OFILES += networks/gnutls_buffered.o
CFLAGS += -DUSE_GNUTLS_BUFFERED
endif

ifeq ($(USE_OPENSSL_BUFFERED),1)
OFILES += networks/openssl_buffered.o
CFLAGS += -DUSE_OPENSSL_BUFFERED
endif



ifeq ($(USE_PROTOCOLS),1)
ifneq ($(USE_SERVER),1)
$(error You must have some form of server network transport enabled if you hope to use an s2s protocol)
endif
OFILES += protocols.o
endif



ifeq ($(USE_PSEUDOCLIENTS),1)
OFILES += pseudoclients.o
CFLAGS += -DUSE_PSEUDOCLIENTS
endif



ifeq ($(FUTEX),1)
CFLAGS += -DUSE_FUTEX
endif

ifeq ($(MISERABLE_SPINLOCKS),1)
ifeq ($(FUTEX),1)
$(error Why are you trying to use miserable spinlocks when using futexes? Choose one)
endif
CFLAGS += -DUSE_MISERABLE_SPINLOCKS
endif

ifeq ($(ATOMICS),1)
CFLAGS += -DUSE_ATOMICS
endif



IP_ENABLED := 0

ifeq ($(IPv4),1)
CFLAGS += -DUSE_IPv4
IP_ENABLED := 1
endif

ifeq ($(IPv6),1)
CFLAGS += -DUSE_IPv6
IP_ENABLED := 1
endif

ifneq ($(IP_ENABLED),1)
$(error I don't know how you intend to use TCP/IP without IP. Enable at least one of IPv4 and IPv6)
endif



ifeq ($(SAFE_STACK),1)
CFLAGS += -fstack-check
endif



DEPS = $(shell $(CC) $(CFLAGS) -M -MT $(1).$(2) $(1).c | sed 's_\\$$__') .makeopts Makefile


.PHONY: all clean
all: HaxIRCd $(SOFILES)

HaxIRCd: main.c .makeopts Makefile
	$(CC) main.c -o HaxIRCd

HaxIRCd.so: $(OFILES) .makeopts Makefile
	$(LD) $(OFILES) -shared -o $@ $(LDFLAGS)

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

%.so: %.o
	$(LD) $(LDFLAGS) -shared $< -o $@

$(call DEPS,config,o)

$(call DEPS,general_network,o)

$(call DEPS,real_main,o)

$(call DEPS,main,o)

$(call DEPS,mutex,o)

ifeq ($(USE_PLAINTEXT),1)
$(call DEPS,networks/plaintext,o)
endif

ifeq ($(USE_GNUTLS),1)
$(call DEPS,networks/gnutls,o)
endif

ifeq ($(USE_OPENSSL),1)
$(call DEPS,networks/openssl,o)
endif

ifeq ($(USE_PLAINTEXT_BUFFERED),1)
$(call DEPS,networks/plaintext_buffered,o)
endif

ifeq ($(USE_GNUTLS_BUFFERED),1)
$(call DEPS,networks/gnutls_buffered,o)
endif

ifeq ($(USE_OPENSSL_BUFFERED),1)
$(call DEPS,networks/openssl_buffered,o)
endif

ifeq ($(USE_CLIENT),1)
$(call DEPS,client_network,o)
endif

ifeq ($(USE_SERVER),1)
$(call DEPS,server_network,o)
endif

ifeq ($(USE_PROTOCOLS),1)
$(call DEPS,protocols,o)
endif

ifeq ($(INSPIRCD2_PROTOCOL),1)
$(call DEPS,protocols/inspircd2,o)
endif

ifeq ($(INSPIRCD3_PROTOCOL),1)
$(call DEPS,protocols/inspircd3,o)
endif

ifeq ($(INSPIRCD4_PROTOCOL),1)
$(call DEPS,protocols/inspircd4,o)
endif

ifeq ($(USE_PSEUDOCLIENTS),1)
$(call DEPS,pseudoclients,o)
endif

ifeq ($(HAXSERV_PSEUDOCLIENT),1)
$(call DEPS,pseudoclients/haxserv,o)
endif

ifeq ($(SERVICES_PSEUDOCLIENT),1)
$(call DEPS,pseudoclients/services,o)
endif

clean:
	$(RM) HaxIRCd
	for file in `find . -name '*.so'`; do $(RM) $$file; done
	for file in `find . -name '*.o'`; do $(RM) $$file; done