2 ############################################################
3 # source: param-load.shlib
4 # author: CottonCandyOwner(CottonCandyOwner@126.com)
6 ############################################################
8 # this file is used to load param defined in
9 # build/dest/dest-<dest>/*.
10 # before using func in toolchain.shlib, inc this file,
11 # and invoke one_dest_init() to load parameters in config
13 ############################################################
27 ######################
28 # section: common comment info
29 ######################
31 ######################
32 # section: variable define
33 ######################
37 ######################
38 # section: private function
39 ######################
41 buildimilist_dbgout
()
48 # fsyntax: buildparam_dbgout <output-string>
49 # fdesc: output string by dbgout switch.
53 if [[ ! "${dbgout_opt}" =~ buildparam_dbgout
]]; then
58 echo -ne "$@" >> ${OUTDIR}/buildparam.log
59 echo -ne "$@" >> ${OUTDIR}/buildinfo.log
68 ######################
69 # section: public function
70 ######################
73 # fsyntax: dbgout_construct_param
82 CXX_SRC_FILE_LIST_Y
=""
83 CPP_SRC_FILE_LIST_Y
=""
84 ASM_SRC_FILE_LIST_Y
=""
86 STATIC_LIB_FILE_LIST_Y
=""
89 for name
in $namelist; do
93 namelist
="${!ASFLAGS*}"
94 for name
in $namelist; do
98 namelist
="${!CFLAGS*}"
99 for name
in $namelist; do
103 namelist
="${!CXXFLAGS*}"
104 for name
in $namelist; do
108 namelist
="${!CPPFLAGS*}"
109 for name
in $namelist; do
113 namelist
="${!ARFLAGS*}"
114 for name
in $namelist; do
118 namelist
="${!LDFLAGS*}"
119 for name
in $namelist; do
131 [[ "$DEST_NAME" == general
]] && DEST_TYPE
=null
&& return
133 loadimi tools
/cmpl
/defination
/pkgdirs.imi
136 eval "DEST_CFG_DIR_NAME=\"${DEST_CFG_DIR_NAME_EVL}\""
137 eval "DEST_IMI_FILE=\"${DEST_IMI_FILE_EVL}\""
139 # echo "DEST_CFG_DIR_NAME_EVL = $DEST_CFG_DIR_NAME_EVL"
140 # echo "DEST_CFG_DIR_NAME = $DEST_CFG_DIR_NAME"
141 # echo "DEST_IMI_FILE_EVL = $DEST_IMI_FILE_EVL"
142 # echo "loadimi $DEST_IMI_FILE"
143 loadimi
$DEST_IMI_FILE
145 if [[ -z "${DEST_TYPE}" ]]; then
146 echo "[error] DEST_TYPE is NULL in $DEST_IMI_FILE."
150 # append [] on DEST_TYPE just for good looking.
151 if [[ "${DEST_TYPE:0:1}" == \
[ && "${DEST_TYPE: -1:1}" == \
] ]]; then
152 DEST_TYPE
="${DEST_TYPE:1:-1}"
156 load_file_with_pfx
()
160 local filelist
=$
(ls -1 $1* 2>/dev
/null
)
162 for file in $filelist; do
163 if strstr
"${file}" =~ \.imi$
; then
164 interpreter
="$(head -n 1 | grep -oE "loadimi
")"
165 test -n "$interpreter" && loadimi
${file} && continue
174 # fsyntax: one_dest_cflags_init <dest-name>
175 # fdesc: specified dest paramter load
177 one_dest_cflags_init
()
182 cd build
/dest
/dest-
$1
184 filelist
=$
(ls -1 FLAGS
* 2>/dev
/null
)
185 for file in $filelist; do
186 # echo load file $file
187 if strstr
"${file}" =~ \.imi$
; then
194 filelist
=$
(ls -1 ASFLAGS
* 2>/dev
/null
)
195 for file in $filelist; do
196 # echo load file $file
197 if strstr
"${file}" =~ \.imi$
; then
204 filelist
=$
(ls -1 CFLAGS
* 2>/dev
/null
)
205 for file in $filelist; do
206 # echo load file $file
207 if strstr
"${file}" =~ \.imi$
; then
214 filelist
=$
(ls -1 CXXFLAGS
* 2>/dev
/null
)
215 for file in $filelist; do
216 # echo load file $file
217 if strstr
"${file}" =~ \.imi$
; then
224 filelist
=$
(ls -1 CPPFLAGS
* 2>/dev
/null
)
225 for file in $filelist; do
226 # echo load file $file
227 if strstr
"${file}" =~ \.imi$
; then
236 buildparam_dbgout
"CFLAGS=$CFLAGS\n"
240 # fsyntax: one_dest_ldflags_init <dest-name>
241 # fdesc: specified dest paramter load
243 one_dest_ldflags_init
()
248 cd build
/dest
/dest-
$1
250 filelist
=$
(ls -1 ARFLAGS
* 2>/dev
/null
)
251 for file in $filelist; do
252 # echo load file $file
253 if strstr
"${file}" =~ \.imi$
; then
260 filelist
=$
(ls -1 LDFLAGS
* 2>/dev
/null
)
261 for file in $filelist; do
262 # echo load file $file
263 if strstr
"${file}" =~ \.imi$
; then
272 buildparam_dbgout
"LDFLAGS=$LDFLAGS\n"
276 # fsyntax: one_dest_cfg <dest-name>
277 # fdesc: specified dest paramter load
281 buildparam_dbgout
"###################################\n"
282 buildparam_dbgout
"###################################\n"
283 buildparam_dbgout
"one_dest_cfg($1)\n"
285 DEST_CFG_DIR_NAME
="dest-$1"
286 eval "DEST_CFG_DIR=\"${DEST_CFG_DIR_EVL}\""
289 # set | grep -E "^DST_FILE"
291 # set | grep -E "^SRC_FILE.*=$"
293 one_dest_cflags_init
"$@"
294 buildparam_dbgout
"===================== CFLAGS_DEF_LIST_Y=\"$CFLAGS_DEF_LIST_Y\"\n"
296 one_dest_ldflags_init
"$@"
298 buildparam_dbgout
"+++++++++++++++++++++ CFLAGS_DEF_LIST_Y=\"$CFLAGS_DEF_LIST_Y\"\n"
299 buildparam_dbgout
"===================== CFLAGS=\"$CFLAGS\"\n"
301 buildparam_dbgout
"+++++++++++++++++++++ CFLAGS=\"$CFLAGS\"\n"
305 # fsyntax: one_dest_srclist_init <dest-name>
306 # fdesc: specified dest paramter load
308 one_dest_srclist_init
()
310 # TBD: disable src-list load in init. load it before corresponding
311 # program language src file list compile.
313 # load src list files
314 # -src-file and -src-dir can be included in this loading.
316 strstr
! ${file} =~ .
+-src-.
+ && continue
317 # echo loadlist $file
319 done < <(ls -d -1 -f $DEST_CFG_DIR/{*.lst
,*.list
} 2>/dev
/null
)
322 # load LDFLAGS_LIBPATH.list
323 # buildparam_dbgout "STATIC_LIB_FILE_LIST=$STATIC_LIB_FILE_LIST\n "
324 eval "STATIC_LIB_FILE_LIST=\"${STATIC_LIB_FILE_LIST_FILE_EVL}\""
325 loadlist
$STATIC_LIB_FILE_LIST
329 # fsyntax: load_dest_cmpl_param_imi <dest>
330 # fdesc: this func should be invoked after one_dest_cfg().
332 load_dest_cmpl_param_imi
()
335 local DEST_CFG_DIR_NAME
=
337 # load global param define
338 loadimi tools
/cmpl
/defination
/cmpldest.imi
340 # load general param define in srcpkg
341 DEST_CFG_DIR_NAME
=dest-general
342 eval PARAMTERS_IMI_FILE
="\"$PARAMTERS_IMI_FILE_EVL\""
343 [[ -e $PARAMTERS_IMI_FILE ]] && loadimi
$PARAMTERS_IMI_FILE
345 # load one dest param define in srcpkg
346 DEST_CFG_DIR_NAME
="dest-$1"
347 eval PARAMTERS_IMI_FILE
="\"$PARAMTERS_IMI_FILE_EVL\""
348 [[ -e $PARAMTERS_IMI_FILE ]] && loadimi
$PARAMTERS_IMI_FILE
378 if [[ ${1} == 'TARGET' || ${1} == 'BUILD' || ${1} == 'HOST' ]]; then
384 for cmd
in $cmdlist; do
385 eval ${cmd}=\${${PFX}_${cmd}}
390 # fsyntax: one_dest_init <dest-name>
391 # fdesc: specified dest paramter load
395 [[ -z "$1" ]] && err
"specify the dest name to be init."
401 # some param in .imi file should be defined as _SYNTAX suffix.
402 # load by source, eval in code.
406 # init toolchain in auto, for compiler cmd infos in host/target.
410 echo =========================== 1 MACHTYPE
=$MACHTYPE
415 # load parameter files in one dest, .imi & .list.
420 # create $OUTDIR & $OBJDIR for compile.
422 eval mkdir
-p $OUTDIR $OBJDIR $HOSTBIN_DIR $GENCODE_OUTDIR $INSTPKG_OUTDIR
425 # update extname info if dest build type changed.
427 # inc ${SRCPKG_DIR_FULL}/tools/cmpl/defination/extname.imi
428 # loadimi tools/cmpl/defination/destdir.imi
432 load_dest_cmpl_param_imi
$1
433 one_dest_srclist_init
$1
435 # update toolchain cmd lnfo by Dest.imi
436 # set build type for compiler cross prefix.
437 [[ -n $DEST_BUILDTYPE ]] && set_cmplr
$DEST_BUILDTYPE
439 # declare -p CC TARGET_CC BUILD_CC HOST_CC
440 # declare -p CC TARGET_VERSION TARGET_CROSS DEST_BUILDTYPE
442 echo "[CMPL-DEST] $DEST_NAME"
443 buildparam_dbgout
"==================== DEST_BUILDTYPE=$DEST_BUILDTYPE\n"
444 buildparam_dbgout
"==================== CC=$CC\n"
447 # fsyntax: get_machtype <MACHINE> <OS> <INFO>
450 echo $@ |
tr ' ' '-' |
sed -E "s/^-//g; s/-$//g; s/--//g;"
455 local dir
="$(dirname $1)"
457 local toolchain
="$(echo ~/.cmplr/toolchain/)"
459 test ! -f "$cmplr" -a ! -f `which $cmplr` && echo "error: $cmplr is not a valid compiler" && return
461 unset MACHINE OS INFO TOOLCHAIN MACHTYPE
462 mkdir
-pv ~
/.cmplr
/toolchain
/
464 set -- $
(basename ${1} |
tr '-' ' ')
467 VER
="$(cmplr_ver $cmplr)"
468 if test "$#" = 1; then
470 elif test "$#" = 3; then
474 elif test "$#" = 4; then
479 elif test "$#" = 5; then
484 elif test "$#" = 6; then
491 MACHTYPE
="$(get_machtype ${MACHINE} ${OS} ${INFO})"
492 test -z "$MACHTYPE" && return # && MACHTYPE=$TOOLCHAIN
494 toolchain
="$toolchain/$TOOLCHAIN/${MACHTYPE}-${VER}.imi"
496 mkdir
-pv `dirname $toolchain`
498 test $?
!= 0 -o -s $toolchain && return
500 echo "MACHINE=\"$MACHINE\"" >> $toolchain
501 echo "OS=\"$OS\"" >> $toolchain
502 echo "INFO=\"$INFO\"" >> $toolchain
503 echo "VER=\"$VER\"" >> $toolchain
504 echo "MACHTYPE=\"$MACHTYPE\"" >> $toolchain
506 echo "DIR_PFX=\"$(dirname `which $cmplr`)\"" >> $toolchain
508 echo cross compiler
: $toolchain
515 test -n "$ARCH" && fname
=${ARCH}
516 test -n "$SYS" && fname
=${fname}-${$SYS}
517 test -n "$VENDOR" && fname
=${fname}-${VENDOR}
518 ls -1 ~
/.cmplr
/toolchain
/$TOOLCHAIN/${fname}* 2>/dev
/null
523 $(ls -1 ~/.cmplr/toolchain/$TOOLCHAIN/${fname}* 2>/dev/null)
535 TOOLCHAIN
=${TOOLCHAIN:-$TARGET_TOOLCHAIN}
536 test -n "$TOOLCHAIN" -a ! -f "$TOOLCHAIN" -a -z "$(which $TOOLCHAIN)" &&
537 echo "[HINT]: TOOLCHAIN = $TOOLCHAIN is not valid. use gcc instead." &&
539 TOOLCHAIN
=${TOOLCHAIN:-gcc}
541 ARCH
="${ARCH:-$TARGET_ARCH}"
542 SYS
="${SYS:-$TARGET_SYS}"
543 VENDOR
="${INFO:-$TARGET_VENDOR}"
544 VERSION
="${VER:-$TARGET_VERSION}"
545 toolchain
="$(get_cmplr_cfgfile)"
546 # declare -p toolchain TOOLCHAIN
547 # declare -p ARCH SYS VENDOR VERSION CMPLR
548 test -n "$toolchain" -a -f "$toolchain" && source $toolchain
549 test -z "$toolchain" && unset ARCH SYS VENDOR VERSION
552 # load cross compiler from envar.
554 # loadimi ${SRCPKG_DIR_FULL}/build/toolchain-cfg.imi
555 TARGET_CROSS
="${TARGET_CROSS:-$CROSS}"
556 for type in TARGET BUILD HOST
; do
557 if eval test -n \"\
${${type}_CROSS
}\"; then
558 if eval test -f \"\
${${type}_CROSS
}${TOOLCHAIN}\"; then
559 eval install_cmplr
\"\
${${type}_CROSS
}${TOOLCHAIN}\"
560 eval ${type}_MACHINE
=$MACHINE
562 eval ${type}_INFO
=$INFO
563 eval ${type}_VER
=$VER
564 eval ${type}_MACHTYPE
="$(get_machtype $MACHINE $OS $INFO $VER)"
565 eval ${type}_TOOLCHAIN
=$TOOLCHAIN
567 eval echo "cross compiler \${${type}_CROSS} does not valid."
572 unset MACHINE OS INFO VER
574 # cmd below are used for CROSS parameter checking.
575 # declare -p TARGET_MACHINE TARGET_OS TARGET_INFO TARGET_VER TARGET_MACHTYPE TARGET_TOOLCHAIN
576 # declare -p BUILD_MACHINE BUILD_OS BUILD_INFO BUILD_VER BUILD_MACHTYPE BUILD_TOOLCHAIN
577 # declare -p HOST_MACHINE HOST_OS HOST_INFO HOST_VER HOST_MACHTYPE HOST_TOOLCHAIN
579 echo =========================== MACHTYPE
=$MACHTYPE
581 inc
${SRCPKG_DIR_FULL}/tools
/cmpl
/platform
/toolchain_info.imi
583 echo =========================== MACHTYPE
=$MACHTYPE
585 # other build utilities.
586 #loadimi ../toolset/toolset.imi
589 toolchain_default_param_load
()
591 loadimi tools
/cmpl
/defination
/cmplparam.imi
592 loadimi tools
/cmpl
/defination
/cmpldest.imi
597 loadimi build
/toolchain-cfg.imi
602 ######################
604 ######################
628 param_imi_list
="PARAMTERS_IMI_FILE"
631 ARFLAGS_MISC_IMI_FILE
632 CFLAGS_DEF_LIST_FILE_Y
633 CFLAGS_INCPATH_LIST_FILE_Y
634 CFLAGS_MISC_IMI_FILE"
638 LDFLAGS_LIB_LIST_FILE
639 LDFLAGS_LIBPATH_LIST_FILE_Y
640 LDFLAGS_MISC_IMI_FILE"
643 # fsyntax: load_param_file_list <file-name-list-envar>
644 # fdesc: specified dest paramter load
646 load_param_file_list
()
648 # echo "load_param_file_list(${!1})"
649 for name
in ${!1}; do
650 if test -z $name || strstr
$name =~ ^
[[:blank
:]][#] ; then
655 # echo $name=${!name}
656 eval "local $name=\"\${${name}_EVL}\""
657 # buildparam_dbgout "param: $name=${!name}\n"
658 eval "$name=\"${!name}\""
659 # buildparam_dbgout "$name=${!name}\n"
661 [[ -z "${!name}" ]] && continue
663 if strstr
"${!name}" =~ \.imi$
; then