2 ############################################################
3 # source: toolchain.shlib
4 # author: devenkong(18151155@qq.com)
6 ############################################################
8 # toolchain cmd set. it uses fname.shlib to get output
9 # dirs, and ../platform/toolchain_info.imi for cmd name with
10 # cross compile prefix. before invoke func in this file, load
11 # parameters defined in dest/dest-xxx/* by param-load.shlib.
12 ############################################################
17 # @ fhex2fbin/fbin2fhex
22 # @ absolution of toolchain cmd & op.
23 # !# cmd: gcc/ld/ar ...
24 # !# compile, asm2o(), c2o(), cpp2o(),
25 # !# link, o2exe(), o2a(), o2dlib(), o2drv()
26 # !# postage-proc, progstrip()
27 # !# postage-info, prog_size_info(), prog_symbols(), prog_func_symbs(),
28 # prog_var_symbs(), prog_inner_symbs(), prog_ext_symbs(),
29 # # postage-output, exe2bin(), exe2hex(), hex2bin(), bin2hex(),
30 # fhex2bin(), fbin2hex(),
31 # # general log output info, dbg output info.
32 # !@ compile hdr file dep list.
34 # !@ different cpu arch optimzation opt.(untested)
38 # @ prev & post invoke
45 # this func copied from incfile.shlib. due to the file is not in a fixed dir,
46 # it can'nt be used by source operation.
48 if [[ -z $
(declare -F inc
) ]]; then
53 [[ -z "$1" ||
! -f "$1" ]] && return
63 # file name format define
70 ######################
71 # section: common comment info
72 ######################
74 ######################
75 # section: variable define
76 ######################
80 ######################
81 # section: private function
82 ######################
86 test "${OPT_VERBOSE_INFO}" == 'Y' && echo "$@"
93 ######################
94 # section: public function
95 ######################
97 #########################################
99 #########################################
113 # attention -lncurses paramter must be put after .o file,
114 # or it report err that symbol not found.
115 # cmd="${CC} ${ASFLAGS_OUT} ${ASFLAGS_EXT} ${CFLAGS} ${LDFLAGS} $(echo ${SRC_FILE[@]}) -o ${DST_FILE[0]}"
118 # XXX: if there is blank in quoted "string", it will be shorten to single.
119 # append '\' before it.
121 cmd
="$(echo "${cmd//[[:space:]]/ }" | tr -s ' ')"
123 # release var after cmd is filled.
124 unset SRC_FILE DST_FILE
127 # TBD: do parameter checking work here.
133 # if stdout is redirected by '|' pipe,
134 # it will not display in colorfull.
135 # the commented statement does not display in colorfull.
137 # output="$( eval $cmd 2>&1 )"
138 eval $cmd 2>&1 > /tmp
/output.log
141 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build-dbgout.log
142 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build.log
144 if test $ret = 0 ||
! test -s /tmp
/output.log
&& test "${verbose_mode,,}" != y
; then
145 toolchain_dbgout
-ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
147 echo -ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
149 test "${OPT_VERBOSE_INFO}" == 'Y' && cat /tmp
/output.log
>> ${OUTDIR}/build-dbgout.log
152 if test $ret != 0 ; then
160 # fsyntax: asm2o <src-file> <output-file>
161 # fdesc: asm汇编程序.S文件编译成.o文件。
167 [[ -n "${1}" ]] && SRC_FILE
[0]="$1"
168 [[ -n "${2}" ]] && DST_FILE
[1]="$2"
170 eval cmd
=\"$ASM2O_CMD_FMT\"
174 [[ $cmd == 0 ]] && CMPL_OBJ_LIST
+="$fdst"
175 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
181 # fsyntax: src2dst_filename
182 # fdesc: compile each src file.
186 [[ -z "${SRC_FILE[0]}" ]] && echo -e "[error
]: SRC_FILE
[0] should not be NULL
, and
'\n$(declare -p DST_FILE)'.
\n" >&2 && exit
188 SRC_FILE="${SRC_FILE//\,/\ }"
190 [[ -z "${DST_FILE[0]}" ]] && fname_src2dst $SRC_FILE
191 [[ -z "${DST_FILE[1]}" ]] && fname_src2obj $SRC_FILE
193 [[ OPT_CALLGRAPH =~ '' ]] &&
195 [[ -z "${DST_FILE[2]}" ]] && fname_src2dep $SRC_FILE
196 [[ -z "${DST_FILE[3]}" ]] && fname_src2graph $SRC_FILE
200 # set those two by cmd opt or envar or DEBUG/RELEASE opt.
206 # fsyntax: c2o <src-file> [ <obj-file> [ <dep-file> [<graph-file>] ] ]
207 # fdesc: .c src file compile to .o file. parameters can be given in func arg,
208 # and envar SRC_FILE & DST_FILE. you can given one param <obj-file> only,
209 # it will generate others in auto.
216 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[c]}$
]] && SRC_FILE
[0]="$1"
217 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[obj]}$ ]] && DST_FILE[1]="$2"
218 [[ -n "${3}" && "${2}" =~ \.dephdr$ ]] && DST_FILE[2]="$3"
219 [[ -n "${4}" && "${2}" =~ \.cgraph$ ]] && DST_FILE[3]="$4"
222 fdst="${DST_FILE[1]} "
224 mkdir -p $(dirname ${DST_FILE[1]})
228 # echo SRC_FILE=${SRC_FILE[@]}
229 # echo DST_FILE=${DST_FILE[@]}
232 CFLAGS_CALLGRAPH_Y=""
233 if test -n "${DST_FILE[2]}" && test "${OPT_DEPHDR^^}" == 'Y'; then
234 eval "CFLAGS_DEPHDR_
${OPT_DEPHDR^^}=\"$CFLAGS_DEPHDR_Y_EVL\""
236 if test -n "${DST_FILE[3]}" && test "${OPT_CALL_GRAPH^^}" == 'Y'; then
237 eval "CFLAGS_CALLGRAPH_
${OPT_CALLGRAPH^^}=\"$CFLAGS_CALLGRAPH_Y_EVL\""
240 eval cmd=\"$C2O_CMD_FMT\"
244 [[ $cmd == 0 ]] && CMPL_OBJ_LIST+="$fdst"
245 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
252 # fdesc: .cc文件编译成.o文件。
258 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[cxx]}$ ]] && SRC_FILE[0]="$1"
259 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[obj]}$
]] && DST_FILE
[1]="$2"
260 [[ -n "${3}" && "${2}" =~ \.dephdr$
]] && DST_FILE
[2]="$3"
261 [[ -n "${4}" && "${2}" =~ \.cgraph$
]] && DST_FILE
[3]="$4"
263 fdst
="${DST_FILE[1]} "
265 mkdir
-p $
(dirname ${DST_FILE[0]})
268 CFLAGS_CALLGRAPH_Y
=""
269 if test -n "${DST_FILE[2]}" && test ${OPT_DEPHDR^^} == 'Y'; then
270 eval "CFLAGS_DEPHDR_${OPT_DEPHDR}=\"$CFLAGS_DEPHDR_Y_EVL\""
272 if test -n "${DST_FILE[3]}" && test ${OPT_CALL_GRAPH^^} == 'Y'; then
273 eval "CFLAGS_CALLGRAPH_${OPT_CALLGRAPH}=\"$CFLAGS_CALLGRAPH_Y_EVL\""
276 eval cmd
=\"$CXX2O_CMD_FMT\"
280 [[ $cmd == 0 ]] && CMPL_OBJ_LIST
+="$fdst"
281 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
288 # fdesc: cpp程序.cpp文件编译成.o文件。
295 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[cpp]}$
]] && SRC_FILE
[0]="$1"
296 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[obj]}$ ]] && DST_FILE[1]="$2"
297 [[ -n "${3}" && "${2}" =~ \.dephdr$ ]] && DST_FILE[2]="$3"
298 [[ -n "${4}" && "${2}" =~ \.cgraph$ ]] && DST_FILE[3]="$4"
300 fdst="${DST_FILE[1]} "
302 mkdir -p $(dirname ${DST_FILE[0]})
305 CFLAGS_CALLGRAPH_Y=""
306 if test -n "${DST_FILE[2]}" && test ${OPT_DEPHDR^^} == 'Y'; then
307 eval "CFLAGS_DEPHDR_
${OPT_DEPHDR:+Y}=\"$CFLAGS_DEPHDR_Y_EVL\""
309 if test -n "${DST_FILE[3]}" && test ${OPT_CALL_GRAPH^^} == 'Y'; then
310 eval "CFLAGS_CALLGRAPH_
${OPT_CALLGRAPH:+Y}=\"$CFLAGS_CALLGRAPH_Y_EVL\""
313 eval cmd=\"$CPP2O_CMD_FMT\"
317 [[ $cmd == 0 ]] && CMPL_OBJ_LIST+="$fdst"
318 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
326 # fdesc: .asm文件编译成exe文件。
331 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[asm]}$ ]] && SRC_FILE[0]="$1"
332 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[obj]}$
]] && DST_FILE
[1]="$2"
333 [[ -n "${3}" && "${2}" =~ \.dephdr$
]] && DST_FILE
[2]="$3"
334 [[ -n "${4}" && "${2}" =~ \.cgraph$
]] && DST_FILE
[3]="$4"
337 mkdir
-p $
(dirname ${DST_FILE[0]})
339 eval cmd
=\"$ASM2EXE_CMD_FMT\"
343 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
350 # fdesc: c语言程序.c文件编译成.o文件。
355 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[c]}$
]] && SRC_FILE
[0]="$1"
356 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[obj]}$ ]] && DST_FILE[1]="$2"
357 [[ -n "${3}" && "${2}" =~ \.dephdr$ ]] && DST_FILE[2]="$3"
358 [[ -n "${4}" && "${2}" =~ \.cgraph$ ]] && DST_FILE[3]="$4"
361 mkdir -p $(dirname ${DST_FILE[0]})
363 eval cmd=\"$C2EXE_CMD_FMT\"
367 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
374 # fdesc: cpp程序.cpp文件编译成.o文件。
380 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[cxx]}$ ]] && SRC_FILE[0]="$1"
381 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[obj]}$
]] && DST_FILE
[1]="$2"
382 [[ -n "${3}" && "${2}" =~ \.dephdr$
]] && DST_FILE
[2]="$3"
383 [[ -n "${4}" && "${2}" =~ \.cgraph$
]] && DST_FILE
[3]="$4"
386 mkdir
-p $
(dirname ${DST_FILE[0]})
388 eval cmd
=\"$CXX2EXE_CMD_FMT\"
392 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
399 # fdesc: cpp程序.cpp文件编译成.o文件。
405 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[cpp]}$
]] && SRC_FILE
[0]="$1"
406 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[obj]}$ ]] && DST_FILE[1]="$2"
407 [[ -n "${3}" && "${2}" =~ \.dephdr$ ]] && DST_FILE[2]="$3"
408 [[ -n "${4}" && "${2}" =~ \.cgraph$ ]] && DST_FILE[3]="$4"
411 mkdir -p $(dirname ${DST_FILE[0]})
413 eval cmd=\"$CPP2EXE_CMD_FMT\"
417 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
423 #########################################
425 #########################################
429 # fdesc: .o文件链接成.o文件。
435 [[ -n "${1}" ]] && SRC_FILE
[0]="$1"
436 [[ -n "${2}" ]] && DST_FILE
[0]="$2"
437 [[ -n "${3}" ]] && DST_FILE
[2]="$3"
438 [[ -n "${4}" ]] && DST_FILE
[3]="$4"
441 mkdir
-p $
(dirname ${DST_FILE[0]})
443 eval cmd
=\"$O2O_CMD_FMT\"
447 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
453 # fsyntax: link_filename_fix
454 # fdesc: compile each src file.
461 # eval "ext
=\"\
${LANG_EXT_NAME[${lang,,}]}\""
462 #"${SRC_FILE[0]##*.}"
464 # obj="${DSTDIR}/${obj//\.$ext/\.o}"
465 # DST_FILE[0]="${DSTDIR}/${DST_FILE[0]}"
468 for ((i=0; i<${#SRC_FILE[@]}; i++)); do
469 if [[ ! "${SRC_FILE[$i]}" =~ ${OBJDIR} ]]; then
470 SRC_FILE[$i]="${OBJDIR}/${SRC_FILE[$i]}"
474 # DST_FILE[0]="${OUTDIR}/${DST_FILE[0]}"
479 # fdesc: .o files link to static library.
488 [[ -n "${1}" && "${!2}" =~ ${EXT_NAME[obj]}$
]] && SRC_FILE
[0]="$1"
489 [[ -n "${2}" && "${!2}" =~ ${EXT_NAME[lib]}$ ]] && DST_FILE[1]="$2"
490 [[ -n "${3}" && "${!2}" =~ \.dephdr$ ]] && DST_FILE[2]="$3"
491 [[ -n "${4}" && "${!2}" =~ \.cgraph$ ]] && DST_FILE[3]="$4"
495 # echo DST_FILE=$DST_FILE
498 mkdir -p $(dirname ${DST_FILE[0]})
500 eval cmd=\"$O2LIB_CMD_FMT\"
502 [[ $? != 0 ]] && return $?
507 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
514 # fdesc: .o files link to general static library.
519 # if test $ret != 0 ; then
528 # fdesc: .o files link to dynamic library.
534 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[obj]}$ ]] && SRC_FILE[0]="$1"
535 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[dll]}$
]] && DST_FILE
[1]="$2"
536 [[ -n "${3}" && "${2}" =~ \.dephdr$
]] && DST_FILE
[2]="$3"
537 [[ -n "${4}" && "${2}" =~ \.cgraph$
]] && DST_FILE
[3]="$4"
540 mkdir
-p $
(dirname ${DST_FILE[0]})
542 eval cmd
=\"$O2DLL_CMD_FMT\"
546 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
553 # fdesc: .o files link to static & dynamic library.
563 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[obj]}$
]] && SRC_FILE
[0]="$1"
564 [[ -n "${2}" && "${2}" =~ (${EXT_NAME[lib]}|${EXT_NAME[dll]})$ ]] && DST_FILE[1]="$2"
565 [[ -n "${3}" && "${2}" =~ \.dephdr$ ]] && DST_FILE[2]="$3"
566 [[ -n "${4}" && "${2}" =~ \.cgraph$ ]] && DST_FILE[3]="$4"
569 mkdir -p $(dirname ${DST_FILE[0]})
572 srcfile=( ${SRC_FILE[@]} )
573 DST_FILE="${DST_FILE%\.*}.a
"
575 eval cmd=\"$O2LIB_CMD_FMT\"
577 [[ $? != 0 ]] && return $?
580 [[ $? != 0 ]] && return $?
582 SRC_FILE=( ${srcfile[@]} )
583 DST_FILE="${file%\.*}.so
"
584 eval cmd=\"$O2DLL_CMD_FMT\"
588 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
595 # fdesc: .o files link to executables.
601 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[obj]}$ ]] && SRC_FILE[0]="$1"
602 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[exe]}$
]] && DST_FILE
[1]="$2"
603 [[ -n "${3}" && "${2}" =~ \.dephdr$
]] && DST_FILE
[2]="$3"
604 [[ -n "${4}" && "${2}" =~ \.cgraph$
]] && DST_FILE
[3]="$4"
607 mkdir
-p $
(dirname ${DST_FILE[0]})
609 eval cmd
=\"$O2EXE_CMD_FMT\"
613 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
620 # fdesc: .o文件链接成elf格式linux的drv文件。
626 [[ -n "${1}" && "${2}" =~ ${EXT_NAME[obj]}$
]] && SRC_FILE
[0]="$1"
627 [[ -n "${2}" && "${2}" =~ ${EXT_NAME[drv]}$ ]] && DST_FILE[1]="$2"
628 [[ -n "${3}" && "${2}" =~ \.dephdr$ ]] && DST_FILE[2]="$3"
629 [[ -n "${4}" && "${2}" =~ \.cgraph$ ]] && DST_FILE[3]="$4"
632 mkdir -p $(dirname ${DST_FILE[0]})
634 eval cmd=\"$O2DRV_CMD_FMT\"
638 test "${OPT_OBJSIZE_INFO^^}" == 'Y' && eval ${SIZE} ${DST_FILE[1]}
643 #########################################
644 # build postage processing & info.
645 # size of .text/.data/.rodata/.bss.
646 # internal symbol of an executable file.
647 # export symbol of an executable file.
650 # nm -D <file>, dynamic symbol. U, imported; T, exported.
651 # nm -g <file>, global symbol, all symbol.
653 # objdump -t <file> | grep -e "\.text", native code symbol.
654 # objdump -t <file> | grep -e "\.data", initialized var symbol.
655 # objdump -t <file> | grep -e "\.rodata", read only var symbol.
656 # objdump -t <file> | grep -e "\.bss", uninitialized var symbol.
658 # size <file>, it display size info in .text/.data(.rodata)/.bss
659 #########################################
663 # fdesc: delete debug symbol info .etc .
671 # attention -lncurses paramter must be put after .o file,
672 # or it report err that symbol not found.
673 cmd
="${STRIP} $(echo ${DST_FILE[@]})"
675 toolchain_dbgout
-ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
678 output
="$( eval $cmd 2>&1; )"
681 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build-dbgout.log
682 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build.log
684 if test $ret == 0 ||
test -z "$output" ; then
685 toolchain_dbgout
-ne " === ${cmd}\n"
687 toolchain_dbgout
-ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
688 toolchain_dbgout
"$output"
689 echo "$output" >> ${OUTDIR}/build-dbgout.log
692 if test $ret != 0 ; then
700 # fsyntax: prog_sizeinfo
701 # fdesc: size of .text/.data/.rodata/.bss.
711 DST_FILE
="${OUTDIR}/${!3}"
714 # for file in ${SRC_FILE[@]}; do
715 # if test -f "${DSTDIR}/${file}" ; then
716 # filelist+="${DSTDIR}/${file} "
719 # filelist+="${DST_FILE}"
721 # attention -lncurses paramter must be put after .o file,
722 # or it report err that symbol not found.
723 cmd
="${SIZE} $(basename ${DST_FILE})"
725 toolchain_dbgout
-ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
728 cd $
(dirname ${DST_FILE})
729 output
="$( eval ${cmd} 2>&1; )"
733 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build-dbgout.log
734 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build.log
736 if test $ret == 0 ||
test -z "$output" ; then
737 toolchain_dbgout
-ne " === ${cmd}\n"
740 toolchain_dbgout
-ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
742 echo "$output" >> ${OUTDIR}/build-dbgout.log
745 if test $ret != 0 ; then
753 # fsyntax: prog_symboals
754 # fdesc: output .text/.data/.rodata/.bss symbols in executables.
762 toolchain_dbgout
"[$file]"
763 { ${OBJDUMP} -t $file; ret
=$?
; } |
grep -o -e "\*UND\*.*" -e "\.bss.*" -e "\.rodata.*" -e "\.data.*" -e "\.text.*" |
grep -v $
'[ |\t]'"\..*" |
grep -v \"00000000\" |
sort |
sed -e "s/\.text/func-i/g; s/\*UND\*/func-e/g; s///g; s/\.data/var-i/g; s/\.bss/var/g; s/\.rodata/var-e/g;"
764 [[ $ret != 0 ]] && break;
765 done <<< "${SRC_FILE[@]}"
767 if test $ret != 0 ; then
777 # fsyntax: prog_inner_symbs
778 # fdesc: output internal symbols in executables.
786 [[ $SYMB_FILTER_SYS == 'y' ]] && param
="-v \"00000000\""
789 toolchain_dbgout
"[$file]"
790 { ${OBJDUMP} -t $file; ret
=$?
; } |
grep -o -e "\.text.*"|
grep -v $
'[ |\t]'"\..*" |
sort |
sed -e "s/\.text/func-i/g;"
791 done <<< "${SRC_FILE[@]}"
793 if test $ret != 0 ; then
801 # fsyntax: prog_ext_symbs
802 # fdesc: output external symbols in executables.
810 toolchain_dbgout
"[$file]"
811 { ${OBJDUMP} -t $file; ret
=$?
; } |
grep -o -e "\*UND\*.*"|
grep -v $
'[ |\t]'"\..*" |
grep -v \"00000000\" |
sort |
sed -e "s/\*UND\*/func-e/g; s///g;"
812 done <<< "${SRC_FILE[@]}"
814 if test $ret != 0 ; then
822 # fsyntax: prog_func_symbs
823 # fdesc: output function symbols in executables.
831 toolchain_dbgout
"[$file]"
832 { ${OBJDUMP} -t $file; ret
=$?
; } |
grep -o -e "\*UND\*.*" -e "\.text.*" |
grep -v $
'[ |\t]'"\..*" |
sort |
sed -e "s/\.text/func-i/g; s/\*UND\*/func-e/g; s///g;"
833 done <<< "${SRC_FILE[@]}"
835 if test $ret != 0 ; then
843 # fsyntax: prog_func_symbs
844 # fdesc: output function symbols in executables.
852 toolchain_dbgout
"[$file]"
853 { ${OBJDUMP} -t $file; ret
=$?
; } |
grep -o -e "\.bss.*" -e "\.rodata.*" -e "\.data.*" |
grep -v $
'[ |\t]'"\..*" |
grep -v \"00000000\" |
sort |
sed -e "s/\.text/func-i/g; s/\*UND\*/func-e/g; s///g;"
854 done <<< "${SRC_FILE[@]}"
856 if test $ret != 0 ; then
864 #########################################
865 # bin/hex output and transform.
866 #########################################
871 # fdesc: bin二进制文件转换成hex字符串。
881 # fdesc: elf文件读取code/data的section,保存成bin文件。
888 { objcopy
-t $file |
grep -o -e "\.bss.*" -e "\.rodata.*" -e "\.data.*"; ret
=$?
; } |
grep -v $
'[ |\t]'"\..*" |
grep -v \"00000000\" |
sort |
sed -e "s/\.text/func-i/g; s/\*UND\*/func-e/g; s///g;"
890 if test $ret != 0 ; then
899 # fdesc: bin二进制文件转换成hex字符串。
903 # hexdump -e '/1 "%02x " '
904 xxd
-ps -c 16 - 2>/dev
/null
909 # fdesc: hex字符串转换成bin二进制数据文件。
917 # fsyntax: fbin2fhex <srcfile> <dst>
918 # fdesc: bin二进制文件转换成hex文件。
922 xxd
-ps -c 16 $1 2>/dev
/null
> $2
927 # fdesc: hex文件转换成bin二进制数据文件。
939 echo "[error]: cmd not defined. look at the defination in toolchain/${TOOLCHAIN}.imi, or use another toolchain." >&2
943 # syntax: without_pfx <pfx>
947 eval local varlist
="\${!${1}*}"
949 for var
in ${varlist}; do
950 eval name
="\${var#$1}"
958 get_toolchain_info
()
960 echo 'int main(){}' > /tmp
/dummy.c
964 # test the parameters setting in files.
965 # use c2exe() instead of directly invoke, it can test for some 'GCC' cross-compiler.
967 # gcc /tmp/dummy.c -I. -L/tmp/lib -Wl,-rpath,/tmp/lib -rdynamic -lpthread -v -Wl,--verbose &> /tmp/dummy.log
968 LDFLAGS_EXT
="-v -Wl,--verbose -lpthread" c2exe
/tmp
/dummy.c
/tmp
/dummy
> /tmp
/dummy.log
972 # get include paths for '#include <...>'
974 # echo "===== get include path ====="
975 INC_PATHS
=( `grep -B100 '^End of search list.' /tmp/dummy.log | grep -A100 '^#include <...>' | grep -v 'End of search list.' | grep -v '#include <...>'` )
977 # echo ${INC_PATHS[@]}
979 # /usr/lib/gcc/i686-linux-gnu/5/include
981 # /usr/lib/gcc/i686-linux-gnu/5/include-fixed
982 # /usr/include/i386-linux-gnu
986 # get lib paths in linking
988 # echo "===== get lib path ====="
989 LIB_PATHS
=( `grep 'SEARCH.*/usr/lib' /tmp/dummy.log |sed 's|; |\n|g' | sed 's|SEARCH_DIR("=||g' | sed 's|")||g' | sed 's|;||g'` )
991 # echo ${LIB_PATHS[@]}
992 #/usr/local/lib/i386-linux-gnu
994 #/usr/lib/i386-linux-gnu
1001 #/usr/i686-linux-gnu/lib32
1002 #/usr/i686-linux-gnu/lib
1005 # get lib libpthread linked in.
1007 # echo "===== get libs ====="
1008 LINKED_LIBS
=( `grep -e 'succeeded' /tmp/dummy.log | grep -v '\.o[[:blank:]]*' | sed 's|attempt to open ||g' | sed 's| succeeded||g' | xargs file -L 2>/dev/null| grep -E 'ELF|archive' | sed 's|:.*$||g'` )
1010 # echo ${LINKED_LIBS[@]}
1011 #/lib/i386-linux-gnu/libpthread.so.0
1012 #/usr/lib/i386-linux-gnu/libpthread_nonshared.a
1014 rm /tmp
/dummy.c
/tmp
/dummy
/tmp
/dummy.log
1019 #loadimi ../platform/param.imi
1022 # toolchain config info & general define info.
1023 # TBD: config info should be get from cmd param or envar.
1025 loadimi
${SRCPKG_DIR_FULL}/build
/toolchain-cfg.imi
1027 echo =========================== MACHTYPE
=$MACHTYPE
1029 loadimi
${SRCPKG_DIR_FULL}/tools
/build-srcpkg
/platform
/toolchain_info.imi
1031 echo =========================== MACHTYPE
=$MACHTYPE
1033 # other build utilities.
1034 #loadimi ../toolset/toolset.imi
1037 toolchain_default_param_load
()
1039 loadimi tools
/build-srcpkg
/info
/paramters.imi
1044 ######################
1045 # section: file tail
1046 ######################
1052 # fsyntax: toolchain_chk
1053 # fdesc: check toolchain if it can works in usual. save flags in
1054 # build-srcpkg config file.
1063 # fsyntax: dev_env_chk
1064 # fdesc: check commands and build env.
1073 # fsyntax: dep_lib_chk
1074 # fdesc: check external lib file if it exist and can works.
1075 # save checking resualt into build-srcpkg config file.
1084 # fsyntax: dep_syshdr_chk
1085 # fdesc: check system .h file if it exist.