-
Notifications
You must be signed in to change notification settings - Fork 95
/
Makefile.bindings
731 lines (602 loc) · 26.4 KB
/
Makefile.bindings
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
ifneq ($(V),1)
.SILENT:
endif
# temp: for $(SOV) to work
VERSION := 0.44
ifndef CROSSPLATFORM_MK
include $(_CF_DIR)crossplatform.mk
include $(_CF_DIR)default.cf
endif
# naming conventions
#
# _bg_name_of_an_internal_bindings_generation_related_variable
# _bgNameOfAnInternalBindingsGenerationRelatedFunction
# _internalNameOfAFunctionThatIsOnlyUsedByOneOtherFunction
#
# _bg_rule_template_nameOfABindingsGenerationRelatedRuleTemplate
# _bg_rule_guard_nameOfABindingsGenerationRelatedRuleTemplate_$(...)
#
# USER_FACING_OR_CROSSPLATFORM_MK_OR_DEFAULT_CF_VARIABLE_NAME
#
# bgen output rule templates and supporting variables
################################################################################################################################
# user options
# most important user options
#
# todo: find better names?
# BG_ADD_LIB_GOALS or BG_LIB_GOALS
# BG_ADD_LIB_SEARCH_LOCATIONS or BG_LIB_SEARCH_LOCATIONS
ifndef BG_LIB_GOALS
_bg_input_lib_names := eC ecere EDA $(BG_ADD_LIB_GOALS)
else
_bg_input_lib_names := $(BG_LIB_GOALS)
endif
ifndef BG_LIB_SEARCH_LOCATIONS
_bg_lib_search_paths := obj/$(PLATFORM)/lib $(BG_ADD_LIB_SEARCH_LOCATIONS)
else
_bg_lib_search_paths := $(BG_LIB_SEARCH_LOCATIONS)
endif
# general user options
#
# BINDINGS_DIR
ifndef BINDINGS_DIR
_bg_dir := bindings
else
_bg_dir := $(BINDINGS_DIR)
endif
# more obscure user options
#
# BGEN_NO_SELF_DEPENDENCY
ifdef BGEN_NO_SELF_DEPENDENCY
_bg_no_self_dep := 1
endif
# internal variables
_bg_lang_c := C
_bg_lang_cpp := C++
_bg_header_c := h
_bg_header_cpp := hpp
_bg_bypass_c :=
_bg_bypass_cpp := -bypassmacros
_bg_dep_ec := $(_CF_DIR)obj/$(PLATFORM)/lib/$(LP)ec$(SO)
_bg_dep_ec2 := $(_CF_DIR)obj/$(PLATFORM)/lib/$(LP)ec2$(SO)
_bg_dep_ecere := $(_CF_DIR)obj/$(PLATFORM)/lib/$(LP)ecere$(SO)
_bg_deps := $(_bg_dep_ec) $(_bg_dep_ec2) $(_bg_dep_ecere)
_bg_quiet := $(if $(SILENT_IS_ON),-quiet,)
# note: this is rather hard coded
# todo: need some kind of user options
_bg_args := -fren Log=__e_log,Logf=__e_logf,Sleep=__sleep,Print=printx
_bg_dir_c := $(_bg_dir)/c
_bg_dir_cpp := $(_bg_dir)/cpp
# hard coded library names
_bg_eC := eC
_bg_ecere := ecere
_bg_ecereCOM := ecereCOM
# functions
# note: _eCToEcereCOM is an accepted exception to the naming convention
_eCToEcereCOM = $(if $(subst $(_bg_eC),,$(1)),,$(_bg_ecereCOM))
_bgCorrectLibName = $(if $(call _eCToEcereCOM,$(1)),$(call _eCToEcereCOM,$(1)),$(1))
# note: _bgGetLibFileNameFromBindingName only used here? should be _internalSomething
_bgGetLibFileNameFromBindingName = $(LP)$(call _bgCorrectLibName,$(1))$(SO)
_internalFindLib = $(firstword $(foreach _search_loc,$(_bg_lib_search_paths),$(if $(wildcard $(_search_loc)/$(call _bgGetLibFileNameFromBindingName,$(1))),$(_search_loc)/$(call _bgGetLibFileNameFromBindingName,$(1)),)))
# todo: see what to do with this warning or error message instead of $(empty) in the following function: $(info unable to find $(1) library.)
_bgFindLibPathByBindingName = $(if $(call _internalFindLib,$1),$(call _internalFindLib,$1),$(empty))
# rule templates
define _bg_rule_template_bgenOutput
# info: this rule template will become the rules that will call bgen to generate either:
# libraryName.c and libraryName.h or libraryName.cpp and libraryName.hpp; or:
# libraryName.h or libraryName.hpp when only a header is needed
# note: python too? not tested yet!
$(_bg_dir)/$(2)/$(1).$(3): $(call _bgFindLibPathByBindingName,$(1)) $(if $(_bg_no_self_dep),,$(BGEN) $(_bg_deps))
$(BGEN) $(strip -dir $(_bg_dir)/$(2) $(_bg_args) $(4) $(_bg_quiet) -$(2) $(_bg_bypass_$(2)) $$<)
# @$(call echo,Generated $(_bg_lang_$(2)) bindings for $$<)
endef
# bindings (c, cpp) building rule templates and supporting variables
################################################################################################################################
_BG_VERSION := 0.44
_BG_VER := $(if $(LINUX_TARGET),$(if $(LINUX_HOST),$(if $(_BG_VERSION),.$(_BG_VERSION),),),)
_BG_SOV := $(SO)$(_BG_VER)
_BG_CONFIG := release
_BG_CFLAGS_c = $(CFLAGS)
_BG_CFLAGS_cpp = $(CFLAGS)
_BG_LDFLAGS_c = $(LDFLAGS)
_BG_LDFLAGS_cpp = $(LDFLAGS)
_BG_OFLAGS = $(OFLAGS)
_BG_LIBS =
_BG_OBJ_DIR_SUFFIX := .$(_BG_CONFIG).$(PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)
# todo: fix crossplatform.mk' SHAREDLIB by removing the $(if $(SHARED_LIBRARY_TARGET),,)
SHAREDLIB := $(if $(OSX_TARGET),-dynamiclib -single_module -multiply_defined suppress,-shared)
_BG_LIBS += $(SHAREDLIB) $(EXECUTABLE) $(LINKOPT)
_BG_CFLAGS_cpp += -std=c++17 -fno-exceptions -fno-rtti -Wcomment
ifndef STATIC_LIBRARY_TARGET
_BG_OFLAGS += \
-L$(_CF_DIR)obj/$(PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/bin \
-L$(_CF_DIR)obj/$(PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib \
$(foreach _search_loc,$(_bg_lib_search_paths),-L$(_search_loc))
endif
_BG_LDFLAGS_cpp += -Wl,-nostdlib
ifndef CPP_BINDINGS_EMBEDDED_C_DISABLE
_embedded_c := 1
endif
# current working deps:
define _bg_rule_template_bindingSourceObject =
$(_BG_OBJ_$(3)_$(1))$(1).$(2)$(O): $(strip $(_bg_dir)/$(2)/$(1).$(2) $(if $(subst cpp,,$(2)),,$(_bg_dir)/c/$(1).h $(_bg_dir_c)/$(_bg_eC).c $(if $(subst $(_bg_eC),,$(1)),$(if $(subst $(_bg_ecere),,$(1)),$(_bg_dir_c)/$(_bg_ecere).c,),)) $(if $(subst $(_bg_eC),,$(1)),$(_bg_dir)/$(2)/$(_bg_eC).$(_bg_header_$(2)) $(if $(subst $(_bg_ecere),,$(1)),$(_bg_dir)/$(2)/ecere.$(_bg_header_$(2)),),) $(if $(subst gnosis3,,$(1)),,$(_bg_dir)/c/EDA.h))
$(CC) $(strip $(_BG_CFLAGS_$(2)) $(_BG_PRJ_CFLAGS_$(2)_$(1)) -c $(call quote_path,$$<) -o $(call quote_path,$$@))
endef
define _bg_rule_template_bindingLibAll =
.PHONY: internal_bg_lib_all_$(2)_$(1)
internal_bg_lib_all_$(2)_$(1): internal_bg_lib_objdir_$(2)_$(1) $(_BG_TARGET_$(2)_$(1));
.PHONY: internal_bg_lib_objdir_$(2)_$(1)
internal_bg_lib_objdir_$(2)_$(1):
$(call mkdir,$(_BG_OBJ_$(2)_$(1)))
$(_BG_OBJECTS_$(2)_$(1)): | internal_bg_lib_objdir_$(2)_$(1)
$(_BG_TARGET_$(2)_$(1)): $(strip $(_BG_SOURCES_$(2)_$(1)) $(_BG_OBJECTS_$(2)_$(1))) | internal_bg_lib_objdir_$(2)_$(1)
$(CC) $(strip $(_BG_LDFLAGS_$(2)) $(_BG_OFLAGS) $(_BG_OBJECTS_$(2)_$(1)) $(_BG_LIBS_$(2)_$(1)) -o $$@ $(INSTALLNAME))
ifndef NOSTRIP
$(STRIP) $(strip $(STRIPOPT) $$@)
endif
ifdef LINUX_TARGET
ifdef LINUX_HOST
$(if $(basename $(_BG_VER)),ln -sf $(LP)$(_BG_MODULE_$(2)_$(1))$(SO)$(_BG_VER) $(_BG_OBJ_$(2)_$(1))$(LP)$(_BG_MODULE_$(2)_$(1))$(SO)$(basename $(_BG_VER)),)
$(if $(_BG_VER),ln -sf $(LP)$(_BG_MODULE_$(2)_$(1))$(SO)$(_BG_VER) $(_BG_OBJ_$(2)_$(1))$(LP)$(_BG_MODULE_$(1))$(SO),)
endif
endif
$(call cp,$$@,$(_CF_DIR)$(HOST_SODESTDIR))
ifdef LINUX_TARGET
ifdef LINUX_HOST
$(if $(basename $(_BG_VER)),ln -sf $(LP)$(_BG_MODULE_$(2)_$(1))$(SO)$(_BG_VER) $(_CF_DIR)$(HOST_SODESTDIR)$(LP)$(_BG_MODULE_$(1))$(SO)$(basename $(_BG_VER)),)
$(if $(_BG_VER),ln -sf $(LP)$(_BG_MODULE_$(2)_$(1))$(SO)$(_BG_VER) $(_CF_DIR)$(HOST_SODESTDIR)$(LP)$(_BG_MODULE_$(2)_$(1))$(SO),)
endif
endif
# note: we need a bgen feature to ask for dependencies and then generate the rules for dependencies
# we're doing this for now:
endef
define _bg_rule_template_lib_vars_and_rules =
$(eval _BG_MODULE_$(2)_$(1) := $(1)_$(2))
$(eval _BG_BINDING_MODULE_$(1) := $(call _bgCorrectLibName,$(1)))
$(eval _BG_OBJ_$(2)_$(1) := $(_bg_dir)/$(2)/obj/$(1)$(_BG_OBJ_DIR_SUFFIX)/)
$(eval _BG_TARGET_$(2)_$(1) := $(_BG_OBJ_$(2)_$(1))$(LP)$(_BG_MODULE_$(2)_$(1))$(_BG_SOV))
$(eval _BG_SONAME_$(2)_$(1) := $(if $(LINUX_TARGET),-Wl,-soname,$(LP)$(MODULE)$(SO).0,))
$(eval _BG_SOURCES_$(2)_$(1) := $(_bg_dir)/$(2)/$(1).$(2))
$(eval _BG_OBJECTS_$(2)_$(1) := $(_BG_OBJ_$(2)_$(1))$(1).$(2)$(O) $(if $(subst cpp,,$(2)),,$(_BG_OBJ_$(2)_$(1))$(1).c$(O)))
$(eval _BG_LIBS_$(2)_$(1) := $(_BG_LIBS))
ifdef STATIC_LIBRARY_TARGET
$(eval _BG_LIBS_$(2)_$(1) += $(strip $(call _L,$(_BG_BINDING_MODULE_$(1)))))
# note: we need a bgen feature to ask for dependencies and then generate the rules for dependencies
# we're doing this for now:
$(eval _BG_LIBS_$(2)_$(1) += $(strip $(if $(subst $(_bg_eC),,$(1)),$(call _L,$(_bg_eC)_$(2)),)))
$(eval _BG_LIBS_$(2)_$(1) += $(strip $(if $(subst $(_bg_eC),,$(1)),$(if $(subst ecere,,$(1)),$(call _L,$(_bg_ecere)) $(call _L,$(_bg_ecere)_$(2)),),)))
ifeq ($(2),cpp)
$(eval _BG_LIBS_$(2)_$(1) += $(strip $(if $(subst $(_bg_eC),,$(1)),$(call _L,$(_bg_ecere)) $(call _L,$(_bg_ecere)_c),$(call _L,$(_bg_ecereCOM)) $(call _L,$(_bg_eC)_c))))
endif
ifeq ($(2),c)
$(eval _BG_PRJ_CFLAGS_$(2)_$(1) := $(strip $(if $(DEBUG),-g,-O2 -ffast-math) $(FPIC) -w $(if $(_CF_DIR),-I$(_CF_DIR)bindings/c,)))
ifdef C_BINDINGS_SYMBOLS_PREFIX_ENABLE
$(eval _BG_PRJ_CFLAGS_$(2)_$(1) += -DECPRFX=eC_)
endif
else
ifeq ($(2),cpp)
$(eval _BG_PRJ_CFLAGS_$(2)_$(1) := $(strip $(if $(DEBUG),-g,-O2 -ffast-math) $(FPIC) -w $(if $(_CF_DIR),-I$(_CF_DIR)bindings/c,) $(if $(_CF_DIR),-I$(_CF_DIR)bindings/cpp,)))
$(eval _BG_PRJ_CFLAGS_$(2)_$(1) += $(strip -DECPRFX=eC_ $(if $(subst eC,,$(1)),,-DECERECOM_ONLY)))
endif
endif
endif
$(call _bg_rule_template_bgenOutput,$(1),$(2),$(2))
$(call _bg_rule_template_bgenOutput,$(1),$(2),$(_bg_header_$(2)),--header-only)
$(call _bg_rule_template_bindingLibAll,$1,$(2))
$(call _bg_rule_template_bindingSourceObject,$(1),$(2),$(2))
ifeq ($(2),cpp)
$(call _bg_rule_template_bindingSourceObject,$(1),c,$(2))
endif
endef
#$(call _bg_rule_template_bindingSourceObject,$(_bg_eC),c,2)
#$(call _bg_rule_template_bindingSourceObject,$(_bg_ecere),cpp,3)
ifneq ($(_bg_input_lib_names),)
# $(foreach _goal,$(_bg_input_lib_names),$(info $(_goal))$(call echo $(call _bg_rule_template_lib_vars_and_rules,$(_goal),c))$(eval $(call _bg_rule_template_lib_vars_and_rules,$(_goal),c)))
$(foreach _goal,$(_bg_input_lib_names),$(eval $(call _bg_rule_template_lib_vars_and_rules,$(_goal),c)))
$(foreach _goal,$(_bg_input_lib_names),$(eval $(call _bg_rule_template_lib_vars_and_rules,$(_goal),cpp)))
# $(eval $(call _bg_rule_template_bindingSourceObject,c))
# $(eval $(call _bg_rule_template_bindingSourceObject,cpp))
endif
_bg_all_outputs_sources_c := $(foreach _goal,$(_bg_input_lib_names),$(_bg_dir_c)/$(_goal).c)
.PHONY: c-bindings-gen
c-bindings-gen: $(_bg_all_outputs_sources_c) ;
# @$(call echo,All C bindings ($(strip $(_bg_input_lib_names))) are ready.)
.PHONY: c-bindings-gen-%
c-bindings-gen-%: $(_bg_dir_c)/%.c ;
# @$(call echo,C bindings for $* are ready.)
_bg_all_outputs_libs_c := $(foreach _goal,$(_bg_input_lib_names),$(_bg_dir_c)/obj/$(_goal)$(_BG_OBJ_DIR_SUFFIX)/$(LP)$(_goal)_c$(SOV))
.PHONY: c-bindings-lib
c-bindings-lib: $(_bg_all_outputs_libs_c) ;
# why is this broken?
.PHONY: c-bindings-lib-%
c-bindings-lib-%: $(_bg_dir_c)/obj/%$(_BG_OBJ_DIR_SUFFIX)/$(LP)%_c$(SOV)
@$(call echo,dep: $(_bg_dir_c)/obj/$*$(_BG_OBJ_DIR_SUFFIX)/$(LP)$*_c$(SOV))
#.PHONY: c-bindings-lib-%
#c-bindings-lib-%: ;
# @$(call echo,dep: $(_bg_dir_c)/obj/$*$(_BG_OBJ_DIR_SUFFIX)/$(LP)$*_c$(SOV))
_bg_all_outputs_sources_cpp := $(foreach _goal,$(_bg_input_lib_names),$(_bg_dir_cpp)/$(_goal).cpp)
.PHONY: cpp-bindings-gen
cpp-bindings-gen: $(_bg_all_outputs_sources_cpp) ;
# @$(call echo,All C bindings ($(strip $(_bg_input_lib_names))) are ready.)
.PHONY: cpp-bindings-gen-%
cpp-bindings-gen-%: $(_bg_dir_cpp)/%.cpp ;
# @$(call echo,C bindings for $* are ready.)
_bg_all_outputs_libs_cpp := $(foreach _goal,$(_bg_input_lib_names),$(_bg_dir_cpp)/obj/$(_goal)$(_BG_OBJ_DIR_SUFFIX)/$(LP)$(_goal)_cpp$(SOV))
.PHONY: cpp-bindings-lib
cpp-bindings-lib: $(_bg_all_outputs_libs_cpp) ;
# why is this broken?
.PHONY: cpp-bindings-lib-%
cpp-bindings-lib-%: $(_bg_dir_cpp)/obj/%$(_BG_OBJ_DIR_SUFFIX)/$(LP)%_cpp$(SOV) ;
# tests
.PHONY: test-new-bindings-stuff
test-new-bindings-stuff: test-new-c-bindings-stuff test-new-cpp-bindings-stuff
.PHONY: test-new-%-bindings-stuff
test-new-%-bindings-stuff:
@$(call echo,"")
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/eC.$(_bg_header_$*)
$(MAKE) V=1 $(_bg_dir_$*)/eC.$*
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/eC.$*
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/eC.$*
$(MAKE) V=1 $(_bg_dir_$*)/obj/eC$(_BG_OBJ_DIR_SUFFIX)/eC.$*.o
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/obj/eC$(_BG_OBJ_DIR_SUFFIX)/eC.$*.o
$(MAKE) V=1 $(_bg_dir_$*)/obj/eC$(_BG_OBJ_DIR_SUFFIX)/$(LP)eC_$*$(SOV)
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/obj/eC$(_BG_OBJ_DIR_SUFFIX)/$(LP)eC_$*$(SOV)
$(call rmr,$(_bg_dir))
@$(call echo,"")
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/ecere.$(_bg_header_$*)
$(MAKE) V=1 $(_bg_dir_$*)/ecere.$*
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/ecere.$*
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/ecere.$*
$(MAKE) V=1 $(_bg_dir_$*)/obj/ecere$(_BG_OBJ_DIR_SUFFIX)/ecere.$*.o
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/obj/ecere$(_BG_OBJ_DIR_SUFFIX)/ecere.$*.o
$(MAKE) V=1 $(_bg_dir_$*)/obj/ecere$(_BG_OBJ_DIR_SUFFIX)/$(LP)ecere_$*$(SOV)
$(call rmr,$(_bg_dir))
$(MAKE) V=1 $(_bg_dir_$*)/obj/ecere$(_BG_OBJ_DIR_SUFFIX)/$(LP)ecere_$*$(SOV)
$(call rmr,$(_bg_dir))
# End of New Stuff
################################################################################################################################
################################################################################################################################
# Old Stuff -- All
################################################################################################################################
renameEcereCOM = $(subst ecereCOM,eC,$(1))
#$(call renameEcereCOM,$(word $(1),$(BGEN_LIBS))) $(call selectLib,$(1))
selectLib = $(word $(1),$(BGEN_LIBS))
ifndef C_BINDINGS_DIR
C_BINDINGS_DIR := $(_bg_dir)/c
endif
ifndef CPP_BINDINGS_DIR
CPP_BINDINGS_DIR := $(_bg_dir)/cpp
endif
ifndef PY_BINDINGS_DIR
PY_BINDINGS_DIR := $(_bg_dir)/py
endif
ifndef BGEN_LIBS
BGEN_LIBS := obj/linux/lib/$(LP)ecereCOM$(SO) obj/linux/lib/$(LP)ecere$(SO) obj/linux/lib/$(LP)EDA$(SO) $(ADDITIONAL_BGEN_LIBS)
endif
_BGEN_OUTS := $(foreach _lib,$(BGEN_LIBS),$(call renameEcereCOM,$(call lib_path_to_name,$(_lib))))
_BGEN_C_OUTPUT := $(addsuffix .h,$(_BGEN_OUTS)) $(addsuffix .c,$(_BGEN_OUTS)) $(addsuffix _c.Makefile,$(_BGEN_OUTS))
_BGEN_CPP_OUTPUT := $(addsuffix .h,$(_BGEN_OUTS)) $(addsuffix .c,$(_BGEN_OUTS)) $(addsuffix _cpp.Makefile,$(_BGEN_OUTS))
_BGEN_PY_OUTPUT := $(addprefix cffi-,$(addsuffix .h,$(_BGEN_OUTS))) $(addsuffix .py,$(_BGEN_OUTS)) $(addprefix build_,$(addsuffix .py,$(_BGEN_OUTS)))
# note: this is needed because we chdir without the use of a makefile specifying a different _CF_DIR
# and cannot call bgen with the usual relative path specified by $(BGEN)
# i.e.: +cd $(C_BINDINGS_DIR) && $(BGEN) $(_bg_args) $(_bg_quiet) -c $(BGEN_LIBS)
#ROOT_ABSPATH = $(dir $(realpath $(firstword $(MAKEFILE_LIST))))
#BGEN := $(call sys_path,$(ROOT_ABSPATH)$(_CF_DIR)obj/$(HOST_PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/bin/bgen$(HOST_E))
ifdef WINDOWS_HOST
PYTHON := python
else
PYTHON := python3
endif
PY_VER := 3
_bg_lang_py := Python $(PY_VER)
lib_path_to_name = $(basename $(if $(LP),$(patsubst $(LP)%$(SO),%$(SO),$(notdir $(1))),$(notdir $(1))))
get_binding_name = $(call renameEcereCOM,$(call lib_path_to_name,$(call selectLib,$(1))))
bg_src_file_c = $(call get_binding_name,$(1)).c
bg_src_file_cpp = $(call get_binding_name,$(1)).cpp
bg_src_file_py = $(call get_binding_name,$(1)).py
bg_hdr_file_c = $(call get_binding_name,$(1)).h
bg_hdr_file_cpp = $(call get_binding_name,$(1)).hpp
bg_hdr_file_py =
bg_mak_file_c = $(call get_binding_name,$(1))_c.Makefile
bg_mak_file_cpp = $(call get_binding_name,$(1))_cpp.Makefile
bg_mak_file_py = build_$(call get_binding_name,$(1)).py
bg_file_path_c = $(C_BINDINGS_DIR)/$(call bg_$(3)_file_$(2),$(1))
bg_file_path_cpp = $(CPP_BINDINGS_DIR)/$(call bg_$(3)_file_$(2),$(1))
bg_file_path_py = $(PY_BINDINGS_DIR)/$(call bg_$(3)_file_$(2),$(1))
bg_bld_cmd_c = $(_MAKE) -f $(call bg_mak_file_$(2),$(1)) $(3)
bg_bld_cmd_cpp = $(_MAKE) -f $(call bg_mak_file_$(2),$(1)) $(3)
bg_bld_cmd_py = $(PYTHON) $(call bg_mak_file_$(2),$(1))
bg_print_lib_name = $(call echo,$(call get_binding_name,$(1)))
bg_bind_____echo = $(call bg_bind_echo_,$(1),$(2))
bg_bind_echo_ = $(if $(call selectLib,$(1)),$(if $(wildcard $(call bg_file_path_$(2),$(1),$(2),mak)),@$(call echo,Building $(_bg_lang_$(2)) bindings for $(call get_binding_name,$(1)) ($(call selectLib,$(1)))...),),)
bg_bind_cd_build = $(if $(call selectLib,$(1)),$(if $(wildcard $(call bg_file_path_$(2),$(1),$(2),mak)),$(call _bg_bind_cd_build,$(1),$(2),$(3)),$(call echo,Error: $(call bg_file_path_$(2),$(1),$(2),mak) not found!)),)
_bg_bind_cd_build = +cd $(_bg_dir)/$(2) && $(call bg_bld_cmd_$(2),$(1),$(2),$(3))
# todo: make this an actual error?
bg_bind_any_gened_exists = $(wildcard $(call bg_file_path_$(2),$(1),$(2),src))$(wildcard $(call bg_file_path_$(2),$(1),$(2),hdr))$(wildcard $(call bg_file_path_$(2),$(1),$(2),mak))
bg_bind_rmr_gened = $(if $(call selectLib,$(1)),$(if $(2),$(if $(call bg_bind_any_gened_exists,$(1),$(2)),$(call rmr,$(call bg_file_path_$(2),$(1),$(2),src) $(call bg_file_path_$(2),$(1),$(2),hdr) $(call bg_file_path_$(2),$(1),$(2),mak)),),),)
################################################################################################################################
.PHONY: bgentalk
bgentalk: bindings_build
@$(call echo,"")
@$(call echo, have a great day!)
@$(call echo, -bgen)
.PHONY: list_bindings_name
list_bindings_name:
$(call bg_print_lib_name,1)
$(call bg_print_lib_name,2)
$(call bg_print_lib_name,3)
$(call bg_print_lib_name,4)
$(call bg_print_lib_name,5)
$(call bg_print_lib_name,6)
$(call bg_print_lib_name,7)
$(call bg_print_lib_name,8)
$(call bg_print_lib_name,9)
.PHONY: bindings
bindings: bgentalk
.PHONY: bindingsgen
bindingsgen: bindings_gen
.PHONY: bindings_gen
bindings_gen: c_bindings_gen cpp_bindings_gen py_bindings_gen
.PHONY: bindings_build
bindings_build: c_bindings_build cpp_bindings_build py_bindings_build
.PHONY: bindings_clean
.NOTPARALLEL: bindings_clean
bindings_clean: c_bindings_clean cpp_bindings_clean py_bindings_clean
.PHONY: bindings_cleantarget
.NOTPARALLEL: bindings_cleantarget
bindings_cleantarget: c_bindings_cleantarget cpp_bindings_cleantarget py_bindings_cleantarget
.PHONY: bindings_realclean
.NOTPARALLEL: bindings_realclean
bindings_realclean: c_bindings_realclean cpp_bindings_realclean py_bindings_realclean
.PHONY: bindings_wipeclean
.NOTPARALLEL: bindings_wipeclean
bindings_wipeclean: c_bindings_wipeclean cpp_bindings_wipeclean py_bindings_wipeclean
.PHONY: bindings_distclean
.NOTPARALLEL: bindings_distclean
bindings_distclean:
$(call rmr,$(_bg_dir)/)
# C
################################################################################################################################
.PHONY: c_bindings
c_bindings: c_bindings_build
.PHONY: c_bindings_gen
.NOTPARALLEL: c_bindings_gen
c_bindings_gen: $(if $(ASSUME_BGEN_UNCHANGED),,$(BGEN)) $(BGEN_LIBS) #$(BINARIES)
@$(call echo,Generating C bindings...)
$(call mkdir,$(_bg_dir))
$(call mkdir,$(C_BINDINGS_DIR))
$(if $(BGEN_SKIP),,$(BGEN) -dir $(C_BINDINGS_DIR) $(_bg_args) $(_bg_quiet) -c $(BGEN_LIBS))
.PHONY: c_bindings_build
.NOTPARALLEL: c_bindings_build
c_bindings_build: c_bindings_gen
$(call bg_bind_____echo,1,c)
$(call bg_bind_cd_build,1,c,all)
$(call bg_bind_____echo,2,c)
$(call bg_bind_cd_build,2,c,all)
$(call bg_bind_____echo,3,c)
$(call bg_bind_cd_build,3,c,all)
$(call bg_bind_____echo,4,c)
$(call bg_bind_cd_build,4,c,all)
$(call bg_bind_____echo,5,c)
$(call bg_bind_cd_build,5,c,all)
$(call bg_bind_____echo,6,c)
$(call bg_bind_cd_build,6,c,all)
$(call bg_bind_____echo,7,c)
$(call bg_bind_cd_build,7,c,all)
$(call bg_bind_____echo,8,c)
$(call bg_bind_cd_build,8,c,all)
$(call bg_bind_____echo,9,c)
$(call bg_bind_cd_build,9,c,all)
.PHONY: c_bindings_install
.NOTPARALLEL: c_bindings_install
c_bindings_install:
install $(INSTALL_FLAGS) $(OBJLIBDIR)$(LP)ecere_c$(SOV) $(DESTLIBDIR)/$(LP)ecere_c$(SOV)
install $(INSTALL_FLAGS) $(OBJLIBDIR)$(LP)eC_c$(SOV) $(DESTLIBDIR)/$(LP)eC_c$(SOV)
install $(INSTALL_FLAGS) $(OBJLIBDIR)$(LP)EDA_c$(SOV) $(DESTLIBDIR)/$(LP)EDA_c$(SOV)
ln -sf $(LP)ecere_c$(SOV) $(DESTLIBDIR)/$(LP)ecere_c$(SO).0
ln -sf $(LP)eC_c$(SOV) $(DESTLIBDIR)/$(LP)eC_c$(SO).0
ln -sf $(LP)EDA_c$(SOV) $(DESTLIBDIR)/ec/$(LP)EDA_c$(SO).0
.PHONY: c_bindings_clean
.NOTPARALLEL: c_bindings_clean
c_bindings_clean:
$(call bg_bind_cd_build,1,c,clean)
$(call bg_bind_cd_build,2,c,clean)
$(call bg_bind_cd_build,3,c,clean)
$(call bg_bind_cd_build,4,c,clean)
$(call bg_bind_cd_build,5,c,clean)
$(call bg_bind_cd_build,6,c,clean)
$(call bg_bind_cd_build,7,c,clean)
$(call bg_bind_cd_build,8,c,clean)
$(call bg_bind_cd_build,9,c,clean)
$(call rmr,$(_BGEN_C_OUTPUT))
.PHONY: c_bindings_cleantarget
.NOTPARALLEL: c_bindings_cleantarget
c_bindings_cleantarget:
$(call bg_bind_cd_build,1,c,cleantarget)
$(call bg_bind_cd_build,2,c,cleantarget)
$(call bg_bind_cd_build,3,c,cleantarget)
$(call bg_bind_cd_build,4,c,cleantarget)
$(call bg_bind_cd_build,5,c,cleantarget)
$(call bg_bind_cd_build,6,c,cleantarget)
$(call bg_bind_cd_build,7,c,cleantarget)
$(call bg_bind_cd_build,8,c,cleantarget)
$(call bg_bind_cd_build,9,c,cleantarget)
.PHONY: c_bindings_realclean
.NOTPARALLEL: c_bindings_realclean
c_bindings_realclean:
$(call rmr,$(C_BINDINGS_DIR)/obj)
$(call bg_bind_rmr_gened,1,c)
$(call bg_bind_rmr_gened,2,c)
$(call bg_bind_rmr_gened,3,c)
$(call bg_bind_rmr_gened,4,c)
$(call bg_bind_rmr_gened,5,c)
$(call bg_bind_rmr_gened,6,c)
$(call bg_bind_rmr_gened,7,c)
$(call bg_bind_rmr_gened,8,c)
$(call bg_bind_rmr_gened,9,c)
.PHONY: c_bindings_wipeclean
c_bindings_wipeclean:
$(call rmr,$(C_BINDINGS_DIR))
$(call bg_bind_rmr_gened,1,c)
$(call bg_bind_rmr_gened,2,c)
$(call bg_bind_rmr_gened,3,c)
$(call bg_bind_rmr_gened,4,c)
$(call bg_bind_rmr_gened,5,c)
$(call bg_bind_rmr_gened,6,c)
$(call bg_bind_rmr_gened,7,c)
$(call bg_bind_rmr_gened,8,c)
$(call bg_bind_rmr_gened,9,c)
# C++
################################################################################################################################
.PHONY: cpp_bindings
.NOTPARALLEL: cpp_bindings
cpp_bindings: cpp_bindings_build
.PHONY: cpp_bindings_gen
.NOTPARALLEL: cpp_bindings_gen
cpp_bindings_gen: $(BINARIES)
@$(call echo,Generating C++ bindings...)
$(call mkdir,$(_bg_dir))
$(call mkdir,$(CPP_BINDINGS_DIR))
$(if $(BGEN_SKIP),,$(BGEN) -dir $(CPP_BINDINGS_DIR) $(_bg_args) $(_bg_quiet) -cpp $(_bg_bypass_cpp) $(BGEN_LIBS))
.PHONY: cpp_bindings_build
.NOTPARALLEL: cpp_bindings_build
cpp_bindings_build: cpp_bindings_gen
$(call bg_bind_____echo,1,cpp)
$(call bg_bind_cd_build,1,cpp,all)
$(call bg_bind_____echo,2,cpp)
$(call bg_bind_cd_build,2,cpp,all)
$(call bg_bind_____echo,3,cpp)
$(call bg_bind_cd_build,3,cpp,all)
$(call bg_bind_____echo,4,cpp)
$(call bg_bind_cd_build,4,cpp,all)
$(call bg_bind_____echo,5,cpp)
$(call bg_bind_cd_build,5,cpp,all)
$(call bg_bind_____echo,6,cpp)
$(call bg_bind_cd_build,6,cpp,all)
$(call bg_bind_____echo,7,cpp)
$(call bg_bind_cd_build,7,cpp,all)
$(call bg_bind_____echo,8,cpp)
$(call bg_bind_cd_build,8,cpp,all)
$(call bg_bind_____echo,9,cpp)
$(call bg_bind_cd_build,9,cpp,all)
.PHONY: cpp_bindings_clean
.NOTPARALLEL: cpp_bindings_clean
cpp_bindings_clean:
$(call bg_bind_cd_build,1,cpp,clean)
$(call bg_bind_cd_build,2,cpp,clean)
$(call bg_bind_cd_build,3,cpp,clean)
$(call bg_bind_cd_build,4,cpp,clean)
$(call bg_bind_cd_build,5,cpp,clean)
$(call bg_bind_cd_build,6,cpp,clean)
$(call bg_bind_cd_build,7,cpp,clean)
$(call bg_bind_cd_build,8,cpp,clean)
$(call bg_bind_cd_build,9,cpp,clean)
$(call rmr,$(_BGEN_CPP_OUTPUT))
.PHONY: cpp_bindings_cleantarget
.NOTPARALLEL: cpp_bindings_cleantarget
cpp_bindings_cleantarget:
$(call bg_bind_cd_build,1,cpp,cleantarget)
$(call bg_bind_cd_build,2,cpp,cleantarget)
$(call bg_bind_cd_build,3,cpp,cleantarget)
$(call bg_bind_cd_build,4,cpp,cleantarget)
$(call bg_bind_cd_build,5,cpp,cleantarget)
$(call bg_bind_cd_build,6,cpp,cleantarget)
$(call bg_bind_cd_build,7,cpp,cleantarget)
$(call bg_bind_cd_build,8,cpp,cleantarget)
$(call bg_bind_cd_build,9,cpp,cleantarget)
.PHONY: cpp_bindings_realclean
.NOTPARALLEL: cpp_bindings_realclean
cpp_bindings_realclean:
$(call rmr,$(CPP_BINDINGS_DIR)/obj)
$(call bg_bind_rmr_gened,1,cpp)
$(call bg_bind_rmr_gened,2,cpp)
$(call bg_bind_rmr_gened,3,cpp)
$(call bg_bind_rmr_gened,4,cpp)
$(call bg_bind_rmr_gened,5,cpp)
$(call bg_bind_rmr_gened,6,cpp)
$(call bg_bind_rmr_gened,7,cpp)
$(call bg_bind_rmr_gened,8,cpp)
$(call bg_bind_rmr_gened,9,cpp)
.PHONY: cpp_bindings_wipeclean
.NOTPARALLEL: cpp_bindings_wipeclean
cpp_bindings_wipeclean:
$(call rmr,$(CPP_BINDINGS_DIR))
$(call bg_bind_rmr_gened,1,cpp)
$(call bg_bind_rmr_gened,2,cpp)
$(call bg_bind_rmr_gened,3,cpp)
$(call bg_bind_rmr_gened,4,cpp)
$(call bg_bind_rmr_gened,5,cpp)
$(call bg_bind_rmr_gened,6,cpp)
$(call bg_bind_rmr_gened,7,cpp)
$(call bg_bind_rmr_gened,8,cpp)
$(call bg_bind_rmr_gened,9,cpp)
# Python
################################################################################################################################
.PHONY: py_bindings
.NOTPARALLEL: py_bindings
py_bindings: py_bindings_build
.PHONY: py_bindings_gen
.NOTPARALLEL: py_bindings_gen
py_bindings_gen: $(BINARIES)
@$(call echo,Generating Python bindings...)
$(call mkdir,$(_bg_dir))
$(call mkdir,$(PY_BINDINGS_DIR))
$(if $(BGEN_SKIP),,$(BGEN) -dir $(PY_BINDINGS_DIR) $(_bg_args) $(_bg_quiet) -py $(BGEN_LIBS))
OBJLIBDIR := $(OBJDIR)$(PLATFORM)$(COMPILER_SUFFIX)$(DEBUG_SUFFIX)/lib/
.PHONY: py_bindings_build
.NOTPARALLEL: py_bindings_build
py_bindings_build: c_bindings_build py_bindings_gen
$(if $(wildcard $(ADDITIONAL_BGEN_LIBS)),$(call cp,$(wildcard $(ADDITIONAL_BGEN_LIBS)),$(OBJLIBDIR)),)
ifdef PY_NA
$(error Using $(PYTHON) failed. Please set PYTHON to point to a valid python program name or location)
else
$(call bg_bind_____echo,1,py)
$(call bg_bind_cd_build,1,py)
$(call bg_bind_____echo,2,py)
$(call bg_bind_cd_build,2,py)
$(call bg_bind_____echo,3,py)
$(call bg_bind_cd_build,3,py)
$(call bg_bind_____echo,4,py)
$(call bg_bind_cd_build,4,py)
$(call bg_bind_____echo,5,py)
$(call bg_bind_cd_build,5,py)
$(call bg_bind_____echo,6,py)
$(call bg_bind_cd_build,6,py)
$(call bg_bind_____echo,7,py)
$(call bg_bind_cd_build,7,py)
$(call bg_bind_____echo,8,py)
$(call bg_bind_cd_build,8,py)
$(call bg_bind_____echo,9,py)
$(call bg_bind_cd_build,9,py)
endif
.PHONY: py_bindings_clean
.NOTPARALLEL: py_bindings_clean
py_bindings_clean:
$(call rmr,$(_BGEN_PY_OUTPUT))
.PHONY: py_bindings_cleantarget
.NOTPARALLEL: py_bindings_cleantarget
py_bindings_cleantarget:
# @$(call echo,todo: py_bindings_cleantarget)
.PHONY: py_bindings_realclean
.NOTPARALLEL: py_bindings_realclean
py_bindings_realclean:
$(call rmr,$(PY_BINDINGS_DIR)/obj)
$(call rmr,$(PY_BINDINGS_DIR)/__pycache__)
# @$(call echo,todo: py_bindings_realclean -- _py*.c _py*.pyd)
.PHONY: py_bindings_wipeclean
.NOTPARALLEL: py_bindings_wipeclean
py_bindings_wipeclean:
$(call rmr,$(PY_BINDINGS_DIR))
# why is this MAKEFILE_LIST empty recipe causing warnings? :/
#$(MAKEFILE_LIST): ;
#$(SOURCES): ;
#$(RESOURCES): ;