5 # @ gen src list from a subdir, and compile
6 # @ compile a subdir by invoke build in subdir.
7 # @ compile & link for a target in target list.
16 # fsyntax: taskinfo_dbgout <output-string>
17 # fdesc: output string by dbgout switch.
21 if [[ ! "${dbgout_opt}" =~ taskinfo ]]; then
26 echo -ne "$@" >> ${OUTDIR}/buildinfo.log
32 [[ -n "$usage" ]] && echo $usage
40 OBJDIR="$(eval echo ${OBJDIR_FMT})"
42 rm $OBJ_LIST ${OBJDIR} $OUTDIR -rf
45 [[ -z $dst ]] && continue
46 eval echo rm "${OUTDIR}${DST_FMT}" -rf
47 eval rm ${OUTDIR}${DST_FMT} -rf
57 # build src to executables
58 TASK_RUNNING "STEP_BUILD_DEST"
62 # TASK_RUNNING "STEP_ODC"
66 # TASK_RUNNING "STEP_INSTPKG"
73 # build default platform
74 TASK_RUNNING "STEP_BUILD_DEST"
76 for hwplat in $ARCH_LIST_Y; do
78 echo "===================================="
79 echo "= build for ARCH=$ARCH"
80 echo "===================================="
81 TASK_RUNNING "STEP_BUILD_DEST"
96 # build src to executables
97 TASK_RUNNING "STEP_BUILD_DEST"
100 build_subcmd_example ()
104 [[ ! -e "build/dest/dest-example" ]] && echo "there is no dest named example defined." && exit
106 TASK_RUNNING "STEP_DEFAULT_DEST" example
109 build_subcmd_install ()
124 build_subcmd_config ()
129 build_subcmd_genpkg ()
136 # fdesc: general subcmd proc.
140 while test $# -gt 0; do
143 -v) shift; outdir=$1;;
144 -h) shift; dirargs="$dirargs -I '$1'"; dirs="$dirs $1";;
147 dir="$(basename $PWD)"
148 file="${dir}-$(date +%Y%m%d).zip"
150 mkdir -pv $(dirname $file)
151 rm ${file} 2>/dev/null
152 echo "zip -r ${file} ${dir}"
153 zip -r ${file} ${dir}
155 [[ $SRCBAK_DIR != '../' && $SRCBAK_DIR != '..' ]] && mkdir -pv $SRCBAK_DIR && mv ../$file ${SRCBAK_DIR}/ -f
158 gz) echo TBD; exit 0;;
159 bz) echo TBD; exit 0;;
160 xz) echo TBD; exit 0;;
162 -v) echo "version: $scriptversion"; exit 0;;
163 -h) echo "$usage"; exit 0;;
167 build_subcmd_help "$@"
171 build_subcmd_clean "$@"
175 build_subcmd_all "$@"
179 build_subcmd_full "$@"
183 build_subcmd_arch "$@"
187 build_subcmd_example "$@"
191 build_subcmd_install "$@"
195 build_subcmd_test "$@"
199 build_subcmd_doc "$@"
203 build_subcmd_config "$@"
207 build_subcmd_genpkg "$@"
210 --version) echo "$version"; exit 0;;
211 --help) echo "$usage"; exit 0;;
213 echo "$0: Unknown option \`$1'." >&2
214 echo "$0: Try \`--help' for more information." >&2
217 if test -z "$PACKAGE"; then
219 elif test -z "$MANUAL_TITLE"; then
222 echo "$0: extra non-option argument \`$1'." >&2
230 # one_dest_init() in param-load.shlib
233 [[ ! -z $@ ]] && force=1
238 # OBJDIR="$(eval echo ${OBJDIR_FMT})"
240 # DEST_CFG_DIR_NAME=${DST_LIST}
250 if [[ -n $line ]]; then
252 [[ -f "${line}_test.c" ]] && echo ${line}_test.c
261 [[ -z $SUB_SRCDIR_LIST ]] && return
263 for subdir in $SUB_SRCDIR_LIST; do
265 [[ ! -f "cmpl.sh" ]] && echo "err: there no cmpl.sh file exist in subdir '$subdir'." && exit -1
267 # running in subscript, parameters are not changed by sub-script.
268 ( SUB_SRCDIR_LIST="" ./cmpl.sh "$@" )
269 [[ $? != 0 ]] && echo "err: builld dir $subdir failed." && exit -1
272 STATIC_LIBS+=" ${OUTDIR}lib${subdir##*/}.a"
273 # STATIC_LIBS+=" ${STATIC_LIB}"
279 local listname=${1^^}_SRC_LIST_Y
281 if [[ ${1^^} == ASM || ${1^^} == C || ${1^^} == CXX || ${1^^} == CPP ]] ;then
287 echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
289 OBJDIR="$(eval echo ${OBJDIR_FMT})"
293 echo \$SRC_LIST=$SRC_LIST
295 for srcfile in ${!listname}; do
296 # objfile=${srcfile##*/}
297 objfile="${OBJDIR}${srcfile//\.(S|s|asm|c|cxx|cpp)/\.o}"
298 echo $srcfile gcc compile to $objfile ...
300 if [[ $srcfile -nt $objfile
301 # || cmpl.sh -nt $srcfile
303 || ! -f $objfile ]]; then
305 mkdir -p $(dirname $objfile)
306 # depfile=${objfile//\.o/\.dep}
308 # SRC_FILE[0]="${srcfile}"
309 # DST_FILE[0]="${objfile}"
310 # DST_FILE[1]="${objfile//.o/.dep}"
311 [[ $EN_SRCHDR_DEP == 1 ]] && CCFLAGS_DEPHDR="$CCFLAGS_DEPHDR_EVL"
313 tpchk ${srcfile} ${objfile}
314 [[ $? != 1 ]] && continue;
316 # echo $CC ${CFLAGS} $CCFLAGS_DEPHDR -c $srcfile -o $objfile
317 # $CC ${CFLAGS} $CCFLAGS_DEPHDR -c $srcfile -o $objfile
319 echo c2o $srcfile $objfile # $depfile
320 c2o $srcfile $objfile # $depfile
322 [[ $? != 0 ]] && echo "gcc($CC) compile ($objfile) failed." && exit -1
330 for srcfile in $${!listname}; do
331 # objfile=${srcfile##*/}
332 objfile="$OBJDIR${srcfile%.*}.o"
333 OBJ_LIST+=" $objfile"
335 echo OBJ_LIST=$OBJ_LIST
341 local listname=${1^^}_SRC_LIST_Y
343 if [[ ${1^^} == ASM || ${1^^} == C || ${1^^} == CXX || ${1^^} == CPP ]] ;then
349 echo xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
351 OBJDIR="$(eval echo ${OBJDIR_FMT})"
355 echo \$SRC_LIST=$SRC_LIST
357 for srcfile in ${!listname}; do
358 # objfile=${srcfile##*/}
359 objfile="${OBJDIR}${srcfile//\.c/\.o}"
360 # objfile="${srcfile//\.c/\.o}"
361 echo $srcfile gcc compile to $objfile ...
363 if [[ $srcfile -nt $objfile
364 # || cmpl.sh -nt $srcfile
366 || ! -f $objfile ]]; then
368 mkdir -p $(dirname $objfile)
369 # depfile=${objfile//\.o/\.dep}
371 # SRC_FILE[0]="${srcfile}"
372 # DST_FILE[0]="${objfile}"
373 # DST_FILE[1]="${objfile//.o/.dep}"
374 [[ $EN_SRCHDR_DEP == 1 ]] && CCFLAGS_DEPHDR="$CCFLAGS_DEPHDR_EVL"
376 tpchk ${srcfile} ${objfile} dest-$2
377 [[ $? = 1 ]] && continue;
379 # echo $CC ${CFLAGS} $CCFLAGS_DEPHDR -c $srcfile -o $objfile
380 # $CC ${CFLAGS} $CCFLAGS_DEPHDR -c $srcfile -o $objfile
382 # echo c2o $srcfile $objfile # $depfile
383 c2o $srcfile $objfile # $depfile
385 [[ $? != 0 ]] && echo "gcc($CC) compile ($objfile) failed." && exit -1
393 for srcfile in ${!listname}; do
394 # objfile=${srcfile##*/}
395 objfile="$OBJDIR${srcfile%\.*}.o"
396 OBJ_LIST+=" $objfile"
398 # echo OBJ_LIST=$OBJ_LIST
403 if [[ true || "${DST_FMT}" == '${dst}' ]]; then
404 outputfile="${DST_NAME}"
405 outputfile="${OUTDIR}/${DST_NAME}.a"
408 # echo outputfile=$outputfile
410 [[ ! -f $outputfile ]] && echo dest file is not exist && flag_link=1
411 for srcfile in $ASM_SRC_LIST_Y $C_SRC_LIST_Y $CXX_SRC_LIST_Y $CPP_SRC_LIST_Y; do
412 objfile+="${OBJDIR}${srcfile%\.*}.o "
413 [[ -z $flag_link && "$srcfile" -nt "$outputfile" ]] && flag_link=1 \
414 #&& echo $srcfile '-nt' $outputfile && ls -l $srcfile $outputfile
415 [[ -z $flag_link && "$objfile" -nt "$outputfile" ]] && flag_link=1 \
416 #&& echo $objfile '-nt' $outputfile && ls -l $objfile $outputfile
418 [[ $flag_link != 1 ]] && return 2
419 echo ${outputfile} gcc static lib link ...
421 SRC_FILE=( $objfile )
422 o2lib "" ${DEST_NAME}.a
424 [[ $? != 0 ]] && echo "gcc link ($(echo $outputfile)) failed." && exit -1
434 if [[ true || "${DST_FMT}" == '${dst}' ]]; then
435 outputfile="${DST_NAME}"
436 outputfile="${OUTDIR}/${DST_NAME}.a"
439 # echo outputfile=$outputfile
441 [[ ! -f $outputfile ]] && echo dest file is not exist && flag_link=1
442 for srcfile in $ASM_SRC_LIST_Y $C_SRC_LIST_Y $CXX_SRC_LIST_Y $CPP_SRC_LIST_Y; do
443 objfile+="${OBJDIR}${srcfile%\.*}.o "
444 [[ -z $flag_link && "$srcfile" -nt "$outputfile" ]] && flag_link=1 \
445 #&& echo $srcfile '-nt' $outputfile && ls -l $srcfile $outputfile
446 [[ -z $flag_link && "$objfile" -nt "$outputfile" ]] && flag_link=1 \
447 #&& echo $objfile '-nt' $outputfile && ls -l $objfile $outputfile
449 [[ $flag_link != 1 ]] && return 2
450 echo ${outputfile} gcc static lib link ...
452 SRC_FILE=( $objfile )
453 o2dll $srcfile ${DEST_NAME}.a
455 [[ $? != 0 ]] && echo "gcc link ($(echo $outputfile)) failed." && exit -1
465 if [[ true || "${DST_FMT}" == '${dst}' ]]; then
466 outputfile="${DST_LIST%%[[:blank:]]}"
467 outputfile="${OUTDIR}/${outputfile#*[[:blank:]]}"
471 [[ ! -f $outputfile ]] && echo dest file is not exist && flag_link=1
472 for srcfile in $ASM_SRC_LIST_Y $C_SRC_LIST_Y $CXX_SRC_LIST_Y $CPP_SRC_LIST_Y; do
473 objfile+="${OBJDIR}${srcfile%\.*}.o "
474 [[ -z $flag_link && "$srcfile" -nt "$outputfile" ]] && flag_link=1 \
475 #&& echo $srcfile '-nt' $outputfile && ls -l $srcfile $outputfile
476 [[ -z $flag_link && "$objfile" -nt "$outputfile" ]] && flag_link=1 \
477 #&& echo $objfile '-nt' $outputfile && ls -l $objfile $outputfile
479 [[ $flag_link != 1 ]] && return
480 echo $outputfile gcc link ...
483 # XXX: pay attenssion on the sequence of -lxxx parameter.
484 # it would leading link error in un-suitable sequence.
486 SRC_FILE=( $objfile )
487 o2exe "" $(basename $outputfile)
489 [[ $? != 0 ]] && echo "gcc link ($(echo $outputfile)) failed." && exit -1
499 # OBJDIR="$(eval echo ${OBJDIR_FMT})"
501 if [[ true || "${DST_FMT}" == '${dst}' ]]; then
502 outputfile="${DST_LIST%%[[:blank:]]}"
503 outputfile="${OUTDIR}/${outputfile#*[[:blank:]]}"
507 echo outputfile=$outputfile
509 [[ ! -f $outputfile ]] && echo dest file is not exist && flag_link=1
510 for srcfile in $ASM_SRC_LIST_Y $C_SRC_LIST_Y $CXX_SRC_LIST_Y $CPP_SRC_LIST_Y; do
511 # srcfile=${srcfile##*/}
512 objfile+="${OBJDIR}${srcfile%\.*}.o "
513 echo srcfile=$srcfile
514 echo objfile=$objfile
515 # OBJ_LIST+=" $objfile"
516 [[ -z $flag_link && "$srcfile" -nt "$outputfile" ]] && flag_link=1 \
517 #&& echo $srcfile '-nt' $outputfile && ls -l $srcfile $outputfile
518 [[ -z $flag_link && "$objfile" -nt "$outputfile" ]] && flag_link=1 \
519 #&& echo $objfile '-nt' $outputfile && ls -l $objfile $outputfile
521 [[ $flag_link != 1 ]] && return
522 echo $outputfile gcc link ...
524 for file in $STATIC_LIBS; do
526 STATIC_LINK_LIBS+=" ${file//*lib/-l}";
530 # XXX: pay attenssion on the sequence of -lxxx parameter.
531 # it would leading link error in un-suitable sequence.
534 # echo "$LINK -L${OUTDIR} $OBJ_LIST -o $outputfile ${STATIC_LINK_LIBS} $LDFLAGS "
535 # $LINK -L${OUTDIR} $OBJ_LIST -o $outputfile ${STATIC_LINK_LIBS} $LDFLAGS
537 SRC_FILE=( $objfile )
538 echo SRC_FILE=${SRC_FILE[@]}
539 o2exe "" $(basename $outputfile)
541 [[ $? != 0 ]] && echo "gcc link ($(echo $outputfile)) failed." && exit -1
548 for dst in $DST_LIST; do
549 outputfile="${OUTDIR}$(eval echo ${DST_FMT})"
550 echo $outputfile gcc build ...
552 objfile1="${OBJDIR}${dst}.o"
553 objfile2="${OBJDIR}${dst}_test.o"
554 if [[ $outputfile -nt $objfile1 || $outputfile -nt $objfile2
555 || build.sh -nt $outputfile
557 || ! -f $outputfile ]]; then
558 echo "$LINK $LDFLAGS $SLIB_LIST $objfile1 $objfile2 -o $outputfile"
559 $LINK $LDFLAGS $SLIB_LIST $objfile1 $objfile2 -o $outputfile
560 [[ $? != 0 ]] && echo "gcc($CC) link ($outputfile) failed." && exit -1
568 CFLAGS="${MACRO_DEF} ${INC_PATHS} ${MISC_CFLAGS} "
569 echo CFLAGS="\"$CFLAGS\""
570 LDFLAGS="${INC_LIBS} ${MISC_LDFLAGS} "
585 for DEST in $(cat build/dest/dest.list); do
586 [[ -z $DEST ]] && continue
601 # link > link.txt 2>&1
606 if [[ $flag_clean != 1 ]]; then
609 TASK_RUNNING "STEP_BUILD_DEST"
617 ##########################################################################
628 # OBJDIR="$(eval echo ${OBJDIR_FMT})"
630 if [[ true || "${DST_FMT}" == '${dst}' ]]; then
631 outputfile="${DST_LIST%%[[:blank:]]}"
632 outputfile="${OUTDIR}/${outputfile#*[[:blank:]]}"
636 echo outputfile=$outputfile
638 [[ ! -f $outputfile ]] && echo dest file is not exist && flag_link=1
639 for srcfile in $ASM_SRC_LIST_Y $C_SRC_LIST_Y $CXX_SRC_LIST_Y $CPP_SRC_LIST_Y; do
640 # srcfile=${srcfile##*/}
641 objfile+="${OBJDIR}${srcfile%\.*}.o "
642 echo srcfile=$srcfile
643 echo objfile=$objfile
644 # OBJ_LIST+=" $objfile"
645 [[ -z $flag_link && "$srcfile" -nt "$outputfile" ]] && flag_link=1 \
646 #&& echo $srcfile '-nt' $outputfile && ls -l $srcfile $outputfile
647 [[ -z $flag_link && "$objfile" -nt "$outputfile" ]] && flag_link=1 \
648 #&& echo $objfile '-nt' $outputfile && ls -l $objfile $outputfile
650 [[ $flag_link != 1 ]] && return
651 echo $outputfile gcc link ...
653 for file in $STATIC_LIBS; do
655 STATIC_LINK_LIBS+=" ${file//*lib/-l}";
659 # XXX: pay attenssion on the sequence of -lxxx parameter.
660 # it would leading link error in un-suitable sequence.
663 # echo "$LINK -L${OUTDIR} $OBJ_LIST -o $outputfile ${STATIC_LINK_LIBS} $LDFLAGS "
664 # $LINK -L${OUTDIR} $OBJ_LIST -o $outputfile ${STATIC_LINK_LIBS} $LDFLAGS
666 SRC_FILE=( $objfile )
667 echo SRC_FILE=${SRC_FILE[@]}
668 o2exe "" $(basename $outputfile)
670 [[ $? != 0 ]] && echo "gcc link ($(echo $outputfile)) failed." && exit -1
677 for dst in $DST_LIST; do
678 outputfile="${OUTDIR}$(eval echo ${DST_FMT})"
679 echo $outputfile gcc build ...
681 objfile1="${OBJDIR}${dst}.o"
682 objfile2="${OBJDIR}${dst}_test.o"
683 if [[ $outputfile -nt $objfile1 || $outputfile -nt $objfile2
684 || build.sh -nt $outputfile
686 || ! -f $outputfile ]]; then
687 echo "$LINK $LDFLAGS $SLIB_LIST $objfile1 $objfile2 -o $outputfile"
688 $LINK $LDFLAGS $SLIB_LIST $objfile1 $objfile2 -o $outputfile
689 [[ $? != 0 ]] && echo "gcc($CC) link ($outputfile) failed." && exit -1
695 #########################################################################
706 O2LIB_CMD_EVL='${AR} ${ARFLAGS} ${outputfile}.a $(echo ${OBJ_LIST})'
709 OUTDIR_FMT='${PWD}/output/'
710 [[ -z $OUTDIR ]] && export OUTDIR="$PWD/output/" # it must have a '/' at last.
711 OBJDIR_FMT='${DSTDIR}/obj/'
712 OBJDIR="${OUTDIR}/obj/"
713 SRCBAK_DIR=${SRCBAK_DIR='../'}