-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathrules_c.mk
1349 lines (1095 loc) · 43.8 KB
/
rules_c.mk
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
# Copyright (c) 2012-2017 Turbulenz Limited.
# Released under "Modified BSD License". See COPYING for full text.
############################################################
all:
C_MODULES := $(LIBS) $(DLLS) $(APPS)
$(call log,C_MODULES = $(C_MODULES))
ifeq (1,$(SYNTAX_CHECK_MODE))
ifneq (,$(filter %.c,$(CHK_SOURCES))$(filter %.cpp,$(CHK_SOURCES))$(filter %.cpp,$(CHK_SOURCES)))
C_SYNTAX_CHECK := 1
# $(warning CHK_SOURCES = $(CHK_SOURCES))
endif
endif
# $(warning C_SYNTAX_CHECK = $(C_SYNTAX_CHECK))
############################################################
cdeps?= -MP -MD -MF
cout?=-o$(space)
cobj?=.o
cdeptarget?=-MT
cdeptargetpre?=
cdeptargetpost?=
libprefix?=lib
libsuffix?=.a
dllout?= -o #
appout?= -o #
#
# Platform Checks
#
# (these checks are performed here so they don't cause terminal errors
# for clients who aren't building C++ apps).
ifeq (macosx,$(TARGETNAME))
# Check which SDK version we have available
ifeq (,$(shell $(MACOSX_XCODE_BIN_PATH)xcodebuild -showsdks | grep macosx$(XCODE_SDK_VER)))
# This technique works if only the Command Line tools are available.
ifeq (,$(wildcard $(shell xcode-select --print-path)/SDKs/MacOSX$(XCODE_SDK_VER).sdk))
$(error Cant find SDK version $(XCODE_SDK_VER))
endif
endif
# Check the SDK ROOT location
ifeq (,$(wildcard $(XCODE_SDK_ROOT)))
$(error couldnt find SDK dir $(XCODE_SDK_ROOT))
endif
endif
############################################################
#
# Full deps
#
# 1 - mod
#
# Not the clearest piece of code in the world, but ...
#
# For each dependencies of $(1), recursively calculate their full
# dependencies. Then, with the full deep dependencies of our deps
# calculated, iterate through all dependencies, adding new words on
# the left so that the deepest dependencies appear on the right (to
# satisfy the gcc linker)
#
define _calc_fulldeps
# Make sure each dep has been calculated
$(foreach d,$($(1)_deps), \
$(if $(filter $(d),$(LIBS) $(DLLS)),, \
$(error $(1)_deps contains '$(d)' which is not a LIB or DLL) \
) \
$(if $($(d)_depsdone),$(call log,$(d) deps already done),$(eval \
$(call _calc_fulldeps,$(d)) \
)) \
)
# For each dep, add any words in $(dep)_fulldeps not already in $(1)_fulldeps
$(foreach d,$($(1)_deps), \
$(if $(filter $(d),$($(1)_fulldeps)),$(call log,$(d) already in fulldeps),\
$(eval $(1)_depstoadd := ) \
$(foreach dd,$($(d)_fulldeps), \
$(if $(filter $(dd),$($(1)_fulldeps)),$(call log,dep $(dd) already in list for $(d)),\
$(call log,adding dep $(dd))\
$(eval $(1)_depstoadd := $($(1)_depstoadd) $(dd))\
$(call log,depstoadd: $($(1)_depstoadd))\
)\
)\
$(eval $(1)_fulldeps := $(d) $($(1)_depstoadd) $($(1)_fulldeps)) \
)\
)
$(1)_depsdone:=1
$(call log,Deps for $(1): $($(1)_fulldeps))
endef
$(foreach mod,$(C_MODULES),$(eval \
$(call _calc_fulldeps,$(mod)) \
))
$(foreach mod,$(C_MODULES),$(call log,$(mod)_fulldeps = $($(mod)_fulldeps)))
############################################################
#
# Path calculations for all modules types
#
# Conditionally translate _src and _incdirs to absolute paths. Set
# <mod>_incdirs_abs to always be the absolute paths.
ifeq (1,$(ABSPATHS))
# <mod>_src
$(foreach mod,$(C_MODULES), \
$(eval \
$(mod)_src:=$(foreach s,$($(mod)_src),$(call abspath_or_orig,$(s)))) \
$(eval \
$(mod)_incdirs:=$(foreach i,$($(mod)_incdirs),$(call abspath_or_orig,$(i)))) \
$(eval $(mod)_incdirs_abs:=$($(mod)_incdirs)) \
)
else
$(foreach mod,$(C_MODULES), \
$(eval $(mod)_incdirs_abs:=$(foreach i,$($(mod)_incdirs),$(abspath $(i)))) \
)
endif
ifeq (1,$(ABSPATHS_EXT))
$(foreach ext,$(EXT), $(eval \
$(ext)_incdirs:=$(foreach i,$($(ext)_incdirs),$(call abspath_or_orig,$(i)))\
))
endif
# calc <mod>_headerfiles - all headers for the module
$(foreach mod,$(C_MODULES),$(eval \
$(mod)_headerfiles := $(foreach i,$($(mod)_incdirs),$(wildcard $(i)/*.h)) \
))
# calc full path of each <ext>_libdir
$(foreach ext,$(EXT), $(eval \
$(ext)_libdir:=$(strip $(foreach l,$($(ext)_libdir),$(realpath $(l)))) \
))
# calc full path of external dlls
$(foreach ext,$(EXT), $(eval \
$(ext)_dlls := \
$(foreach l,$($(ext)_lib), \
$(foreach d,$($(ext)_libdir), \
$(wildcard $(d)/$(libprefix)$(l)$(dllsuffix)*) \
) \
) \
$(filter-out %$(libsuffix) -l%,$($(ext)_libfile)) \
))
# if it's a platform with .lib files accompanying .dlls (i.e. Windows)
# where we don't include input .dlls int he link commnd line, filter
# the dlls out from <ext>_libfiles, now that we have the list of dlls
# to copy.
ifneq (,$(dlllibsuffix))
$(foreach ext,$(EXT),$(eval \
$(ext)_libfile := $(filter-out %$(dllsuffix),$($(ext)_libfile))) \
)
endif
# calc <mod>_depincdirs and <mod>_depincdirs_abs - include dirs from
# dependencies
$(foreach mod,$(C_MODULES), \
$(eval \
$(mod)_depincdirs := \
$(sort $(foreach d,$($(mod)_fulldeps),$($(d)_incdirs))) \
) \
$(eval \
$(mod)_depincdirs_abs := \
$(sort $(foreach d,$($(mod)_fulldeps),$($(d)_incdirs_abs))) \
) \
)
# # calc <mod>_depheaderfiles - include files of dependencies
# $(foreach mod,$(C_MODULES),$(eval \
# $(mod)_depheaderfiles := $(foreach d,$($(mod)_fulldeps),$($(d)_headerfiles)) \
# ))
# calc <mod>_depcxxflags
$(foreach mod,$(C_MODULES),$(eval \
$(mod)_depcxxflags := $(foreach d,$($(mod)_fulldeps),$($(d)_cxxflags)) \
))
# cal <mod>_depextlibs - libs from dependencies
$(foreach mod,$(C_MODULES),$(eval \
$(mod)_depextlibs := $(foreach d,$($(mod)_fulldeps),$($(d)_extlibs)) \
))
$(call log,npturbulenz_depextlibs = $(npturbulenz_depextlibs))
# calc external include dirs
$(foreach mod,$(C_MODULES),$(eval \
$(mod)_ext_incdirs := \
$(foreach e,$(sort $($(mod)_extlibs) $($(mod)_depextlibs)),$($(e)_incdirs)) \
))
# calc external lib dirs
$(foreach mod,$(C_MODULES),$(eval \
$(mod)_ext_libdirs := $(foreach e,$($(mod)_extlibs) $($(mod)_depextlibs), \
$($(e)_libdir) \
) \
))
# calc external libs.
# <extlib>_lib values are prefixed with -l
# <extlib>_libfiles values are included as-is
$(foreach mod,$(C_MODULES),\
$(eval $(mod)_ext_lib_files := \
$(foreach e,$($(mod)_extlibs) $($(mod)_depextlibs), \
$(if $(filter $(e),$(EXT)),, \
$(error $(mod)_extlibs contains '$(e)', not in EXT) \
) \
$($(e)_libfile) \
)) \
$(eval $(mod)_ext_lib_flags := \
$(foreach e,$($(mod)_extlibs) $($(mod)_depextlibs), \
$(addprefix $(DLLFLAGS_LIB),$($(e)_lib)) \
$($(e)_libfile) \
)) \
)
# calc the full list of external dynamic libs for apps and dlls
$(foreach b,$(DLLS) $(APPS),\
$(eval $(b)_ext_dlls := \
$(foreach e,$($(b)_extlibs) $($(b)_depextlibs),$($(e)_dlls)) \
) \
)
$(call log,npturbulenz_ext_dlls = $(npturbulenz_ext_dlls))
############################################################
# External dlls need to be copied to bin
# 1 - module name
# 2 - dest
# 3 - src
ifneq (1,$(DISABLE_COPY_EXTERNAL_DLLS))
define _copy_dll_rule
$($(1)_dllfile) $($(1)_appfile) : $(2)
$(2) :: $(3)
@$(MKDIR) -p $$(dir $$@)
@echo [COPY-DLL] \($(1)\) $$(notdir $$<)
$(CMDPREFIX) $(CP) $$^ $$@
$(1)_cleanfiles += $(2)
endef
endif
# 1 - EXT name
define _null_external_dll
.PHONY : $(1)
$(1) :
endef
############################################################
# calc <mod>_OBJDIR
$(foreach mod,$(C_MODULES),$(eval $(mod)_OBJDIR := $(OBJDIR)/$(mod)))
# calc <mod>_DEPDIR
$(foreach mod,$(C_MODULES),$(eval $(mod)_DEPDIR := $(DEPDIR)/$(mod)))
ifeq (1,$(C_SYNTAX_CHECK))
UNITY := 0
endif
#
# For unity builds, replace the src list with a single file, and a
# rule to create it.
#
ifeq ($(UNITY),1)
UNITY_MODULES := \
$(foreach mod,$(C_MODULES),$(if $(filter 1,$($(mod)_unity)),$(mod)))
endif
$(foreach mod,$(UNITY_MODULES), \
$(eval $(mod)_unity_src := $(realpath $($(mod)_src))) \
$(eval $(mod)_src := $($(mod)_OBJDIR)/$(mod)_unity.cpp) \
)
#
# Output paths
#
# set <lib>_libfile - Final LIB file
$(foreach lib,$(LIBS),$(eval \
$(lib)_libfile ?= $(LIBDIR)/$(libprefix)$(lib)$(libsuffix)) \
)
# <dll>_dllfile - Final DLL file
# <dll>_dlllibfile - Lib file to link with (dllfile on *nix, dlllib on Windows)
# <dll>_pdbfile - PDB file (Windows only)
# <app>_appfile - Final APP file
# <app>_pdbfile - PDB file (Windows only)
# _make_dll_paths, _make_app_paths
# 1 - dll / app
ifneq (,$(dlllibsuffix))
define _make_dll_paths
$(1)_dllfile ?= $(BINDIR)/$(dllprefix)$(dll)$(dllsuffix)
$(1)_dlllibfile ?= $$($(1)_dllfile:$(dllsuffix)=$(dlllibsuffix))
endef
define _make_app_paths
$(1)_appfile ?= $(BINDIR)/$(app)$(binsuffix)
endef
else
define _make_dll_paths
$(1)_dllfile ?= $(BINDIR)/$(dllprefix)$(dll)$(dllsuffix)
$(1)_dlllibfile ?= $$($(1)_dllfile)
endef
define _make_app_paths
$(1)_appfile ?= $(BINDIR)/$(app)$(binsuffix)
endef
endif
# calc <dll>_dllfile
$(foreach dll,$(DLLS),$(eval $(call _make_dll_paths,$(dll))))
# calc <app>_appfile
$(foreach app,$(APPS),$(eval $(call _make_app_paths,$(app))))
ifneq (,$(pdbsuffix))
$(foreach m,$(DLLS),$(eval \
$(m)_pdbfile ?= $$($(m)_dllfile:$(dllsuffix)=$(pdbsuffix)) \
))
$(foreach m,$(APPS),$(eval \
$(m)_pdbfile ?= $$($(m)_appfile:$(binsuffix)=$(pdbsuffix)) \
))
endif
#
# Precopiled headers
#
# for each module, if _pch is set, we need vars:
ifeq (1,$(PCH))
$(foreach mod,$(C_MODULES), \
$(if $($(mod)_pch), \
$(eval \
_$(mod)_pchfile := $($(mod)_OBJDIR)/$(notdir $($(mod)_pch:.h=.h.gch)) \
) \
$(eval \
_$(mod)_pchdep := $($(mod)_DEPDIR)/$(notdir $($(mod)_pch:.h=.h.d)) \
) \
) \
)
endif
#
# For each module, create cxx_obj_dep list
#
# 1 - module
# 2 - src file
ifeq (,$(SRCROOT))
_mk_cpp_obj=$($(1)_OBJDIR)/$(notdir $(2:.cpp=$(cobj)))
_mk_cpp_dep=$($(1)_DEPDIR)/$(notdir $(2:.cpp=.cpp.d))
_mk_c_obj=$($(1)_OBJDIR)/$(notdir $(2:.c=$(cobj)))
_mk_c_dep=$($(1)_DEPDIR)/$(notdir $(2:.c=.c.d))
_mk_cc_obj=$($(1)_OBJDIR)/$(notdir $(2:.cc=$(cobj)))
_mk_cc_dep=$($(1)_DEPDIR)/$(notdir $(2:.cc=.cc.d))
_mk_mm_obj=$($(1)_OBJDIR)/$(notdir $(2:.mm=.mm$(cobj)))
_mk_mm_dep=$($(1)_DEPDIR)/$(notdir $(2:.mm=.mm.d))
else
# Convert all source paths to absolute so we can filter on SRCROOT
$(foreach mod,$(C_MODULES), $(eval $(mod)_src=$(abspath $($(mod)_src))))
override SRCROOT:=$(call ensure_trailing_slash,$(realpath $(SRCROOT)))
# Keep any dir structure past SRCROOT, otherwise just use the
# basename. Because we use realpath above, the subst ..,__ is
# probably unnecessary, but we keep it just to be safe.
_mk_obj_path=$(word 1, \
$(if $(findstring $(SRCROOT),$(1)), \
$(subst ..,__,$(subst $(SRCROOT),,$(1)))) \
$(notdir $(1)) \
)
_mk_cpp_obj=$($(1)_OBJDIR)/$(subst ..,__,$(call _mk_obj_path,$(2:.cpp=$(cobj))))
_mk_cpp_dep=$($(1)_DEPDIR)/$(subst ..,__,$(call _mk_obj_path,$(2:.cpp=.cpp.d)))
_mk_c_obj=$($(1)_OBJDIR)/$(subst ..,__,$(call _mk_obj_path,$(2:.c=$(cobj))))
_mk_c_dep=$($(1)_DEPDIR)/$(subst ..,__,$(call _mk_obj_path,$(2:.c=.cpp.d)))
_mk_cc_obj=$($(1)_OBJDIR)/$(subst ..,__,$(call _mk_obj_path,$(2:.cc=$(cobj))))
_mk_cc_dep=$($(1)_DEPDIR)/$(subst ..,__,$(call _mk_obj_path,$(2:.cc=.cc.d)))
_mk_mm_obj=$($(1)_OBJDIR)/$(subst ..,__,$(call _mk_obj_path,$(2:.mm=.mm$(cobj))))
_mk_mm_dep=$($(1)_DEPDIR)/$(subst ..,__,$(call _mk_obj_path,$(2:.mm=.mm.d)))
endif
# 1 - module name
define _make_cxx_obj_dep_list
$(1)_cxx_obj_dep := \
$(foreach s,$(filter %.cpp,$($(1)_src)), \
$(s)!$(call _mk_cpp_obj,$(1),$(s))!$(call _mk_cpp_dep,$(1),$(s)) \
) \
$(foreach s,$(filter %.c,$($(1)_src)), \
$(s)!$(call _mk_c_obj,$(1),$(s))!$(call _mk_c_dep,$(1),$(s)) \
) \
$(foreach s,$(filter %.cc,$($(1)_src)), \
$(s)!$(call _mk_cc_obj,$(1),$(s))!$(call _mk_cc_dep,$(1),$(s)) \
)
endef
# 1 - module name
define _make_cmm_obj_dep_list
$(1)_cmm_obj_dep := $(foreach s,$(filter %.mm,$($(1)_src)), \
$(s)!$(call _mk_mm_obj,$(1),$(s))!$(call _mk_mm_dep,$(1),$(s)) \
)
endef
$(foreach mod,$(C_MODULES), \
$(eval $(call _make_cxx_obj_dep_list,$(mod))) \
)
# only look for .mm's on mac and ios
ifneq (,$(filter macosx ios,$(TARGETNAME)))
$(foreach mod,$(C_MODULES), $(eval \
$(call _make_cmm_obj_dep_list,$(mod)) \
))
endif
#
# Functions for getting src, obj and dep files
#
_getsrc = $(word 1,$(subst !, ,$(1)))
_getobj = $(word 2,$(subst !, ,$(1)))
_getdep = $(word 3,$(subst !, ,$(1)))
#
# File names (absolute/relative/subdirs etc) fixed at this opint, so
# it's safe to invoke rules for source generation
#
# 1 - mod
define _make_cxx_unity_file
$($(1)_src) : $($(1)_unity_src)
$(MKDIR) -p $($(1)_OBJDIR)
echo > $$@
for i in $($(1)_unity_src) ; do echo \#include \"$$$$i\" >> $$@ ; done
endef
$(foreach mod,$(UNITY_MODULES), \
$(eval $(call _make_cxx_unity_file,$(mod))) \
)
#
# For each modules, calculate the full object list and full depfile list
#
$(foreach mod,$(C_MODULES),$(eval \
$(mod)_OBJECTS := \
$(foreach sod,$($(mod)_cxx_obj_dep),$(call _getobj,$(sod))) \
$(foreach sod,$($(mod)_cmm_obj_dep),$(call _getobj,$(sod))) \
))
$(foreach mod,$(C_MODULES),$(eval \
$(mod)_DEPFILES := \
$(_$(mod)_pchdep) \
$(foreach sod,$($(mod)_cxx_obj_dep),$(call _getdep,$(sod))) \
$(foreach sod,$($(mod)_cmm_obj_dep),$(call _getdep,$(sod))) \
))
$(call log,npengine_DEPFILES = $(npengine_DEPFILES))
#
# Flags
#
# 1 - mod
# 2 - flags string
define _make_cxx_flags_file
$(1)_flags_file ?= $($(1)_OBJDIR)/.flags
.FORCE :
$$($(1)_flags_file) : .FORCE
@if [ '$(strip $(2))' != "`cat $$@ 2>/dev/null | tr -d '\n'`" ] ; then \
echo [FLAGS $(TARGET)-$(ARCH)-$(CONFIG)] \($1\) $$@ ; \
$(MKDIR) -p $$(dir $$@) ; \
echo '$(foreach f,$(2),\n$(f))' > $$@ ; \
fi
# Keeping the old version for reference:
# ifneq ('$(shell $(CAT) $(2))','$(strip $(3))')
# # $$(info .flags: '$$(shell cat $(2) 2>/dev/null)')
# # $$(info new fl: '$$(strip $(3))')
# $$(shell $(MKDIR) -p $($(1)_OBJDIR))
# $$(shell $(MKDIR) -p $($(1)_OBJDIR))
# $$(shell echo '$(strip $(3))' > $(2))
# endif
$($(1)_OBJECTS) $(_$(1)_pchfile) : $$($(1)_flags_file)
$(1)_cleanfiles += $$($(1)_flags_file)
endef
ifneq (1,$(DISABLE_FLAG_CHECKS))
$(foreach mod,$(C_MODULES),$(eval \
$(call _make_cxx_flags_file,$(mod), \
$(strip $(filter-out $($(1)_remove_cxxflags), \
$(CSYSTEMFLAGS) \
$(CXXFLAGSPRE) $(CXXFLAGS) $($(mod)_depcxxflags) \
$($(mod)_cxxflags) $($(mod)_local_cxxflags) \
$(addprefix -I,$($(mod)_incdirs_abs)) \
$(addprefix -I,$($(mod)_depincdirs_abs)) \
$(addprefix -I,$($(mod)_ext_incdirs)) $(CXXFLAGSPOST) \
)) \
) \
))
endif
#
# Function to make a flymake target for a source file
#
# 1 - flymake src
# 2 - module_name
define _target_flymake_src
_fm_found += \
$(filter $(1)%,$($(2)_cxx_obj_dep) $($(2)_cmm_obj_dep))
endef
ifeq (1,$(C_SYNTAX_CHECK))
FLYMAKESRC:=$(strip $(abspath $(CHK_SOURCES)))
$(foreach mod,$(C_MODULES),\
$(eval $(call _target_flymake_src,$(FLYMAKESRC),$(mod))) \
)
# $(warning _fm_found: $(_fm_found))
ifneq (,$(strip $(_fm_found)))
$(foreach mod,$(C_MODULES),\
$(eval $(mod)_cxx_obj_dep := $(subst $(FLYMAKESRC),$(CHK_SOURCES),$($(mod)_cxx_obj_dep))) \
$(eval $(mod)_cmm_obj_dep := $(subst $(FLYMAKESRC),$(CHK_SOURCES),$($(mod)_cmm_obj_dep))) \
)
# $(warning standalone_cxx_obj_dep = $(standalone_cxx_obj_dep))
# $(warning standalone_cmm_obj_dep = $(standalone_cmm_obj_dep))
_obj := $(call _getobj,$(_fm_found))
.PHONY : $(_obj)
check-syntax: $(_obj)
else
ifneq (android,$(TARGET))
check-syntax:
$(MAKE) -s CHK_SOURCES=$(CHK_SOURCES) SYNTAX_CHECK_MODE=1 TARGET=android check-syntax
endif
endif
endif
#
# For each module, create the object build rules, generating the
# dependency files as a side-effect of a single run.
#
# 1 - mod
# 2 - .h source file
# 3 - .h.pch dest file
# 4 - depfile
define _make_pch_rule
.PRECIOUS : $(3)
$(3) : $(2)
@$(MKDIR) -p $($(1)_OBJDIR) $($(1)_DEPDIR)
@echo [PCH $(ARCH)] \($(1)\) $$(notdir $$@)
$(CMDPREFIX)$(CXX) \
$(filter-out $($(1)_remove_cxxflags), \
$(CXXSYSTEMFLAGS) $(CXXFLAGSPRE) $(CXXFLAGS) $($(1)_depcxxflags) \
$($(1)_cxxflags) $($(1)_local_cxxflags) \
) \
$(if $(DISABLE_DEP_GEN),, \
$(cdeps) $4 $(cdeptarget) $(cdeptargetpre)$4$(cdeptargetpost) \
$(cdeptarget) $(cdeptargetpre)$$@$(cdeptargetpost) \
) \
$(addprefix -I,$($(1)_incdirs)) \
$(addprefix -I,$($(1)_depincdirs)) \
$(addprefix -I,$($(1)_ext_incdirs)) \
$(filter-out $($(1)_remove_cxxflags), \
$(CXXFLAGSPOST) $($(call file_flags,$(2))) \
) \
$(PCHFLAGS) \
$(cout)$$@ $(csrc) $$< || ($(RM) -f $(3) $(4) && exit 1)
endef
# 1 - mod
# 2 - cxx srcfile
# 3 - object file
# 4 - depfile
define _make_c_object_rule
.PRECIOUS : $(3)
$(3) : $(2) $(_$1_pchfile)
$(CMDPREFIX)$(MKDIR) $($(1)_OBJDIR) $($(1)_DEPDIR)
@echo [CC $(TARGET)-$(ARCH)-$(CONFIG)] \($(1)\) $$(notdir $$<)
$(CMDPREFIX)$(CC) \
$(if $(_$1_pchfile),-include $(_$1_pchfile:.gch=)) \
$(CSYSTEMFLAGS) $(CFLAGSPRE) $(CFLAGS) \
$($(1)_depcxxflags) $($(1)_cflags) $($(1)_local_cflags) \
$(if $(DISABLE_DEP_GEN),, \
$(cdeps) $4 $(cdeptarget) $(cdeptargetpre)$4$(cdeptargetpost) \
$(cdeptarget) $(cdeptargetpre)$$@$(cdeptargetpost) \
$(cdeptarget) $(cdeptargetpre)$(3).clang-tidy$(cdeptargetpost) \
) \
$(addprefix -I,$($(1)_incdirs)) \
$(addprefix -I,$($(1)_depincdirs)) \
$(addprefix -I,$($(1)_ext_incdirs)) \
$(CFLAGSPOST) $($(call file_flags,$(2))) \
$(cout)$$@ $(csrc) $$<
$(call cc-post,$(1),$(2),$(3),$(4))
$(3).S : $(2)
$(CMDPREFIX)$(MKDIR) $($(1)_OBJDIR) $($(1)_DEPDIR)
@echo [C2ASM $(TARGET)-$(ARCH)-$(CONFIG)] \($(1)\) $$(notdir $$<)
$(CMDPREFIX)$(CC) \
$(if $(_$1_pchfile),-include $(_$1_pchfile:.gch=)) \
$(CSYSTEMFLAGS) $(CFLAGSPRE) $(CFLAGS) \
$($(1)_depcxxflags) $($(1)_cflags) $($(1)_local_cflags) \
$(addprefix -I,$($(1)_incdirs)) \
$(addprefix -I,$($(1)_depincdirs)) \
$(addprefix -I,$($(1)_ext_incdirs)) \
$(CFLAGSPOST) $($(call file_flags,$(2))) \
$(cout)$$@ -S $$<
$(1)_asm : $(3).S
$(3).clang-tidy : $(2)
$(CMDPREFIX)$(MKDIR) $($(1)_OBJDIR) $($(1)_DEPDIR)
@echo [CC TIDY $(TARGET)-$(ARCH)-$(CONFIG)] \($(1)\) $$<
$(CMDPREFIX)if (! $(CLANG_TIDY) $$< -- \
$(if $(_$1_pchfile),-include $(_$1_pchfile:.gch=)) \
$(CFLAGSPRE) $(CFLAGS) \
$($(1)_depcxxflags) $($(1)_cflags) $($(1)_local_cflags) \
$(addprefix -I,$($(1)_incdirs)) \
$(addprefix -I,$($(1)_depincdirs)) \
$(addprefix -I,$($(1)_ext_incdirs)) \
$(CFLAGSPOST) $($(call file_flags,$(2))) \
$(cout)$$@ $(csrc) $$< > $$@ 2>&1) || \
( grep -e 'warning:' -e 'error:' $$@ ) ; then \
cat $$@ ; rm $$@ ; $(FALSE) ; \
fi
ifneq (1,$($(1)_no_tidy))
$(1)_tidy : $(3).clang-tidy
$(1)_cleanfiles += $(3).clang-tidy
endif
endef
# 1 - mod
# 2 - cxx srcfile
# 3 - object file
# 4 - depfile
define _make_cxx_object_rule
.PRECIOUS : $(3)
$(3) : $(2) $(_$1_pchfile)
$(CMDPREFIX)$(MKDIR) $$(dir $$@)
@echo [CXX $(TARGET)-$(ARCH)-$(CONFIG)] \($(1)\) $$(notdir $$<)
$(CMDPREFIX)$(CXX) \
$(if $(_$1_pchfile),-include $(_$1_pchfile:.gch=)) \
$(filter-out $($(1)_remove_cxxflags), \
$(CXXSYSTEMFLAGS) $(CXXFLAGSPRE) $(CXXFLAGS) $($(1)_depcxxflags) \
$($(1)_cxxflags) $($(1)_local_cxxflags) \
) \
$(if $(DISABLE_DEP_GEN),, \
$(cdeps) $4 $(cdeptarget) $(cdeptargetpre)$4$(cdeptargetpost) \
$(cdeptarget) $(cdeptargetpre)$$@$(cdeptargetpost) \
$(cdeptarget) $(cdeptargetpre)$(3).clang-tidy$(cdeptargetpost) \
) \
$(addprefix -I,$($(1)_incdirs)) \
$(addprefix -I,$($(1)_depincdirs)) \
$(addprefix -I,$($(1)_ext_incdirs)) \
$(filter-out $($(1)_remove_cxflags), \
$(CXXFLAGSPOST) $($(call file_flags,$(2))) \
) \
$(cout)$$@ $(csrc) $$< || ($(RM) -f $(3) $(4) && exit 1)
$(if $(DISABLE_DEP_GEN),, $(if $($(1)_unity_src), \
echo >> $4 ; echo $(2) : $($(1)_unity_src) >> $4 \
))
$(call cxx-post,$(1),$(2),$(3),$(4))
$(2):
$(4):
$(3).S : $(2)
$(CMDPREFIX)$(MKDIR) $$(dir $$@)
@echo [CC2ASM $(TARGET)-$(ARCH)-$(CONFIG)] \($(1)\) $$(notdir $$<)
$(CMDPREFIX)$(CXX) \
$(if $(_$1_pchfile),-include $(_$1_pchfile:.gch=)) \
$(filter-out $($(1)_remove_cxxflags), \
$(CXXSYSTEMFLAGS) $(CXXFLAGSPRE) $(CXXFLAGS) $($(1)_depcxxflags) \
$($(1)_cxxflags) $($(1)_local_cxxflags) \
) \
$(addprefix -I,$($(1)_incdirs)) \
$(addprefix -I,$($(1)_depincdirs)) \
$(addprefix -I,$($(1)_ext_incdirs)) \
$(filter-out $($(1)_remove_cxflags), \
$(CXXFLAGSPOST) $($(call file_flags,$(2))) \
) \
$(cout)$$@ -S $$<
$(1)_asm : $(3).S
$(3).clang-tidy : $(2)
$(CMDPREFIX)$(MKDIR) -p $$(dir $$@)
@echo [CXX TIDY $(TARGET)-$(ARCH)-$(CONFIG)] \($(1)\) $$<
$(CMDPREFIX)if (! $(CLANG_TIDY) $$< -- \
$(if $(_$1_pchfile),-include $(_$1_pchfile:.gch=)) \
$(filter-out $($(1)_remove_cxxflags), \
$(CXXFLAGSPRE) $(CXXFLAGS) $($(1)_depcxxflags) \
$($(1)_cxxflags) $($(1)_local_cxxflags) \
) \
$($(1)_depcxxflags) $($(1)_cxxflags) $($(1)_local_cxxflags) \
$(addprefix -I,$($(1)_incdirs)) \
$(addprefix -I,$($(1)_depincdirs)) \
$(addprefix -I,$($(1)_ext_incdirs)) \
$(filter-out $($(1)_remove_cxflags), \
$(CXXFLAGSPOST) $($(call file_flags,$(2))) \
) \
$(cout)$$@ $(csrc) $$< > $$@ 2>&1 ) || \
grep -e 'warning:' -e 'error:' $$@ ; then \
cat $$@ ; rm $$@ ; $(FALSE) ; \
fi
ifneq (1,$($(1)_no_tidy))
$(1)_tidy : $(3).clang-tidy
$(1)_cleanfiles += $(3).clang-tidy
endif
endef
# 1 - mod
# 2 - mm srcfile
# 3 - object file
# 4 - depfile
define _make_cmm_object_rule
.PRECIOUS : $(3)
$(3) : $(2) $(_$1_pchfile)
$(CMDPREFIX)$(MKDIR) $$(dir $$@)
@echo [CMM $(TARGET)-$(ARCH)-$(CONFIG)] \($(1)\) $$(notdir $$<)
$(CMDPREFIX)$(CMM) \
$(if $(_$1_pchfile),-include $(_$1_pchfile:.gch=)) \
$(filter-out $($(1)_remove_cxflags), \
$(CXXSYSTEMFLAGS) $(CMMFLAGSPRE) $(CMMFLAGS) $($(1)_depcxxflags) \
$($(1)_cxxflags) $($(1)_local_cxxflags) \
) \
$(cdeps) $4 $(cdeptarget) $(cdeptargetpre)$4$(cdeptargetpost) \
$(cdeptarget) $(cdeptargetpre)$$@$(cdeptargetpost) \
$(addprefix -I,$($(1)_incdirs)) \
$(addprefix -I,$($(1)_depincdirs)) \
$(addprefix -I,$($(1)_ext_incdirs)) \
$(filter-out $($(1)_remove_cxflags), \
$(CMMFLAGSPOST) $($(call file_flags,$(2))) \
) \
$$< $(cout) $$@
endef
# DEPS WERE:
# $(2) $($(1)_headerfiles) $($(1)_depheaderfiles)
# 1 - mod
define _make_object_rules
$(if $(_$(1)_pchfile), \
$(call _make_pch_rule,$(1),$($(1)_pch),$(_$(1)_pchfile),$(_$(mod)_pchdep)) \
)
$(foreach sod,$($(1)_cxx_obj_dep), \
$(if $(filter %.cpp %.cc,$(call _getsrc,$(sod))), \
$(eval $(call _make_cxx_object_rule,$(1), \
$(call _getsrc,$(sod)), \
$(call _getobj,$(sod)), \
$(call _getdep,$(sod)) \
)), \
$(eval $(call _make_c_object_rule,$(1), \
$(call _getsrc,$(sod)), \
$(call _getobj,$(sod)), \
$(call _getdep,$(sod)) \
)) \
) \
)
$(foreach sod,$($(1)_cmm_obj_dep),$(eval \
$(call _make_cmm_object_rule,$(1),$(call _getsrc,$(sod)),$(call _getobj,$(sod)),$(call _getdep,$(sod))) \
))
# Define the phony _asm and _tidy targets for this module
.PHONY: $(1)_asm $(1)_tidy
$(1)_tidy : $(foreach d,$($(1)_deps),$(d)_tidy)
endef
$(foreach mod,$(C_MODULES),$(eval $(call _make_object_rules,$(mod))))
############################################################
# LIBRARY
# <mod>_deplibs = all libraries we depend upon
# depend on the libs for all dependencies
$(foreach mod,$(C_MODULES), \
$(eval $(mod)_deplibs := $(foreach d,$($(mod)_fulldeps),$($(d)_libfile))) \
$(eval $(mod)_depdlls := $(foreach d,$($(mod)_fulldeps),$($(d)_dllfile))) \
$(eval $(mod)_deplibs_cmdline := \
$(foreach d,$($(mod)_fulldeps), \
$(if $($(d)_keepsymbols), \
$(DLLKEEPSYM_PRE) $($(d)_libfile) $($(d)_dlllibfile) $(DLLKEEPSYM_POST),\
$($(d)_libfile) $($(d)_dlllibfile) ) \
)) \
)
# each lib depends on the object files for that module
# 1 - string
# 2 - file
define _append_line_to_file
$(CMDPREFIX)echo $1 >> "$2"
endef
# 1 - mod
ifeq (1,$(LIB_LIST_FILES))
define _make_lib_rule
$($(1)_libfile).objects : $($(1)_OBJECTS)
$(CMDPREFIX)$(MKDIR) -p $$(dir $$@)
$(CMDPREFIX)$(RM) -f $$@
$$(foreach o,$($(1)_OBJECTS),$$(call _append_line_to_file,$$o,$$@))
$($(1)_libfile) : $($(1)_libfile).objects
@echo [AR $(TARGET)-$(ARCH)-$(CONFIG)] $$(notdir $$@)
$(CMDPREFIX)$(RM) -f $$@
$(CMDPREFIX)$(MKDIR) $$(dir $$@)
$(CMDPREFIX)$(AR) $(ARFLAGSPRE) $(arout)$$@ @$$< $(ARFLAGSPOST)
.PHONY : $(1)
$(1) : $($(1)_libfile)
endef
else
define _make_lib_rule
$($(1)_libfile) : $($(1)_OBJECTS)
$(CMDPREFIX)$(MKDIR) -p $$(dir $$@)
@echo [AR $(TARGET)-$(ARCH)-$(CONFIG)] $$(notdir $$@)
$(CMDPREFIX)$(RM) -f $$@
$(CMDPREFIX)$(MKDIR) $$(dir $$@)
$(CMDPREFIX)$(AR) $(ARFLAGSPRE) $(arout)$$@ $($(1)_OBJECTS) $(ARFLAGSPOST)
.PHONY : $(1)
$(1) : $($(1)_libfile)
endef
endif
$(foreach lib,$(LIBS),$(eval \
$(call _make_lib_rule,$(lib)) \
))
############################################################
# DLLS
# rules to copy the dependent dlls
$(foreach dll,$(DLLS), \
$(foreach d,$($(dll)_ext_dlls),$(eval \
$(call _copy_dll_rule,$(dll),$(dir $($(dll)_dllfile))/$(notdir $(d)),$(d)) \
)) \
)
# 1 - module
define _make_dll_rule
$($(1)_dllfile) : $($(1)_depdlls) $($(1)_deplibs) $($(1)_OBJECTS) $($(1)_ext_lib_files)
@$(MKDIR) -p $$(dir $$@)
@echo [DLL $(TARGET)-$(ARCH)-$(CONFIG)] $$@
$(CMDPREFIX)$(DLL) $(DLLFLAGSPRE) \
$($(1)_DLLFLAGSPRE) \
$(addprefix $(DLLFLAGS_PDB),$($(1)_pdbfile)) \
$(if $(dlllibsuffix),$(addprefix $(DLLFLAGS_DLLLIB),$($(1)_dlllibfile))) \
$(if $(DLLFLAGS_LIBDIR), \
$(addprefix $(DLLFLAGS_LIBDIR),$($(1)_ext_libdirs)) \
) \
$($(1)_OBJECTS) \
$($(1)_deplibs_cmdline) \
$($(1)_ext_lib_flags) \
$(DLLFLAGSPOST) \
$($(1)_DLLFLAGSPOST) \
$(dllout)$$@
$(call dll-post,$(1))
$(if $($(1)_poststep),($($(1)_poststep)) || $(RM) -f $$@)
.PHONY : $(1)
$(1) : $($(1)_dllfile)
endef
# rule to make dll file
$(foreach dll,$(DLLS),$(eval \
$(call _make_dll_rule,$(dll)) \
))
############################################################
# APPLICATIONS
# rules to copy the dependent dlls
$(foreach app,$(APPS), \
$(foreach a,$($(app)_ext_dlls),$(eval \
$(call _copy_dll_rule,$(app),$(dir $($(app)_appfile))/$(notdir $(a)),$(a)) \
)) \
)
# 1 - mod
define _make_app_rule
$($(1)_appfile) : $($(1)_deplibs) $($(1)_depdlls) $($(1)_OBJECTS) \
$($(1)_ext_lib_files)
@$(MKDIR) -p $$(dir $$@)
@echo [LD $(TARGET)-$(ARCH)-$(CONFIG)] $$@
$(CMDPREFIX)$(LD) $(LDFLAGSPRE) \
$(addprefix $(LDFLAGS_LIBDIR),$($(1)_ext_libdirs)) \
$(LDFLAGS_PDB)$($(1)_pdbfile) \
$($(1)_OBJECTS) \
$($(1)_deplibs_cmdline) \
$($(1)_ext_lib_flags) \
$(LDFLAGSPOST) \
$($(1)_LDFLAGS) \
$(appout)$$@
$(call app-post,$(1))
$($(1)_poststep)
.PHONY : $(1)
$(1) : $($(1)_appfile)
endef
# rule to make app file
$(foreach app,$(APPS),$(eval \
$(call _make_app_rule,$(app)) \
))
# <mod>_run rule
# 1 - mod
define _run_app_rule
.PHONY : $(1)_run
$(1)_run : $(1)
$(RUNPREFIX) $(call _run_prefix,$(1)) $($(1)_appfile) $($(1)_runargs)
endef
$(foreach app,$(APPS),$(eval \
$(call _run_app_rule,$(app)) \
))
############################################################
# BUNDLES (macosx only)
$(foreach b,$(BUNDLES),\