AQStack test code.
[reglxgmr.git] / tools / cmpl / shlib / param-load.shlib
blob15d227a990ad15173608d3f021384153f132bd3b
1 #!/bin/bash
2 ############################################################
3 # source: param-load.shlib
4 # author: CottonCandyOwner(CottonCandyOwner@126.com)
5 # date: 2023-02-15
6 ############################################################
7 # note:
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
12 # dir.
13 ############################################################
16 # todo£º
20 # TBD:
22 # @
25 inc porting.shlib
27 ######################
28 # section: common comment info
29 ######################
31 ######################
32 # section: variable define
33 ######################
37 ######################
38 # section: private function
39 ######################
41 buildimilist_dbgout ()
43 return
44 echo "$@"
48 # fsyntax: buildparam_dbgout <output-string>
49 # fdesc: output string by dbgout switch.
51 buildparam_dbgout ()
53 if [[ ! "${dbgout_opt}" =~ buildparam_dbgout ]]; then
54 return
57 echo -ne "$@"
58 echo -ne "$@" >> ${OUTDIR}/buildparam.log
59 echo -ne "$@" >> ${OUTDIR}/buildinfo.log
62 err ()
64 echo $@ >&2
65 exit -1
68 ######################
69 # section: public function
70 ######################
73 # fsyntax: dbgout_construct_param
74 # fdesc:
76 dest_param_reset ()
78 local name=
79 local namelist=
81 C_SRC_FILE_LIST_Y=""
82 CXX_SRC_FILE_LIST_Y=""
83 CPP_SRC_FILE_LIST_Y=""
84 ASM_SRC_FILE_LIST_Y=""
85 SH_SRC_FILE_LIST_Y=""
86 STATIC_LIB_FILE_LIST_Y=""
88 namelist="${!FLAGS*}"
89 for name in $namelist; do
90 eval $name=""
91 done
93 namelist="${!ASFLAGS*}"
94 for name in $namelist; do
95 eval $name=""
96 done
98 namelist="${!CFLAGS*}"
99 for name in $namelist; do
100 eval $name=""
101 done
103 namelist="${!CXXFLAGS*}"
104 for name in $namelist; do
105 eval $name=""
106 done
108 namelist="${!CPPFLAGS*}"
109 for name in $namelist; do
110 eval $name=""
111 done
113 namelist="${!ARFLAGS*}"
114 for name in $namelist; do
115 eval $name=""
116 done
118 namelist="${!LDFLAGS*}"
119 for name in $namelist; do
120 eval $name=""
121 done
123 INC_PKG=""
129 dest_info_init ()
131 [[ "$DEST_NAME" == general ]] && DEST_TYPE=null && return
133 loadimi tools/cmpl/defination/pkgdirs.imi
135 # load dest.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."
147 exit
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 ()
158 local file=
159 local interpreter=
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
166 sourceimi ${file}
167 else
168 loadlist ${file}
170 done
174 # fsyntax: one_dest_cflags_init <dest-name>
175 # fdesc: specified dest paramter load
177 one_dest_cflags_init ()
179 local dir=`pwd`
180 local filelist=
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
188 loadimi ${file}
189 else
190 loadlist ${file}
192 done
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
198 loadimi ${file}
199 else
200 loadlist ${file}
202 done
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
208 loadimi ${file}
209 else
210 loadlist ${file}
212 done
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
218 loadimi ${file}
219 else
220 loadlist ${file}
222 done
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
228 loadimi ${file}
229 else
230 loadlist ${file}
232 done
234 cd $dir 2>/dev/null
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 ()
245 local dir=`pwd`
246 local filelist=
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
254 loadimi ${file}
255 else
256 loadlist ${file}
258 done
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
264 loadimi ${file}
265 else
266 loadlist ${file}
268 done
270 cd $dir 2>/dev/null
272 buildparam_dbgout "LDFLAGS=$LDFLAGS\n"
276 # fsyntax: one_dest_cfg <dest-name>
277 # fdesc: specified dest paramter load
279 one_dest_cfg ()
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}\""
288 unsetenv DST_FILE
289 # set | grep -E "^DST_FILE"
290 unsetenv SRC_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.
312 if true; then
313 # load src list files
314 # -src-file and -src-dir can be included in this loading.
315 while read file; do
316 strstr ! ${file} =~ .+-src-.+ && continue
317 # echo loadlist $file
318 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 ()
334 local tmp=
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
352 set_cmplr ()
354 local cmdlist="
358 LINK
359 SLIB
360 DLIB
361 RANLIB
363 STRIP
364 OBJDUMP
365 OBJCOPY
366 READELF
368 SIZE
369 GCOV
371 GPROF
372 ADDR2LINE
374 CROSS"
376 local PFX=
378 if [[ ${1} == 'TARGET' || ${1} == 'BUILD' || ${1} == 'HOST' ]]; then
379 PFX=$1
380 else
381 return
384 for cmd in $cmdlist; do
385 eval ${cmd}=\${${PFX}_${cmd}}
386 done
390 # fsyntax: one_dest_init <dest-name>
391 # fdesc: specified dest paramter load
393 one_dest_init ()
395 [[ -z "$1" ]] && err "specify the dest name to be init."
397 DEST_NAME=${1}
400 # TBD:
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.
408 toolchain_init
410 echo =========================== 1 MACHTYPE=$MACHTYPE
412 dest_param_reset
415 # load parameter files in one dest, .imi & .list.
417 dest_info_init
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
430 one_dest_cfg general
431 one_dest_cfg $1
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>
448 get_machtype ()
450 echo $@ | tr ' ' '-' | sed -E "s/^-//g; s/-$//g; s/--//g;"
453 install_cmplr ()
455 local dir="$(dirname $1)"
456 local cmplr="$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 '-' ' ')
465 # echo $@
467 VER="$(cmplr_ver $cmplr)"
468 if test "$#" = 1; then
469 return
470 elif test "$#" = 3; then
471 MACHINE=$1
472 OS=$2
473 TOOLCHAIN=$3
474 elif test "$#" = 4; then
475 MACHINE=$1
476 OS=$2
477 INFO=$3
478 TOOLCHAIN=$4
479 elif test "$#" = 5; then
480 MACHINE=$1
481 OS=$3
482 INFO=$4
483 TOOLCHAIN=$5
484 elif test "$#" = 6; then
485 MACHINE=$1
486 OS=$3
487 INFO=$4
488 VER=${VER:-$5}
489 TOOLCHAIN=$6
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`
497 touch $toolchain
498 test $? != 0 -o -s $toolchain && return
499 echo > $toolchain
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
505 echo >> $toolchain
506 echo "DIR_PFX=\"$(dirname `which $cmplr`)\"" >> $toolchain
508 echo cross compiler: $toolchain
511 get_cmplr_cfgfile ()
513 local fname=
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
519 return
520 while read file; do
521 source $file
522 done << EOF
523 $(ls -1 ~/.cmplr/toolchain/$TOOLCHAIN/${fname}* 2>/dev/null)
527 toolchain_init ()
529 local type=
530 local toolchain=
533 # cross parameter
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." &&
538 TOOLCHAIN=
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
561 eval ${type}_OS=$OS
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
566 else
567 eval echo "cross compiler \${${type}_CROSS} does not valid."
568 exit
571 done
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
595 toolchain_ver_chk ()
597 loadimi build/toolchain-cfg.imi
602 ######################
603 # section: file tail
604 ######################
606 return
628 param_imi_list="PARAMTERS_IMI_FILE"
630 cflag_param_list="
631 ARFLAGS_MISC_IMI_FILE
632 CFLAGS_DEF_LIST_FILE_Y
633 CFLAGS_INCPATH_LIST_FILE_Y
634 CFLAGS_MISC_IMI_FILE"
636 ldflag_param_list="
637 DEP_PKG_LIST_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
651 continue;
654 # echo name=$name
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
664 loadimi ${!name}
665 else
666 loadlist ${!name}
668 done