-
Notifications
You must be signed in to change notification settings - Fork 175
/
Makefile
4775 lines (3889 loc) · 143 KB
/
Makefile
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
#
# Core Makefile
#
# Copyright (C) 2016-2024 Wu Zhangjin <[email protected]>
#
TOP_DIR := $(CURDIR)
# Disable the implict rules for our Makefile
# ref: https://stackoverflow.com/questions/4122831/disable-make-builtin-rules-and-variables-from-inside-the-make-file
.SUFFIXES:
SUFFIXES :=
%: %,v
%: RCS/%,v
%: RCS/%
%: s.%
%: SCCS/s.%
# Force set default goal
.DEFAULT_GOAL := board
# Phony targets
PHONY :=
comma := ,
empty :=
space := $(empty) $(empty)
USER := $(or $(UNIX_USER),ubuntu)
UID := $(or $(UNIX_UID),1000)
WARN_ON_USER ?= 1
# Check running host
LAB_ENV_ID := /home/$(USER)/Desktop/lab.desktop
ifeq ($(wildcard $(LAB_ENV_ID)),)
ifeq ($(wildcard ../../configs/linux-lab),)
$(error ERR: No Cloud Lab found, please refer to 'Download the lab' part of README.md)
else
$(error ERR: Please not try Linux Lab in local host, but use it with Cloud Lab, please refer to 'Run and login the lab' part of README.md)
endif
endif
# Warning if run as root
ifeq ($(WARN_ON_USER), 1)
# Check running user, must as $(USER)
ifeq ($(TEST_TIMEOUT),)
ifneq ($(shell whoami),$(USER))
$(warning WARN: Please not run as 'root', but as general user: '$(USER)', please try 'sudo -su $(USER)'.)
endif
endif
# Check permission issue, must available to ubuntu
FILE_USER_UID=$(shell stat -c '%U %u' /.git/description)
ifeq ($(firstword $(FILE_USER_UID)),$(USER))
WARN_ON_USER := 0
else
ifeq ($(word 2,$(FILE_USER_UID)),$(UID))
WARN_ON_USER := 0
endif
endif
ifneq ($(WARN_ON_USER),0)
$(warning WARN: Lab should **NOT** belong to 'root', please change their owner in host: 'sudo chown $$USER:$$USER -R /path/to/cloud-lab/{*,.git}')
$(warning WARN: Cancel this warning via: 'export WARN_ON_USER=0')
endif
endif # Warning on user
# Detect system version of docker image
OS := $(shell sed -ne "/CODENAME/s/[^=]*=//gp" /etc/lsb-release)
# Current variables: board, plugin, module
define _uc_init
uc_$1 := $(shell echo $1 | tr a-z A-Z)
endef
define _uc
$(or $(uc_$1),$(eval $(call _uc_init,$1))$(uc_$1))
endef
define _lc_init
lc_$1 := $(shell echo $1 | tr A-Z a-z)
endef
define _lc
$(or $(lc_$1),$(eval $(call _lc_init,$1))$(lc_$1))
endef
define load_config
ifneq ($(wildcard .$1_config),)
$(call _uc,$1)_CONFIG := $(shell cat .$1_config 2>/dev/null)
endif
endef
#$(warning $(call load_config,board))
$(foreach c,board plugin module mpath, $(eval $(call load_config,$c)))
# Verbose logging control
ifeq ($V, 1)
Q :=
S :=
else
Q ?= @
NPD ?= --no-print-directory
S ?= -s $(NPD)
endif
# Board config: B/BOARD persistent, b/board temporarily
BOARD_DEFAULT ?= arm/vexpress-a9
board ?= $(b)
B ?= $(board)
ifeq ($(B),)
ifeq ($(BOARD_CONFIG),)
BOARD := $(BOARD_DEFAULT)
else
BOARD ?= $(BOARD_CONFIG)
endif
else
BOARD := $(B)
endif
# Plugin config: P/PLUGIN persistent, p/plugin temporarily (FIXME: this feature is really required?)
plugin ?= $(p)
P ?= $(plugin)
ifeq ($(P),)
ifeq ($(origin P), command line)
PLUGIN :=
else
ifneq ($(PLUGIN_CONFIG),)
PLUGIN ?= $(PLUGIN_CONFIG)
endif
endif
else
PLUGIN := $(P)
endif
# Core directories
TOOL_DIR := tools
BOARDS_DIR := boards
BOARD_DIR := $(TOP_DIR)/$(BOARDS_DIR)/$(BOARD)
TFTPBOOT := tftpboot
HOME_DIR := /home/$(USER)
GDBINIT_DIR := $(TOP_DIR)/.gdb
TOP_SRC := $(TOP_DIR)/src
TOP_BUILD := $(TOP_DIR)/build
FEATURE_DIR := $(TOP_SRC)/feature/linux
# Search board in basic arch list while board name given without arch specified
ifneq ($(BOARD),)
BASE_ARCHS := arm aarch64 mipsel mips64el ppc i386 x86_64 riscv32 riscv64 csky s390x s390 loongarch64 loongarch alpha parisc sparc
ifeq ($(wildcard $(BOARD_DIR)/Makefile),)
ARCH := $(strip $(firstword $(foreach arch,$(BASE_ARCHS),$(if $(wildcard $(TOP_DIR)/$(BOARDS_DIR)/$(arch)/$(BOARD)),$(arch) ))))
ifneq ($(ARCH),)
override BOARD := $(ARCH)/$(BOARD)
override BOARD_DIR := $(TOP_DIR)/$(BOARDS_DIR)/$(BOARD)
#$(info LOG: Current board is $(BOARD))
else
_ARCH := $(firstword $(subst /,$(space),$(BOARD)))
ifneq ($(filter $(_ARCH),$(BASE_ARCHS)),)
$(error ERR: do you mean the $(_ARCH) boards, please list with 'make list ARCH=$(_ARCH)')
else
MACH := $(notdir $(BOARD))
matched_boards := $(strip $(foreach arch,$(BASE_ARCHS),$(if $(wildcard $(TOP_DIR)/$(BOARDS_DIR)/$(arch)/$(MACH)),$(arch)/$(MACH) )))
ifneq ($(matched_boards),)
$(error ERR: $(BOARD) not exist, do you mean: $(matched_boards), check more with 'make list')
else
$(error ERR: $(BOARD) not exist, check available boards with 'make list')
endif
endif
endif
endif
endif
# Check if it is a plugin
BOARD_PREFIX := $(subst /,,$(dir $(BOARD)))
PLUGIN_DIR := $(TOP_DIR)/$(BOARDS_DIR)/$(BOARD_PREFIX)
PLUGIN_FLAG := $(PLUGIN_DIR)/.plugin
ifeq ($(wildcard $(PLUGIN_FLAG)),)
PLUGIN_DIR :=
else
_PLUGIN ?= 1
endif
# add board directories
BOARD_TOOLCHAIN ?= $(BOARD_DIR)/toolchains
# add a standlaone bsp directory
BSP_DIR ?= $(BOARD_DIR)/bsp
BSP_TOOLCHAIN ?= $(BSP_DIR)/toolchains
BSP_CONFIG := $(BSP_DIR)/configs
BSP_PATCH := $(BSP_DIR)/patch
# Get the machine name for qemu-system-$(XARCH)
MACH ?= $(notdir $(BOARD))
# Prebuilt directories (in standalone prebuilt repo, github.com/tinyclub/prebuilt)
PREBUILT_DIR := $(TOP_DIR)/prebuilt
PREBUILT_TOOLCHAINS := $(PREBUILT_DIR)/toolchains
PREBUILT_BIOS := $(PREBUILT_DIR)/bios
# Core source: remote and local
#QEMU_GIT ?= https://github.com/qemu/qemu.git
#QEMU_GIT ?= https://gitee.com/mirrors/qemu.git
QEMU_GIT ?= https://gitlab.com/qemu-project/qemu.git
_QEMU_GIT := $(QEMU_GIT)
_QEMU_SRC ?= $(if $(QEMU_FORK),$(call _lc,$(QEMU_FORK)-qemu),qemu)
QEMU_SRC ?= $(_QEMU_SRC)
#UBOOT_GIT ?= https://github.com/u-boot/u-boot.git
#UBOOT_GIT ?= https://gitee.com/mirrors/u-boot.git
UBOOT_GIT ?= https://gitlab.com/qemu-project/u-boot.git
_UBOOT_GIT := $(UBOOT_GIT)
_UBOOT_SRC ?= $(if $(UBOOT_FORK),$(call _lc,$(UBOOT_FORK)-uboot),u-boot)
UBOOT_SRC ?= $(_UBOOT_SRC)
#KERNEL_GIT ?= https://github.com/tinyclub/linux-stable.git
# KERNEL_GIT ?= https://mirrors.tuna.tsinghua.edu.cn/git/linux-stable.git
KERNEL_GIT ?= https://gitlab.com/linux-kernel/stable.git
#KERNEL_GIT ?= git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
_KERNEL_GIT := $(KERNEL_GIT)
_KERNEL_SRC ?= $(if $(KERNEL_FORK),$(call _lc,$(KERNEL_FORK)-kernel),linux-stable)
KERNEL_SRC ?= $(_KERNEL_SRC)
# Use faster mirror instead of git://git.buildroot.net/buildroot.git
#ROOT_GIT ?= https://github.com/buildroot/buildroot
ROOT_GIT ?= https://gitee.com/mirrors/buildroot.git
_ROOT_GIT := $(ROOT_GIT)
_ROOT_SRC ?= $(if $(ROOT_FORK),$(call _lc,$(ROOT_FORK)-buildroot),buildroot)
ROOT_SRC ?= $(_ROOT_SRC)
BOARD_MAKEFILE := $(BOARD_DIR)/Makefile
# Common functions
define _stamp
$($(call _uc,$1)_BUILD)/.stamp_$1-$2
endef
## Version specific variable
## GCC = GCC[LINUX_v2.6.12]
##
## GCC = 4.4
## LINUX = v2.6.35
## GCC[LINUX_v2.6.35] = 4.3
##
## A=$(call __v,GCC,LINUX), 4.3
## B=$(call _v,GCC,LINUX), 4.4 if LINUX is not v2.6.35
define ___v
$($1[$2_$($2)$(if $($3),$(comma)$3_$($3))])
endef
define __v
$(if $($3),$(or $(call ___v,$1,$2,$3),$(or $(call ___v,$1,$2),$(call ___v,$1,$3))),$(call ___v,$1,$2))
endef
define _v
$(or $(call __v,$1,$2),$(or $3,$($1)))
endef
define __vsp
ifneq ($(call __v,$1,$2,$3),)
$2_$1 := $(call __v,$1,$2,$3)
endif
endef
define __vsp_override
ifneq ($(call __v,$1,$2,$3),)
override $2_$1 := $(call __v,$1,$2,$3)
endif
endef
define __vs
ifneq ($(call __v,$1,$2,$3),)
$1 := $(call __v,$1,$2,$3)
endif
endef
define __vs_override
ifneq ($(call __v,$1,$2,$3),)
override $1 := $(call __v,$1,$2,$3)
endif
endef
define _vs
$1 := $(call _v,$1,$2)
endef
# Convert version string to version number, support 4 levels version string, like: v2.6.30.5, v4.4.297, we support: v1024.1023.1023.1023
define _v2v_init
vn_$(subst .,,$1) := $(shell echo $1 | tr -d -c '[0-9.]' | awk -F"." '{ printf("%d\n",$$1*1073741824 + $$2*1048576 + $$3*1024 + $$4);}')
endef
define _v2v
$(or $(vn_$(subst .,,$1)),$(eval $(call _v2v_init,$1))$(vn_$(subst .,,$1)))
endef
define _vsif
ifeq ($(shell expr $(call _v2v,$($3)) \$4 $(call _v2v,$(5))),1)
$1 := $2
endif
endef
define _any
$(shell echo $($1) | grep -E -q "^v|^[0-9]" && [ $$(expr $(call _v2v,$($1)) \$2 $(call _v2v,$3)) -eq 1 ] && echo $($1))
endef
define _range
$(shell echo $($1) | grep -E -q "^v|^[0-9]" && [ $$(expr $(call _v2v,$($1)) \>= $(call _v2v,$2)) -eq 1 -a $$(expr $(call _v2v,$($1)) \<= $(call _v2v,$3)) -eq 1 ] && echo $($1))
endef
define _latest_init
latest_$1 := $(shell tmp=$$(mktemp) && wget -v $2 -O $$tmp && echo $$(grep -A1 "scrolling.*data-tab='tags'" $$tmp | tail -1 | sed -e "s/<[^>]*>//g") && rm $$tmp || echo $3)
endef
# name: $1, url: $2, default: $3
define _latest
$(if $(LATEST_TAG),$(or $(latest_$1),$(eval $(call _latest_init,$1,$2,$3))$(latest_$1)),$3)
endef
# $(BOARD_DIR)/Makefile.linux_$(LINUX)
define _f
$3/$2.$1
endef
define _vf
$(call _f,$(if $4,$(call _lc,$1)_$($1),$(call _lc,$1)),$2,$3)
endef
# include $3/$2.lowcase($1)_$1
define _i
$1_$2 := $$(call _vf,$1,$2,$3,$4)
ifneq ($$(wildcard $$($1_$2)),)
include $$($1_$2)
endif
endef
# include $(BOARD_DIR)/Makefile.linux_$(LINUX)
define _vi
$(call _i,$1,$2,$3,1)
endef
define _bvi
$(call _vi,$1,$2,$(BOARD_DIR))
endef
define _bi
$(call _i,$1,$2,$(BOARD_DIR))
endef
define _ti
$(call _i,$1,$2,$(TOP_DIR))
endef
define _hi
$(call _i,$1,$2,$(HOME_DIR))
endef
# Include board detailed configuration
define board_config
$(call _bi,GCC,Makefile)
$(call _bi,ROOT,Makefile)
$(call _bi,NET,Makefile)
$(call _bvi,LINUX,Makefile)
endef
# include $(TOP_DIR)/.labinit if exist
$(eval $(call _ti,labinit))
$(eval $(call _ti,labconfig))
$(eval $(call _hi,labconfig))
# Loading board configurations
ifneq ($(BOARD),)
# include $(BOARD_DIR)/.labinit
$(eval $(call _bi,labinit))
$(eval $(call _bi,labconfig))
endif
QEMU_FORK_ := $(if $(QEMU_FORK),$(call _lc,$(QEMU_FORK))/,)
UBOOT_FORK_ := $(if $(UBOOT_FORK),$(call _lc,$(UBOOT_FORK))/,)
KERNEL_FORK_ := $(if $(KERNEL_FORK),$(call _lc,$(KERNEL_FORK))/,)
ROOT_FORK_ := $(if $(ROOT_FORK),$(call _lc,$(ROOT_FORK))/,)
_QEMU_FORK := $(if $(QEMU_FORK),$(call _lc,/$(QEMU_FORK)),)
_UBOOT_FORK := $(if $(UBOOT_FORK),$(call _lc,/$(UBOOT_FORK)),)
_KERNEL_FORK := $(if $(KERNEL_FORK),$(call _lc,/$(KERNEL_FORK)),)
_ROOT_FORK := $(if $(ROOT_FORK),$(call _lc,/$(ROOT_FORK)),)
BSP_QEMU ?= $(BSP_DIR)/qemu$(_QEMU_FORK)
BSP_UBOOT ?= $(BSP_DIR)/uboot$(_UBOOT_FORK)
BSP_ROOT ?= $(BSP_DIR)/root$(_ROOT_FORK)
BSP_KERNEL ?= $(BSP_DIR)/kernel$(_KERNEL_FORK)
BSP_BIOS ?= $(BSP_DIR)/bios
PREBUILT_QEMU := $(PREBUILT_DIR)/qemu$(_QEMU_FORK)
PREBUILT_UBOOT := $(PREBUILT_DIR)/uboot$(_UBOOT_FORK)
PREBUILT_ROOT := $(PREBUILT_DIR)/root$(_ROOT_FORK)
PREBUILT_KERNEL := $(PREBUILT_DIR)/kernel$(_KERNEL_FORK)
BOARD_QEMU ?= $(BOARD_DIR)/qemu$(_QEMU_FORK)
BOARD_UBOOT ?= $(BOARD_DIR)/uboot$(_UBOOT_FORK)
BOARD_ROOT ?= $(BOARD_DIR)/root$(_ROOT_FORK)
BOARD_KERNEL ?= $(BOARD_DIR)/kernel$(_KERNEL_FORK)
# CPU MMU
nommu ?= 0
NOMMU ?= $(nommu)
# Allow run Kernel as BIOS
LINUX_BIOS ?= 0
KERNEL_BIOS ?= $(LINUX_BIOS)
# Nolibc support
nolibc ?= $(noroot)
NOLIBC ?= $(nolibc)
ifneq ($(BOARD),)
ifneq ($(wildcard $(BOARD_MAKEFILE)),)
include $(BOARD_MAKEFILE)
endif
$(eval $(call _bi,labcustom))
# include $(BOARD_DIR)/.labfini
$(eval $(call _bi,labfini))
endif
# include $(TOP_DIR)/.labbegin if exist
$(eval $(call _ti,labbegin))
$(eval $(call _ti,labcustom))
# Customize kernel git repo and local dir
$(eval $(call __vs,KERNEL_SRC,LINUX,KERNEL_FORK))
$(eval $(call __vs,KERNEL_GIT,LINUX,KERNEL_FORK))
$(eval $(call __vs,ROOT_SRC,BUILDROOT,ROOT_FORK))
$(eval $(call __vs,ROOT_GIT,BUILDROOT,ROOT_FORK))
$(eval $(call __vs,UBOOT_SRC,UBOOT,UBOOT_FORK))
$(eval $(call __vs,UBOOT_GIT,UBOOT,UBOOT_FORK))
$(eval $(call __vs,QEMU_SRC,QEMU,QEMU_FORK))
$(eval $(call __vs,QEMU_GIT,QEMU,QEMU_FORK))
# Allow configure default LINUX version for different kernel fork repo
$(eval $(call __vs,LINUX,KERNEL_FORK))
ifeq ($(HOST_OS),Windows)
CACHE_BUILD ?= 1
endif
ifeq ($(ONESHOT),1)
CACHE_BUILD := 1
CACHE_SRC := 1
FAST_FETCH := 1
endif
ifeq ($(CACHE_BUILD),1)
CACHE_BUILD_TARGET := cache-build
endif
ifeq ($(CACHE_BUILD)$(CACHE_SRC)$(FAST_FETCH),111)
ifneq ($(LOCAL_FETCH),0)
_TOP_SRC := $(TOP_SRC)
endif
TOP_SRC := $(TOP_BUILD)/src
endif
# Don't touch the kernel code, let kernel developer do himself
ifeq ($(DEVMODE),1)
SKIP_VERIFY ?= 1
SKIP_CHECKOUT ?= 1
SKIP_NOTICE ?= 1
endif
ifneq ($(vip),0)
SKIP_NOTICE ?= 1
endif
# Allow boards to customize source and repos
KERNEL_ABS_SRC := $(TOP_SRC)/$(KERNEL_SRC)
ROOT_ABS_SRC := $(TOP_SRC)/$(ROOT_SRC)
UBOOT_ABS_SRC := $(TOP_SRC)/$(UBOOT_SRC)
QEMU_ABS_SRC := $(TOP_SRC)/$(QEMU_SRC)
$(eval $(call __vs,DTS,LINUX))
$(eval $(call __vs,DTB,LINUX))
#
# Prefer new binaries to the prebuilt ones control
#
# PBK = 1, prebuilt kernel; 0, new building kernel if exist
# PBR = 1, prebuilt rootfs; 0, new building rootfs if exist
# PBD = 1, prebuilt dtb ; 0, new building dtb if exist
# PBQ = 1, prebuilt qemu ; 0, new building qemu if exist
# PBU = 1, prebuilt uboot ; 0, new building qemu if exist
#
# Allow using contrary alias: k/kernel,r/root,d/dtb,q/qemu,u/uboot for PBK,PBR,PBD,PBQ,PBU
#
# Notes: the uppercase of d,q,u has been used for other cases,
# so, use the lowercase here.
#
define _pb
ifneq ($$($(call _lc,$1)),)
ifneq ($$(filter $$($(call _lc,$1)),1 new build),)
PB$1 := 0
endif
ifneq ($$(filter $$($(call _lc,$1)),0 old pre prebuild prebuilt),)
PB$1 := 1
endif
endif
endef
define _lpb
__$1 := $(subst x,,$(firstword $(foreach i,K U D R Q,$(findstring x$i,x$(call _uc,$1)))))
ifneq ($$($1),)
ifneq ($$(filter $$($1),1 new build),)
PB$$(__$1) := 0
endif
ifneq ($$(filter $$($1),0 old pre prebuild prebuilt),)
PB$$(__$1) := 1
endif
endif
ifneq ($(BUILD),)
ifneq ($$(filter $1,$(BUILD)),)
PB$$(__$1) := 0
endif
endif
endef # _lpb
define default_detectbuild
ifneq ($$($2),)
override BUILD += $1
endif
endef
#$(warning $(foreach i,K R D Q U,$(call _pb,$i)))
$(eval $(foreach i,K R D Q U,$(call _pb,$i)))
#$(warning $(foreach i,kernel root dtb qemu uboot,$(call _lpb,$i)))
$(eval $(foreach i,kernel root dtb qemu uboot,$(call _lpb,$i)))
# Init 9pnet share variables
ifeq ($(origin SHARE_DIR),command line)
SHARE := 1
else
SHARE ?= 0
endif
SHARE_DIR ?= hostshare
HOST_SHARE_DIR ?= $(SHARE_DIR)
GUEST_SHARE_DIR ?= /hostshare
SHARE_TAG ?= hostshare
# Supported apps and their version variable
APPS := kernel uboot root qemu
APP_MAP ?= bsp:BSP kernel:LINUX uboot:UBOOT root:BUILDROOT qemu:QEMU
APP_TARGETS := source download checkout patch defconfig olddefconfig oldconfig menuconfig build cleanup cleansrc cleanall cleanstamp clean distclean saveall save saveconfig savepatch clone help list debug boot test test-debug upload env config
define gengoalslist
$(foreach i,$(or $2,$(APP_MAP)),$(if $($(lastword $(subst :,$(space),$i))),$(firstword $(subst :,$(space),$i))-$1))
endef
define genaliastarget
$(strip $(foreach i,$(APP_MAP),$(if $(subst $(call _lc,$(lastword $(subst :,$(space),$i))),,$(firstword $(subst :,$(space),$i))),$(call _lc,$(lastword $(subst :,$(space),$i))))))
endef
define genaliassource
$(or $(strip $(subst $1,,$(foreach i,$(APP_MAP),$(subst $(call _lc,$(lastword $(subst :,$(space),$i))),$(firstword $(subst :,$(space),$i)),$1)))),$1)
endef
# Support alias, root -> buildroot, kernel -> linux
ifneq ($(BUILD),)
override BUILD := $(call genaliassource,$(subst $(comma),$(space),$(BUILD)))
endif
ifeq ($(BUILD),all)
override BUILD :=
$(foreach i,$(APP_MAP),$(eval $(call default_detectbuild,$(firstword $(subst :,$(space),$i)),$(lastword $(subst :,$(space),$i)))))
endif
first_target := $(firstword $(MAKECMDGOALS))
ifneq ($(findstring -defconfigx,$(first_target)x),)
# use the rest as arguments for "defconfig"
reserve_target := $(first_target:-defconfig=)
APP_ARGS := $(filter-out $(reserve_target),$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
ifneq ($(APP_ARGS),)
CFG_PREFIX := $(subst x,,$(firstword $(foreach i,K U R Q,$(findstring x$i,x$(call _uc,$(first_target))))))
$(CFG_PREFIX)CFG := $(APP_ARGS)
endif
endif
# add the same implementation of _stamp as __stamp for all !cleanstamp targets, used to let 'make cleanstamp kernel-build' work without rebuild
ifneq ($(first_target),cleanstamp)
define __stamp
$(call _stamp,$1,$2)
endef
endif
# common commands
ifneq ($(filter $(first_target),$(APPS)),)
# The second targets passed after APPS, use them as the argument of the APPS.
APP_ARGS := $(filter-out $(first_target),$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
x := $(subst src/$(_$(call _uc,$(first_target))_SRC)/,,$(APP_ARGS))
endif
ifneq ($(filter $(first_target),$(APP_TARGETS)),)
APP_ARGS := $(filter-out $(first_target),$(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS)))
define cli_detectapp
ifeq ($$(origin $2),command line)
APP += $1
endif
endef
define default_detectapp
ifneq ($$($2),)
override app += $1
endif
endef #default_detectapp
ifneq ($(APP_ARGS),)
APP := $(firstword $(APP_ARGS))
else
APP :=
$(foreach i,$(APP_MAP),$(eval $(call cli_detectapp,$(firstword $(subst :,$(space),$i)),$(lastword $(subst :,$(space),$i)))))
endif
ifneq ($(APP),)
app ?= $(APP)
override app := $(call genaliassource,$(subst $(comma),$(space),$(app)))
endif
ifeq ($(app),all)
override app :=
$(foreach i,$(APP_MAP),$(eval $(call default_detectapp,$(firstword $(subst :,$(space),$i)),$(lastword $(subst :,$(space),$i)))))
ifeq ($(first_target), upload)
override app+= dtb modules
endif
endif
ifeq ($(app),)
ifneq ($(filter $(MAKECMDGOALS),list help config),)
app := default
else
app := kernel
endif
endif
endif # common commands
# Prepare build environment
SCRIPT_GETCCVER := tools/gcc/version.sh
define genbuildenv
GCC_$2 := $$(or $$(call __v,GCC,$2,$3),$(GCC))
CCORI_$2 := $$(or $$(call __v,CCORI,$2,$3),$(CCORI))
ifneq ($$(CCORI_$2)$$(GCC_$2),)
ifeq ($$(CCORI_$2)$$(CCORI),)
CCORI_$2 := internal
CCORI := internal
else
$$(eval $$(call __vs,CCORI,$2,$3))
endif
ifneq ($$(GCC_$2),$$(shell $(SCRIPT_GETCCVER) $(CCPATH) $(CCPRE)))
GCC_$2_SWITCH := 1
endif
endif
ifeq ($$(filter $(XARCH),i386 x86_64),)
HOST_GCC_$2 := $$(or $$(call __v,HOST_GCC,$2,$3),$(HOST_GCC))
HOST_CCORI_$2 := $$(or $$(call __v,HOST_CCORI,$2,$3),$(HOST_CCORI))
ifneq ($$(HOST_CCORI_$2)$$(HOST_GCC_$2),)
ifeq ($$(HOST_CCORI_$2)$$(HOST_CCORI),)
HOST_CCORI_$2 := internal
endif
# Use the default gcc directly for i386
ifneq ($$(HOST_GCC_$2),$$(shell $(SCRIPT_GETCCVER)))
HOST_GCC_$2_SWITCH := 1
endif
endif
endif
endef # genbuildenv
# Customize toolchains for different docker images
$(eval $(call __vs,CCORI,OS))
$(eval $(call __vs,GCC,OS))
$(eval $(call __vs,HOST_GCC,OS))
PREBUILT_TOOLCHAIN_MAKEFILE := $(PREBUILT_TOOLCHAINS)/$(XARCH)/Makefile
# Local toolchain package means builtin toolchain too
ifneq ($(wildcard $(CCURL)),)
CCORI := builtin
CCORI_LIST += builtin
endif
ifneq ($(wildcard $(PREBUILT_TOOLCHAIN_MAKEFILE)),)
include $(PREBUILT_TOOLCHAIN_MAKEFILE)
endif
ifneq ($(GCC),)
# Force using internal CCORI if GCC specified and there is really an internal gcc
ifeq ($(CCORI),)
ifneq ($(shell which $(CCPRE)gcc),)
CCORI := internal
endif
endif
endif
ifeq ($(filter $(XARCH),i386 x86_64),)
ifneq ($(HOST_GCC),)
# Force using internal CCORI if GCC specified
ifeq ($(HOST_CCORI),)
HOST_CCORI := internal
endif
endif
endif
# tuning notify method
notice := error
# stop error for force targets ??
ifneq ($(findstring xforce, x$(MAKECMDGOALS)),)
notice := warning
endif
# warning instead of error for bsp downloading
ifneq ($(findstring xbsp, x$(MAKECMDGOALS)),)
notice := warning
endif
# warning instead of error for BOARD switch
ifeq ($(MAKECMDGOALS),)
notice := warning
endif
# warning instead of error for clone targets
ifneq ($(findstring clone, $(MAKECMDGOALS)),)
notice := ignore
endif
ifneq ($(SKIP_NOTICE),)
notice := ignore
endif
# generate verify function
define genverify
ifneq ($$($2),)
ifneq ($$(BSP_$1),)
ifneq ($$(wildcard $$(BSP_$1)),)
ifeq ($1,KERNEL)
$2_LIST ?= $$(filter-out $$(shell cd $$(BSP_$1) && ls -d -p */* | sed -ne "/\/.*\//{s%/.*%%g;p}"),$$(shell cd $$(BSP_$1) && ls -d * 2>/dev/null | sort -V))
else
$2_LIST ?= $$(shell ls $$(BSP_$1) | sort -V)
endif
endif
endif
# If Linux version specific qemu list defined, use it
$$(eval $$(call __vs_override,$2_LIST,$$(or $3,LINUX)))
ifneq ($$($2_LIST),)
ifeq ($$(filter $$($2), $$($2_LIST)),)
$$(if $4,$$(eval $$(call $4)))
verify_notice := $$(BOARD): $$($2) not in supported $2 list: $$($2_LIST),$(if $(KERNEL_FORK), KERNEL_FORK is set as $(KERNEL_FORK)$(comma))
verify_notice += update may help: 'make bsp B=$$(BOARD)'
ifneq ($$(filter $$(call _lc,$1),$(APPS)),)
verify_notice += or clone one please: 'make $$(call _lc,$1)-clone $2_NEW=$$($2)'
endif
ifneq ($$(notice), ignore)
ifeq ($$(notice), error)
$$(error ERR: $$(verify_notice))
else
$$(warning WARN: $$(verify_notice))
endif
endif
endif
endif
endif
# Strip prefix of LINUX to get the real version, e.g. XXX-v3.10, XXX may be the customized repo name
ifneq ($$($1_SRC),)
ifneq ($$(_$1_SRC), $$($1_SRC))
_$2 := $$(subst $$(shell basename $$($1_SRC))-,,$$($2))
ifeq ($$(findstring $$(TOP_SRC),$$($1_SRC)),)
$1_ABS_SRC := $$(TOP_SRC)/$$($1_SRC)
else
$1_ABS_SRC := $$($1_SRC)
endif
endif
endif
endef
# Verify LINUX argument
#$(warning $(call genverify,KERNEL,LINUX))
$(eval $(call genverify,KERNEL,LINUX))
# Verify ROOT argument
#$(warning $(call genverify,ROOT,BUILDROOT))
$(eval $(call genverify,ROOT,BUILDROOT))
# Verify UBOOT argument
#$(warning $(call genverify,UBOOT,UBOOT))
$(eval $(call genverify,UBOOT,UBOOT))
# Verify QEMU argument
#$(warning $(call genverify,QEMU,QEMU))
$(eval $(call genverify,QEMU,QEMU))
# Kernel features configuration, e.g. kft, gcs ...
f ?= $(feature)
F ?= $(f)
FEATURES ?= $(F)
FEATURE ?= $(FEATURES)
ifneq ($(FEATURE),)
FEATURE_ENVS := $(foreach i, $(subst $(comma),$(space),$(FEATURE)), \
$(shell f_env=$(FEATURE_DIR)/$(i)/$(LINUX); \
if [ -f $$f_env/env.$(XARCH).$(MACH) ]; then \
echo $$f_env/env.$(XARCH).$(MACH); \
elif [ -f $$f_env/env.$(MACH) ]; then \
echo $$f_env/env.$(MACH); \
fi))
ifneq ($(wildcard $(FEATURE_ENVS)),)
include $(FEATURE_ENVS)
endif
endif
# Core images: qemu, bootloader, kernel and rootfs
$(eval $(call __vs,ROOTFS,LINUX))
$(eval $(call __vs,BUILDROOT,LINUX))
$(eval $(call __vs,UBOOT,LINUX))
$(eval $(call __vs,QEMU,LINUX))
$(eval $(call __vs,QEMU,OS))
$(eval $(call __vs,QTOOL,OS))
$(eval $(call __vs,BIOS,LINUX))
_BIMAGE := $(BIMAGE)
_KIMAGE := $(KIMAGE)
_ROOTFS := $(ROOTFS)
_QTOOL := $(QTOOL)
# Core build: for building in standalone directories
TOP_BUILD_MACH := $(TOP_BUILD)/$(XARCH)/$(MACH)
QEMU_BUILD := $(TOP_BUILD_MACH)/$(QEMU_FORK_)qemu/$(QEMU)
UBOOT_BUILD := $(TOP_BUILD_MACH)/$(UBOOT_FORK_)uboot/$(UBOOT)
KERNEL_BUILD := $(TOP_BUILD_MACH)/$(KERNEL_FORK_)linux/$(LINUX)
ROOT_BUILD := $(TOP_BUILD_MACH)/$(ROOT_FORK_)buildroot/$(BUILDROOT)
BSP_BUILD := $(TOP_BUILD_MACH)/bsp
# Cross Compiler toolchains
ifneq ($(XARCH), i386)
BUILDROOT_CCPRE := $(XARCH)-linux-
else
BUILDROOT_CCPRE := i686-linux-
endif
BUILDROOT_CCPATH := $(ROOT_BUILD)/host/usr/bin
# Add internal toolchain to list (the one installed in docker image)
ifneq ($(CCPRE),)
ifneq ($(shell which $(CCPRE)gcc),)
CCORI_INTERNAL := 1
endif
# Add builtin toolchain to list (the one builtin the bsp or plugin)
ifeq ($(CCORI),)
ifneq ($(CCPATH),)
ifneq ($(wildcard $(CCPATH)/$(CCPRE)gcc),)
CCORI_LIST += builtin
endif
endif
endif
else
ifneq ($(filter $(XARCH),i386 x86_64),)
ifneq ($(shell which gcc),)
CCORI_INTERNAL := 1
endif
endif
endif
ifeq ($(CCORI_INTERNAL), 1)
ifeq ($(filter internal, $(CCORI_LIST)),)
CCORI_LIST += internal
endif
endif
# Add buidroot toolchain to list
ifneq ($(wildcard $(BUILDROOT_CCPATH)/$(BUILDROOT_CCPRE)gcc),)
ifeq ($(filter buildroot, $(CCORI_LIST)),)
CCORI_LIST += buildroot
endif
ifeq ($(CCORI), buildroot)
CCPATH := $(BUILDROOT_CCPATH)
CCPRE := $(BUILDROOT_CCPRE)
endif
endif
CCORI ?= null
# If no CCORI specified, check internal, buildroot, external one by one
ifeq ($(CCORI), null)
# Check if there is a local toolchain
ifneq ($(CCPRE),)
ifneq ($(shell which $(CCPRE)gcc),)
CCORI := internal
endif
else
ifneq ($(filter $(XARCH),i386 x86_64),)
ifneq ($(shell which gcc,)
CCORI := internal
endif
endif
endif
# Check if buildroot version exists
ifeq ($(CCPATH),)
ifneq ($(wildcard $(BUILDROOT_CCPATH)/$(BUILDROOT_CCPRE)gcc),)
CCORI := buildroot
CCPATH := $(BUILDROOT_CCPATH)
CCPRE := $(BUILDROOT_CCPRE)
endif
else
ifneq ($(wildcard $(CCPATH)/$(CCPRE)gcc),)
CCORI := builtin
endif
endif
else # CCORI != null
# Check if internal toolchain is there
ifeq ($(CCORI), internal)
ifeq ($(shell which $(CCPRE)gcc),)
$(error ERR: No internal toolchain found, please find one via: make toolchain-list)
endif
endif
# Check if external toolchain downloaded
ifeq ($(filter $(CCORI),buildroot internal),)
ifneq ($(CCPRE),)
ifneq ($(CCPATH),)
ifeq ($(wildcard $(CCPATH)/$(CCPRE)gcc),)
# If CCORI specified and it is not there, just download one
ifeq ($(wildcard $(TOOLCHAIN)),)
ifneq ($(notice),ignore)
ifeq ($(notice),error)
$(error ERR: No internal and external toolchain found, please refer to prebuilt/toolchains/ and prepare one)
else
$(warning WARN: No internal and external toolchain found, please refer to prebuilt/toolchains/ and prepare one)
endif
endif
endif
endif
endif
endif
endif
endif # CCORI = null
# If none exists
ifeq ($(CCORI), null)
$(info ERR: No toolchain found, please refer to prebuilt/toolchains/ and prepare one)
endif
CCORI_LIST ?= $(CCORI)
ifneq ($(CCORI),)
ifeq ($(filter $(CCORI), $(CCORI_LIST)),)
$(error Supported gcc original list: $(CCORI_LIST))
endif
endif
#$(warning $(call genbuildenv,kernel,LINUX,OS))
$(eval $(call genbuildenv,kernel,LINUX,OS))
$(eval $(call genbuildenv,uboot,UBOOT,OS))
$(eval $(call genbuildenv,qemu,QEMU,OS))
$(eval $(call genbuildenv,root,BUILDROOT,OS))
ifneq ($(LD_LIBRARY_PATH),)
ifneq ($(LLPATH),)
L_PATH := LD_LIBRARY_PATH=$(LLPATH):$(LD_LIBRARY_PATH)
else
L_PATH := LD_LIBRARY_PATH=$(LD_LIBRARY_PATH)
endif
else
ifneq ($(LLPATH),)
L_PATH := LD_LIBRARY_PATH=$(LLPATH)
endif
endif
C_PATH ?= env PATH=$(if $(CCPATH),$(CCPATH):)$(PATH)$(if $(RUST_PATH),:$(RUST_PATH)) $(L_PATH)
#$(info Using gcc: $(CCPATH)/$(CCPRE)gcc, $(CCORI))
TOOLCHAIN ?= $(PREBUILT_TOOLCHAINS)/$(XARCH)
# Parallel Compiling threads
HOST_CPU_THREADS := $$(nproc)
JOBS ?= $(HOST_CPU_THREADS)
# Emulator configurations
ifeq ($(KERNEL_BIOS),0)