forked from tinyclub/linux-lab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
3259 lines (2614 loc) · 91 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
#
TOP_DIR := $(CURDIR)
# Phony targets
PHONY :=
USER ?= ubuntu
# Check running host
LAB_ENV_ID=/home/$(USER)/Desktop/lab.desktop
ifneq ($(LAB_ENV_ID),$(wildcard $(LAB_ENV_ID)))
ifneq (../../configs/linux-lab, $(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
# Check running user, must as ubuntu
ifneq ($(shell whoami),$(USER))
$(error ERR: Must run Linux Lab as general user: '$(USER)', not use it as root, please try 'su ubuntu'.)
endif
# Check permission issue, must available to ubuntu
ifneq ($(shell stat -c '%U' /.git/HEAD),$(USER))
$(error ERR: Must make sure Cloud Lab and Linux Lab available to user: '$(USER)', please try 'make perm' or change their owner in host.)
endif
# Current variables: board, plugin, module
BOARD_CONFIG := $(shell cat .board_config 2>/dev/null)
PLUGIN_CONFIG := $(shell cat .plugin_config 2>/dev/null)
MODULE_CONFIG := $(shell cat .module_config 2>/dev/null)
MPATH_CONFIG := $(shell cat .mpath_config 2>/dev/null)
# Verbose logging control
ifeq ($V, 1)
Q :=
S :=
else
S ?= -s
Q ?= @
endif
# Board config: B/BOARD persistent, b/board temporarily
board ?= $(b)
B ?= $(board)
ifeq ($(B),)
ifeq ($(BOARD_CONFIG),)
BOARD := arm/vexpress-a9
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)
FEATURE_DIR := feature/linux
TFTPBOOT := tftpboot
HOME_DIR := /home/$(USER)/
# Search board in basic arch list while board name given without arch specified
BASE_ARCHS := arm aarch64 mipsel ppc i386 x86_64 loongson csky
ifneq ($(BOARD_DIR),$(wildcard $(BOARD_DIR)))
ARCH := $(shell for arch in $(BASE_ARCHS); do if [ -d $(TOP_DIR)/$(BOARDS_DIR)/$$arch/$(BOARD) ]; then echo $$arch; break; fi; done)
ifneq ($(ARCH),)
override BOARD := $(ARCH)/$(BOARD)
override BOARD_DIR := $(TOP_DIR)/$(BOARDS_DIR)/$(BOARD)
ifeq ($(filter _boot, $(MAKECMDGOALS)), _boot)
$(info LOG: Current board is $(BOARD))
endif
else
$(error ERR: $(BOARD) not exist, check available boards in 'make list')
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
ifneq ($(PLUGIN_FLAG), $(wildcard $(PLUGIN_FLAG)))
PLUGIN_DIR:=
_PLUGIN := 0
else
_PLUGIN := 1
endif
# add board directories
BOARD_ROOT ?= $(BOARD_DIR)/root
BOARD_KERNEL ?= $(BOARD_DIR)/kernel
BOARD_UBOOT ?= $(BOARD_DIR)/uboot
BOARD_QEMU ?= $(BOARD_DIR)/qemu
BOARD_TOOLCHAIN ?= $(BOARD_DIR)/toolchains
# add a standlaone bsp directory
BSP_DIR ?= $(BOARD_DIR)/bsp
BSP_ROOT ?= $(BSP_DIR)/root
BSP_KERNEL ?= $(BSP_DIR)/kernel
BSP_UBOOT ?= $(BSP_DIR)/uboot
BSP_QEMU ?= $(BSP_DIR)/qemu
BSP_TOOLCHAIN ?= $(BSP_DIR)/toolchains
BSP_CONFIG = $(BSP_DIR)/configs
BSP_PATCH = $(BSP_DIR)/patch
# Support old directory arch
ifeq ($(BSP_DIR),$(wildcard $(BSP_DIR)))
_BSP_CONFIG := $(BSP_CONFIG)
else
_BSP_CONFIG := $(BOARD_DIR)
endif
# 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_ROOT := $(PREBUILT_DIR)/root
PREBUILT_KERNEL := $(PREBUILT_DIR)/kernel
PREBUILT_BIOS := $(PREBUILT_DIR)/bios
PREBUILT_UBOOT := $(PREBUILT_DIR)/uboot
PREBUILT_QEMU := $(PREBUILT_DIR)/qemu
# Core source: remote and local
#QEMU_GIT ?= https://github.com/qemu/qemu.git
QEMU_GIT ?= https://gitee.com/mirrors/qemu.git
_QEMU_GIT := $(QEMU_GIT)
_QEMU_SRC ?= 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 := $(UBOOT_GIT)
_UBOOT_SRC ?= 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 := $(KERNEL_GIT)
# git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git
_KERNEL_SRC ?= 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 ?= buildroot
ROOT_SRC ?= $(_ROOT_SRC)
_LINUX=$(LINUX)
KERNEL_ABS_SRC := $(TOP_DIR)/$(KERNEL_SRC)
ROOT_ABS_SRC := $(TOP_DIR)/$(ROOT_SRC)
UBOOT_ABS_SRC := $(TOP_DIR)/$(UBOOT_SRC)
QEMU_ABS_SRC := $(TOP_DIR)/$(QEMU_SRC)
BOARD_MAKEFILE := $(BOARD_DIR)/Makefile
# Common functions
_uc = $(shell echo $1 | tr a-z A-Z)
_lc = $(shell echo $1 | tr A-Z a-z)
_stamp = $(3)/.stamp_$(1)-$(2)
## 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))])
endef
define _v
$(if $(call __v,$1,$2),$(call __v,$1,$2),$(if $3,$3,$($1)))
endef
#$(shell a="$(call __v,$1,$2)"; if [ -n "$$a" ]; then echo "$$a"; else echo $($1); fi)
define __vs
ifneq ($$(call __v,$(1),$(2)),)
$(3) $(1) := $$(call __v,$(1),$(2))
endif
endef
define _vs
$(1) := $$(call _v,$(1),$(2))
endef
# $(BOARD_DIR)/Makefile.linux_$(LINUX)
define _f
$(3)/$(2).$(1)
endef
define _vf
$(call _f,$(if $(4),$(call _lc,$1)_$($1),$(1)),$(2),$(3))
endef
# include $(3)/$(2).lowcase($(1))_$(1)
define _i
$(1)_$(2) := $$(call _vf,$(1),$(2),$(3),$(4))
ifeq ($$($(1)_$(2)),$$(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
# Makefile.config/beforeconfig/afterconfig hooks for more
define board_config
$(call _bi,beforeconfig.private,Makefile)
$(call _bi,beforeconfig,Makefile)
$(call _bi,config.private,Makefile)
$(call _bi,config,Makefile)
$(call _bi,GCC,Makefile)
$(call _bi,ROOT,Makefile)
$(call _bi,NET,Makefile)
$(call _bvi,LINUX,Makefile)
$(call _bi,afterconfig,Makefile)
$(call _bi,afterconfig.private,Makefile)
endef
define fixup_arch
ifneq ($$(KERNEL_SRC),)
ifneq ($$(_KERNEL_SRC),$$(KERNEL_SRC))
KERNEL_ABS_SRC := $$(KERNEL_SRC)
endif
endif
IS_ARCH = $$(shell cd $$(KERNEL_ABS_SRC); git show $$(call _v,LINUX,LINUX):arch/$$(ARCH)/boot >/dev/null 2>&1; echo $$$$?)
ifneq ($$(IS_ARCH),0)
ARCH := $$(XARCH)
endif
endef
# include Makefile.init if exist
# the .private version is for user local customization, should not be added in mainline repository
$(eval $(call _ti,init,Makefile))
$(eval $(call _ti,init.private,Makefile))
$(eval $(call _ti,config,Makefile))
$(eval $(call _ti,config.private,Makefile))
# Loading board configurations
ifneq ($(BOARD),)
# include $(BOARD_DIR)/Makefile.init if exist
$(eval $(call _bi,init.private,Makefile))
$(eval $(call _bi,init,Makefile))
include $(BOARD_MAKEFILE)
# include $(BOARD_DIR)/Makefile.fini if exist
$(eval $(call _bi,fini,Makefile))
$(eval $(call _bi,fini.private,Makefile))
$(eval $(call _bi,labconfig))
endif
$(eval $(call _ti,labconfig))
$(eval $(call _hi,labconfig))
# Customize kernel git repo and local dir
$(eval $(call __vs,KERNEL_SRC,LINUX))
$(eval $(call __vs,KERNEL_GIT,LINUX))
# Prepare build environment
define genbuildenv
GCC_$(1) = $$(call __v,GCC,$(1))
CCORI_$(1) = $$(call __v,CCORI,$(1))
ifeq ($$(findstring $(2),$$(MAKECMDGOALS)),$(2))
ifneq ($$(CCORI_$(1))$$(GCC_$(1)),)
ifeq ($$(CCORI_$(1))$$(CCORI),)
CCORI := internal
endif
GCC_$(1)_SWITCH := 1
endif
endif
endef # genbuildenv
#$(warning $(call genbuildenv,LINUX,kernel))
$(eval $(call genbuildenv,LINUX,kernel))
#$(warning $(call genbuildenv,UBOOT,uboot))
$(eval $(call genbuildenv,UBOOT,uboot))
#$(warning $(call genbuildenv,QEMU,qemu))
$(eval $(call genbuildenv,QEMU,qemu))
#$(warning $(call genbuildenv,BUILDROOT,root))
$(eval $(call genbuildenv,BUILDROOT,root))
ifneq ($(GCC),)
# Force using internal CCORI if GCC specified
ifeq ($(CCORI),)
CCORI := internal
endif
GCC_SWITCH := 1
endif
# generate verify function
define genverify
ifneq ($$($2),)
ifneq ($$(BSP_$(1)),)
ifeq ($$(BSP_$(1)), $$(wildcard $$(BSP_$(1))))
$(2)_LIST ?= $$(shell ls $$(BSP_$(1)))
endif
endif
# If Linux version specific qemu list defined, use it
$$(eval $$(call __vs,$(2)_LIST,$$(if $(3),$(3),LINUX),override))
ifneq ($$($(2)_LIST),)
ifneq ($$(filter $$($2), $$($(2)_LIST)), $$($2))
$$(if $(4),$$(eval $$(call $(4))))
$$(error Supported $(2) list: $$($(2)_LIST))
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)))
$(1)_ABS_SRC := $$($(1)_SRC)
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 f, $(shell echo $(FEATURE) | tr ',' ' '), \
$(shell if [ -f $(FEATURE_DIR)/$(f)/$(LINUX)/env.$(XARCH).$(MACH) ]; then \
echo $(FEATURE_DIR)/$(f)/$(LINUX)/env.$(XARCH).$(MACH); \
elif [ -f $(FEATURE_DIR)/$(f)/$(LINUX)/env.$(MACH) ]; then \
echo $(FEATURE_DIR)/$(f)/$(LINUX)/env.$(MACH); fi))
ifneq ($(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))
_BIMAGE := $(BIMAGE)
_KIMAGE := $(KIMAGE)
_ROOTFS := $(ROOTFS)
_QTOOL := $(QTOOL)
# Core output: for building in standalone directories
TOP_OUTPUT := $(TOP_DIR)/output
TOP_OUTPUT_ARCH := $(TOP_OUTPUT)/$(XARCH)
QEMU_OUTPUT := $(TOP_OUTPUT_ARCH)/qemu-$(QEMU)-$(MACH)
UBOOT_OUTPUT := $(TOP_OUTPUT_ARCH)/uboot-$(UBOOT)-$(MACH)
KERNEL_OUTPUT := $(TOP_OUTPUT_ARCH)/linux-$(LINUX)-$(MACH)
ROOT_OUTPUT := $(TOP_OUTPUT_ARCH)/buildroot-$(BUILDROOT)-$(MACH)
BSP_OUTPUT := $(TOP_OUTPUT_ARCH)/bsp-$(MACH)
# Cross Compiler toolchains
ifneq ($(XARCH), i386)
BUILDROOT_CCPRE = $(XARCH)-linux-
else
BUILDROOT_CCPRE = i686-linux-
endif
BUILDROOT_CCPATH = $(ROOT_OUTPUT)/host/usr/bin
# Add internal toolchain to list (the one installed in docker image)
ifneq ($(CCPRE),)
ifeq ($(shell /usr/bin/which $(CCPRE)gcc >/dev/null 2>&1; echo $$?),0)
CCORI_INTERNAL := 1
endif
# Add builtin toolchain to list (the one builtin the bsp or plugin)
ifeq ($(CCORI),)
ifneq ($(CCPATH),)
ifeq ($(shell env PATH=$(CCPATH) /usr/bin/which $(CCPRE)gcc >/dev/null 2>&1; echo $$?),0)
CCORI_LIST += builtin
endif
endif
endif
else
ifeq ($(filter $(XARCH),i386 x86_64),$(XARCH))
ifeq ($(shell /usr/bin/which gcc >/dev/null 2>&1; echo $$?),0)
CCORI_INTERNAL := 1
endif
endif
endif
ifeq ($(CCORI_INTERNAL), 1)
ifneq ($(filter internal, $(CCORI_LIST)), internal)
CCORI_LIST += internal
endif
endif
# Add buidroot toolchain to list
ifeq ($(shell env PATH=$(BUILDROOT_CCPATH) /usr/bin/which $(BUILDROOT_CCPRE)gcc >/dev/null 2>&1; echo $$?),0)
ifneq ($(filter buildroot, $(CCORI_LIST)), buildroot)
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),)
ifeq ($(shell /usr/bin/which $(CCPRE)gcc >/dev/null 2>&1; echo $$?),0)
CCORI := internal
endif
else
ifeq ($(filter $(XARCH),i386 x86_64),$(XARCH))
ifeq ($(shell /usr/bin/which gcc >/dev/null 2>&1; echo $$?),0)
CCORI := internal
endif
endif
endif
# Check if buildroot version exists
ifeq ($(CCPATH),)
ifeq ($(shell env PATH=$(BUILDROOT_CCPATH) /usr/bin/which $(BUILDROOT_CCPRE)gcc >/dev/null 2>&1; echo $$?),0)
CCORI := buildroot
CCPATH := $(BUILDROOT_CCPATH)
CCPRE := $(BUILDROOT_CCPRE)
endif
else
ifeq ($(shell env PATH=$(CCPATH) /usr/bin/which $(CCPRE)gcc >/dev/null 2>&1; echo $$?),0)
CCORI := builtin
endif
endif
else # CCORI != null
# Check if internal toolchain is there
ifeq ($(CCORI), internal)
ifneq ($(shell /usr/bin/which $(CCPRE)gcc >/dev/null 2>&1; echo $$?),0)
$(error ERR: No internal toolchain found, please find one via: make toolchain-list)
endif
endif
# Check if external toolchain downloaded
ifneq ($(filter $(CCORI), buildroot), $(CCORI))
ifneq ($(CCPRE),)
ifneq ($(CCPATH),)
ifneq ($(shell env PATH=$(CCPATH) /usr/bin/which $(CCPRE)gcc >/dev/null 2>&1; echo $$?),0)
# If CCORI specified and it is not there, just download one
ifeq ($(TOOLCHAIN), $(wildcard $(TOOLCHAIN)))
CC_TOOLCHAIN := toolchain-source
else
$(error ERR: No internal and external toolchain found, please refer to prebuilt/toolchains/ and prepare one)
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 ($(filter $(CCORI), $(CCORI_LIST)), $(CCORI))
$(error Supported gcc original list: $(CCORI_LIST))
endif
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
ifneq ($(CCPATH),)
C_PATH ?= env PATH=$(CCPATH):$(PATH) $(L_PATH)
endif
#$(info Using gcc: $(CCPATH)/$(CCPRE)gcc, $(CCORI))
TOOLCHAIN ?= $(PREBUILT_TOOLCHAINS)/$(XARCH)
# Parallel Compiling threads
HOST_CPU_THREADS := $(shell grep -c processor /proc/cpuinfo)
JOBS ?= $(HOST_CPU_THREADS)
#
# 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)),)
ifeq ($$($(call _lc,$1))),1)
PB$1 := 0
else
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),)
ifeq ($$($1),1)
PB$$(_$(1)) := 0
else
PB$$(_$(1)) := 1
endif
endif
endef
#$(warning $(foreach x,K R D Q U,$(call _pb,$x)))
$(eval $(foreach x,K R D Q U,$(call _pb,$x)))
#$(warning $(foreach x,kernel root dtb qemu uboot,$(call _lpb,$x)))
$(eval $(foreach x,kernel root dtb qemu uboot,$(call _pb,$x)))
# Emulator configurations
ifneq ($(BIOS),)
BIOS_ARG := -bios $(BIOS)
endif
# Another qemu-system-$(ARCH)
QEMU_SYSTEM ?= $(QEMU_OUTPUT)/$(XARCH)-softmmu/qemu-system-$(XARCH)
ifeq ($(QEMU_SYSTEM),$(wildcard $(QEMU_SYSTEM)))
PBQ ?= 0
else
PBQ := 1
endif
ifeq ($(PBQ), 1)
ifneq ($(QTOOL),)
ifeq ($(QTOOL),$(wildcard $(QTOOL)))
QEMU_SYSTEM := $(QTOOL)
endif
endif
QTOOL_LINUX ?= $(call __v,QTOOL,LINUX)
ifneq ($(QTOOL_LINUX),)
ifeq ($(QTOOL_LINUX),$(wildcard $(QTOOL_LINUX)))
QEMU_SYSTEM := $(QTOOL_LINUX)
endif
endif
endif
ifneq ($(QEMU),)
ifeq ($(QEMU_SYSTEM),$(wildcard $(QEMU_SYSTEM)))
QEMU_PATH := env PATH=$(dir $(QEMU_SYSTEM)):$(PATH)
endif
endif
EMULATOR := $(QEMU_PATH) $(XENVS) qemu-system-$(XARCH) $(BIOS_ARG)
# Linux configurations
LINUX_PKIMAGE := $(ROOT_OUTPUT)/images/$(PORIIMG)
LINUX_KIMAGE := $(KERNEL_OUTPUT)/$(ORIIMG)
LINUX_UKIMAGE := $(KERNEL_OUTPUT)/$(UORIIMG)
ifeq ($(LINUX_KIMAGE),$(wildcard $(LINUX_KIMAGE)))
PBK ?= 0
else
PBK := 1
endif
# Customize DTS?
_DTS := $(DTS)
ifeq ($(DTS),)
ifneq ($(ORIDTS),)
DTS := $(KERNEL_SRC)/$(ORIDTS)
ORIDTB ?= $(ORIDTS:.dts=.dtb)
endif
ifneq ($(ORIDTB),)
ORIDTS := $(ORIDTB:.dtb=.dts)
DTS := $(KERNEL_SRC)/$(ORIDTS)
endif
endif
ifneq ($(DTS),)
DTB_TARGET ?= $(patsubst %.dts,%.dtb,$(shell echo $(DTS) | sed -e "s%.*/dts/%%g"))
LINUX_DTB := $(KERNEL_OUTPUT)/$(ORIDTB)
ifeq ($(LINUX_DTB),$(wildcard $(LINUX_DTB)))
ifneq ($(ORIDTB),)
PBD ?= 0
else
PBD := 1
endif
else
PBD := 1
endif
endif
PKIMAGE ?= $(LINUX_PKIMAGE)
KIMAGE ?= $(LINUX_KIMAGE)
UKIMAGE ?= $(LINUX_UKIMAGE)
DTB ?= $(LINUX_DTB)
ifeq ($(PBK),0)
KIMAGE := $(LINUX_KIMAGE)
UKIMAGE := $(LINUX_UKIMAGE)
endif
ifeq ($(PBD),0)
DTB := $(LINUX_DTB)
endif
# Prebuilt path (not top dir) setting
ifneq ($(_BIMAGE),)
PREBUILT_UBOOT_DIR ?= $(dir $(_BIMAGE))
endif
ifneq ($(_KIMAGE),)
PREBUILT_KERNEL_DIR ?= $(dir $(_KIMAGE))
endif
ifneq ($(_ROOTFS),)
PREBUILT_ROOT_DIR ?= $(dir $(_ROOTFS))
endif
ifneq ($(_QTOOL),)
PREBUILT_QEMU_DIR ?= $(patsubst %/bin/,%,$(dir $(_QTOOL)))
endif
# Uboot configurations
UBOOT_BIMAGE := $(UBOOT_OUTPUT)/u-boot
PREBUILT_BIMAGE := $(PREBUILT_UBOOT_DIR)/u-boot
ifeq ($(UBOOT_BIMAGE),$(wildcard $(UBOOT_BIMAGE)))
PBU ?= 0
else
PBU := 1
endif
ifeq ($(UBOOT_BIMAGE),$(wildcard $(UBOOT_BIMAGE)))
U ?= 1
else
ifeq ($(PREBUILT_BIMAGE),$(wildcard $(PREBUILT_BIMAGE)))
U ?= 1
else
U := 0
endif
endif
BIMAGE ?= $(UBOOT_BIMAGE)
ifeq ($(PBU),0)
BIMAGE := $(UBOOT_BIMAGE)
endif
# Use u-boot as 'kernel' if uboot used (while PBU=1/U=1 and u-boot exists)
$(eval $(call __vs,U,LINUX))
ifneq ($(U),0)
QEMU_KIMAGE := $(BIMAGE)
else
QEMU_KIMAGE := $(KIMAGE)
endif
# Root configurations
# TODO: buildroot defconfig for $ARCH
# Verify rootdev argument
#$(warning $(call genverify,ROOTDEV,ROOTDEV,,0))
$(eval $(call genverify,ROOTDEV,ROOTDEV,,0))
ROOTDEV ?= /dev/ram0
$(eval $(call _vs,ROOTDEV,LINUX))
FSTYPE ?= ext2
ROOTFS_UBOOT_SUFFIX := .cpio.uboot
ROOTFS_HARDDISK_SUFFIX := .$(FSTYPE)
ROOTFS_INITRD_SUFFIX := .cpio.gz
# Real one
BUILDROOT_ROOTDIR := $(ROOT_OUTPUT)/target
# As a temp variable
_BUILDROOT_ROOTDIR := $(ROOT_OUTPUT)/images/rootfs
BUILDROOT_UROOTFS := $(_BUILDROOT_ROOTDIR)$(ROOTFS_UBOOT_SUFFIX)
BUILDROOT_HROOTFS := $(_BUILDROOT_ROOTDIR)$(ROOTFS_HARDDISK_SUFFIX)
BUILDROOT_IROOTFS := $(_BUILDROOT_ROOTDIR)$(ROOTFS_INITRD_SUFFIX)
PREBUILT_ROOT_DIR ?= $(BSP_ROOT)/$(BUILDROOT)
PREBUILT_KERNEL_DIR ?= $(BSP_KERNEL)/$(LINUX)
PREBUILT_UBOOT_DIR ?= $(BSP_UBOOT)/$(UBOOT)/$(LINUX)
PREBUILT_QEMU_DIR ?= $(BSP_QEMU)/$(QEMU)
PREBUILT_ROOTDIR ?= $(PREBUILT_ROOT_DIR)/rootfs
PREBUILT_UROOTFS ?= $(PREBUILT_ROOTDIR)$(ROOTFS_UBOOT_SUFFIX)
PREBUILT_HROOTFS ?= $(PREBUILT_ROOTDIR)$(ROOTFS_HARDDISK_SUFFIX)
PREBUILT_IROOTFS ?= $(PREBUILT_ROOTDIR)$(ROOTFS_INITRD_SUFFIX)
# Check default rootfs type: dir, hardisk (.img, .ext*, .vfat, .f2fs, .cramfs...), initrd (.cpio.gz, .cpio), uboot (.uboot)
ROOTFS_TYPE_TOOL := tools/root/rootfs_type.sh
ROOTDEV_TYPE_TOOL := tools/root/rootdev_type.sh
PBR ?= 0
_PBR := $(PBR)
ifeq ($(_PBR), 0)
ifneq ($(BUILDROOT_IROOTFS),$(wildcard $(BUILDROOT_IROOTFS)))
ifeq ($(PREBUILT_IROOTFS),$(wildcard $(PREBUILT_IROOTFS)))
PBR := 1
endif
endif
endif
# Proxy kernel is built in buildroot
ifeq ($(PBR),0)
PKIMAGE := $(LINUX_PKIMAGE)
endif
# Prefer ROOTFS: command line > environment override > buildroot > prebuilt
ifeq ($(PBR),0)
ifeq ($(BUILDROOT_IROOTFS),$(wildcard $(BUILDROOT_IROOTFS)))
ROOTFS := $(BUILDROOT_IROOTFS)
IROOTFS := $(BUILDROOT_IROOTFS)
UROOTFS := $(BUILDROOT_UROOTFS)
HROOTFS := $(BUILDROOT_HROOTFS)
ROOTDIR := $(BUILDROOT_ROOTDIR)
endif
endif
BSP_SUBMODULE=$(shell grep $(BOARD)/bsp -q $(TOP_DIR)/.gitmodules; echo $$?)
ifeq ($(BSP_SUBMODULE),0)
ifneq ($(BSP_ROOT),$(wildcard $(BSP_ROOT)))
BSP_DOWNLOADED := 0
endif
endif
ROOTFS_TYPE := $(shell $(ROOTFS_TYPE_TOOL) $(ROOTFS))
ROOTDEV_TYPE := $(shell $(ROOTDEV_TYPE_TOOL) $(ROOTDEV))
# FIXME: workaround if the .cpio.gz or .ext2 are removed and only rootfs/ exists
ifeq ($(findstring not invalid or not exists,$(ROOTFS_TYPE)),not invalid or not exists)
ROOTFS := $(dir $(ROOTFS))
ROOTFS_TYPE := $(shell $(ROOTFS_TYPE_TOOL) $(ROOTFS))
endif
ifeq ($(findstring not invalid or not exists,$(ROOTFS_TYPE)),not invalid or not exists)
INVALID_ROOTFS := 1
endif
ifeq ($(findstring not support yet,$(ROOTDEV_TYPE)),not support yet)
INVALID_ROOTDEV := 1
endif
ifneq ($(MAKECMDGOALS),)
ifeq ($(filter $(MAKECMDGOALS),_boot root-dir-rebuild root-rd-rebuild root-hd-rebuild),$(MAKECMDGOALS))
ifeq ($(findstring $(BSP_DIR),$(ROOTFS)),$(BSP_DIR))
ifeq ($(BSP_DOWNLOADED),0)
# Allow download bsp automatically
INVALID_ROOTFS := 0
INVALID_ROOTDEV := 0
endif
endif
ifeq ($(INVALID_ROOTFS),1)
$(error rootfs: $(ROOTFS_TYPE), try run 'make bsp' to get newer rootfs.)
endif
ifeq ($(INVALID_ROOTDEV),1)
$(error rootdev: $(ROOTDEV_TYPE), try run 'make bsp' to get newer rootfs.)
endif
endif
endif
comma := ,
empty :=
space := $(empty) $(empty)
_ROOTFS_TYPE=$(subst $(comma),$(space),$(ROOTFS_TYPE))
FS_TYPE := $(firstword $(_ROOTFS_TYPE))
FS_PATH := $(word 2,$(_ROOTFS_TYPE))
FS_SUFFIX := $(word 3,$(_ROOTFS_TYPE))
# Buildroot use its own ROOTDIR in /target, not in images/rootfs
ifneq ($(ROOTFS), $(BUILDROOT_IROOTFS))
ifeq ($(FS_TYPE),dir)
ROOTDIR := $(FS_PATH)
else
ROOTDIR := $(FS_PATH:$(FS_SUFFIX)=)
endif
ifeq ($(FS_TYPE),rd)
IROOTFS := $(ROOTFS)
else
IROOTFS := $(ROOTDIR)$(ROOTFS_INITRD_SUFFIX)
endif
ifeq ($(FS_TYPE),hd)
HROOTFS := $(ROOTFS)
else
HROOTFS := $(ROOTDIR)$(ROOTFS_HARDDISK_SUFFIX)
endif
UROOTFS := $(ROOTDIR)$(ROOTFS_UBOOT_SUFFIX)
endif
_ROOTDEV_TYPE := $(subst $(comma),$(space),$(ROOTDEV_TYPE))
DEV_TYPE := $(firstword $(_ROOTDEV_TYPE))
# Board targets
BOARD_TOOL := ${TOOL_DIR}/board/show.sh
export GREP_COLOR=32;40
FILTER ?= ^[ [\./_a-z0-9-]* \]|^ *[\_a-zA-Z0-9]* *
# all: 0, plugin: 1, noplugin: 2
BTYPE ?= ^_BASE|^_PLUGIN
define getboardvars
cat $(BOARD_MAKEFILE) | egrep -v "^ *\#|ifeq|ifneq|else|endif|include |call |eval " | egrep -v "_BASE|_PLUGIN" | cut -d'?' -f1 | cut -d'=' -f1 | cut -d':' -f1 | tr -d ' '
endef
define showboardvars
echo [ $(BOARD) ]:"\n" $(foreach v,$(or $(VAR),$(or $(1),$(shell $(call getboardvars))))," $(v) = $($(v)) \n") | tr -s '/' | egrep --colour=auto "$(FILTER)"
endef
board: board-save plugin-save board-cleanstamp board-show
board-cleanstamp:
ifneq ($(BOARD),$(BOARD_CONFIG))
$(Q)make -s cleanstamp
endif
board-show:
$(Q)$(call showboardvars)
board-init: cleanstamp
board-clean:
$(Q)rm -rf .board_config
board-save:
ifneq ($(BOARD),)
ifeq ($(board),)
ifneq ($(BOARD),$(BOARD_CONFIG))
$(Q)$(shell echo "$(BOARD)" > .board_config)
endif
endif
endif
PHONY += board board-init board-clean board-save board-cleanstamp
board-edit:
$(Q)vim $(BOARD_MAKEFILE)
board-config: board-save cleanstamp
$(foreach vs, $(MAKEOVERRIDES), tools/board/config.sh $(vs) $(BOARD_MAKEFILE) $(LINUX);)
PHONY += board-config board-edit
# Permission preparation
perm:
sudo chown $(USER):$(USER) -R ./ /.git /configs /tools
# Plugin targets
ifeq ($(filter command line, $(origin P) $(origin PLUGIN)), command line)
ifeq ($(PLUGIN),)
PLUGIN_CLEAN = plugin-clean
endif
endif
plugin-save: $(PLUGIN_CLEAN)
ifneq ($(PLUGIN),)
ifeq ($(plugin),)
$(Q)$(shell echo "$(PLUGIN)" > .plugin_config)
endif
endif
plugin-clean:
$(Q)rm -rf .plugin_config
plugin: plugin-save
$(Q)echo $(PLUGIN)
plugin-list:
$(Q)find $(BOARDS_DIR) -maxdepth 3 -name ".plugin" | xargs -i dirname {} | xargs -i basename {} | cat -n
plugin-list-full:
$(Q)find $(BOARDS_DIR) -maxdepth 3 -name ".plugin" | xargs -i dirname {} | cat -n
PHONY += plugin-save plugin-clean plugin plugin-list plugin-list-full
# List targets for boards and plugins
INFO ?= raw
ifneq ($(INFO),raw)
define getboardlist
find $(BOARDS_DIR)/$(2) -maxdepth 3 -name "Makefile" -exec egrep -H "$(or $(1),$(BTYPE))" {} \; | sort -t':' -k2 | cut -d':' -f1 | sed -e "s%boards/\(.*\)/Makefile%\1%g"
endef
list:
$(Q)$(foreach x,$(shell $(call getboardlist)),make -s board-show b=$x VAR="ARCH CPU LINUX ROOTDEV";)
list-board:
$(Q)$(foreach x,$(shell $(call getboardlist)),make -s board-show b=$x VAR="ARCH";)
list-short:
$(Q)$(foreach x,$(shell $(call getboardlist)),make -s board-show b=$x VAR="ARCH LINUX";)
list-base:
$(Q)$(foreach x,$(shell $(call getboardlist,"^_BASE")),make -s board-show b=$x VAR="ARCH";)
list-plugin:
$(Q)$(foreach x,$(shell $(call getboardlist,"^_PLUGIN")),make -s board-show b=$x VAR="ARCH";)
list-full: