-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathGNUmakefile
1847 lines (1575 loc) · 65.9 KB
/
GNUmakefile
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
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//DEBUG = 1
DEBUG = 1
LARGEFILE = 1
WARNINGS = all no-unused-variable
#WARNINGS += error
INSTALL = install
ROOT := $(shell cygpath -am / 2>/dev/null | sed "s|/$$||")
ROOTNAME := $(shell basename "$(ROOT)" | tr "[[:upper:]]" "[[:lower:]]")
ifneq ($(ROOTNAME),$(subst msys,,$(subst git-sdk,,$(subst cygwin,,$(ROOTNAME)))))
SYSNAME := $(subst git-sdk-,gitsdk,$(ROOTNAME))
endif
ifneq ($(CROSS_COMPILE),$(subst /,-,$(CROSS_COMPILE)))
PKG_CONFIG_PATH := $(subst /bin,/lib/pkgconfig,$(CROSS_COMPILE))
endif
#$(info PKG_CONFIG_PATH=$(PKG_CONFIG_PATH))
define NL =
endef
#file-exists = $(shell echo "Checking for $(1) ..." 1>&2; test -e "$(1)" && echo 1)
#$(info ROOTNAME=$(ROOTNAME))
#$(info SYSNAME=$(SYSNAME))
OS ?= $(shell uname -o | tr "[[:upper:]]" "[[:lower:]]")
ifeq ($(CC),)
CC := gcc
endif
ifeq ($(CC),cc)
CC := gcc
endif
CXX = g++
include build/functions.mk
ifeq ($(SHARED),1)
add-library = $(patsubst %,$(BUILDDIR)lib%.so,$(call clean-lib,$(1)))
else
add-library = $(patsubst %,$(BUILDDIR)%.a,$(call clean-lib,$(1)))
endif
add-lib-sources = $(wildcard $(foreach NAME,$(1),$(patsubst %,lib/%/*.c,$(1))))
#check-header = $(info $(call cmd-check-header,$(1)))
DEFINES_FILE := build/defines.mk
#$(foreach inc,sys/types.h inttypes.h vcruntime.h stdint.h stddef.h errno.h,$(call def-include-exists,$(inc)))
#$(info HAVE_SYS_TYPES_H=$(HAVE_SYS_TYPES_H))
#$(info HAVE_INTTYPES_H=$(HAVE_INTTYPES_H))
#$(info HAVE_VCRUNTIME_H=$(HAVE_VCRUNTIME_H))
#$(info HAVE_STDINT_H=$(HAVE_STDINT_H))
#$(info HAVE_STDDEF_H=$(HAVE_STDDEF_H))
#$(info HAVE_ERRNO_H=$(HAVE_ERRNO_H))
define NL =
$(EMPTY)
$(EMPTY)
endef
define CHECK_SCOPE_ID =
#include <sys/types.h>\n
#include <sys/socket.h>\n
#include <netinet/in.h>\n
\n
int main() {\n
struct sockaddr_in6 sa;\n
sa.sin6_family = PF_INET6;\n
sa.sin6_scope_id = 23;\n
(void)sa;\n
return 0;\n
}\n
endef
HAVE_PIPE_FLAG := $(call check-try-compile,$(default-program),-pipe)
ifneq ($(HAVE_PIPE_FLAG),1)
NOPIPE := 1
endif
HAVE_OPT_FLAG := $(call check-try-compile,$(default-program),-O0)
ifneq ($(HAVE_OPT_FLAG),1)
NOOPT := 1
endif
HAVE_WARN_FLAGS := $(call check-try-compile,$(default-program),-Wall -Wno-strict-aliasing -Wno-unused-function -Wno-unused-variable)
ifneq ($(HAVE_WARN_FLAGS),1)
NOWARN := 1
endif
HAVE_DEBUG_FLAGS := $(call check-try-compile,$(default-program),-g -ggdb)
ifneq ($(HAVE_DEBUG_FLAGS),1)
NODEBUG := 1
endif
$(info HAVE_DEBUG_FLAGS: $(HAVE_DEBUG_FLAGS))
HAVE_SCOPE := $(call check-try-compile,$(CHECK_SCOPE_ID))
ifeq ($(HAVE_SCOPE),1)
DEFINES += LIBC_HAS_SCOPE_ID=1
endif
#$(info HAVE_SCOPE=$(HAVE_SCOPE))
ifeq ($(call check-include-exists,errno.h),1)
DEFINES += HAVE_ERRNO_H=1
endif
HAVE_N2I := $(call check-include-exists,net/if.h)
ifeq ($(HAVE_N2I),1)
DEFINES += HAVE_N2I=1
endif
#$(info HAVE_N2I=$(HAVE_N2I))
LIBC_HAS_IP6 := $(call check-function-exists,inet_pton)
ifeq ($(LIBC_HAS_IP6),1)
DEFINES += LIBC_HAS_IP6=1
endif
#$(info LIBC_HAS_IP6=$(LIBC_HAS_IP6))
HAVE_PIPE2 := $(call check-function-exists,pipe2)
ifeq ($(HAVE_PIPE2),1)
DEFINES += HAVE_PIPE2=1
endif
#$(info HAVE_PIPE2=$(HAVE_PIPE2))
HAVE_WORDEXP := $(call check-function-exists,wordexp)
ifeq ($(HAVE_WORDEXP),1)
DEFINES += HAVE_WORDEXP=1
endif
#$(info HAVE_WORDEXP=$(HAVE_WORDEXP))
HAVE_FNMATCH := $(call check-function-exists,fnmatch)
ifeq ($(HAVE_FNMATCH),1)
DEFINES += HAVE_FNMATCH=1
endif
#$(info HAVE_FNMATCH=$(HAVE_FNMATCH))
HAVE_LSTAT := $(call check-function-exists,lstat)
ifeq ($(HAVE_LSTAT),1)
DEFINES += HAVE_LSTAT=1
endif
#$(info HAVE_LSTAT=$(HAVE_LSTAT))
HAVE_GETDELIM := $(call check-function-exists,getdelim)
ifeq ($(HAVE_GETDELIM),1)
DEFINES += HAVE_GETDELIM=1
endif
#$(info HAVE_GETDELIM=$(HAVE_GETDELIM))
HAVE_ROUND := $(call check-function-exists,round)
ifeq ($(HAVE_ROUND),1)
DEFINES += HAVE_ROUND=1
endif
#$(info HAVE_ROUND=$(HAVE_ROUND))
HAVE_ALLOCA := $(call check-function-exists,alloca,,alloca.h)
ifeq ($(HAVE_ALLOCA),1)
DEFINES += HAVE_ALLOCA=1
endif
#$(info HAVE_ALLOCA=$(HAVE_ALLOCA))
HAVE_SENDFILE := $(call check-function-exists,sendfile)
ifeq ($(HAVE_SENDFILE),1)
DEFINES += HAVE_SENDFILE=1
endif
#$(info HAVE_SENDFILE=$(HAVE_SENDFILE))
HAVE_CYGWIN_CONV_PATH := $(call check-function-exists,cygwin_conv_path)
ifeq ($(HAVE_CYGWIN_CONV_PATH),1)
DEFINES += HAVE_CYGWIN_CONV_PATH=1
endif
#$(info HAVE_CYGWIN_CONV_PATH=$(HAVE_CYGWIN_CONV_PATH))
HAVE_POPEN := $(call check-function-exists,popen)
ifeq ($(HAVE_POPEN),1)
DEFINES += HAVE_POPEN=1
endif
#$(info HAVE_POPEN=$(HAVE_POPEN))
HAVE_GETOPT := $(call check-function-exists,getopt)
ifeq ($(HAVE_GETOPT),1)
DEFINES += HAVE_GETOPT=1
endif
#$(info HAVE_GETOPT=$(HAVE_GETOPT))
HAVE_GETOPT_LONG := $(call check-function-exists,getopt_long)
ifeq ($(HAVE_GETOPT_LONG),1)
DEFINES += HAVE_GETOPT_LONG=1
endif
#$(info HAVE_GETOPT_LONG=$(HAVE_GETOPT_LONG))
#$(call def-include-exists,errno.h,HAVE_ERRNO_H)
#$(call def-include-exists,sys/devpoll.h,HAVE_DEVPOLL)
#$(info HAVE_DEVPOLL=$(HAVE_DEVPOLL))
ifneq ($(subst tcc,,$(CC)),$(CC))
BUILD := $(shell (set -x; $(CROSS_COMPILE)$(CC) -vv | sed '1!d ; s, version [^ ]\+ , , ; s,[()],,g; s,\s\+,-,g ; s,Linux,linux,g; s,\(.*\)-\(.*\)-\(.*\),\2-\3-\1,'))
else
BUILD := $(shell $(CROSS_COMPILE)$(CC) -dumpmachine)
endif
ifneq ($(CC),$(subst m32,,$(CC)))
BUILD := $(subst x86_64,i386,$(BUILD))
endif
#ifneq ($(BUILD),$(subst -pc-,-,$(BUILD)))
#BUILD := $(subst -pc-,-,$(BUILD))
#endif
$(info BUILD: $(BUILD))
CCVER := $(shell $(CROSS_COMPILE)$(CC) -dumpversion)
CXXVER := $(shell $(CROSS_COMPILE)$(CXX) -dumpversion)
ifneq ($(DIET),0)
ifneq ($(DIET),1)
ifneq ($(DIET),)
CC := $(DIET) $(CC)
PREFIX := $(patsubst %/bin/diet,%,$(DIET))
USE_DIET := 1
endif
endif
endif
ifneq ($(CROSS_COMPILE),$(subst diet,,$(CROSS_COMPILE)))
USE_DIET := 1
endif
ifneq ($(CROSS_COMPILE),$(subst musl,,$(CROSS_COMPILE)))
USE_MUSL := 1
endif
#$(info PREFIX: $(PREFIX))
#$(info DIET: $(DIET))
#$(info USE_DIET: $(USE_DIET))
ifneq ($(USE_DIET),1)
ifeq ($(word 1,(CROSS_COMPILE)),diet)
USE_DIET := 1
else
USE_DIET := 0
endif
endif
ifeq ($(word 3,$(subst -, ,$(BUILD))),mingw32)
MINGW := 1
else
MINGW := 0
endif
ifeq ($(word 3,$(subst -, ,$(BUILD))),msys)
MSYS := 1
ifeq ($(shell grep -q msys-1.0.dll /bin/sh.exe && echo 1),1)
BUILD := $(subst msys,msys1,$(BUILD))
endif
else
MSYS := 0
endif
ifeq ($(word 3,$(subst -, ,$(BUILD))),cygwin)
CYGWIN := 1
else
CYGWIN := 0
endif
ifeq ($(USE_DIET),1)
DO_CXX := 0
else
DO_CXX := 0
endif
ifeq ($(CROSS_COMPILE),)
HOST ?= $(BUILD)
else
ifeq ($(USE_MUSL),1)
HOST := $(subst gnu,musl,$(BUILD))
else
ifneq ($(subst tcc,,$(CC)),$(CC))
HOST := $(shell (set -x; $(CROSS_COMPILE)$(CC) -vv | sed '1!d ; s, version [^ ]\+ , , ; s,[()],,g; s,\s\+,-,g ; s,Linux,linux,g; s,\(.*\)-\(.*\)-\(.*\),\2-\3-\1,'))
else
ifeq ($(USE_DIET),1)
HOST := $( shell set -x; $(CROSS_COMPILE)$(CC) -dumpmachine | sed 's|[-.0-9]*\\\$$|| ;; s|\\r\$$||' )
else
HOST := $( shell set -x; $(CROSS_COMPILE)$(CC) -dumpmachine | sed 's|[-.0-9]*\\\$$|| ;; s|\\r\$$|| ;; s|-unknown-|-|g' )
endif
endif
endif
endif
ifneq ($(CC),$(subst m32,,$(CC)))
HOST := $(subst x86_64,i386,$(HOST))
endif
ifneq ($(HOST),$(subst linux,,$(HOST)))
#ifneq ($(HOST),$(subst -pc-,-,$(HOST)))
#HOST := $(subst -pc-,-,$(HOST))
#endif
endif
ifeq ($(USE_DIET),1)
HOST := $(subst -diet-,-,$(HOST))
HOST := $(subst gnu,dietlibc,$(HOST))
endif
#$(info USE_DIET: $(USE_DIET))
#$(info MINGW: $(MINGW))
#$(info HOST: $(HOST))
ifeq ($(PREFIX),)
PREFIX := $(shell $(CROSS_COMPILE)$(CC) -print-search-dirs |sed -n 's,.*:\s\+=\?,,; s,/bin.*,,p ; s,/lib.*,,p' |head -n1 )
endif
#$(info PREFIX: $(PREFIX))
ifneq ($(SYSROOT),)
CC += --sysroot=$(SYSROOT)
endif
#ifeq ($(SYSROOT),)
#ifneq ($(CROSS_COMPILE),$(subst /,-,$(CROSS_COMPILE)))
#SYSROOT := $(subst /bin/,,$(CROSS_COMPILE))
#else
#SYSROOT = $(shell $(CROSS_COMPILE)$(CC) -print-search-dirs | sed -n "/^lib/ { s|.*:\s\+|| ; s|^=|| ; /;/ { s|.*;|;| }; /;/! { s|.*:|| } ; s|^;|| ; s|/lib.*|| ; s|/mingw$$|| ; s|/usr$$|| ; s|/$$||; p }" )
#
#endif
#$(info SYSROOT: $(SYSROOT))
#endif
prefix ?= $(PREFIX)
bindir = ${prefix}/bin
mandir = ${prefix}/share/man
man3dir = $(mandir)/man3
ifneq ($(HOST),)
TRIPLET := $(subst -, ,$(HOST))
endif
ifneq ($(USE_DIET),1)
ifneq ($(HOST),$(BUILD))
ifeq ($(CROSS_COMPILE),)
CROSS_COMPILE := $(HOST)-
endif
endif
endif
ifeq ($(DEBUG),1)
BUILDTYPE = debug
else
BUILDTYPE = release
DO_STRIP := 1
endif
ifeq ($(PROF),1)
BUILDTYPE := prof
endif
ifeq ($(HOST),$(BUILD))
CROSS_COMPILE :=
endif
PKG_CONFIG := pkg-config
ifneq ($(CROSS_COMPILE),)
ifeq ($(call cmd-exists,$(CROSS_COMPILE)$(PKG_CONFIG)),1)
PKG_CONFIG := $(CROSS_COMPILE)$(PKG_CONFIG)
else
P := $(shell set -x; ls -d /usr/$(CROSS_COMPILE:%-=%)/sys*root/*/lib/pkgconfig)
ifeq ($(call file-exists,$(P)),1)
PKG_CONFIG_PATH := $(P)
ifeq ($(SYSROOT),)
SYSROOT := $(dir $(subst /lib/pkgconfig,,$(P)))
#$(info SYSROOT=$(SYSROOT))
endif
else
P := $(shell set -x; ls -d /usr/$(CROSS_COMPILE:%-=%)/lib/pkgconfig)
ifeq ($(call file-exists,$(P)),1)
PKG_CONFIG_PATH := $(P)
endif
endif
endif
endif
ifneq ($(MSYS),1)
C11_COMPILER_DEFINES := $(shell $(call get-compiler-defs,-std=c11))
#$(info C11_COMPILER_DEFINES: $(C11_COMPILER_DEFINES))
ifneq ($(C11_COMPILER_DEFINES),)
CC += -std=c11
endif
endif
AR := ar
ifeq ($(call cmd-exists,$(CROSS_COMPILE)$(AR)),1)
AR := $(CROSS_COMPILE)$(AR)
endif
RANLIB := ranlib
ifeq ($(call cmd-exists,$(CROSS_COMPILE)$(RANLIB)),1)
RANLIB := $(CROSS_COMPILE)$(RANLIB)
endif
STRIP := strip
ifeq ($(call cmd-exists,$(CROSS_COMPILE)$(STRIP)),1)
STRIP := $(CROSS_COMPILE)$(STRIP)
endif
#$(info PKG_CONFIG: $(PKG_CONFIG))
#$(info PKG_CONFIG_PATH: $(PKG_CONFIG_PATH))
#PKG_CONFIG_CMD := $(if $(SYSROOT)$(PKG_CONFIG_PATH),env $(if $(SYSROOT),PKG_CONFIG_SYSROOT_DIR=$(SYSROOT) ,)$(if $(PKG_CONFIG_PATH),PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) ,),)$(PKG_CONFIG)
PKG_CONFIG_CMD := $(if $(SYSROOT)$(PKG_CONFIG_PATH),env ,)$(if $(PKG_CONFIG_PATH),PKG_CONFIG_PATH=$(PKG_CONFIG_PATH) ,)$(PKG_CONFIG)
#$(info PKG_CONFIG_CMD: $(PKG_CONFIG_CMD))
ifneq ($(TRIPLET),)
ARCH := $(word 1,$(TRIPLET))
OS := $(shell echo $(word 3,$(TRIPLET)) |sed "s|[0-9].*||")
KERN := $(word 2,$(TRIPLET))
SYS := $(word 3,$(TRIPLET))
W := 4
ifeq ($(KERN),pc)
KERN := $(SYS)
endif
ifeq ($(SYS),pc)
SYS := $(word $(W),$(TRIPLET))
W := 5
endif
ifeq ($(SYS),w64)
SYS := $(word $(W),$(TRIPLET))
endif
endif
#$(info Arch: $(ARCH))
#$(info OS: $(OS))
#$(info KERN: $(KERN))
#$(info SYS: $(SYS))
USE_WINSOCK := $(call check-function-exists,WSAStartup,-lws2_32,winsock2.h)
ifeq ($(MSYS),1)
USE_WINSOCK := 0
endif
ifeq ($(CYGWIN),1)
USE_WINSOCK := 0
endif
#$(info USE_WINSOCK=$(USE_WINSOCK))
ifeq ($(USE_WINSOCK),1)
WINSOCK_LIB = -lws2_32 -lmswsock
IPHLPAPI_LIB = -liphlpapi
endif
ifeq ($(MSYS),1)
#WINSOCK_LIB = -lws2_32
ADVAPI32_LIB = -ladvapi32
IPHLPAPI_LIB = -liphlpapi
endif
$(call def-function-exists,ZLIB,deflate,-lz)
HAVE_ZLIB := $(call check-function-exists,deflate,-lz)
#$(info HAVE_ZLIB=$(HAVE_ZLIB))
HAVE_LIBLZMA := $(call check-function-exists,lzma_code,-llzma)
ifneq ($(HAVE_LIBLZMA),1)
HAVE_LIBLZMA := $(call check-function-exists,lzma_code,-llzma -lpthread)
LIBLZMA := -llzma -lpthread
else
LIBLZMA := -llzma
endif
$(info HAVE_LIBLZMA=$(HAVE_LIBLZMA))
HAVE_LIBBZ2 := $(call check-function-exists,BZ2_bzCompress,-lbz2)
$(info HAVE_LIBBZ2=$(HAVE_LIBBZ2))
#$(call def-function-exists,EPOLL,epoll_wait,)
#$(info HAVE_EPOLL=$(HAVE_EPOLL))
$(call def-function-exists,KQUEUE,kevent,)
#$(info HAVE_KQUEUE=$(HAVE_KQUEUE))
$(call def-function-exists,POLL,poll,)
#$(info HAVE_POLL=$(HAVE_POLL))
#$(call def-function-exists,SIGWAITINFO,sigwaitinfo,)
#$(info HAVE_SIGWAITINFO=$(HAVE_SIGWAITINFO))
$(call def-function-exists,SIGIO,sigtimedwait,)
#$(info HAVE_SIGIO=$(HAVE_SIGIO))
HAVE_LSEEK64 := $(call check-function-exists,lseek64)
HAVE_LSEEK := $(call check-function-exists,lseek)
HAVE_LLSEEK := $(call check-function-exists,llseek)
HAVE_POSIX_MEMALIGN := $(call check-function-exists,posix_memalign)
#$(info HAVE_POSIX_MEMALIGN=$(HAVE_POSIX_MEMALIGN))
#$(info HAVE_LSEEK64=$(HAVE_LSEEK64) HAVE_LSEEK=$(HAVE_LSEEK64) HAVE_LLSEEK=$(HAVE_LLSEEK64))
#$(info llseek: $(call check-function-exists,llseek))
ifeq ($SUBLIME_FILENAME),None)
PATH = /c/git-sdk-64/usr/bin
MAKE = c:/git-sdk-64/usr/bin/make
endif
ifneq ($(OS),linux)
ifeq ($(ARCH),x86_64)
M64 = 64
endif
endif
ifeq ($(OS),msys)
EXEEXT = .exe
STATIC_LIBGCC := 1
endif
ifneq ($(HOST),$(subst msys,,$(HOST)))
EXEEXT = .exe
STATIC_LIBGCC := 1
endif
ifeq ($(KERN),cygwin)
EXEEXT = .exe
endif
ifeq ($(OS),mingw)
EXEEXT = .exe
STATIC_LIBGCC := 1
ifeq ($(ARCH),x86_64)
#M64_ := -x64
endif
endif
ifeq ($(OS),cygwin)
EXEEXT = .exe
endif
ifeq ($(OS),mingw32)
EXEEXT = .exe
endif
BOOST_LIBS = boost_random
#$(info SYS: $(SYS))
#$(info KERN: $(KERN))
#$(info ARCH: $(ARCH))
#$(info OS: $(OS))
#$(info Host: $(HOST))
#$(info Build: $(BUILD))
HOST1 := $(word 1,$(subst -, ,$(HOST)))
HOST2 := $(word 2,$(subst -, ,$(HOST)))
HOST3 := $(subst $(HOST1)-$(HOST2)-,,$(HOST))
#$(info HOST1=$(HOST1), HOST2=$(HOST2), HOST3=$(HOST3))
#ifneq ($(SYSNAME),)
#BUILDDIR = $(subst w64,$(SYSNAME),$(BUILDDIR))
#endif
ifeq ($(HOST2),pc)
HOST2 := $(SYSNAME)
endif
ifeq ($(HOST2),w64)
HOST2 := $(SYSNAME)
endif
ifeq ($(HOST2),)
ifneq ($(KERN),)
HOST2 := $(KERN)
else
HOST2 := pc
endif
endif
#ifneq ($(SYSNAME),)
#HOST := $(subst w64,$(SYSNAME),$(HOST))
#endif
TOOLCHAIN := $(HOST1)-$(HOST2)-$(HOST3)
#ifeq ($(OS),mingw32)
#TOOLCHAIN = $(HOST)-$(shell $(CROSS_COMPILE)gcc -dumpversion)
#else
#TOOLCHAIN = $(HOST)
#endif
#
#$(info TOOLCHAIN: $(TOOLCHAIN))
HOST := $(subst unknown-,,$(HOST))
ifneq ($(CC),$(subst clang,,$(CC)))
BUILD := $(subst gnu,clang,$(BUILD))
HOST := $(subst gnu,clang,$(HOST))
endif
ifneq ($(CC),$(subst zapcc,,$(CC)))
BUILD := $(subst gnu,zapcc,$(BUILD))
HOST := $(subst gnu,zapcc,$(HOST))
endif
ifeq ($(CC),tcc)
BUILD := $(subst gnu,tcc,$(BUILD))
HOST := $(subst gnu,tcc,$(HOST))
DEFINES += inline=__inline
endif
ifneq (${builddir},)
BUILDDIR = ${builddir}/$(BUILD_TYPE)/
else
ifneq ($(HOST),$(BUILD))
BUILDDIR = build/$(HOST)/$(BUILD_TYPE)/
else
# ifeq ($(CROSS_COMPILE),)
BUILDDIR = build/$(HOST)/$(BUILD_TYPE)/
# else
# BUILDDIR = build/$(patsubst %-,%,$(CROSS_COMPILE))/$(BUILD_TYPE)/
# endif
endif
endif
export BUILDDIR
vpath lib lib/array lib/alloc lib/cb lib/cbmap lib/binfmt lib/buffer lib/byte lib/dir lib/fmt lib/hashmap lib/hmap lib/http lib/io lib/list lib/mmap lib/open lib/pe lib/coff lib/playlist lib/process lib/map lib/scan lib/socket lib/str lib/stralloc lib/tai lib/taia lib/uint16 lib/uint32 lib/uint64 lib/wait $(BUILDDIR) tests
VPATH = lib:lib/array:lib/alloc:lib/binfmt:lib/buffer:lib/cb:lib/cbmap:lib/byte:lib/dir:lib/fmt:lib/hmap:lib/hashmap:lib/http:lib/io:lib/list:lib/mmap:lib/open:lib/pe:lib/coff:lib/playlist:lib/process:lib/map:lib/scan:lib/socket:lib/str:lib/stralloc:lib/tai:lib/taia:lib/uint16:lib/uint32:lib/uint64:lib/wait:$(BUILDDIR):tests
ifeq ($(CXXOPTS),)
##$(info OS: "$(OS)")
ifneq ($(OS),msys)
endif
endif
CPPFLAGS := -I.
ifneq ($(SELECT),)
DEFINES += USE_SELECT=$(SELECT)
endif
#DEFINES += INLINE=inline
#DEFINES += PATH_MAX=4096
ifeq ($(READDIR),)
ifeq ($(SYS),mingw32)
#DEFINES += USE_READDIR=0
READDIR :=0
else
ifeq ($(SYS),msys)
READDIR := 1
#DEFINES += USE_READDIR=0
endif
endif
endif
ifeq ($(OS),wasi)
READDIR := 1
DEFINES += _BSD_SOURCE=1
endif
$(info READDIR: $(READDIR))
ifeq ($(WIN32),)
ifeq ($(SYS),mingw32)
WIN32 := 1
else
ifeq ($(SYS),msys)
WIN32 := 1
endif
endif
endif
ifeq ($(WIN32),)
WIN32 := 0
endif
ifeq ($(WIN32),1)
#OTHERLIBS := -lws2_32 -lmswsock
endif
ifeq ($(WIN32),1)
WIDECHAR := 1
endif
ifeq ($(SYS),msys)
WIDECHAR := 0
endif
ifeq ($(WIDECHAR),)
WIDECHAR := 0
endif
ifneq ($(WIDECHAR),)
DEFINES += USE_WIDECHAR=$(WIDECHAR)
endif
ifneq ($(READDIR),)
DEFINES += USE_READDIR=$(READDIR)
endif
ifeq ($(LARGEFILE),1)
DEFINES += _FILE_OFFSET_BITS=64
DEFINES += _LARGEFILE_SOURCE=1
endif
DEFINES += _GNU_SOURCE=1
WARNINGS += no-strict-aliasing
STRIP ?= strip
ifneq ($(NOPIPE),1)
CFLAGS = -pipe
endif
CFLAGS_Prof = -pg $(if $(NOOPT),,-O2)
CFLAGS_Debug = -g -ggdb $(if $(NOOPT),,$(if $(NOOPT),,-O0))
CFLAGS_MinSizeRel = -g -fomit-frame-pointer $(if $(NOOPT),,-Os)
CFLAGS_RelWithDebInfo = -g -ggdb $(if $(NOOPT),,-O2)
CFLAGS_Release = -g -fomit-frame-pointer $(if $(NOOPT),,-O2)
CXXFLAGS = -pipe
CXXFLAGS += -std=c++11
CXXFLAGS_Prof = -pg -O2 $(if $(NOOPT),,-O2)
CXXFLAGS_Debug = -g -ggdb $(if $(NOOPT),,$(if $(NOOPT),,-O0))
CXXFLAGS_MinSizeRel = -g -fomit-frame-pointer $(if $(NOOPT),,-Os)
CXXFLAGS_RelWithDebInfo = -g -ggdb $(if $(NOOPT),,-O2)
CXXFLAGS_Release = -g -fomit-frame-pointer $(if $(NOOPT),,-O2)
ifeq ($(BUILD_TYPE),)
ifeq ($(PROF),1)
BUILD_TYPE = Prof
else
ifeq ($(DEBUG),1)
ifeq ($(RELEASE),1)
BUILD_TYPE = RelWithDebInfo
else
BUILD_TYPE = Debug
endif
else
ifeq ($(MINSIZE),1)
BUILD_TYPE = MinSizeRel
else
BUILD_TYPE = Release
endif
endif
endif
endif
#$(info BUILDDIR: \
)
#$(info builddir: $(builddir))
ifeq ($(BUILD_TYPE),Prof)
DEBUG := 0
RELEASE := 1
MINSIZE := 0
endif
ifeq ($(BUILD_TYPE),Debug)
DEBUG := 1
RELEASE := 0
MINSIZE := 0
endif
ifeq ($(BUILD_TYPE),RelWithDebInfo)
DEBUG := 1
RELEASE := 1
MINSIZE := 0
endif
ifeq ($(BUILD_TYPE),MinSizeRel)
DEBUG := 0
RELEASE := 1
MINSIZE := 1
endif
ifeq ($(BUILD_TYPE),Release)
DEBUG := 0
RELEASE := 1
MINSIZE := 0
endif
ifeq ($(DEBUG),1)
DEFINES += _DEBUG=1 DEBUG_OUTPUT=1
else
DEFINES += NDEBUG=1
endif
ifeq ($(HMAP_DEBUG),1)
DEFINES += HMAP_DEBUG=1
endif
FLAGS += $(CFLAGS_$(BUILD_TYPE))
CXXFLAGS += $(CXXFLAGS_$(BUILD_TYPE))
ifeq ($(USE_DIET),1)
STATIC := 1
endif
ifneq ($(STATIC),1)
STATIC := 0
endif
#$(info DIET: $(DIET))
#$(info STATIC: $(STATIC))
ifneq ($(subst tcc,,$(CC)),$(CC))
HOST := $(shell (set -x; $(CROSS_COMPILE)$(CC) -vv | sed '1!d ; s, version [^ ]\+ , , ; s,[()],,g; s,\s\+,-,g ; s,Linux,linux,g; s,\(.*\)-\(.*\)-\(.*\),\2-\3-\1,'))
else
ifeq ($(HOST),)
HOST := $(shell $(CROSS_COMPILE)$(CC) -dumpmachine)
endif
endif
ifneq ($(HOST),$(subst mingw,,$(HOST)))
MINGW := 1
endif
ifneq ($(MINGW),1)
MINGW := 0
endif
ifeq ($(MINGW),1)
CFLAGS += -fno-stack-check -fno-stack-protector -mno-stack-arg-probe
LDFLAGS += -static-libgcc
#DEFINES += open=_open read=_read write=_write close=_close
#LDFLAGS += -static-lib{asan,gfortran,lsan,tsan,ubsan}
WIN32 := 1
endif
ifeq ($(CYGWIN),1)
WIN32 := 1
endif
ifeq ($(STATIC),1)
#LDFLAGS += -static
PKG_CONFIG += --static
ifeq ($(MINGW)$(STATIC),10)
LDFLAGS += -static-libgcc -static-libstdc++
else
LDFLAGS += -static
endif
endif
ifeq ($(WIN32),1)
EXTRA_LIBS += -lkernel32
endif
ifeq ($(STATIC_LIBGCC),1)
LDFLAGS += -static-libgcc
endif
ifeq ($(STATIC_LIBSTDCXX),1)
LDFLAGS += -static-libstdc++
endif
ifeq ($(STRIP),1)
LDFLAGS += -s
endif
RM = rm -f
ifneq ($(shell uname -s)-$(shell uname -o),MINGW32_NT-5.1-Msys)
ifeq ($(STATIC),)
ifeq ($(CYGWIN),)
LDFLAGS += -static-libgcc -static-libstdc++
endif
endif
endif
ifneq ($(BOOST_INCLUDE_DIR),)
CXXFLAGS += -I$(BOOST_INCLUDE_DIR)
endif
ifneq ($(BOOST_LIB_DIR),)
LIBS += -L$(BOOST_LIB_DIR) $(patsubst %,-l%,$(BOOST_LIBS))
endif
WARNINGS += no-unused-function
ifeq ($(PIE),1)
CFLAGS += -fPIE
LDFLAGS += -pie
endif
LDFLAGS += -L$(prefix)/lib$(if $(ARCH),-$(ARCH))
#$(info HOST:
$(info MSYS: $(MSYS))
#ifeq ($(MSYS),1)
# CFLAGS += -I/usr/include/w32api
#endif
DEFINES += NO_BUILTINS=1
#CFLAGS = $(patsubst %,-W%,$(WARNINGS))
#DEFS := $(patsubst %,-D%,$(DEFINES))
#DEFS += $(EXTRA_DEFS)
#DEFS := $(sort $(DEFS))
LIB_SRC = $(wildcard *_*.c umult*.c)
LIB_OBJ = $(patsubst %.o,$(BUILDDIR)%.o,$(patsubst %.c,%.o,$(LIB_SRC)))
pkg-conf = $(foreach L,$(2),$(shell $(PKG_CONFIG_CMD) $(1) $(L) |sed "s,\([[:upper:]]:/\),\
-I\1,g ; /^-I$$/d"))
#$(info ICONV_CFLAGS: $(ICONV_CFLAGS))
#$(info ICONV_LIBS: $(ICONV_LIBS))
#ifeq ($(USE_DIET),1)
#STATIC := 1
#endif
#ifeq ($(STATIC),1)
#endif
#
#LIBRARIES = $(patsubst %,$(BUILDDIR)lib%$(M64_).a,z bz2 lzma)
PROGRAMS = $(patsubst %,$(BUILDDIR)%$(M64_)$(EXEEXT),binfmttest bsdiffcat buffertest ccat compiler-wrapper count-depth decode-ls-lR dnsip dnsname dnstest eagle-gen-cmds eagle-init-brd \
eagle-to-circuit eagle-to-svg elf64list elflist elfwrsec genmakefile hexedit httptest impgen jsontest jsonpp list-r macho32list mediathek-list mediathek-parser ntldd omflist opensearch-dump pathtool pelist pkgcfg plsconv rdir-test reg2cmd regfilter sln strarraytest torrent-progress xmlpp xml2json xmltest xmltest2 xmltest3 xmltest4 xml2moon ziptest cc-wrap ar-wrap cofflist msys-shell tcping cmake-run httpproxy parse testihex piccfg crc strip-comments logserial libc-resolv-override setuidgid testini)
MAN3 = $(wildcard lib/*/*.3)
#opensearch-dump
LIBSOURCES = $(wildcard lib/*/*.c)
ifeq ($(DO_CXX),1)
PROGRAMS += \
piccfghex$(M64_)$(EXEEXT)
# $(BUILDDIR)mediathek-parser-cpp$(M64_)$(EXEEXT)
endif
OBJECTS = $(PROGRAMS:%=%.o) $(LIB_OBJ)
vpath $(BUILDDIR) lib src
VPATH = $(BUILDDIR):.:lib:src
#$(info Programs: $(PROGRAMS))
##$(info ARCH: $(ARCH))
##$(info BUILD: $(BUILD))
##$(info BUILDDIR: \
)
##$(info BUILDTYPE: $(BUILDTYPE))
##$(info CCVER: $(CCVER))
##$(info CROSS_COMPILE: $(CROSS_COMPILE))
##$(info CXXVER: $(CXXVER))
$(info HOST: $(HOST))
$(info TOOLCHAIN: $(TOOLCHAIN))
$(info KERN: $(KERN))
##$(info M64: $(M64))
$(info OS: $(OS))
##$(info STATIC: $(STATIC))
##$(info TRIPLET: $(TRIPLET))
ifeq ($(OS),darwin)
READDIR := 1
#DEFINES += USE_READDIR=1
#CFLAGS += -DUSE_READDIR=1
#CPPFLAGS += -DUSE_READDIR=1
ifneq ($(HAVE_LSEEK64),)
io_seek = lseek64
else
ifeq ($(HAVE_LSEEK),1)
io_seek = lseek
else
ifeq ($(HAVE__LLSEEK),1)
io_seek = _llseek
else
ifeq ($(HAVE_LLSEEK),1)
io_seek = llseek
else
ifeq ($(HAVE__LSEEK),1)
io_seek = _lseek
else
ifeq ($(HAVE__LSEEKI64),1)
io_seek = _lseeki64
else
ifeq ($(HAVE_LSEEK),1)
io_seek = lseek
endif
endif
endif
endif
endif
endif
endif
endif
ifeq ($(HAVE_ZLIB),1)
DEFINES += HAVE_ZLIB=1
CPPFLAGS += -DHAVE_ZLIB=1
LIBS = -lz
endif
ifeq ($(HAVE_LIBLZMA),1)
DEFINES += HAVE_LIBLZMA=1
CPPFLAGS += -DHAVE_LIBLZMA=1
endif
ifeq ($(HAVE_LIBBZ2),1)
DEFINES += HAVE_LIBBZ2=1
CPPFLAGS += -DHAVE_LIBBZ2=1
LIBBZ2 = -lbz2
endif
ifeq ($(HAVE_ERRNO_H),1)
DEFINES += HAVE_ERRNO_H=1
endif
ifeq ($(io_seek),)
io_seek := lseek
endif
ifneq ($(io_seek),)
DEFINES += io_seek=$(io_seek)
endif
ifeq ($(HAVE_POSIX_MEMALIGN),1)
DEFINES += HAVE_POSIX_MEMALIGN=1
endif
#CPPFLAGS += $(DEFS:%=-D%)
ifneq ($(EXTRA_CPPFLAGS),)
CPPFLAGS += $(EXTRA_CPPFLAGS)
endif
ifneq ($(EXTRA_LDFLAGS),)
LDFLAGS += $(EXTRA_LDFLAGS)
endif
#
$(info DEFINES: $(DEFINES))
ifneq ($(NOWARN),1)
FLAGS += $(patsubst %,-W%,$(WARNINGS))
endif
CPPFLAGS += $(patsubst %,-D%,$(DEFINES))
CPPFLAGS := $(sort $(CPPFLAGS))
FLAGS += $(CPPFLAGS)
FLAGS := $(sort $(FLAGS))
#FLAGS := $(sort $(FLAGS))
FLAGS_FILE := $(patsubst %/,%,$(dir $(patsubst %/,%,$(BUILDDIR))))/$(notdir $(patsubst %/,%,$(BUILDDIR))).flags
SPACE := $(DUMMY) $(DUMMY)
define NL
endef
ifneq ($(HOST),($(subst msys1,,$(HOST))))
NO_AT ?= 1
endif
NO_AT := 1
ifneq ($(NO_AT),1)
CFLAGS += @$(FLAGS_FILE)
else
CFLAGS += $(shell cat $(FLAGS_FILE))
endif
ifneq ($(SYSROOT),)
ifneq ($(call file-exists,$(SYSROOT)),1)
SYSROOT :=
endif
endif
ifeq ($(SYSROOT),)
ifeq ($(call file-exists,/opt/$(HOST)/sys-root),1)
SYSROOT := /opt/$(HOST)/sys-root
else
ifeq ($(call file-exists,/usr/$(HOST)/sys-root),1)
SYSROOT := /usr/$(HOST)/sys-root
else
ifeq ($(call file-exists,/usr/$(HOST)/sysroot),1)
SYSROOT := /usr/$(HOST)/sysroot