improve of cmpl.
[bush.git] / tools / build-srcpkg-bak-20240503 / shlib / worklist.shlib
blobca73fddec4ec248179d84d87354465e8e8d4768c
1 #!/bin/bash
2 ############################################################
3 # source: worklist.shlib
4 # author: devenkong(18151155@qq.com)
5 # date: 2024-01-01
6 ############################################################
7 # Copyright (C) 2022- Free Software Foundation, Inc.
8 # This configure script is free software; the Free Software
9 # Foundation gives unlimited permission to copy, distribute
10 # and modify it.
11 ############################################################
12 # note:
13 # this file is the supporting libarary for bulid-step.
15 ############################################################
19 # todoļ¼š
20 # @ modify prefix CATA_ID_ to <XXX>_CID_, and change code in relative
21 # functions. use create catalog id function to create/release a catalog
22 # id. so, thare are more then one catalog id can work in a time.
23 # todo: to be tested
26 #. shlibinc
28 #include stdio.shlib
29 #include gplib.shlib
33 ##############################
34 # section: public comment info
35 ##############################
39 ##############################
40 # section: variable define
41 ##############################
44 shlib_worklist_init ()
49 shlib_worklist_init
52 # global variable init function invoking.
53 # invoke GVAR_INIT if it is running at first time.
55 #GVAR_INIT worklist
58 ##############################
59 # section: private function
60 ##############################
62 infoo ()
64 echo -ne "$@\n"
68 # fsyntax: cmpl_dbgout <srcfile> <dstfile>
69 # fdesc: display compile info.
71 cmpl_dbgout ()
73 infoo " [CC] $1 => $(basename ${1%.*}.o)"
77 # fsyntax: link_dbgout <srcfile> <dstfile>
78 # fdesc: display link info.
80 link_dbgout ()
82 local DST_FILE="${OUTDIR}/${!2}"
83 local SRC_FILE=( $OBJ_LIST )
84 local tmp=
86 if test "$((${#SRC_FILE[@]} + ${#STATIC_LIB_LIST_Y[@]}))" -gt 10 ; then
87 infoo " [LINK] ${SRC_FILE[0]} ... ${SRC_FILE[$((${#SRC_FILE[@]}-1))]}"
88 else
89 tmp="${SRC_FILE[@]} ${STATIC_LIB_LIST_Y[@]}"
90 tmp="${tmp//$'\n'/ }"
91 # XXX:
92 tmp="$(echo ${tmp} | sed -e 's/[[:space:]]+/ /g')"
93 infoo " [LINK] ${tmp//\ /$'\n '}"
96 if test "${DEST_TYPE,,}" == 'libdll' ; then
97 infoo " [LINK] => $(basename ${DST_FILE%\.*}).a"
98 infoo " [LINK] => $(basename ${DST_FILE%\.*}).so"
99 else
100 infoo " [LINK] => $(basename ${DST_FILE})"
105 # fsyntax: src2exe_dbgout <srcfile> <dstfile>
106 # fdesc: display compile info.
108 src2exe_dbgout ()
110 infoo " [EXE] $1 => $(basename ${1%%.*})"
113 warn ()
115 echo "[warn]: $@"
118 dbgoutd ()
120 echo "$@" >&2
125 # fsyntax: taskinfo_dbgout <output-string>
126 # fdesc: output string by dbgout switch.
128 taskinfo_dbgout ()
130 if [[ ! "${dbgout_opt}" =~ taskinfo ]]; then
131 return
134 dbgoutd "$@"
135 echo -ne "$@" >> ${OUTDIR}/buildinfo.log
136 return
140 # fsyntax: taskfunc_dbgout <output-string>
141 # fdesc: task func info.
143 taskfunc_dbgout ()
145 local pfx=
146 local i=
148 if [[ ! "${dbgout_switch}" =~ taskfunc ]]; then
149 return
152 for ((i=0; i<$task_level; i++)); do
153 pfx+="="
154 done
156 dbgoutd "${pfx}>$@"
157 echo -ne "${pfx}>$@" >> ${OUTDIR}/buildstep.log
158 [[ "${dbgout_switch}" =~ taskinfo ]] && echo -ne "${pfx}>$@" >> ${OUTDIR}/buildinfo.log
159 return
163 # fsyntax: taskstep_dbgout <output-string>
164 # fdesc: used for task info output, and it can be setted in
165 # build_step_dbgout_list.
167 taskstep_dbgout ()
169 local pfx=
170 local i=
171 local step=$1
173 if [[ ! "${dbgout_switch}" =~ taskstep ]]; then
174 return
177 [[ -z $1 ]] && err "taskstep_dbgout() invoked without parameter." && return
178 # step info filter by env.
179 if [[ -n $build_step_dbgout_list && ! "${build_step_dbgout_list}" =~ "$1" ]]; then
180 return
181 else
182 if [[ -n $build_step_dbgout_dis_list && "${build_step_dbgout_dis_list}" =~ "$1" ]]; then
183 return
186 shift
187 [[ -z $1 ]] && err "taskstep_dbgout() invoked without parameter." && return
189 for ((i=0; i<$task_level; i++)); do
190 pfx+="="
191 done
193 dbgoutd "${pfx}>$@"
194 echo -ne "${pfx}>$@" >> ${OUTDIR}/buildstep.log
195 [[ "${dbgout_switch}" =~ taskinfo ]] && echo -ne "${pfx}>$@" >> ${OUTDIR}/buildinfo.log
196 return
200 # fsyntax: tasklist_dbgout <output-string>
201 # fdesc: used for tasklist info output.
203 tasklist_dbgout ()
205 local pfx=
206 local i=
208 if [[ ! "${dbgout_switch}" =~ tasklist ]]; then
209 return
212 for ((i=0; i<$task_level; i++)); do
213 pfx+="="
214 done
216 dbgoutd "${pfx}>$@"
217 echo -ne "${pfx}>$@" >> ${OUTDIR}/buildstep.log
218 [[ "${dbgout_switch}" =~ taskinfo ]] && echo -ne "${pfx}>$@" >> ${OUTDIR}/buildinfo.log
219 return
223 # fsyntax: buildstep_dbgout <output-string>
224 # fdesc: used in build step func.
226 buildstep_dbgout ()
228 local pfx=
229 local i=
231 if [[ ! "${dbgout_switch}" =~ buildstep ]]; then
232 return
235 for ((i=0; i<$task_level; i++)); do
236 pfx+="="
237 done
239 echo -ne "${pfx}>$@"
240 echo -ne "${pfx}>$@" >> ${OUTDIR}/buildstep.log
241 [[ "${dbgout_switch}" =~ taskinfo ]] && echo -ne "${pfx}>$@" >> ${OUTDIR}/buildinfo.log
242 return
246 # fsyntax: info_dbgout_init <output-string>
247 # fdesc: init debug out info.
249 info_dbgout_init ()
251 task_level=0
252 # echo "info_dbgout_init()"
253 [[ -z ${OUTDIR} ]] && err "\${OUTDIR} is NULL string.\n" && return
255 mkdir -p "${OUTDIR}"
256 # echo \${OUTDIR}=${OUTDIR}
259 if [[ "${dbgout_switch}" =~ buildstep|taskstep ]]; then
260 echo > ${OUTDIR}/buildstep.log
263 if [[ "${dbgout_switch}" =~ taskinfo ]]; then
264 echo > ${OUTDIR}/buildinfo.log
267 if [[ "${dbgout_switch}" =~ buildparam ]]; then
268 echo > ${OUTDIR}/buildparam.log
274 ##############################
275 # section: public function
276 ##############################
278 #############################################################################
280 # tpchk funcs.
281 # @ desttpchk(): dest & src tp chk.
282 # @ step_lang_src_tpchk(): lang src tp chk.
283 # @ tpchk(): src & obj tp chk, and hdr tp chk.
285 ############################################################################
288 # fsyntax: srcdesttpchk
289 # fdesc: load src-list file.
291 srcdesttpchk ()
293 local srcfile=
294 local dstfile=
295 local param=
296 local libdir=
297 local flag=
298 local filelist=
300 # skip condition for .o file checking changing.
301 dstfile="${OUTDIR}/$(basename ${1%\.*})"
302 if test -f "${dstfile}" ; then
303 srcfile="$1"
304 [[ ${OUTDIR}/${DEST_CFG_DIR_NAME}/$srcfile -nt $dstfile ]] && return 0
305 else
306 return 0
309 # skip condition for .a file checking changing.
310 for param in $LDFLAGS; do
311 if [[ $param =~ ^-l(.*) ]]; then
312 srcfile="${OUTDIR}/lib${BASH_REMATCH[1]}.a"
313 if test -f "$srcfile" ; then
314 [[ $srcfile -nt $dstfile ]] && return 0
317 if [[ $param =~ ^-L(.*) ]]; then
318 libdir+=( "${BASH_REMATCH[1]}" )
320 done
322 # skip condition for .a file checking changing.
323 ret=1
324 for srcfile in $STATIC_LIB_LIST_Y; do
325 flag=0
326 if test -f $srcfile ; then
327 [[ $srcfile -nt $dstfile ]] && ret=0 && filelist+="$srcfile "
328 elif test -f "${OUTDIR}/${srcfile}" ; then
329 srcfile="${OUTDIR}/${srcfile}"
330 [[ $srcfile -nt $dstfile ]] && ret=0 && filelist+="$srcfile "
331 else
332 for param in ${libdir[@]}; do
333 if test -f $srcfile ; then
334 [[ $srcfile -nt $dstfile ]] && ret=0
335 # echo srcfile=$srcfile
336 # echo dstfile=$dstfile
337 filelist+="$srcfile "
338 flag=1
339 break;
341 done
342 [[ $flag != 1 ]] && warn "static lib file '$srcfile' is not in specified lib path.\n"
344 done
346 STATIC_LIB_LIST_Y="$filelist"
347 if test $ret == 0 ; then
348 return 0
349 else
350 infoo "dest file ($dstfile) is existing, skip linking."
351 return $ret
356 # fsyntax: desttpchk
357 # fdesc: load src-list file.
359 desttpchk ()
361 local srcfile=
362 local dstfile=
363 local param=
364 local libdir=
365 local flag=
366 local filelist=
368 # skip condition for .o file checking changing.
369 dstfile="${OUTDIR}/${!2}"
370 if test -f "${dstfile}" ; then
371 for srcfile in ${!1}; do
372 [[ ${OUTDIR}/${DEST_CFG_DIR_NAME}/$srcfile -nt $dstfile ]] && return 0
373 done
374 else
375 return 0
378 # skip condition for .a file checking changing.
379 for param in $LDFLAGS; do
380 if [[ $param =~ ^-l(.*) ]]; then
381 srcfile="${OUTDIR}/lib${BASH_REMATCH[1]}.a"
382 if test -f "$srcfile" ; then
383 [[ $srcfile -nt $dstfile ]] && return 0
386 if [[ $param =~ ^-L(.*) ]]; then
387 libdir+=( "${BASH_REMATCH[1]}" )
389 done
391 # skip condition for .a file checking changing.
392 ret=1
393 for srcfile in $STATIC_LIB_LIST_Y; do
394 flag=0
395 if test -f $srcfile ; then
396 [[ $srcfile -nt $dstfile ]] && ret=0 && filelist+="$srcfile "
397 elif test -f "${OUTDIR}/${srcfile}" ; then
398 srcfile="${OUTDIR}/${srcfile}"
399 [[ $srcfile -nt $dstfile ]] && ret=0 && filelist+="$srcfile "
400 else
401 for param in ${libdir[@]}; do
402 if test -f $srcfile ; then
403 [[ $srcfile -nt $dstfile ]] && ret=0
404 # echo srcfile=$srcfile
405 # echo dstfile=$dstfile
406 filelist+="$srcfile "
407 flag=1
408 break;
410 done
411 [[ $flag != 1 ]] && warn "static lib file '$srcfile' is not in specified lib path.\n"
413 done
415 STATIC_LIB_LIST_Y="$filelist"
416 if test $ret == 0 ; then
417 return 0
418 else
419 infoo "dest file ($dstfile) is existing, skip linking."
420 return $ret
425 # fsyntax: src_hdr_tpchk <dstfile>
426 # fdesc: chk tp between srcfile and hdrfile.
428 src_hdr_tpchk ()
430 local line=
431 local extname="${LANG_EXT_NAME[${1,,}]}"
432 local objfile="$1"
433 local deplistfile="${objfile//\.o/.dep}"
435 buildstep_dbgout "src_hdr_tpchk ($@) $deplistfile\n"
437 [[ ! -f $deplistfile ]] && return 0
439 while read line; do
440 [[ ! -n "$line" ]] && continue
441 line="${line%:*}"
442 [[ ! -e $line ]] && warn "hdr file ($line) in $deplistfile file does not exist." && return 2
444 if test ${line:0:1} == '/' ; then
445 SYS_INC_LIST+="$line"$'\n'
446 [[ $line -nt $1 ]] && echo "sys in file $line is modified." && return 0
447 else
448 APP_INC_LIST+="$line"$'\n'
450 # hdr file newer then src file,
451 # src file to be recompiled.
453 [[ $line -nt $objfile ]] && echo "file $line is modified." && return 0
455 done < <(cat ${deplistfile} | grep -v "[\\]$" | tr -s ' ' $'\n')
457 return 1
461 # fsyntax: tpchk <srcfile> <dstfile>
462 # fdesc: chk tp between src-file and dest-file, it also chk tp
463 # between src & hdr.
465 tpchk ()
467 local file=
468 local srcfile="$1"
469 local destfile=
471 file="${srcfile%%\,*}"
472 file="${file%\.*}"
473 destfile="${OBJDIR}/${file}${EXT_NAME[obj]}"
475 [[ ! -f ${destfile} ]] && return 0
476 for file in ${srcfile//\,/ }; do
477 [[ ${file} -nt ${destfile} ]] && echo recompile $srcfile && return 0
478 done
480 src_hdr_tpchk "${destfile}"
481 [[ $? == 0 ]] && return 0;
483 # skip
484 return 1
488 # fsyntax: step_lang_src_tpchk <langlist-var> [<parameter-list> ... ]
489 # fdesc: chk tp between srcfile and dstfile(obj).
491 step_lang_src_tpchk ()
493 local extname=
494 local obj=
495 local srcfile=
496 local dstfile=
497 local SRC_LIST_N2B_CMPL=
498 local langlist=( $1 )
499 local lang=
500 local vname=
502 # taskinfo_dbgout "step_lang_src_tpchk ($@)"
505 # check ${lang}_SRlanglistC_LIST_Y list.
507 lang="${1^^}"
508 extname=${LANG_EXT_NAME[${lang,,}]}
509 # for lang in ${langlist[@]} ; do
510 vname="${lang}_SRC_LIST_Y"
511 eval ${vname}="\"\${${vname}[@]//,/ }\""
513 if test -z "${!vname}" ; then
514 eval ${lang}_SRC_CMPL_LIST=""
515 taskinfo_dbgout "no src file in src list \'\${${lang}_SRC_LIST_Y[@]}\'."
516 return 0
518 OBJ_LIST+="${!vname//\.${extname}/\.o}"
519 # OBJ_LIST+="${!vname}"
521 # get obj file list that has been compiled.
522 mkdir -p ${OBJDIR}/
523 OBJ_LIST_N2B_CPLE=`cd ${OBJDIR}/; ls -1 $(echo "${!vname//\.c/\.o}" | tr ',' ' ') 2>/dev/null`
524 [[ -z "$OBJ_LIST_N2B_CPLE" ]] && eval ${lang}_SRC_CMPL_LIST=\"\${\!vname}\" && return 0
526 # test compiled obj file, to check if it need to be recompiled.
527 for obj in ${OBJ_LIST_N2B_CPLE}; do
528 srcfile="${obj//\.o/\.${extname}}"
529 dstfile="${OBJDIR}/${obj}"
531 # check if file does not need to be compiled.
532 if test "${dstfile}" -nt "${srcfile}" ; then
533 # hdr file tp chk.
534 src_hdr_tpchk $dstfile
535 [[ $? == 1 ]] && SRC_LIST_N2B_CMPL+="${srcfile}"$'\n'
536 [[ $? == 2 ]] && echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
538 done
539 # echo "SRC_LIST_N2B_CMPL=$SRC_LIST_N2B_CMPL"
541 # get files to be compiled.
542 if test -n "$SRC_LIST_N2B_CMPL" ; then
543 flag=compile
544 eval "${lang}_SRC_CMPL_LIST=\"`comm <(echo \"${!vname}\" | sort) <(echo \"$SRC_LIST_N2B_CMPL\" | sort) -3`\""
545 # | sed -e "/^\t/d"
546 else
547 eval "${lang}_SRC_CMPL_LIST=\"${!vname}\""
549 # eval echo "========= ${lang}_SRC_CMPL_LIST=\"\${${lang}_SRC_CMPL_LIST}\""
550 # eval taskinfo_dbgout "========= ${lang}_SRC_CMPL_LIST=\"\${${lang}_SRC_CMPL_LIST}\""
551 # done
553 return 0
556 #############################################################################
558 # general.
560 ############################################################################
562 # $ [[ "VOID on_prev_construct (int a)" =~ ((.*)[[:space:]]+)?([[:alnum:]_]*)[[:space:]]*([\(](.*)[\)])? ]] && echo "BASH_REMATCH=\"${BASH_REMATCH[@]}\""
563 # BASH_REMATCH="VOID on_prev_construct (int a) VOID on_prev_construct VOID on_prev_construct (int a) int a"
565 # @ detect latest non "(" string as the function name.
566 # @ string after "(" string is paramter
567 # @ string before function name is ret type.
570 # fsyntax:
571 # fdesc: dispose input string in $1, output P_RET P_FUNC & P_PARAM[]
573 str2func ()
575 local i=
576 local idx=
578 unset P_RET P_PARAM P_FUNC
579 declare -g P_RET=""
580 declare -g P_PARAM=""
581 declare -g P_FUNC=""
583 # check if func expr
584 # echo \$@=$@
585 if [[ "$1" =~ ((.*)[[:space:]]+)?([[:alnum:]_]*)[[:space:]]*([\(](.*)[\)])? ]]; then
586 for ((i=0; i<${#BASH_REMATCH[@]}; i++)); do
587 # echo BASH_REMATCH[$i]=${BASH_REMATCH[$i]}
588 [[ -n ${BASH_REMATCH[$i]} ]] && idx=$i
589 [[ ${BASH_REMATCH[$i]:0:1} == '(' ]] && idx=$((i-1)) && break;
590 done
591 # dbgoutd "idx=$idx\n"
592 P_FUNC="${BASH_REMATCH[$idx]}"
593 P_PARAM="${BASH_REMATCH[$((idx+2))]}"
594 P_RET="${BASH_REMATCH[$((idx-1))]}"
596 if test -n "$P_PARAM" ; then
597 # dbgoutd "P_PARAM=$P_PARAM\n"
598 # P_PARAM="\"${P_PARAM//,/\" \"}\""
599 P_PARAM="${P_PARAM//,/ }"
601 eval P_PARAM=( ${P_PARAM} )
602 # dbgoutd "P_PARAM[@]=${P_PARAM[@]}\n"
604 # dbgoutd "P_RET=$P_RET\n"
605 # dbgoutd "P_FUNC=$P_FUNC\n"
606 # dbgoutd "P_PARAM[@]=${P_PARAM[@]}\n"
607 elif test -z "${1//[[:alnum:]_]/}" ; then
608 P_FUNC="$1"
609 else
610 P_FUNC="$1"
611 return 2
614 declare -F $P_FUNC >/dev/null 2>&1
615 # [[ $? != 0 ]] && warn "'$P_FUNC' is a defination of func form, but it is not defined." && return 2
616 [[ $? != 0 ]] && return 3
617 return 0
621 # fsyntax: TASK_RUNNING <task-name-var> [<taskparam>, ... ]
622 # fdesc: running a task by the name of var in arg.
623 # freturn: 0, normal.
624 # 1, break current step.
625 # 2, err, stop doing.
626 # 3,
627 TASK_RUNNING ()
629 local j=
630 local ret=
631 local step=
632 local bakstep="$1"
633 local name=
634 local content=
635 local stepdef=
636 local param=
638 if [[ -n $task_skip_list && $task_skip_list =~ $bakstep ]]; then
639 return 0;
642 [[ -z $1 ]] && err "task name is not specified.\n" && return 0;
644 : $((task_level++))
645 taskstep_dbgout "$1" "TASK_RUNNING ($@)\n"
647 while true; do
648 [[ ! -n $1 ]] && warn "'$1' is not a valid step name." && ret=2 && break
650 # TBD:
651 # check if it is an array.
652 # if yes, use array directly.
653 # the form between multi-line string and array define are all well.
654 # sometimes, use array is better, it can write config info in the
655 # same line.
657 # use seperator with new line, to avoid ' ' in func param.
658 OLD_IFS="$IFS"
659 IFS=$'\n'
660 # use cmdline to strip string.
661 name="$(echo $1)"
662 content="${!1}"
663 stepdef=( $content )
664 IFS="$OLD_IFS"
666 shift 1
667 param=("$@")
669 # skip undefined step.
670 if [[ ${#stepdef[@]} == 0 && ! -v $stepdef ]]; then
671 warn "\$name=$name"
672 warn "\$content=$content"
673 warn "\$stepdef=$stepdef"
674 warn "'$name' is not a valid step.\${#stepdef[@]}=${#stepdef[@]}"
675 warn "set it in 'build/dest/build-step.imi'."
676 ret=0
677 break
681 # if only one item in defination, and it's not a variable define,
682 # it's a func, invoke it.
684 if test "${#stepdef[@]}" == 1 ; then
685 str2func "${stepdef[@]}"
686 ret=$?
687 if test $ret != 3 && test ! -n "${!P_FUNC}" ; then
688 : $((task_level++))
689 taskfunc_dbgout "func $P_FUNC(${P_PARAM[@]} "$@")\n"
690 $P_FUNC ${P_PARAM[@]} "$@"
691 ret=$?
692 taskfunc_dbgout "func ret $P_FUNC($ret)\n"
693 : $((task_level--))
694 [[ $ret == 1 ]] && ret=0 && break
695 [[ $ret != 0 ]] && warn "1 func '$P_FUNC (${P_PARAM[@]//\ /,\ })("$@")' return failed($ret)." && break
696 ret=0
697 break
701 taskstep_dbgout "$bakstep" "xxxxxxxxxxxxxxxxxxxxxxxxx x stepdef[@]=$(echo "${stepdef[@]}" | tr -s '\t' $'\n')\n"
704 # if there are several sub-steps, or the only one is also a step defination,
705 # use nestly invoking.
707 for ((j=0; j<${#stepdef[@]}; j++)); do
708 step="$(echo ${stepdef[$j]})"
709 # taskinfo_dbgout "x xxxxxxxxxxxxxxxxxxxxxxxx xx step[$j]=$step\n"
711 # skip null content and comment content
712 [[ -z $step ]] && continue
713 [[ "$step" =~ ^[[:blank:]]*\# ]] && continue
715 if [[ ! $step =~ '(' ]]; then
716 # if it's an existing var, it's may be a sub-step, invoke TASK_RUNNING() nestly.
717 # but not use ${!step} to access content.
718 # if it's also an existing func, it will be invoked in TASK_RUNNING.
720 #[[ -v $step ]] &&
721 # $step="$(echo $step)"
722 TASK_RUNNING "$step" "${param[@]}"
723 ret=$?
724 # [[ $ret == 1 ]] && ret=0 && break
725 [[ $ret != 0 ]] && break
726 else
727 # if it's a func, invoke func also.
728 str2func "${step}"
729 ret=$?
730 # taskinfo_dbgout "ret=$ret\n"
731 if test $ret == 0 ; then
732 if test "${P_FUNC^^}" == "${P_FUNC}" ; then
733 # if full upper char, it's a step
734 # P_FUNC="$(echo $P_FUNC)"
735 TASK_RUNNING $P_FUNC ${P_PARAM[@]} "${param[@]}"
736 # [[ $ret == 1 ]] && ret=0 && break
737 [[ $? != 0 ]] && taskinfo_dbgout "aaaaaaaaa" && break
738 continue
739 else
740 # otherwize, it's a normal function.
743 : $((task_level++))
744 taskfunc_dbgout "func $P_FUNC(${P_PARAM[@]} "$@")\n"
745 $P_FUNC ${P_PARAM[@]} "$@"
746 ret=$?
747 taskfunc_dbgout "func ret $P_FUNC($ret)\n"
748 : $((task_level--))
749 [[ $ret == 1 ]] && ret=0 && break
750 [[ $ret != 0 ]] && warn "2 func '$P_FUNC (${P_PARAM[@]//\ /,\ })("$@")' return failed($ret)." && break
751 elif test $ret == 3 ; then
752 # $P_FUNC="$(echo $P_FUNC)"
753 step="$P_FUNC"
754 TASK_RUNNING $P_FUNC ${P_PARAM[@]} "${param[@]}"
755 ret=$?
756 # [[ $ret == 1 ]] && ret=0 && break
757 [[ $ret != 0 ]] && taskinfo_dbgout "task ($step) invoking failed($ret).\n" && break
758 else
759 dbgoutd "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n"
762 done
764 # echo "j=$j; \${#stepdef[@]}=${#stepdef[@]}; ret=$ret"
765 # echo "if it's a func, invoke func also."
766 if test ! $j -lt "${#stepdef[@]}" && test ret == 0 ; then
767 str2func "${name}"
768 ret=$?
769 if test $ret == 0 ; then
770 : $((task_level++))
771 taskfunc_dbgout "func $P_FUNC(${P_PARAM[@]} "$@")\n"
772 $P_FUNC ${P_PARAM[@]} "$@"
773 ret=$?
774 taskfunc_dbgout "func ret $P_FUNC($ret)\n"
775 : $((task_level--))
776 [[ $ret == 1 ]] && ret=0 && break
777 [[ $ret != 0 ]] && warn "3 func '$P_FUNC (${P_PARAM[@]//\ /,\ })("$@")' return failed($ret)." && break
781 # ret=0
782 break
783 done
785 taskstep_dbgout "$bakstep" "ret $ret TASK_RUNNING ($name)\n"
786 : $((task_level--))
788 return $ret
791 foo () { local i=0; while [[ -n $1 ]]; do echo "\$1=$1"; shift; done; }
792 # $ foo a b "cd e" f
793 # $1=a
794 # $1=b
795 # $1=cd e
796 # $1=f
797 # $ abc=( aaa "a b c" abc a b c )
798 # $ foo "${abc[@]}"
799 # $1=aaa
800 # $1=a b c
801 # $1=abc
802 # $1=a
803 # $1=b
804 # $1=c
809 # fsyntax: tasklist <list> <task> [<taskparam> ... ]
810 # fdesc: running task accroding the list variable.
812 step_tasklist ()
814 local data=
815 local list="$1"
816 local task="$(echo $2)"
818 : $((task_level++))
819 tasklist_dbgout "x TASK_RUNNING TASKLIST ($@)\n"
821 if test -z "$1" ; then
822 warn "specified list var name '$1' is not valid."
823 return 2
826 tasklist_dbgout "list=$list\n"
827 tasklist_dbgout "$list=${!list}\n"
828 shift 2
829 while read data; do
830 [[ -z $data ]] && continue
831 SRC_FILE=( $data )
832 # taskinfo_dbgout "SRC_FILE=${SRC_FILE[@]}\n"
833 TASK_RUNNING "$task" $data "$@"
834 # break tasklist running if one of them failed.
835 if test $? != 0 ; then
836 tasklist_dbgout "x ret 2 TASK_RUNNING TASKLIST ($@)\n"
837 : $((task_level--))
839 return 2
841 done <<< "${!list}"
843 tasklist_dbgout "x ret 0 TASK_RUNNING TASKLIST ($@)\n"
844 : $((task_level--))
846 return 0
849 step_build_one_dest ()
851 # echo "step_build_dest($@)"
852 DEST_NAME=${1#*-}
853 dest_info_init
855 TASK_RUNNING "STEP_${DEST_TYPE^^}_DEST" $DEST_NAME
859 # fsyntax: step_one_dest_init
860 # fdesc: init one dest build. it loads the relative paramter files.
862 step_one_dest_init ()
864 local dest=${2#*-}
865 local step=
866 local ret=
868 buildstep_dbgout "############################\n"
869 buildstep_dbgout "step_one_dest_init($1, ${!1}, ${2#*-})\n"
870 buildstep_dbgout "############################\n"
872 [[ -n "$2" ]] && declare -g $1="${2#*-}"
874 # init one dest cfg paramter
875 eval "DEST_GENERAL_CFG_DIR=\"${DEST_GENERAL_CFG_DIR_EVL}\""
877 one_dest_init $dest
879 CFLAGS="$CFLAGS"
881 mkdir -p ${OUTDIR}/${DEST_CFG_DIR_NAME}/
883 unset OBJ_LIST
884 declare -g OBJ_LIST=""
886 return 0
889 step_one_lang_cmpl ()
891 local lang=$1
892 local langlist="${!1}"
894 # for lang in $langlist; do
895 TASK_RUNNING STEP_${lang^^}_LANG_CMPL "$@"
896 # done
898 return $?
901 step_link ()
903 local linkstep=
905 taskinfo_dbgout "step_link ($@)"
907 taskinfo_dbgout "OBJ_LIST=$OBJ_LIST"
909 DST_FILE="${OUTDIR}/${!2}"
910 SRC_FILE=( $OBJ_LIST )
912 taskinfo_dbgout "DST_FILE=$DST_FILE\n"
913 taskinfo_dbgout "DEST_NAME=$DEST_NAME\n"
914 taskinfo_dbgout "DEST_FILENAME=$DEST_FILENAME\n"
915 taskinfo_dbgout "DEST_TYPE=$DEST_TYPE\n"
916 taskinfo_dbgout "DEST_EXTNAME=$DEST_EXTNAME\n"
918 if test "${DEST_TYPE:0:1}" == '[' ; then
919 DEST_TYPE=${DEST_TYPE:1:-1}
921 taskinfo_dbgout "DEST_TYPE=$DEST_TYPE\n"
923 linkstep="STEP_${DEST_TYPE^^}_LINK"
924 taskinfo_dbgout "${linkstep}=${!linkstep}"
925 [[ -z ${!linkstep} ]] && err "dest type ${DEST_TYPE} have not define a step named 'STEP_${DEST_TYPE^^}_LINK'.\n" && return 2
926 TASK_RUNNING "${linkstep}" "$@"
928 [[ $? != 0 ]] && err "${CHIGHL}[build-link]: link file \"$DEST_FILENAME\" err.${CNORMAL}" && exit && return 2
930 return 0
933 step_lang_src2exe ()
935 local lang=
937 for lang in $1; do
938 TASK_RUNNING STEP_${lang^^}_LANG_SRC2EXE
939 done
942 step_lang_src2unitsrc ()
944 local lang=
945 local filelist=
946 local name=
948 for lang in $1; do
949 # echo ============== ${lang^^}_SRC_LIST_Y
950 name="${lang^^}_SRC_LIST_Y"
951 for file in ${!name}; do
952 # echo "file=${file%%\.*}_test.${file##*.}"
953 filelist+="${file%%\.*}_test.${file##*.}"$'\n'
954 done
955 eval ${lang^^}_SRC_LIST_Y=\"\$filelist\"
956 done
958 C_SRC_LIST_Y+="$OUTDIR/greatest/greatest.c"
959 mkdir -p $OUTDIR/greatest/
960 [[ ! -e $OUTDIR/greatest/greatest.c ]] && cat - > $OUTDIR/greatest/greatest.c << EOF
961 #include "greatest.h"
963 TEST_MAIN_DEFS();
966 OBJ_LIST=""
967 CFLAGS_EXT="-DGREATEST_MULTIPLE"
968 # LDFLAGS_EXT="-Wl,-T,tools/build-srcpkg/greatest/test.lds"
969 STATIC_LIB_LIST_Y+=" $OUTDIR/${DEST_FILENAME[0]}"
970 DEST_FILENAME="${DEST_FILENAME[1]}"
971 DEST_TYPE="exe"
975 # fsyntax: build_step_init
976 # fdesc: load build-step.imi cfg file.
978 build_step_init ()
980 # load CFLAGS-MISC.imi
981 eval "BUILD_STEP_IMI=\"${BUILD_STEP_IMI_EVL}\""
982 buildparam_dbgout "BUILD_STEP_IMI=$BUILD_STEP_IMI\n"
983 # load_imi_file $BUILD_STEP_IMI
984 # use source instead of load_imi_file
985 . $BUILD_STEP_IMI
987 # load lang.list
988 eval "BUILD_LANG_LIST=\"${BUILD_LANG_LIST_EVL}\""
989 . $BUILD_LANG_LIST
993 # fsyntax: dest_list_init
994 # fdesc: load dest.imi cfg file, to get dest-list.
996 dest_list_init ()
998 # DEST_LIST=
999 # DEST_NAME=
1001 buildparam_dbgout "SRCPKG_DIR=$SRCPKG_DIR\n"
1003 # BUILD_DEST is defined in this file
1004 eval DEST_LIST_FILE="$DEST_LIST_FILE_EVL"
1005 source $DEST_LIST_FILE
1006 DEST_LIST="${BUILD_DEST//dest-/$'\ndest-'}"
1008 buildparam_dbgout "###############################\n"
1009 buildparam_dbgout "dest_list_init($DEST_LIST_FILE)\n"
1010 buildparam_dbgout "DEST_LIST=\"$DEST_LIST\"\n"
1012 declare -g -A DEST_CFG_DIR=( )
1013 # INST_PKG is defined in this file
1014 INSTPKG_LIST_FILE="${SRCPKG_DIR}/build/instpkg/instpkg.list"
1015 declare -g -A INSTPKG_CFG_DIR=( )
1018 construct_init_flag=
1020 construct_init ()
1022 # skip if initialized.
1023 [[ $construct_init_flag == 1 ]] && return
1025 construct_init_work
1027 construct_init_flag=1
1031 # fsyntax: construct_init
1032 # fdesc: init construct variables.
1033 # output:
1034 # SRCPKG_DIR, src pkg root dir.
1035 # OUTDIR, it stores compile mid-file.
1036 # VERSION_STRING,
1037 # SRCPKG_FILENAME,
1038 # SRCPKG_NAME,
1040 construct_init_work ()
1042 local dest=
1044 # SRCPKG_DIR
1045 if [[ -d build ]]; then
1046 SRCPKG_DIR="."
1047 eval "SRCPKG_DIR_ABP=\"$PWD\""
1048 elif [[ $(basename $PWD) == build ]]; then
1049 SRCPKG_DIR=".."
1050 cd ..
1051 eval "SRCPKG_DIR_ABP=\"$PWD\""
1054 # if it has been defined, create src-pkg name sub-dir
1055 if [[ -z $OUTDIR ]]; then
1056 eval "OUTDIR=\"$OUTDIR_EVL\""
1058 if [[ -z $OUTDIR_ABP ]]; then
1059 eval "OUTDIR_ABP=\"$OUTDIR_ABP_EVL\""
1062 info_dbgout_init
1064 date > ${OUTDIR}/build.log
1065 echo >> ${OUTDIR}/build.log
1067 # load srcpkg name & version string.
1068 eval "VERSION_FILE=\"$VERSION_FILE_EVL\""
1070 source $VERSION_FILE
1071 buildparam_dbgout VERSION_STRING=$VERSION_STRING
1072 buildparam_dbgout SRCPKG_FILENAME=$SRCPKG_FILENAME
1073 buildparam_dbgout SRCPKG_NAME=$SRCPKG_NAME
1075 # set env $PATH
1076 PATH="$SRCPKG_DIR/support/:$PATH"
1078 mkdir -p ${OUTDIR}
1080 # load dest.list & build-step.imi to get dest list.
1081 dest_list_init
1082 build_step_init
1084 # load srcpkg shlib file, for some on_xxx() funcs.
1085 [[ -z $SRCPKG_NAME ]] && err "SRCPKG_NAME defined in file of doc/VERSION is not valid.\n"
1086 if [[ -f build/${SRCPKG_NAME}.shlib ]]; then
1087 inc build/${SRCPKG_NAME}.shlib
1088 elif [[ -f build/shlib/${SRCPKG_NAME}.shlib ]]; then
1089 inc build/shlib/${SRCPKG_NAME}.shlib
1090 else
1094 buildstep_dbgout "############################\n"
1095 buildstep_dbgout "construct_init()\n"
1096 buildstep_dbgout "############################\n"
1100 # construct
1101 # construct_all_dest => dest_list_init()/construct_one_dest() => one_dest_init() =>
1102 # compile_src_list()/link_list() => c2o()/o2exe()
1104 construct ()
1106 construct_init
1108 TASK_RUNNING "STEP_BUILD_DEST"
1113 ##############################
1114 # section: file tail
1115 ##############################
1123 # fsyntax: worklist_create <worklist-name>
1124 # fdesc: create variables about a worklist object.
1126 worklist_create ()
1132 # worklist can be create/release dynamically.
1133 # the default worklist is named null string.
1137 # fsyntax: worklist_release <worklist-name>
1138 # fdesc: release variables about a worklist object.
1140 worklist_release ()
1146 # fsyntax: src_list_init
1147 # fdesc: load src-list file.
1149 src_list_init ()
1151 local vname=
1152 local lang=$1
1153 local destdir=$2
1154 local extname="${LANG_EXT_NAME[${lang,,}]}"
1155 local SRC_LIST_FILE="build/dest/dest-$DEST_NAME/${lang,,}-src-file.list"
1156 # local ${lang^^}_SRC_LIST_Y=
1158 # infoo "src_list_init($extname, $@)\n"
1160 vname=${lang^^}_SRC_LIST_Y
1161 eval "${vname}=\"\""
1162 if test -e "${SRC_LIST_FILE}" ; then
1163 . $SRC_LIST_FILE 2>/dev/null
1164 eval "${vname}=\"\${!vname//\.${extname,,}/\$'.${extname,,}\n'}\""
1165 taskinfo_dbgout ${vname}="${!vname}"
1168 # [[ -e $SRC_LIST_FILE ]] && eval "${lang^^}_SRC_LIST_Y=( $(cat $SRC_LIST_FILE | grep -v \"[[:space:]]*#\" | sed -e \"s/^[[:space:]]*#.*$//g\") )"
1170 [[ -z ${!vname} ]] && taskinfo_dbgout no src file in src list. && return 0
1172 # taskinfo_dbgout ${lang^^}_SRC_LIST_Y=${${lang^^}_SRC_LIST_Y[$i]}
1173 return 0
1177 # fsyntax: step_lang_src_tpchk <langlist-var> [<parameter-list> ... ]
1178 # fdesc: chk tp between srcfile and dstfile(obj).
1180 step_lang_exe_tpchk ()
1186 c_src2exe ()
1188 local lang=
1190 for lang in $1; do
1191 TASK_RUNNING STEP_${lang^^}_LANG_CMPL
1192 done