-
Notifications
You must be signed in to change notification settings - Fork 0
/
core.mk
1913 lines (1549 loc) · 63.6 KB
/
core.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
# include once
ifndef CORE_MK
#######
####### helpful variables
#######
comma := ,
empty :=
space := $(empty) $(empty)
#######
####### Set up TOP_BUILD_DIR, TOP_BUILD_DIR_ABS and BUILDSYSTEM variables
#######
ifndef MAKEFILE_LIST
# Work-around for GNU make pre-3.80, which lacks MAKEFILE_LIST and $(eval ...)
TOP_BUILD_DIR := $(shell perl -e 'for ($$_ = "$(CURDIR)"; ! -d "$$_/build-system"; s!(.*)/(.*)!\1!) { $$q .= "../"; } chop $$q; print "$$q"')
ifeq ($(TOP_BUILD_DIR),)
TOP_BUILD_DIR=.
endif
export TOP_BUILD_DIR_ABS := $(shell perl -e 'for ($$_ = "$(CURDIR)"; ! -d "$$_/build-system"; s!(.*)/(.*)!\1!) { } print')
export BUILDSYSTEM := $(TOP_BUILD_DIR_ABS)/build-system
else
# Normal operation for GNU make 3.80 and above
__pop = $(patsubst %/,%,$(dir $(1)))
__tmp := $(call __pop,$(word $(words $(MAKEFILE_LIST)),$(MAKEFILE_LIST)))
# Special case for build-system/Makefile
ifeq ($(__tmp),.)
__tmp := ../$(notdir $(CURDIR))
endif
ifndef TOP_BUILD_DIR
TOP_BUILD_DIR := $(call __pop,$(__tmp))
endif
ifndef TOP_BUILD_DIR_ABS
TOP_BUILD_DIR_ABS := $(CURDIR)
ifneq ($(TOP_BUILD_DIR),.)
$(foreach ,$(subst /, ,$(TOP_BUILD_DIR)),$(eval TOP_BUILD_DIR_ABS := $(call __pop,$(TOP_BUILD_DIR_ABS))))
endif
export TOP_BUILD_DIR_ABS
endif
ifndef BUILDSYSTEM
export BUILDSYSTEM := $(TOP_BUILD_DIR_ABS)/$(notdir $(__tmp))
endif
endif
#######
####### Config:
#######
include $(BUILDSYSTEM)/constants.mk
#
# All available hardware:
#
HARDWARE_ALL = $(strip $(foreach hw, $(filter HARDWARE_%, \
$(filter-out HARDWARE_ALL \
HARDWARE_NAMES, \
$(.VARIABLES))), $($(hw))))
HARDWARE_NAMES = $(filter-out $(HARDWARE_NOARCH), $(HARDWARE_ALL))
#
# All available toolchains:
#
TOOLCHAIN_ALL = $(strip $(foreach t, $(filter TOOLCHAIN_%, \
$(filter-out TOOLCHAIN_ALL \
TOOLCHAIN_NAMES \
TOOLCHAIN_DIR \
TOOLCHAIN_PATH \
TOOLCHAIN_VERSION, \
$(.VARIABLES))), $($(t))))
TOOLCHAIN_NAMES = $(TOOLCHAIN_ALL)
COMPONENT_TOOLCHAINS = $(TOOLCHAIN_ALL)
#######
####### Config:
#######
ifneq ($(wildcard $(BUILDSYSTEM)/build-config.mk),)
include $(BUILDSYSTEM)/build-config.mk
else
include $(BUILDSYSTEM)/build-config.mk.template
endif
# Reading build-config.mk:
# ENABLE_NOARCH & ENABLE_BUILD always enabled:
ENABLE_NOARCH = true
ENABLE_BUILD = true
enabled = $(filter ENABLE_%, $(filter-out ENABLE_ARCH ENABLE_TARGETS, $(.VARIABLES)))
hardware_filter = $(strip $(foreach t, \
$(strip $(foreach b, \
$(enabled), $(if $(filter true, $($(b))), \
$(subst ENABLE_, HARDWARE_, $(b))))), $($(t))))
# If no HARDWARE set
ifeq ($(HARDWARE),)
# COMPONENT_TARGETS must have a value specified in the Makefile
ifeq ($(COMPONENT_TARGETS),)
$(error Error: COMPONENT_TARGETS must have a value)
endif
# End if no HARDWARE set
endif
#######
####### Filter out disabled targets
#######
COMPONENT_TARGETS := $(filter $(hardware_filter), $(COMPONENT_TARGETS))
# Remove duplicates:
COMPONENT_TARGETS := $(sort $(COMPONENT_TARGETS))
#######
####### Filter out disabled toolchains:
#######
COMPONENT_TOOLCHAINS := $(strip \
$(foreach toolchain, $(COMPONENT_TOOLCHAINS), \
$(if $(filter $($(shell echo $(toolchain) | tr '[a-z-]' '[A-Z_]')_HARDWARE_VARIANTS), \
$(COMPONENT_TARGETS)),$(toolchain),)))
COMPONENT_TOOLCHAINS := $(sort $(COMPONENT_TOOLCHAINS))
# Error if TOOLCHAIN is invalid
ifneq ($(TOOLCHAIN),)
ifeq ($(filter $(TOOLCHAIN), $(COMPONENT_TOOLCHAINS)),)
$(error Error: TOOLCHAIN=$(TOOLCHAIN) is invalid for selected COMPONENT_TARGETS in Makefile)
endif
endif
# Error if HARDWARE is invalid
ifneq ($(HARDWARE),)
ifeq ($(filter $(HARDWARE), $(COMPONENT_TARGETS)),)
$(error Error: HARDWARE=$(HARDWARE) is invalid for selected COMPONENT_TARGETS in Makefile)
endif
endif
################################################################
#######
####### Directories setup Section:
#######
#
# Set up SOURCE PACKAGE directory:
#
export SRC_PACKAGE_DIR := sources
export SRC_PACKAGE_PATH := $(TOP_BUILD_DIR)/$(SRC_PACKAGE_DIR)
export SRC_PACKAGE_PATH_ABS := $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)
#
# Set up DESTINATION directories:
#
DEST_DIR_ABS = $(TOP_BUILD_DIR_ABS)/dist
ifeq ($(NEED_ABS_PATH),)
DEST_DIR = $(TOP_BUILD_DIR)/dist
else
DEST_DIR = $(DEST_DIR_ABS)
endif
#
# Default PREFIX: is $(TOP_BUILD_DIR)/dist
#
PREFIX ?= $(DEST_DIR)
#
# Install DIRs (for SCRIPT_, BIN_, ... TARGETS) [should be always ABS]:
#
TARGET_DEST_DIR = $(DEST_DIR_ABS)/$(addprefix ., $(TOOLCHAIN))/$(HARDWARE)
PRODUCTS_DEST_DIR = $(DEST_DIR_ABS)/products/$(TOOLCHAIN)/$(HARDWARE)
ROOTFS_DEST_DIR = $(DEST_DIR_ABS)/rootfs/$(TOOLCHAIN)/$(HARDWARE)
#######
####### End of Directories setup Section.
#######
################################################################
################################################################
#######
####### Targets setup Section:
#######
ifdef TARGET_SETUP_MK
$(error Error: 'target-setup.mk' should not be included directly, include 'constants.mk' instead.)
endif
include $(BUILDSYSTEM)/target-setup.mk
#######
####### End of Targets setup Section.
#######
################################################################
################################################################
# Get toolchain by HARDWARE function:
#
# toolchain()
#
toolchain = $($(strip \
$(foreach v, $(filter %_HARDWARE_VARIANTS, $(.VARIABLES)), \
$(if $(filter $1, $($(v))), \
$(addprefix TOOLCHAIN_,$(subst _HARDWARE_VARIANTS,,$(v))), \
))))
# usage:
# pc32_toolchain = $(call toolchain,$(HARDWARE_PC32))
#
# Get toolchain by HARDWARE function.
################################################################
################################################################
# Check the list of available targets for current Makefile
#
__available_targets = \
$(foreach arch, $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'), \
$(foreach hardware, $($(shell echo ${arch} | tr '[a-z-]' '[A-Z_]')_HARDWARE_VARIANTS), \
$(if $(filter $(hardware),$(COMPONENT_TARGETS)), \
$(if $($(shell echo $(hardware) | tr '[a-z]' '[A-Z]')_FLAVOURS), \
$(foreach flavour, $($(shell echo $(hardware) | tr '[a-z]' '[A-Z]')_FLAVOURS), \
.target_$(arch)_$(hardware)_$(flavour) \
) .target_$(arch)_$(hardware), \
$(if $(FLAVOURS), \
$(foreach flavour, $(FLAVOURS), \
.target_$(arch)_$(hardware)_$(flavour) \
) .target_$(arch)_$(hardware), \
.target_$(arch)_$(hardware) \
) \
), \
) \
) \
)
__available_targets := $(strip $(__available_targets))
__available_targets := $(sort $(__available_targets))
#
#
################################################################
#######
####### Silent make:
#######
#ifeq ($(VERBOSE),)
#ifeq ($(COMPONENT_IS_3PP),)
#MAKEFLAGS += -s
#endif
#endif
#
#ifeq ($(VERBOSE),)
#guiet = @
#else
#quiet =
#endif
#######
####### Number of CPU cores:
#######
NUMPROCS := 1
OS := $(shell uname -s)
ifeq ($(OS),Linux)
NUMPROCS := $(shell grep -c ^processor /proc/cpuinfo)
endif
#######
####### Parallel control:
#######
ifneq ($(NOT_PARALLEL),)
MAKEFLAGS += -j1
.NOTPARALLEL:
endif
#######
####### Global Cleanup List may be start here with += assign symbol:
#######
####### CLEANUP_FILES += ...
#######
####### IMPORTANT NOTE:
####### ==============
####### Do not add directories such as .$(TOOLCHAIN), $(TARGET_BUILD_DIR), $(HARDWARE), etc.
#######
all: BUILD_TREE := true
export BUILD_TREE
all:
@$(MAKE) local_all
clean: CLEAN_TREE := true
export CLEAN_TREE
clean:
@$(MAKE) local_clean
dist_clean: DIST_CLEAN_TREE := true
export DIST_CLEAN_TREE
dist_clean:
@$(MAKE) local_dist_clean
rootfs_clean: ROOTFS_CLEAN_TREE := true
export ROOTFS_CLEAN_TREE
rootfs_clean:
@$(MAKE) local_rootfs_clean
# MAKE goals which not depended from Makefile
__quick_targets := help ccache_stats configure_targets local_clean global_clean downloads_clean build-config.mk $(HACK_TARGETS)
################################################################
#######
####### Build preparations & HW Independed GOALs Section:
#######
#
# GLOBAL setup targets:
# ====================
# These targets are built before all targets. For example, source tarballs
# have to be downloaded before starting the build.
#
# NOTE:
# BUILDSYSTEM is a setup target for other directories and the BUILDSYSTEM
# requires only '.sources' target as a setup target.
#
ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
ifeq ($(shell pwd),$(BUILDSYSTEM))
__setup_targets = .sources
else
__setup_targets = .sources .build_system
endif
endif
.setup:
ifeq ($(__final__),)
.setup: $(__setup_targets)
else
.setup: .makefile
endif
#######
####### If Makefile has been changed we cannot warranty that this is afected only
####### one HW target from the list of targets prepared by this local Makefile.
#######
####### So, in this case we have to clean up all built targets.
#######
# Check if Makefile has been changed:
.makefile: Makefile
ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
ifneq ($(if $(MAKECMDGOALS),$(filter-out $(__quick_targets),$(MAKECMDGOALS)),true),)
@touch $@
ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
@echo ""
@echo -e "#######"
@echo -e "####### New makefile ($(<F)), clean up & rebuild source requires!"
@echo -e "#######"
@echo ""
@$(MAKE) local_dist_clean
@if $(MAKE) local_clean; then true; else rm -f $@; fi
else
@if $(MAKE) download_clean; then true; else rm -f $@; fi
endif
endif
endif
#######
####### Build directory dependencies into .src_requires which
####### is used as a Makefile for srource tarballs downloading
#######
#######
####### NOTE:
####### ====
####### Source tarballs are downloaded once for whole dependencies tree
####### of the current directory where we make the build using command
####### such as 'make' or 'make local_all'.
####### Target local_all is not affects the downloading sources for the
####### whole dependencies tree (target local_all affects the building
####### of packages only).
####### In this case the $(__final__) variable is not defined.
####### On the contrary when the BUILDSYSTEM builds each packages of
####### dependencies tree the $(__final__) variable is defined and
####### we don't try to download sources because they already downloaded.
####### More over we don't need to have the '.src_requires' and
####### '.src_requires_depend' files.
#######
####### Such behavior is invented aspecialy to avoid competition in case
####### when during parallel build different processes can run the same
####### Makefile and all of them can start the sources preparation.
#######
.sources: .src_requires
.src_requires_depend: .src_requires ;
.src_requires: .makefile
ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
ifeq ($(filter %_clean,$(MAKECMDGOALS)),)
ifeq ($(__final__),)
@echo ""
@echo -e "################################################################"
@echo -e "#######"
@echo -e "####### Start of building source requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))':"
@echo -e "#######"
@$(BUILDSYSTEM)/build_src_requires $(TOP_BUILD_DIR_ABS)
@__final__= TREE_RULE=local_all $(MAKE) TOOLCHAIN=$(TOOLCHAIN_NOARCH) HARDWARE=$(HARDWARE_NOARCH) FLAVOUR= -f .src_requires
@echo -e "#######"
@echo -e "####### End of building source requires for '$(subst $(TOP_BUILD_DIR_ABS)/,,$(CURDIR))'."
@echo -e "#######"
@echo -e "################################################################"
@echo ""
@touch $@
@touch .src_requires_depend
endif
endif
endif
.build_system: .src_requires
ifneq ($(shell pwd),$(TOP_BUILD_DIR_ABS))
ifeq ($(shell pwd | grep $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR))$(shell pwd | grep $(BUILDSYSTEM)/3pp/sources),)
ifeq ($(shell pwd | grep $(BUILDSYSTEM)),)
@echo -e "################################################################"
@echo -e "#######"
@echo -e "####### Start to Check the BUILDSYSTEM is ready:"
@echo -e "#######"
@( cd $(BUILDSYSTEM) ; __final__= $(MAKE) TOOLCHAIN=$(TOOLCHAIN_BUILD_MACHINE) HARDWARE=$(HARDWARE_BUILD) FLAVOUR= all )
@echo -e "#######"
@echo -e "####### End of checking the BUILDSYSTEM."
@echo -e "#######"
@echo -e "################################################################"
endif
endif
endif
#######
####### Clean the whole source tree
#######
global_clean: .global_clean
.global_clean:
@echo ""
@echo -e "#######"
@echo -e "####### Cleaning the whole sources tree excluding downloaded sources..."
@echo -e "#######"
@$(BUILDSYSTEM)/global_clean $(addprefix ., $(TOOLCHAIN_NAMES)) $(TOP_BUILD_DIR_ABS)
#######
####### Clean all downloaded source tarballs
#######
downloads_clean: .downloads_clean
.downloads_clean:
@echo ""
@echo -e "#######"
@echo -e "####### Cleaning Up all downloaded sources..."
@echo -e "#######"
@$(BUILDSYSTEM)/downloads_clean $(addprefix ., $(TOOLCHAIN_NOARCH)) $(BUILDSYSTEM)/3pp/sources
ifneq ($(wildcard $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)),)
@$(BUILDSYSTEM)/downloads_clean $(addprefix ., $(TOOLCHAIN_NOARCH)) $(TOP_BUILD_DIR_ABS)/$(SRC_PACKAGE_DIR)
endif
help:
@echo ""
@echo -e "Build System $(SYSTEM_VERSION)"
@echo ""
@echo -e "You can build and install software using command line such as follow:"
@echo ""
@echo -e " $$ [TOOLCHAIN=toolchain] [HARDWARE=hardware] [FLAVOUR=flavour] make [goal]"
@echo ""
@echo -e "The following MAKE goals are available:"
@echo ""
@echo -e " all - perform make build and install software in the all"
@echo -e " required directories which defined by REQUIRES"
@echo -e " variable in the local Makefile;"
@echo -e " local_all - build and install software prepared onlu by local"
@echo -e " Makefile;"
@echo -e " dist_clean,"
@echo -e " local_dist_clean - remove distribution packages from target directory"
@echo -e " defined by PRODUCTS_DEST_DIR variable. Note that"
@echo -e " is depends from targets defined by COMPONENT_TARGETS"
@echo -e " variable or command line;"
@echo -e " rootfs_clean,"
@echo -e " local_rootfs_clean - uninstall packages installed into target 'root file"
@echo -e " system' directory which defined by ROOTFS_DEST_DIR"
@echo -e " variable;"
@echo -e " clean,"
@echo -e " local_clean - clean up all built targets by this Makefile;"
@echo ""
@echo -e " If the one from above goals has prefix 'local_' then this goal affects only"
@echo -e " current directory. Otherwise this goal will be performed for all required"
@echo -e " directories which defined by REQUIRES variable."
@echo ""
@echo -e " configure_targets - select hardwares, for which the software will be built."
@echo -e " This command edits the build-config.mk file;"
@echo ""
@echo -e " requires_tree - create HTML file to show the requires tree for current"
@echo -e " directory. Note that this goal depends on goal all;"
@echo -e " packages_list - create HW.pkglist file which contains the list of packages"
@echo -e " in install order. Note that this goal depends on goal all;"
@echo -e " devices_table - create Devices Table for rootfs image creation procedure;"
@echo -e " ext4fs_image - create Ext4 Root FS for target Boot Image;"
@echo -e " products_release - install files into products directory for release;"
@echo ""
@echo -e " global_clean - clean up whole sourses tree excluding downloaded"
@echo -e " source tarballs;"
@echo -e " downloads_clean - remove all sourse tarball from 'sourses' directory;"
@echo ""
@echo -e " ccache_stats - show the ccache statistic."
@echo ""
@echo -e "Local Makefile is prepared for following target HW platforms:"
@echo ""
@for platform in $(COMPONENT_TARGETS) ; do \
echo -e " $$platform"; \
done
@echo ""
@echo -e "Enjoy."
@echo ""
ccache_stats:
ifeq ($(NO_CCACHE),)
@echo ""
@echo -e "CCACHE statistic:"
@echo ""
@CCACHE_DIR=$(CACHED_CC_OUTPUT) $(CCACHE) -s
@echo ""
@echo -e "To set max cache size make use the following command"
@echo ""
@echo -e " $$ CCACHE_DIR=$(CACHED_CC_OUTPUT) $(CCACHE)-M 64G"
@echo ""
@echo -e "see CCACHE(1) for more information."
@echo ""
else
@echo ""
@echo -e "CCACHE disabled by setting 'NO_CCACHE=$(NO_CCACHE)' variable for this Makefile."
@echo ""
endif
configure_targets: $(BUILDSYSTEM)/build-config.mk
@BUILDSYSTEM=$(BUILDSYSTEM) \
CONFIG=$(BUILDSYSTEM)/build-config.mk \
CONSTANTS=$(BUILDSYSTEM)/constants.mk \
$(BUILDSYSTEM)/configure-targets
#######
####### End of Build preparations & HW Independed GOALs Section.
#######
################################################################
################################################################
#######
####### Source archive and patch handling:
#######
# Patch dependency:
PATCHES_DEP = $(foreach patch,$(PATCHES),\
$(shell $(BUILDSYSTEM)/apply_patches $(patch) -dep-))
SRC_DIR_BASE = $(dir $(SRC_DIR))
# Unpack SRC_ARCHIVE in SRC_DIR and backup old SRC_DIR:
UNPACK_SRC_ARCHIVE = \
@echo "Expanding $(SRC_ARCHIVE)"; \
if [ -d $(SRC_DIR) ]; then mv $(SRC_DIR) $$(mktemp -d $(SRC_DIR).bak.XXXXXX); fi; \
mkdir -p $(SRC_DIR_BASE); \
$(if $(findstring .rpm,$(SRC_ARCHIVE)), \
cd $(SRC_DIR_BASE) && rpm2cpio $(SRC_ARCHIVE) | cpio -id --quiet, \
$(if $(findstring .zip,$(SRC_ARCHIVE)), \
unzip -q -d $(SRC_DIR_BASE) $(SRC_ARCHIVE), \
tar $(if $(findstring .bz2,$(SRC_ARCHIVE)),-xjf, \
$(if $(findstring .xz,$(SRC_ARCHIVE)),-xJf, \
$(if $(findstring .txz,$(SRC_ARCHIVE)),-xJf,-xzf))) \
$(SRC_ARCHIVE) -C $(SRC_DIR_BASE))); \
chmod -R u+w $(SRC_DIR)
# Apply patches in PATCHES on SRC_DIR_BASE:
APPLY_PATCHES = $(quiet)$(foreach patch,$(PATCHES),\
$(BUILDSYSTEM)/apply_patches $(patch) $(SRC_DIR_BASE) &&) true
# Apply patches in PATCHES on BASE of directory defined as argument:
apply-patches = $(quiet)$(foreach patch,$(PATCHES),\
$(BUILDSYSTEM)/apply_patches $(patch) $(dir $1) &&) true
# Apply patches in OPT_PATCHES on SRC_DIR_BASE:
APPLY_OPT_PATCHES = $(quiet)$(foreach patch,$(OPT_PATCHES),\
$(BUILDSYSTEM)/apply_patches $(patch) $(SRC_DIR_BASE) &&) true
# Apply patches in OPT_PATCHES on BASE of directory defined as argument:
apply-opt-patches = $(quiet)$(foreach patch,$(OPT_PATCHES),\
$(BUILDSYSTEM)/apply_patches $(patch) $(dir $1) &&) true
################################################################
# Functions:
# =========
#
# Install package content into the current development environment:
# ----------------------------------------------------------------
#
# NOTE:
# - When we pass ARGS through STDIN [using '--' as end of options] we splits ARGS
# by new-line '\n' symbol.
# - When we pass ARGS in the command line, we have to add | tr '\n' ' ' | filter
# to change new-line with space.
#
install-into-devenv = \
@( cd $1 ; \
find . \( -type d -empty -o -type f -o -type l \) -printf '%P\n' | sed -e 's, ,\\040,g' | \
DO_CREATE_DIST_FILES=1 CWD=$(CURDIR) \
$(BUILDSYSTEM)/install_targets \
--preserve-source-dir=true \
--destination=$(TARGET_DEST_DIR) \
--toolchain=$(TOOLCHAIN) \
--hardware=$(HARDWARE) \
--flavour=$(FLAVOUR) \
-- \
)
# usage:
# $(call install-into-devenv,$(PKGDIR))
# where PKGDIR - is a directory where package installed from sources.
# ----------------------------------------------------------------
#
# Pull and Push variables into Perl Storable Hash saved in the
# $(BUILDSYSTEM)/var/tmp directory. These functions also prints
# echo to stdout stream:
# ----------------------------------------------------------------
push-env = $(shell $(BUILDSYSTEM)/transmitting_hash \
--set --hardware=$(HARDWARE) --flavour=$(FLAVOUR) \
--pool-name=$(strip $1) --name=$(strip $2) --value=$(strip $3))
pull-env = $(shell $(BUILDSYSTEM)/transmitting_hash \
--get --hardware=$(HARDWARE) --flavour=$(FLAVOUR) \
--pool-name=$(strip $1) --name=$(strip $2) --value=$(strip $3))
push-env-vo = $(shell $(BUILDSYSTEM)/transmitting_hash \
--set --value-only --hardware=$(HARDWARE) --flavour=$(FLAVOUR) \
--pool-name=$(strip $1) --name=$(strip $2) --value=$(strip $3))
pull-env-vo = $(shell $(BUILDSYSTEM)/transmitting_hash \
--get --value-only --hardware=$(HARDWARE) --flavour=$(FLAVOUR) \
--pool-name=$(strip $1) --name=$(strip $2) --value=$(strip $3))
#
# usage:
# -----
# environment = $(call push-env, perl, HOME, \'/home/kx\')
# environment += $(call push-env, perl, DIR, \'$(CURDIR)\')
# environment += $(call push-env, perl, BASH, \'/bin/bash\')
# environment += --set $(call push-env, perl, archlib, \'/usr/lib$(LIBSUFFIX)/perl5/$(ARCHNAME)\')
#
# environment = HOME=$(call pull-env-vo, perl, HOME, \'/home/olga\')
# environment += DIR=$(call pull-env-vo, perl, DIR, \'$(CURDIR)\')
# environment += BASH=$(call pull-env-vo, perl, BASH, \'/bin/sh\')
# environment += --set archlib=$(call pull-env-vo, perl, archlib, \'/usr/lib$(LIBSUFFIX)/perl5/$(ARCHNAME)\')
# ----------------------------------------------------------------
#
# End of Functions.
################################################################
################################################################
#
# Example rule:
#
# src_done = $(SRC_DIR)/.source-done
#
# $(src_done): $(SRC_ARCHIVE) $(PATCHES_DEP)
# $(UNPACK_SRC_ARCHIVE)
# $(APPLY_PATCHES)
# <other stuff that needs to be done to the source,
# should be empty in most cases>
# @touch $@
#
################################################################
#######
####### Source archive and patch handling.
#######
################################################################
################################################################
#######
####### Include files with references to BUILD-SYSTEM scripts:
#######
-include $(BUILDSYSTEM)/pkgtool/.config
-include $(BUILDSYSTEM)/progs/.config
-include $(BUILDSYSTEM)/scripts/.config
-include $(BUILDSYSTEM)/sbin/.config
#######
####### References to BUILD-SYSTEM scripts.
#######
################################################################
################################################################
#
# No '__final__' target selected:
# ==============================
#
# Parse TOOLCHAIN, HARDWARE, FLAVOUR selected in command line
# and build the list of '__final__' targets.
#
ifeq ($(__final__),)
#
# The FLAVOUR can be defined in command line.
# If command line defines empty flavour FLAVOUR= then
# we define that variable is set but has no values.
#
__cmdline_flavour_defined = $(if $(filter FLAVOUR,$(.VARIABLES)),true,false)
ifeq ($(__cmdline_flavour_defined),true)
__cmdline_flavour_value = $(FLAVOUR)
else
__cmdline_flavour_value =
endif
##############################################################
# -----------+----------+---------+-------------------+-----
# TOOLCHAIN | HARDWARE | FLAVOUR | FLAVOUR has VALUE | REF
# -----------+----------+---------+-------------------+-----
# defined | defined | defined | yes | (0)
# defined | defined | defined | no | (1)
# defined | defined | ~ | ~ | (2)
# -----------+----------+---------+-------------------+-----
# defined | ~ | defined | yes | (3)
# defined | ~ | defined | no | (4)
# defined | ~ | ~ | ~ | (5)
# -----------+----------+---------+-------------------+-----
# ~ | defined | defined | yes | (6)
# ~ | defined | defined | no | (7)
# ~ | defined | ~ | ~ | (8)
# -----------+----------+---------+-------------------+-----
# ~ | ~ | defined | yes | (9)
# ~ | ~ | defined | no | (A)
# ~ | ~ | ~ | ~ | (B)
# -----------+----------+---------+-------------------+-----
##############################################################
# we allow only available combinations according to component targets and flavours lists
ifeq ($(TOOLCHAIN),)
ifeq ($(HARDWARE),)
ifeq ($(FLAVOUR),)
ifeq ($(__cmdline_flavour_defined),false)
# (B) ======= loop: T, H, F; =======
__target_args = $(__available_targets)
else
# (A) ======= loop: T, H ; where F=0 =======
__target_args = $(foreach arch, $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'), \
$(foreach hardware, $($(shell echo ${arch} | tr '[a-z-]' '[A-Z_]')_HARDWARE_VARIANTS), \
.target_$(arch)_$(hardware) \
) \
)
endif
else
# (9) ======= loop: T, H ; where F=const =======
__target_args = $(foreach arch, $(shell echo $(COMPONENT_TOOLCHAINS) | sed -e 's/x86_64/x86-64/g'), \
$(foreach hardware, $($(shell echo ${arch} | tr '[a-z-]' '[A-Z_]')_HARDWARE_VARIANTS), \
$(if $(filter $(FLAVOUR), $($(shell echo ${hardware} | tr '[a-z]' '[A-Z]')_FLAVOURS)), \
.target_$(arch)_$(hardware)_$(FLAVOUR), \
$(if $(filter $(FLAVOUR), $(FLAVOURS)), \
.target_$(arch)_$(hardware)_$(FLAVOUR), \
) \
) \
) \
)
endif
else
ifeq ($(FLAVOUR),)
ifeq ($(__cmdline_flavour_defined),false)
# (8) ======= loop: T, , F; where H=const =======
__target_args = $(foreach arch, $(shell echo $(call toolchain,$(HARDWARE)) | sed -e 's/x86_64/x86-64/g'), \
$(if $($(shell echo $(HARDWARE) | tr '[a-z]' '[A-Z]')_FLAVOURS), \
$(foreach flavour, $($(shell echo $(HARDWARE) | tr '[a-z]' '[A-Z]')_FLAVOURS), \
.target_$(arch)_$(HARDWARE)_$(flavour) \
) .target_$(arch)_$(HARDWARE), \
$(if $(FLAVOURS), \
$(foreach flavour, $(FLAVOURS), \
.target_$(arch)_$(HARDWARE)_$(flavour) \
), \
) .target_$(arch)_$(HARDWARE) \
) \
)
else
# (7) ======= loop: T, , ; where H=const, F=0 =======
__target_args = $(foreach arch, $(shell echo $(call toolchain,$(HARDWARE)) | sed -e 's/x86_64/x86-64/g'), \
.target_$(arch)_$(HARDWARE) \
)
endif
else
# (6) ======= loop: T, , ; where H=const, F=const =======
__target_args = $(foreach arch, $(shell echo $(call toolchain,$(HARDWARE)) | sed -e 's/x86_64/x86-64/g'), \
.target_$(arch)_$(HARDWARE)_$(FLAVOUR) \
)
endif
endif
else
ifeq ($(HARDWARE),)
ifeq ($(FLAVOUR),)
ifeq ($(__cmdline_flavour_defined),false)
# (5) ======= loop: , H, F; where T=const =======
__target_args = $(foreach hardware, $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_HARDWARE_VARIANTS), \
$(if $($(shell echo ${hardware} | tr '[a-z]' '[A-Z]')_FLAVOURS), \
$(foreach flavour, $($(shell echo ${hardware} | tr '[a-z]' '[A-Z]')_FLAVOURS), \
.target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(hardware)_$(flavour) \
) .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(hardware), \
$(if $(FLAVOURS), \
$(foreach flavour, $(FLAVOURS), \
.target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(hardware)_$(flavour) \
), \
) \
.target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(hardware) \
) \
)
else
# (4) ======= loop: , H, ; where T=const, F=0 =======
__target_args = $(foreach hardware, $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_HARDWARE_VARIANTS), \
.target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(hardware) \
)
endif
else
# (3) ======= loop: , H, ; where T=const, F=const =======
__target_args = $(foreach hardware, $($(shell echo $(TOOLCHAIN) | tr '[a-z-]' '[A-Z_]')_HARDWARE_VARIANTS), \
.target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(hardware)_$(FLAVOUR) \
)
endif
else
ifeq ($(FLAVOUR),)
ifeq ($(__cmdline_flavour_defined),false)
# (2) ======= loop: , , F; where T=const, H=const =======
__target_args = $(if $($(shell echo $(HARDWARE) | tr '[a-z]' '[A-Z]')_FLAVOURS), \
$(foreach flavour, $($(shell echo $(HARDWARE) | tr '[a-z]' '[A-Z]')_FLAVOURS), \
.target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(HARDWARE)_$(flavour) \
) .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(HARDWARE), \
$(if $(FLAVOURS), \
$(foreach flavour, $(FLAVOURS), \
.target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(HARDWARE)_$(flavour) \
) .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(HARDWARE), \
) .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(HARDWARE) \
)
else
# (1) ======= loop: , , ; T=const, H=const, F=0 =======
__target_args = .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(HARDWARE)
endif
else
# (0) ======= loop: , , ; T=const, H=const, F=const =======
__target_args = .target_$(shell echo $(TOOLCHAIN) | sed -e 's/x86_64/x86-64/g')_$(HARDWARE)_$(FLAVOUR)
endif
endif
endif
__target_args := $(strip $(__target_args))
__targets = $(filter $(__target_args), $(__available_targets))
# Now we have to sort targets for that the main targets should be built before flavours!
__targets := $(sort $(__targets))
ifeq ($(__targets),)
$(error Error: Selected combination [TOOLCHAIN=$(TOOLCHAIN), HARDWARE=$(HARDWARE), FLAVOUR=$(FLAVOUR)] is invalid for this Makefile)
endif
$(__targets): .setup
#
# NOTE:
# ====
# Several FLAVOURS can require the same package, for example, base/pkgtool.
# To avoid concurrency problems we have to diable parallel building for Makefiles
# where there are FLAVOURS.
#
# We have to check both HW specific and general FLAVOURS.
#
all-flavour-values = $(strip $(foreach flname, $(filter FLAVOURS %_FLAVOURS, $(.VARIABLES)), $($(flname))))
ifneq ($(all-flavour-values),)
.NOTPARALLEL: $(__targets)
endif
local_all: GOAL = local_all
local_all: $(__targets)
local_clean: GOAL = local_clean
local_clean: $(__targets)
local_dist_clean: GOAL = local_dist_clean
local_dist_clean: $(__targets)
local_rootfs_clean: GOAL = local_rootfs_clean
local_rootfs_clean: $(__targets)
requires_tree: GOAL = requires_tree
requires_tree: $(__targets)
packages_list: GOAL = packages_list
packages_list: $(__targets)
devices_table: GOAL = devices_table
devices_table: $(__targets)
ext4fs_image: GOAL = ext4fs_image
ext4fs_image: $(__targets)
products_release: GOAL = products_release
products_release: $(__targets)
.target_%: TOOLCHAIN = $(shell echo $(word 2, $(subst _, , $@)) | sed -e 's/x86-64/x86_64/g')
.target_%: HARDWARE = $(if $(filter $(shell echo $(word 3, $(subst _, , $@))),$(HARDWARE_ALL)),$(word 3, $(subst _, , $@)))
.target_%: FLAVOUR = $(if $(word 4, $(subst _, , $@)),$(word 4, $(subst _, , $@)),$(if $(filter $(shell echo $(word 3, $(subst _, , $@))),$(HARDWARE_ALL)),,$(word 3, $(subst _, , $@))))
.target_%:
@echo ""
@echo -e "################################################################"
@echo -e "#######"