-
Notifications
You must be signed in to change notification settings - Fork 27
/
Makefile
1457 lines (1313 loc) · 55 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
# Copyright 2017 IBM Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
# Advance Toolchain main Makefile
#
# This file is where all the build starts.
#
# Common targets:
# all - Default target. Build and package the Advance Toolchain.
# Options:
# DESTDIR - Specify the directory where the AT directory
# will be created, e.g.: DESTDIR=/opt
#
# AT_CONFIGSET - Indicates which config set to use.
# Possible values include the name of directories
# inside configs/, e.g.: AT_CONFIGSET=7.0
#
# BUILD_DEBUG_ON - Forces that all build stages be
# retained. Possible values are "yes" or "no".
# If set to "yes", all temporary build steps are
# retained, regardless of the package setting on
# ATCFG_HOLD_* variables.
#
# BUILD_ARCH - Specify which archicteture this toolchain
# will be targeting. Most config sets have their
# default values, but in same cases the config
# set is able to build toolchains for different
# architectures, e.g.: BUILD_ARCH=ppc64le or
# BUILD_ARCH=ppc64
#
# AT_MAKE_CHECK - Specify if package testing should be
# done during the build. Setting this to a value
# other than 'none' will enable testing for all
# packages that have atcfg_make_check defined in
# their stage file. This can be overridden at
# the package level by setting the value of
# ATSRC_PACKAGE_MAKE_CHECK in a package's
# source file. The values for this variable are:
# - none: do not enable package testing at the
# global level
# - strict_fail: Enable package testing at the
# global level and cause the build to fail if
# a package's testing fails.
# - silent_fail: Enable package testing at the
# global level but do not cause the build to
# fail if the package's testing fails.
#
# BUILD_IGNORE_COMPAT - Tells to ignore runtime-compat
# package building. If not provided, it's inferred
# by the contents of AT_OLD_KERNEL on the specific
# <distro>.mk config file.
#
# BUILD_IGNORE_AT_COMPAT - Tells to ignore atXX-compat
# package building. If not provided, it's inferred
# by the contents of other configset variables.
#
# pack - Create a tarball with all the source code necessary to build AT
# on another server.
#
# clone - Clone a config set, copying or symlinking its files.
# Options:
# FROM - Name of the config set being cloned.
#
# TO - Name of config set being create.
#
#
# test / fvtr - Runs the build and the FVTR test suite to validate it.
# Options:
# TEST_NAME - Name of a particular test suite case to
# run (this limits the test case run to this
# single test).
#
# Make sure we're running a recent enough GNU make version.'
ifneq (3.81,$(firstword $(sort $(MAKE_VERSION) 3.81)))
$(error "This file requires GNU make 3.81 or newer version.")
endif
# Set the proper shell to use
SHELL := /bin/bash
# Some shells don't load all the standard values (Ubuntu), so we have to
# manually set all those we need.
USER ?= $(shell whoami)
# Set some basic path information
AT_BASE ?= $(shell pwd)
CONFIG_ROOT := $(AT_BASE)/configs
SCRIPTS_ROOT := $(AT_BASE)/scripts
SCRIPTS_REPO := $(SCRIPTS_ROOT)/repository
HELPERS_ROOT := $(SCRIPTS_ROOT)/helpers
RPMSPEC_ROOT := $(SCRIPTS_ROOT)/specs
SKELETONS_ROOT := $(SCRIPTS_ROOT)/skeletons
UTILITIES_ROOT := $(SCRIPTS_ROOT)/utilities
FETCH_SOURCES := $(AT_BASE)/sources
FETCH_PATCHES := $(AT_BASE)/patches
# Define the build timestamp
AT_TODAY := $(shell date "+%Y%m%d")
# Define the format of the running timestamp
TIME := date -u +%Y-%m-%d_%H.%M.%S
# Only set build environment for targets other the 'clone', 'edit' and 'pack'
ifeq (,$(findstring $(MAKECMDGOALS),clone edit pack))
# Begin setting build environment *****
# *********************************************************
# Find the host arch where the AT is being build
HOST_ARCH := $(shell uname -m 2>&1)
# Check for the required config parameter (config path)
ifndef AT_CONFIGSET
AT_CONFIGSET := $(shell ls -d $(CONFIG_ROOT)/[0-9]*.[0-9] | awk -F '/' '{ print $$NF }' | sort -n | tail -1)
ifeq ($(AT_CONFIGSET),)
$(error Couldn't infer AT_CONFIGSET variable, and no hint was given... Bailing out!)
else
$(warning AT_CONFIGSET variable not informed... Using latest one ($(AT_CONFIGSET)).)
endif
endif
# Verify the setting of AT_MAKE_CHECK
AT_MAKE_CHECK ?= none
ifeq (,$(findstring $(AT_MAKE_CHECK),none strict_fail silent_fail))
$(warning unrecognized value for AT_MAKE_CHECK... value none assumed.)
AT_MAKE_CHECK := none
endif
CONFIG := $(CONFIG_ROOT)/$(AT_CONFIGSET)
CONFIG_SPEC := $(CONFIG)/specs
DEBH_ROOT := $(CONFIG)/deb
# Load all config directives for the build
include $(CONFIG)/base.mk
include $(CONFIG)/build.mk
include $(CONFIG)/sanity.mk
# Define a simple check for file validation
# $(call file_exists,<filename>)
define file_exists
if [[ -r $1 ]]; then \
echo "found"; \
else \
echo "none"; \
fi
endef
# Define a verification for progname
# $(call find_prg,<progname>)
define find_prg
for DIR in $$(echo $${PATH} | tr ":" "\t"); do \
if [[ -x "$${DIR}/$1" ]]; then \
echo "$${DIR}/$1"; \
break; \
fi; \
done
endef
# Assign some essential tools for the build to defines and verify its existence
# lsb_release
LSBTOOL := $(strip $(shell $(call find_prg,lsb_release)))
ifeq ($(LSBTOOL),)
LSBTOOL := $(UTILITIES_ROOT)/lsb_release
endif
# ld
GCC_LD := $(strip $(shell $(call find_prg,ld)))
ifeq ($(GCC_LD),)
$(error Program linker not found... Bailing out!)
endif
# as
GCC_AS := $(strip $(shell $(call find_prg,as)))
ifeq ($(GCC_AS),)
$(error Basic assembler not found... Bailing out!)
endif
# gcc
SYSTEM_CC := $(strip $(shell $(call find_prg,gcc)))
ifeq ($(SYSTEM_CC),)
$(error No gcc system toolchain installed... Bailing out!)
endif
# g++
SYSTEM_CXX := $(strip $(shell $(call find_prg,g++)))
ifeq ($(SYSTEM_CXX),)
$(error No g++ system toolchain installed... Bailing out!)
endif
# autoconf
AUTOCONF := $(strip $(shell $(call find_prg,autoconf)))
ifeq ($(AUTOCONF),)
$(error No autoconf installed... Bailing out!)
endif
# Load basic utilities
ifeq ($(strip $(shell $(call file_exists,$(HELPERS_ROOT)/utilities.mk))),found)
include $(HELPERS_ROOT)/utilities.mk
else
$(error Couldn't find the utilities helper macro... Bailing out!)
endif
# Collect the distro version in which it's being run
DISTRO_INFO := $(shell $(call get_distro_info))
DISTRO_ID := $(shell echo $(DISTRO_INFO) | cut -d ' ' -f 1)
DISTRO_AB := $(shell echo $(DISTRO_INFO) | cut -d ' ' -f 2)
DISTRO_FM := $(shell echo $(DISTRO_ID) | cut -d '-' -f 1)
DISTRO_FILE := $(CONFIG)/distros/$(DISTRO_ID).mk
export DISTRO_ID
# Check if the running distro is supported for builds
ifeq ($(strip $(shell $(call file_exists,$(DISTRO_FILE)))),found)
include $(DISTRO_FILE)
else
$(error Distro $(DISTRO_ID) not supported... Bailing out!)
endif
# When doing a cross build, if the executables should be 32 bit
# reset the HOST_ARCH from x86_64 to i686.
ifeq ($(HOST_ARCH),x86_64)
ifeq ($(BUILD_CROSS_32),yes)
HOST_ARCH := i686
endif
endif
# Prepare the SUB_MAKE variable to use in recipes sub make calls
export SUB_MAKE = $(MAKE)
# Set more path information
BUILD_ID := $(DISTRO_ID)_$(HOST_ARCH)_$(BUILD_ARCH)
# First things first... Check for general build sanity before proceeding
BASE_SANITY := $(strip $(shell $(call base_sanity)))
# Define some internal version name variables
AT_VER_REV := $(AT_MAJOR_VERSION)-$(AT_REVISION_NUMBER)
AT_MAJOR := $(AT_NAME)$(AT_MAJOR_VERSION)
ifeq ($(AT_INTERNAL),none)
AT_FULL_VER := $(AT_VER_REV)
else
AT_FULL_VER := $(AT_VER_REV)-$(AT_INTERNAL)
endif
AT_VER_REV_INTERNAL := $(AT_NAME)$(AT_FULL_VER)
# Macro to check the terminal in which we are being executed
define check_terminal
if [[ ! (("$${TERM:0:6}" == "screen" || $${#TMUX} -gt 0)) ]]; then \
echo "no_session"; \
else \
echo "session"; \
fi
endef
# Check which kind of terminal are we running on...
TERMINAL := $(shell $(call check_terminal))
# If its not a session safe terminal kind, issue a warning...
ifeq ($(TERMINAL),no_session)
$(warning **************************************************)
$(warning You are running this build from a bare shell...)
$(warning Please consider using screen or tmux for this.)
$(warning **************************************************)
endif
# Macro to get all packages name's
define get_package_list
for package in $$(find $(CONFIG)/packages/* -type d -print); do \
[[ -r $${package}/sources ]] && \
echo $$(basename $${package}); \
done
endef
# Macro to get all packages built.
# Extract the list from $(build_targets) variable.
define get_built_packages
$(sort $(foreach name,$(basename $(notdir $(build_targets))),\
$(shell echo $(name) | cut -d_ -f1)))
endef
# Export settings for the FVTR
# $(call build_fvtr_conf,<package_list>)
define build_fvtr_conf
AT_KERNEL=$(AT_KERNEL); \
utilities=$(UTILITIES_ROOT); \
echo "AT_NAME=\"${AT_NAME}\"" > $(CONFIG_EXPT); \
echo "AT_MAJOR_VERSION=\"${AT_MAJOR_VERSION}\"" >> $(CONFIG_EXPT); \
echo "AT_REVISION_NUMBER=\"${AT_REVISION_NUMBER}\"" >> $(CONFIG_EXPT); \
echo "AT_INTERNAL=\"${AT_INTERNAL}\"" >> $(CONFIG_EXPT); \
echo "AT_DEST=\"${AT_DEST}\"" >> $(CONFIG_EXPT); \
echo "AT_BUILD_ARCH=\"${BUILD_ARCH}\"" >> $(CONFIG_EXPT); \
echo "AT_CROSS_BUILD=\"${CROSS_BUILD}\"" >> $(CONFIG_EXPT); \
echo "AT_TARGET=\"${TARGET}\"" >> $(CONFIG_EXPT); \
echo "AT_HOST_ARCH=\"${HOST_ARCH}\"" >> $(CONFIG_EXPT); \
echo "AT_BUILD_LOAD_ARCH=\"${BUILD_LOAD_ARCH}\"" >> $(CONFIG_EXPT); \
echo "AT_OPTMD_LIBS=\"${BUILD_ACTIVE_MULTILIBS}\"" >> $(CONFIG_EXPT); \
for PKG in $1; do \
source $(CONFIG)/packages/$${PKG}/sources; \
PKG_NAME=$$(echo "$${PKG}" | awk '{print toupper($$0)}'); \
echo "AT_$${PKG_NAME}_VER=$${ATSRC_PACKAGE_VER}" >> $(CONFIG_EXPT); \
done; \
echo created
endef
# Pack the assigned source packages to include them into the distribution
# tarball
# $(call pack_source_pkgs,<package_list>)
define pack_source_pkgs
set -e; \
AT_KERNEL=$(AT_KERNEL); \
utilities=$(UTILITIES_ROOT); \
rm -f $(SRC_TAR_FILE); \
for PKG in $1; do \
source $(CONFIG)/packages/$${PKG}/sources; \
if [[ "$${ATSRC_PACKAGE_DISTRIB}" == "yes" ]]; then \
tar_pkgs="$${tar_pkgs} $$(basename $${ATSRC_PACKAGE_WORK})"; \
fi; \
unset $${!ATSRC_PACKAGE_*}; \
done; \
tar_pkgst=$$(echo $${tar_pkgs#$${tar_pkgs%%[![:space:]]*}}); \
tar cpzf $(SRC_TAR_FILE) -C $(SOURCE) $${tar_pkgst}; \
set +e
endef
# Define a logging macro for a given command
# $(call runandlog,<logfile>,<command>)
define runandlog
{ echo "Logging the following command at:"; \
date; \
echo; \
set -x; \
$2; \
ret=$${?}; \
set +x; \
echo; \
date; \
echo "-----------------------------------------------------"; \
} &>> $1
endef
# Create path if needed and return its name
# $(call mkpath,<pathname>,<force_clean>)
define mkpath
if [[ -n "$1" ]]; then \
fpath=$$(echo $1 | sed 's|//*|/|g'); \
if [[ -r $${fpath} ]]; then \
if [[ "$2" == "yes" ]]; then \
rm -rf $${fpath}/*; \
fi; \
elif [[ -e $${fpath} ]]; then \
echo "You can't access this path: $${fpath}. Aborting."; \
exit 1; \
else \
mkdir -p $${fpath}; \
fi; \
echo $${fpath}; \
unset fpath; \
else \
echo $1; \
fi
endef
# Find the number of SMT cores available
# $(call get_smt_cores)
define get_smt_cores
if [[ -r /proc/cpuinfo ]]; then \
CPU_TYPE=$$(cat /proc/cpuinfo | grep cpu | cut -f 2 -d ':' | sort -u | sed 's@^ @@' | cut -f 1 -d ' '); \
CORES_FOUND=$$(cat /proc/cpuinfo | grep "processor" | wc -l); \
echo $${CORES_FOUND}; \
else \
echo 0; \
fi
endef
# Sanity checks for ld and gcc
# $(call sanity_gcc)
define sanity_gcc
if [[ $$(gcc -v --help 2>&1 | grep secure-plt | wc -l) -eq 0 ]]; then \
echo "Failure. Host GCC is too old."; \
exit 1; \
fi
endef
# $(call sanity_ld)
define sanity_ld
if [[ $$($(GCC_LD) --help 2>&1 | grep bss-plt | wc -l) -eq 0 ]]; then \
echo "Failure. Host $(GCC_LD) is too old."; \
exit 1; \
fi
endef
# Create a script to call make again with the same arguments
# $(call create_remake)
define create_remake
echo "#/bin/bash" > remake.sh; \
echo -n "make DESTDIR='$(DESTDIR)'" >> remake.sh; \
echo -n " AT_CONFIGSET='$(AT_CONFIGSET)'" >> remake.sh; \
echo -n " BUILD_ARCH='$(BUILD_ARCH)'" >> remake.sh; \
echo -n " AT_DIR_NAME='$(AT_DIR_NAME)' \"\$${@}\"" >> remake.sh; \
chmod +x remake.sh; \
echo created
endef
# Set the required variables for optimized libraries targets.
#
# Parameters:
# 1. <component name>: Name of the component being built, e.g.: glibc
#
# Description:
# This macro filters the conditions to call provide_proc_tuned macro and
# clears the $(<component>_tuned-archdeps) variable.
# In the end the following variables will be properly configured:
# - tuned_targets
# - <component>_tuned-archdeps
# - <component>_<processor>-deps - only if necessary
# - <component>_<processor>-32-deps - only if necessary
# - <component>_<processor>-64-deps - only if necessary
#
# Example:
# $(call provide_tuneds,<component>)
define provide_tuneds
# Hack around an issue where foreach iterates over a null variable
ifneq ($(TUNED_PROCESSORS),)
# List this package as a dependency in the global tuned target
tuned-targets += $(RCPTS)/$(1)_tuned.rcpt
$(foreach proc,$(TUNED_PROCESSORS),\
$(eval $(call provide_proc_tuned,$(1),$(proc))))
$(1)_tuned-archdeps += $($(1)_tuned-32-archdeps) \
$($(1)_tuned-64-archdeps)
endif
endef
# Setup the variables of a optimized library according to the processor
# and depending on cross compiler settings.
#
# Parameters:
# 1. <component name>: Name of the component being built, e.g.: glibc
# 2. <processor>: Name of the processor to which this component is going to be
# optimized to, e.g.: power7
define provide_proc_tuned
ifeq (x$(CROSS_BUILD),xyes)
ifeq (x$(BUILD_TUNED_ON_CROSS),xyes)
$(call set_provides_arch_tuned,$(1),$(2))
endif
else
$(call set_provides_arch_tuned,$(1),$(2))
endif
endef
# Define the required variables of optimized libraries according to its target.
#
# Parameters:
# 1. <component name>: Name of the component being built, e.g.: glibc
# 2. <processor>: Name of the processor to which this component is going to be
# optimized to, e.g.: power7
# Check if this target doesn't require bi-arch tuned libs.
define set_provides_arch_tuned
ifdef $(1)_tuned-deps
$(1)_tuned-archdeps += $(RCPTS)/$(1)_$(2).tuned.b.rcpt
$(1)_$(2)-deps := $($(1)_tuned-deps)
else
ifdef BUILD_TARGET_ARCH32
$(1)_tuned-32-archdeps += $(RCPTS)/$(1)_$(2)-32.tuned.b.rcpt
$(1)_$(2)-32-deps := $($(1)_tuned-32-deps)
endif
ifdef BUILD_TARGET_ARCH64
$(1)_tuned-64-archdeps += $(RCPTS)/$(1)_$(2)-64.tuned.b.rcpt
$(1)_$(2)-64-deps := $($(1)_tuned-64-deps)
endif
endif
endef
# This macro filters and prepares the requirements for the given target_name
#
# Parameters:
# 1. <target_name>: This is the target name to base your requirements.
# 2. <kind_of_requires>: This is the kind of requires to define (multi =
# 32/64 deps, single = no 32/64 deps).
# 3. <cross_build>: This informs the inclusion of this dependency for cross
# builds (cross_yes = build on cross, cross_no = don't
# build on cross).
# 4. <skip_arch>: (Optional) This informs to skip this dependency for
# builds on given arch (skip_ppc64 = skip on ppc64 build,
# skip_ppc64le = skipe on ppc64le build).
#
# Description:
# This macro filters the conditions to call the set_provides_arch macro and
# clears the $(<target_name>-archdeps) variable.
#
# Example:
# $(call set_provides,<target_name>,<kind_of_requires>,<cross_build>[,<skip_arch>])
define set_provides
$(1)-archdeps :=
ifneq ($(CROSS_BUILD),yes)
ifneq ($(4),skip_$(BUILD_ARCH))
$(call set_provides_arch,$(1),$(2))
endif
else
ifeq ($(3),cross_yes)
$(call set_provides_arch,$(1),$(2))
endif
endif
endef
# This macro prepares the requirements for the given target_name
#
# Parameters:
# 1. <target_name>: This is the target name to base your requirements.
# 2. <kind_of_requires>: This is the kind of requires to define (multi =
# 32/64 deps, single = no 32/64 deps).
#
# Description:
# This macro defines the variables $(<target_name>-archdeps) that should be
# used to set the dependencies of the master target <target-name>. It also
# includes the target as a dependency to "all" through the variable
# $(build_targets)
#
# Example:
# $(call set_provides_arch,<target_name>,<kind_of_requires>,<cross_build>)
define set_provides_arch
ifeq ($(2),multi)
ifdef BUILD_TARGET_ARCH32
$(1)-archdeps += $(RCPTS)/$(1)-32.b.rcpt
endif
ifdef BUILD_TARGET_ARCH64
$(1)-archdeps += $(RCPTS)/$(1)-64.b.rcpt
endif
else
$(1)-archdeps := $(RCPTS)/$(1).b.rcpt
endif
build_targets += $(RCPTS)/$(1).rcpt
endef
define collect_logs
@fname=collected_logs-$(AT_VER_REV_INTERNAL).$(BUILD_ID)_$$($(TIME)).tar.gz; \
echo -e "$$($(TIME)) Collecting log information to $${fname}... "; \
{ unset commit_info; \
if [[ -f commit.info ]]; then \
cp -p commit.info $(AT_WD); \
commit_info="./commit.info"; \
fi; \
cd $(AT_WD) && \
tar czf collected_logs.tar.gz \
./logs/* ./dynamic $${commit_info} \
$$(find ./builds -name 'config.[hlms]*' -print); \
mv -f $(AT_WD)/collected_logs.tar.gz $(AT_BASE)/$${fname}; \
unset commit_info; \
} > /dev/null 2>&1; \
echo "$$($(TIME)) Log information collected!"
endef
# This is a simple heuristics to find out if we need to build the atXX-compat
# RPM package. It's loose and wide in tending to choose a build instead of a
# build denial (it considers "compat" and "supported" previous AT distros), so
# if you are sure that you must skip this package build, state it clearly on
# the config files (preferably on the distro.mk related file), or the check
# could be further restrained.
# Having said that, there is a quick description of its logic:
# We first collect all the supported and compat distros related to this build,
# and for each of them, (from earliest to oldest) we try to locate base support
# for it on the previous AT version. If base support is found, we try to
# identify if the particular build being done was supported (BE or LE). If it's
# found, we send back a "no" as a GO for the build of atXX-compat, otherwise,
# we send back a "yes" as a NO GO (ignore) for the build of atXX-compat.
# Note that we could restrain it further, looking only for AT previous
# "supported" distros, but I'm not sure that it's the correct path to follow.
define build_at_compat_rpm
compat_distros=$$(echo $(AT_COMPAT_DISTROS) \
$(AT_SUPPORTED_DISTROS) | \
sed 's|RHEL|redhat-|g' | \
sed 's|SLES_|suse-|g' | \
tr ' ' '\n' | sort -ru | tr '\n' ' '); \
if [[ -n "$${compat_distros}" ]]; then \
for distro in $${compat_distros}; do \
distro_file="$(CONFIG_ROOT)/$(AT_PREVIOUS_VERSION)/distros/$${distro}.mk"; \
if [[ -f $${distro_file} ]]; then \
supp_archs="$$(cat $${distro_file} | \
grep -o '^AT_SUPPORTED_ARCHS.*$$' | \
sed 's|AT_SUPPORTED_ARCHS := ||g') "; \
if [[ "$${supp_archs}" != "$${supp_archs/$(BUILD_ARCH) /}" ]]; then \
at_comp_found="true"; \
break; \
fi; \
fi; \
done; \
if [[ "$${at_comp_found}" == "true" ]]; then \
echo "no"; \
else \
echo "yes"; \
fi; \
else \
echo "yes"; \
fi
endef
# Copy files from $(1) to $(2) if it exists.
#
# Parameters:
# 1. <source file>: Name of the file to be copied.
# 2. <destination>: Destination where the source file will be saved.
define copy_if_exists
if [[ -n "$(1)" && -e "$(1)" ]]; then \
echo "- $$(basename $(1))"; \
cp $(1) $(2); \
fi
endef
# Create a path, if it fails try to use super-user permission.
# $(call sudo_mkdir, <pathname>)
define sudo_mkdir
if [[ ! (-r $1) ]]; then \
mkdir -p $1; \
if [[ ! (-r $1) ]]; then \
echo "Cannot create $1, trying as super-user..."; \
sudo mkdir -p $(1) && sudo chown "$${USER}." $(1); \
fi; \
fi
endef
# Define the installation path
# DESTDIR, is optional and should be externally defined.
DESTDIR ?= /opt
# Canonicalize DESTDIR path
DESTDIR := $(shell readlink -m "${DESTDIR}")
ifneq ($(AT_INTERNAL),none)
AT_MAJOR_INTERNAL := $(AT_MAJOR)-$(AT_INTERNAL)
AT_DIR_NAME ?= $(AT_VER_REV_INTERNAL)
else
AT_MAJOR_INTERNAL := $(AT_MAJOR)
AT_DIR_NAME ?= $(AT_MAJOR)
endif
AT_DEST := $(shell echo $(DESTDIR)/$(AT_DIR_NAME) | sed 's|//*|/|g')
MESSAGE := $(shell $(call sudo_mkdir,$(AT_DEST)))
ifneq ($(MESSAGE),)
$(warning $(MESSAGE))
endif
ifeq ($(strip $(shell $(call file_exists,$(AT_DEST)))),none)
$(error Couldn't create directory $(AT_DEST)... Bailing out!)
endif
# If the user wants to use a prespecified AT_BUILD we don't care. Otherwise we
# use the current working directory.
AT_WD ?= $(AT_BASE)/$(AT_VER_REV_INTERNAL).$(BUILD_ID)
# Define the actual TEMP_INSTALL path to use on build
TEMP_INSTALL := $(AT_BASE)/tmp.$(AT_VER_REV_INTERNAL).$(BUILD_ID)
# Prepare the list of all packages
PACKAGES_LIST := $(strip $(shell $(call get_package_list)))
# Prepare the tuned processors and libs list
TUNED_PROCESSORS := $(sort $(BUILD_ACTIVE_MULTILIBS))
# Define and create the build structure folders
LOGS := $(strip $(shell $(call mkpath,$(AT_WD)/logs,no)))
RPMS := $(strip $(shell $(call mkpath,$(AT_WD)/rpms,no)))
DEBS := $(strip $(shell $(call mkpath,$(AT_WD)/debs,no)))
PACKS := $(strip $(shell $(call mkpath,$(AT_WD)/tarball,no)))
RCPTS := $(strip $(shell $(call mkpath,$(AT_WD)/receipts,no)))
BUILD := $(strip $(shell $(call mkpath,$(AT_WD)/builds,no)))
SOURCE := $(strip $(shell $(call mkpath,$(AT_WD)/sources,no)))
DYNAMIC_ROOT := $(strip $(shell $(call mkpath,$(AT_WD)/dynamic,no)))
DYNAMIC_SPEC := $(strip $(shell $(call mkpath,$(DYNAMIC_ROOT)/spec,no)))
DYNAMIC_LOAD := $(strip $(shell $(call mkpath,$(DYNAMIC_ROOT)/load,no)))
TEMP_INSTALL := $(strip $(shell $(call mkpath,$(TEMP_INSTALL),no)))
ifeq ($(AT_USE_FEDORA_RELNAM),yes)
RELNOT_FILE := $(RPMS)/release_notes.$(AT_NAME)-$(AT_FULL_VER).tmp
SRC_TAR_FILE := $(PACKS)/$(AT_NAME)-src-$(AT_FULL_VER).tgz
else
RELNOT_FILE := $(RPMS)/release_notes.$(AT_MAJOR_INTERNAL)-$(AT_VER_REV).tmp
SRC_TAR_FILE := $(PACKS)/advance-toolchain-$(AT_MAJOR_INTERNAL)-src-$(AT_VER_REV).tgz
endif
# Name of the exported config file.
CONFIG_EXPT := $(DYNAMIC_ROOT)/config_$(AT_VER_REV_INTERNAL).$(BUILD_ID)
# Define some fetch folder structure
FETCH_SOURCES := $(strip $(shell $(call mkpath,$(FETCH_SOURCES),no)))
FETCH_PATCHES := $(strip $(shell $(call mkpath,$(FETCH_PATCHES),no)))
# If everything is fine until here, load some more defines with macros
# to help the build process
ifeq ($(strip $(shell $(call file_exists,$(HELPERS_ROOT)/rsync_and_patch.mk))),found)
include $(HELPERS_ROOT)/rsync_and_patch.mk
else
$(error Couldn't find the rsync_and_patch helper macro... Bailing out!)
endif
ifeq ($(strip $(shell $(call file_exists,$(HELPERS_ROOT)/build_stage.mk))),found)
include $(HELPERS_ROOT)/build_stage.mk
else
$(error Couldn't find the build_stage helper macro... Bailing out!)
endif
ifeq ($(strip $(shell $(call file_exists,$(HELPERS_ROOT)/standard_buildf.mk))),found)
include $(HELPERS_ROOT)/standard_buildf.mk
else
$(error Couldn't find the standard_buildf helper macro... Bailing out!)
endif
# Check the number of cores on the build machine
NUM_CORES := $(strip $(shell $(call get_smt_cores)))
ifeq ($(NUM_CORES),0)
$(error Couldn't find the number of cores available... Bailing out!)
endif
# Load architecture dependent settings.
ifeq ($(strip $(shell \
$(call file_exists, \
$(CONFIG)/arch/$(HOST_ARCH).$(BUILD_ARCH).mk))), \
found)
include $(CONFIG)/arch/$(HOST_ARCH).$(BUILD_ARCH).mk
else
$(error Build on host $(HOST_ARCH) targeting $(BUILD_ARCH) is not supported.)
endif
ifneq ($(strip $(shell $(call create_remake))),created)
$(error Failed to create remake.sh. Bailing out!)
endif
# Run distro sanity check to validate the build system
ifdef distro_sanity
ifeq ($(CROSS_BUILD),yes)
AT_PKGS_CHECK := $(sort $(AT_CROSS_PKGS_REQ) $(AT_COMMON_PKGS_REQ))
AT_PGMS_CHECK := $(sort $(AT_CROSS_PGMS_REQ) $(AT_COMMON_PGMS_REQ))
else
AT_PKGS_CHECK := $(sort $(AT_NATIVE_PKGS_REQ) $(AT_COMMON_PKGS_REQ))
AT_PGMS_CHECK := $(sort $(AT_NATIVE_PGMS_REQ) $(AT_COMMON_PGMS_REQ))
endif
PKG_DISTRO_SANITY := $(strip $(shell $(call check_packages,$(AT_PKGS_CHECK))))
PGM_DISTRO_SANITY := $(strip $(shell $(call check_programs,$(AT_PGMS_CHECK))))
ifeq ($(PKG_DISTRO_SANITY),abort)
$(error Missing critical requirements for the build process to proceed. Check ./sanity.log for a detailed missing requirements description.)
endif
ifeq ($(PGM_DISTRO_SANITY),abort)
$(error Missing critical requirements for the build process to proceed. Check ./sanity.log for a detailed missing requirements description.)
endif
endif
# Determine the BUILD_IGNORE_COMPAT if still undefined and set it based on
# distro.mk AT_OLD_KERNEL. If AT_OLD_KERNEL isn't defined there, there is no
# compatibility version to build to.
ifeq ($(AT_OLD_KERNEL),)
BUILD_IGNORE_COMPAT ?= yes
else
BUILD_IGNORE_COMPAT ?= no
endif
# If BUILD_IGNORE_AT_COMPAT if still undefined, we try to set it based on
# a heuristics to check the requirement of its build. We must keep in mind
# that there is no clear rule to dismiss the creation of this package, so in
# this heuristics, we try to be as wide and loose as possible to include the
# build of this package. If it's required *not* to build it, please be
# explicit, setting this override on the build process itself, or on the global
# build.mk or on the specific distro.mk file of the build.
ifeq ($(BUILD_IGNORE_AT_COMPAT),)
ifneq ($(AT_PREVIOUS_VERSION),)
BUILD_IGNORE_AT_COMPAT := $(shell $(call build_at_compat_rpm))
else
BUILD_IGNORE_AT_COMPAT := yes
endif
endif
# If it was defined that the atXX-compat rpm package should be build, we must
# guarantee that there is a previous AT version defined to base this build. If
# it is defined, we should set the variables used for the atXX-compat spec
# file, otherwise, we must print a warning message and abort the build due to
# missing critical information on the config files.
ifneq ($(BUILD_IGNORE_AT_COMPAT),yes)
ifeq ($(AT_PREVIOUS_VERSION),)
$(warning No AT_PREVIOUS_VERSION defined, so we can't build the atXX-compat package.)
$(warning If you need to do so, please configure the AT_PREVIOUS_VERSION properly and)
$(warning run the build again.)
$(error Aborting build due to missing required config information...)
else
BUILD_OLD_AT_VERSION := $(AT_PREVIOUS_VERSION)
BUILD_OLD_AT_INSTALL := $(strip $(shell echo $(AT_DEST) | sed "s/$(AT_DIR_NAME)/at$(AT_PREVIOUS_VERSION)/"))
endif
endif
# Determine the default system Toolchain to use
ifeq ($(CROSS_BUILD),no)
# Run a test compilation to verify the system toolchain
DEFAULT_COMPILER := $(shell \
echo "int main() { return 0; }" > ./sample.c; \
$(SYSTEM_CC) ./sample.c; \
echo $$(readelf -h a.out | grep "Class:" | sed 's|^.*ELF||'); \
rm -f ./sample.c ./a.out \
)
# Find out which CPU we are doing the build
AT_BUILD_CPU := $(shell cat /proc/cpuinfo | grep '^cpu' | cut -d ':' -f 2 | sort -u | sed 's@^ @@g' | cut -d ' ' -f 1 | tr [:upper:] [:lower:])
else
SYSTEM_CC := $(SYSTEM_CC) -m$(ENV_BUILD_ARCH)
SYSTEM_CXX := $(SYSTEM_CXX) -m$(ENV_BUILD_ARCH)
DEST_CROSS ?= $(strip $(shell $(call mkpath,$(AT_DEST)/ppc,no)))
endif
# Make sure the environment won't affect the build.
# Under some circumstances if PYTHONPATH is defined, it may break the builds
# or the tests of python and gdb.
unexport PYTHONPATH
endif
# *********************************************************
# Finish setting build environment *****
# Continue processing for targets 'clone', 'edit' and 'pack'
# Directories where artifacts created by this system will be saved after
# running collect-artifacts.
ARTIFACTS := $(strip $(shell $(call mkpath,$(AT_BASE)/artifacts,yes)))
# Default
build_targets :=
.DEFAULT_GOAL := all
.PHONY: all test destclean cleanall clean collect clone edit pack
all: package release
test: fvtr tarball_test
fvtr: $(RCPTS)/fvtr.rcpt
$(RCPTS)/fvtr.rcpt: $(RCPTS)/package.rcpt
@echo "$$($(TIME)) Running FVTR for $(AT_VER_REV_INTERNAL)..."
@+{ cd fvtr; \
AT_WD=$(AT_WD) \
AT_PREVIOUS_VERSION=$(AT_PREVIOUS_VERSION) \
AT_DIR_NAME=$(AT_DIR_NAME) \
./fvtr.sh -f \
$(DYNAMIC_ROOT)/config_$(AT_VER_REV_INTERNAL).$(BUILD_ID) \
$(TEST_NAME) \
2>&1 \
| tee $(LOGS)/test-suite_$(AT_VER_REV_INTERNAL).$(BUILD_ID).log; \
test "$${PIPESTATUS[0]}" -eq "0"; \
};
tarball_test: $(RCPTS)/source_tarball.rcpt
@+{ echo "$$($(TIME)) Checking the source tarball..."; \
if [[ "$(CROSS_BUILD)" == "no" ]]; then \
$(call runandlog,$(LOGS)/_tarball_check.log,$(UTILITIES_ROOT)/check_tarball.sh $(AT_MAJOR_VERSION) $(SRC_TAR_FILE)); \
if [[ $${ret} -ne 0 ]]; then \
echo "Problem checking source tarball."; \
exit 1; \
fi; \
fi; \
echo "$$($(TIME)) Completed source tarball check!"; \
};
clean: destclean
cleanall: destclean
@echo "$$($(TIME)) Cleaning pristine sources and patches..."
@echo "- $(FETCH_SOURCES)"
@rm -rf $(FETCH_SOURCES)
@echo "- $(FETCH_PATCHES)"
@rm -rf $(FETCH_PATCHES)
destclean: localclean
@echo "$$($(TIME)) Removing installation from $(AT_DEST)..."
@echo "- $(AT_DEST)"
@rm -rf $(AT_DEST)/*
@+{ rmdir $(AT_DEST); \
if [[ -e $(AT_DEST) ]]; then \
echo "Cannot remove $(AT_DEST), trying as super-user..."; \
sudo rmdir $(AT_DEST); \
fi; \
};
clean-fvtr: $(RCPTS)/collect-fvtr.rcpt
@echo "$$($(TIME)) Cleaning FVTR logs... "
@find fvtr/ -name '*.log' -delete
@echo "$$($(TIME)) Cleaning FVTR output files... "
@find fvtr/ -name '*.out*' -delete
clean-temp:
@echo "$$($(TIME)) Cleaning $(TEMP_INSTALL)"
@rm -rf ${TEMP_INSTALL}
localclean: collect clean-temp clean-fvtr
@echo "$$($(TIME)) Cleaning build related folders..."
@echo "- $(AT_WD)"
@rm -rf $(AT_WD)
@echo "- $(FETCH_SOURCES)/*.lock"
@rm -rf $(FETCH_SOURCES)/*.lock
@echo "- $(FETCH_PATCHES)/*.lock"
@rm -rf $(FETCH_PATCHES)/*.lock
@echo "- $(AT_BASE)/remake.sh"
@rm -f $(AT_BASE)/remake.sh
@echo "- $(AT_BASE)/sanity.log"
@rm -f $(AT_BASE)/sanity.log
collect: collect-fvtr
$(call collect_logs)
collect-fvtr: $(RCPTS)/collect-fvtr.rcpt
# Copy all generated files (packages, source code tarball, config file, logs,
# etc.) to the directory specified by ARTIFACTS.
# This is useful for the BuildBot in order to find all of these files in a
# standard place.
collect-artifacts:
@echo "$$($(TIME)) Collecting artifacts..."
@$(call copy_if_exists,$(CONFIG_EXPT),$(ARTIFACTS))
@$(call copy_if_exists,$(AT_BASE)/sanity.log,$(ARTIFACTS))
@$(call copy_if_exists,$(shell ls -t $(AT_BASE)/collected_logs-* \
| head -n 1),\
$(ARTIFACTS));
@$(call copy_if_exists,$(RELNOT_FILE),$(ARTIFACTS))
@$(call copy_if_exists,$(SRC_TAR_FILE),$(ARTIFACTS))
@{ \
for pkg in $(RPMS)/$(HOST_ARCH)/* $(DEBS)/*.deb; do \
$(call copy_if_exists,$${pkg},$(ARTIFACTS)); \
done; \
unset pkg; \
}
# This rule updates the revision of all "config/source" files of AT to the
# latest commit. Alternatively, you may update a specific package, passing
# the name as a parameter. See update_revision.sh for more information.
#
# usage:
# make DESTDIR=~ AT_CONFIGSET=next update-revision <package_name>
update-revision:
@+{ packages=$(filter-out $@,$(MAKECMDGOALS)); \
if [[ -z "$${packages}" ]]; then \
packages="$(filter-out kernel,$(FETCH_PACKAGE_LIST))"; \
fi; \
for pkg in $${packages}; do \
. $(UTILITIES_ROOT)/update_revision.sh $(CONFIG)/packages/$${pkg}/sources; \
done; \
}
# Defining an empty rule whenever update-revision is defined. This allows us to
# pass parameters to the update-revision rule.
ifeq (update-revision,$(firstword $(MAKECMDGOALS)))
%:
@:
endif
clone:
@+{ if [[ -n "$(FROM)" && -n "$(TO)" ]]; then \
echo "$$($(TIME)) Cloning config from $(FROM) to $(TO)..."; \
{ pushd "$(CONFIG_ROOT)"; \
find $(FROM) -type d -print | sed 's/^$(FROM)*/$(TO)/g' | xargs mkdir -p; \
contents=$$(find $(FROM) ! -type d -print); \
for source in $${contents}; do \
target=$$(echo $${source} | sed 's/^$(FROM)/$(TO)/g'); \
if [[ -n "$$(echo $${source} | grep '\/distros\/.*$$')" ]]; then \
if [[ -n "$$(ls -l $${source} | grep '^l')" ]]; then \
if [[ -z "$$(readlink $${source} | grep -E '^\.\.\/')" ]]; then \
cp -a $${source} $${target}; \
continue; \
fi; \
fi; \
fi; \
if [[ -n "$$(echo $${source} | grep -e '\/base.mk' -e '\/build.mk' -e '\/sanity.mk')" ]]; then \
cp -a $${source} $${target}; \
continue; \
fi; \
prefix=$$(dirname $$(echo $${source} | sed -e 's/[^\/]\+\//\.\.\//g')); \
ln -sf $${prefix}/$${source} $${target}; \
done; \
popd; \
} > /dev/null 2>&1; \
else \
echo "Please inform FROM=<version> TO=<version>."; \
fi; \
}
edit:
@+{ if [[ -n "$(FROM)" && -n "$(TYPE)" ]]; then \
echo "$$($(TIME)) Materializing config files of type $(TYPE) of config version $(FROM)..."; \
{ pushd "$(CONFIG_ROOT)/$(FROM)/$(TYPE)"; \
if [[ -n "$(FILE)" ]]; then \
cp -L $(FILE) $(FILE).orig && rm -rf $(FILE) && mv $(FILE).orig $(FILE); \
else \
for file in $$(find . -type l -print); do \
cp -L $${file} $${file}.orig && rm -rf $${file} && mv $${file}.orig $${file}; \
done; \
fi; \
popd; \
} > /dev/null 2>&1; \
else \
echo "Please inform at least FROM=<version> TYPE=<sublevel_type>."; \
fi; \
}
# Generate a pack for usage on a build pack area
pack: hash
@echo "$$($(TIME)) Preparing the build pack..."