2 ############################################################
3 # source: toolchain.shlib
4 # author: CottonCandyOwner(CottonCandyOwner@126.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 test -z "$(type inc 2>/dev/null)"; then
54 test -z "$1" ||
test ! -f "$1" && return 1
56 tmp
="$(echo "$1" | tr '[[:punct:]]' '_')"
57 eval test "\${$tmp}" = 1 && return 0
72 # file name format define
79 ######################
80 # section: common comment info
81 ######################
83 ######################
84 # section: variable define
85 ######################
89 ######################
90 # section: private function
91 ######################
95 test "${OPT_VERBOSE_INFO}" = 'Y' -o "${OPT_VERBOSE_INFO}" = 'y' && echo "$@"
102 ######################
103 # section: public function
104 ######################
106 #########################################
108 #########################################
123 # attention -lncurses paramter must be put after .o file,
124 # or it report err that symbol not found.
125 # cmd="${CC} ${ASFLAGS_OUT} ${ASFLAGS_EXT} ${CFLAGS} ${LDFLAGS} $(envar ${SRC_FILE[@]}) -o ${DST_FILE[0]}"
128 # XXX: if there is blank in quoted "string", it will be shorten to single.
129 # append '\' before it.
131 cmd
="$(echo "${cmd}" | tr -s '[[:space:]]' ' ')"
133 # release var after cmd is filled.
138 # TBD: do parameter checking work here.
144 # if stdout is redirected by '|' pipe,
145 # it will not display with color.
147 # output="$( eval $cmd 2>&1 )"
148 eval $cmd > /tmp
/output.log
2>&1
151 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build-dbgout.log
152 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build.log
153 # echo -ne " === ${cmd}\n" >&2
155 if test $ret = 0 ||
! test -s /tmp
/output.log
&& test "${verbose_mode}" != Y
-a "${verbose_mode}" != y
; then
156 toolchain_dbgout
-ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
158 echo -ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
160 test "${OPT_VERBOSE_INFO}" = 'Y' -o "${OPT_VERBOSE_INFO}" = 'y' && cat /tmp/output.log >> ${OUTDIR}/build-dbgout.log
163 test "$ret" != 0 && return 2
168 # fsyntax: asm2o <src-file> <output-file>
169 # fdesc: asm汇编程序.S文件编译成.o文件。
175 test -n "${1}" && SRC_FILE="$1"
176 test -n "${2}" && setenv DST_FILE[1]="$2"
178 eval cmd=\"$ASM2O_CMD_FMT\"
182 test $cmd = 0 && CMPL_OBJ_LIST="$CMPL_OBJ_LIST $fdst"
183 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $
(getenv DST_FILE
[1])
189 # fsyntax: src2dst_filename
190 # fdesc: compile each src file.
194 test -z "${SRC_FILE}" && echo -e "[error]: SRC_FILE[0] should not be NULL, and '\n$(decl -p DST_FILE)'.\n" >&2 && exit
196 local tmp
="$(echo "$SRC_FILE" | sed -E "s
/,.
*\$
//g
")"
197 SRC_FILE
="$(echo "$SRC_FILE" | sed -E "s
/\
,/\
/g
")"
199 test -z "${DST_FILE}" && fname_src2dst
$tmp
200 test -z "$(getenv DST_FILE[1])" && fname_src2obj
$tmp
202 if test "$OPT_DEPHDR" = 'Y' -o "$OPT_DEPHDR" = 'y' -o "$OPT_CALLGRAPH" = 'Y' -o "$OPT_CALLGRAPH" = 'y'; then
203 test -z "$(getenv DST_FILE[2])" && fname_src2dep
$tmp
204 test -z "$(getenv DST_FILE[3])" && fname_src2graph
$tmp
209 # set those two by cmd opt or envar or DEBUG/RELEASE opt.
215 # fsyntax: c2o <src-file> [ <obj-file> [ <dep-file> [<graph-file>] ] ]
216 # fdesc: .c src file compile to .o file. parameters can be given in func arg,
217 # and envar SRC_FILE & DST_FILE. you can given one param <obj-file> only,
218 # it will generate others in auto.
229 test -n "${1}" && strstr
"${1}" =~ $
(getenv EXT_NAME
[$lang])$
&& SRC_FILE
="$1"
230 test -n "${2}" && strstr
"${2}" =~ $
(getenv EXT_NAME
[obj
])$
&& setenv DST_FILE
[1]="$2"
231 test -n "${2}" && strstr
"${2}" =~ $
(getenv EXT_NAME
[exe
])$
&& DST_FILE
="$2"
232 test -n "${3}" && strstr
"${3}" =~ \.dephdr$
&& setenv DST_FILE
[2]="$3"
233 test -n "${4}" && strstr
"${4}" =~ \.cgraph$
&& setenv DST_FILE
[3]="$4"
235 fdst
="$(getenv DST_FILE[1]) "
237 mkdir
-p $
(dirname $
(getenv DST_FILE
[1]))
241 # echo SRC_FILE=$(envar SRC_FILE[@])
242 # echo DST_FILE=$(envar DST_FILE[@])
245 CFLAGS_CALLGRAPH_Y
=""
246 if test -n "$(getenv DST_FILE[2])" && test "${OPT_DEPHDR}" = 'Y' -o "${OPT_DEPHDR}" = 'y'; then
247 eval "CFLAGS_DEPHDR_Y=\"$CFLAGS_DEPHDR_Y_EVL\""
249 if test -n "$(getenv DST_FILE[3])" && test "${OPT_CALL_GRAPH}" = 'Y' -o "${OPT_CALL_GRAPH}" = 'y'; then
250 eval "CFLAGS_CALLGRAPH_Y=\"$CFLAGS_CALLGRAPH_Y_EVL\""
253 eval cmd
=\"\
${${LANG}2${DST}_CMD_FMT}\"
258 test $cmd = 0 && CMPL_OBJ_LIST
="$CMPL_OBJ_LIST $fdst"
259 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $(getenv DST_FILE[1])
272 # fdesc: .cc文件编译成.o文件。
278 test -n "${1}" && strstr "${1}" =~ $(getenv EXT_NAME[cxx])$ && setenv SRC_FILE="$1"
279 test -n "${2}" && strstr "${2}" =~ $(getenv EXT_NAME[obj])$ && setenv DST_FILE[1]="$2"
280 test -n "${3}" && strstr "${3}" =~ \.dephdr$ && setenv DST_FILE[2]="$3"
281 test -n "${4}" && strstr "${4}" =~ \.cgraph$ && setenv DST_FILE[3]="$4"
283 fdst="$
(getenv DST_FILE
[1]) "
285 mkdir -p $(dirname $(getenv DST_FILE[0]))
288 CFLAGS_CALLGRAPH_Y=""
289 if test -n "$
(getenv DST_FILE
[2])" && test "${OPT_DEPHDR}" = 'Y' -o "${OPT_DEPHDR}" = 'y'; then
290 eval "CFLAGS_DEPHDR_Y
=\"$CFLAGS_DEPHDR_Y_EVL\""
292 if test -n "$
(getenv DST_FILE
[3])" && test "${OPT_CALL_GRAPH}" = 'Y' -o "${OPT_CALL_GRAPH}" = 'y'; then
293 eval "CFLAGS_CALLGRAPH_Y
=\"$CFLAGS_CALLGRAPH_Y_EVL\""
296 eval cmd=\"$CXX2O_CMD_FMT\"
300 test $cmd = 0 && CMPL_OBJ_LIST="$CMPL_OBJ_LIST $fdst"
301 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $
(getenv DST_FILE
[1])
308 # fdesc: cpp程序.cpp文件编译成.o文件。
315 test -n "${1}" && strstr
"${1}" =~ $
(getenv EXT_NAME
[cpp
])$
&& SRC_FILE
="$1"
316 test -n "${2}" && strstr
"${2}" =~ $
(getenv EXT_NAME
[obj
])$
&& setenv DST_FILE
[1]="$2"
317 test -n "${3}" && strstr
"${3}" =~ \.dephdr$
&& setenv DST_FILE
[2]="$3"
318 test -n "${4}" && strstr
"${4}" =~ \.cgraph$
&& setenv DST_FILE
[3]="$4"
320 fdst
="$(getenv DST_FILE[1]) "
322 mkdir
-p $
(dirname ${DST_FILE})
325 CFLAGS_CALLGRAPH_Y
=""
326 if test -n "$(getenv DST_FILE[2])" && test "${OPT_DEPHDR}" = 'Y' -o "${OPT_DEPHDR}" = 'y'; then
327 eval "CFLAGS_DEPHDR_Y=\"$CFLAGS_DEPHDR_Y_EVL\""
329 if test -n "$(getenv DST_FILE[3])" && test "${OPT_CALL_GRAPH}" = 'Y' -o "${OPT_CALL_GRAPH}" = 'y'; then
330 eval "CFLAGS_CALLGRAPH_Y=\"$CFLAGS_CALLGRAPH_Y_EVL\""
333 eval cmd
=\"$CPP2O_CMD_FMT\"
337 test $cmd = 0 && CMPL_OBJ_LIST
="$CMPL_OBJ_LIST $fdst"
338 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $(getenv DST_FILE[1])
346 # fdesc: .asm文件编译成exe文件。
351 test -n "${1}" && strstr "${1}" =~ $(getenv EXT_NAME[asm])$ && SRC_FILE="$1"
352 test -n "${2}" && strstr "${2}" =~ $(getenv EXT_NAME[obj])$ && setenv DST_FILE[1]="$2"
353 test -n "${3}" && strstr "${3}" =~ \.dephdr$ && setenv DST_FILE[2]="$3"
354 test -n "${4}" && strstr "${4}" =~ \.cgraph$ && setenv DST_FILE[3]="$4"
357 mkdir -p $(dirname ${DST_FILE})
359 eval cmd=\"$ASM2EXE_CMD_FMT\"
363 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $
(getenv DST_FILE
[1])
370 # fdesc: c语言程序.c文件编译成.o文件。
379 # fdesc: cpp程序.cpp文件编译成.o文件。
385 test -n "${1}" && strstr
"${1}" =~ $
(getenv EXT_NAME
[cxx
])$
&& SRC_FILE
="$1"
386 test -n "${2}" && strstr
"${2}" =~ $
(getenv EXT_NAME
[obj
])$
&& DST_FILE
="$2"
387 test -n "${3}" && strstr
"${3}" =~ \.dephdr$
&& setenv DST_FILE
[2]="$3"
388 test -n "${4}" && strstr
"${4}" =~ \.cgraph$
&& setenv DST_FILE
[3]="$4"
391 mkdir
-p $
(dirname ${DST_FILE})
393 eval cmd
=\"$CXX2EXE_CMD_FMT\"
397 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $(getenv DST_FILE[1])
404 # fdesc: cpp程序.cpp文件编译成.o文件。
410 test -n "${1}" && strstr "${1}" =~ $(getenv EXT_NAME[cpp])$ && SRC_FILE="$1"
411 test -n "${2}" && strstr "${2}" =~ $(getenv EXT_NAME[obj])$ && setenv DST_FILE[1]="$2"
412 test -n "${3}" && strstr "${3}" =~ \.dephdr$ && setenv DST_FILE[2]="$3"
413 test -n "${4}" && strstr "${4}" =~ \.cgraph$ && setenv DST_FILE[3]="$4"
416 mkdir -p $(dirname ${DST_FILE})
418 eval cmd=\"$CPP2EXE_CMD_FMT\"
422 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $
(getenv DST_FILE
[1])
428 #########################################
430 #########################################
434 # fdesc: .o文件链接成.o文件。
440 test -n "${1}" && SRC_FILE
="$1"
441 test -n "${2}" && DST_FILE
="$2"
442 test -n "${3}" && setenv DST_FILE
[2]="$3"
443 test -n "${4}" && setenv DST_FILE
[3]="$4"
446 mkdir
-p $
(dirname ${DST_FILE})
448 eval cmd
=\"$O2O_CMD_FMT\"
452 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $(getenv DST_FILE[1])
458 # fsyntax: link_filename_fix
459 # fdesc: compile each src file.
467 # eval "ext
=\"\
${LANG_EXT_NAME[${lang,,}]}\""
470 # obj="${DSTDIR}/${obj//\.$ext/\.o}"
471 # DST_FILE="${DSTDIR}/${DST_FILE}"
474 for file in $(arrname SRC_FILE); do
475 if [[ ! "$
(eval echo "\"\${$file}\"")" =~ ${OBJDIR} ]]; then
476 setenv $file="${OBJDIR}/$
(eval echo -n "\"\${$file}\"")"
479 # DST_FILE[0]="${OUTDIR}/${DST_FILE[0]}"
484 # fdesc: .o files link to static library.
498 # test -n "${1}" && strstr "${!1}" =~ $(getenv EXT_NAME[$src])$ && eval SRC_FILE=\"\${$1}\"
499 # XXX: if $dst = exe in windows, it matched every time due to no sfx name.
500 # test -n "${2}" && strstr "${!2}" =~ $(getenv EXT_NAME[$dst])$ && DST_FILE="$2"
504 # echo DST_FILE=$DST_FILE
507 mkdir
-p $
(dirname ${DST_FILE})
509 eval cmd
=\"\
${${SRC}2${DST}_CMD_FMT}\"
513 # test $? != 0 && return $?
517 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} ${DST_FILE}
524 # fdesc: .o files link to static library.
530 link_dest obj O lib LIB $@
532 test "$ret" != 0 && return $ret
540 # fdesc: .o files link to general static library.
545 # if test $ret != 0 ; then
554 # fdesc: .o files link to dynamic library.
560 test -n "${1}" && strstr "${1}" =~ $(getenv EXT_NAME[obj])$ && SRC_FILE="$1"
561 test -n "${2}" && strstr "${2}" =~ $(getenv EXT_NAME[dll])$ && setenv DST_FILE[1]="$2"
562 test -n "${3}" && strstr "${3}" =~ \.dephdr$ && setenv DST_FILE[2]="$3"
563 test -n "${4}" && strstr "${4}" =~ \.cgraph$ && setenv DST_FILE[3]="$4"
566 mkdir -p $(dirname ${DST_FILE})
568 eval cmd=\"$O2DLL_CMD_FMT\"
572 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $
(getenv DST_FILE
[1])
579 # fdesc: .o files link to static & dynamic library.
589 test -n "${1}" && strstr
"${1}" =~ $
(getenv EXT_NAME
[obj
])$
&& SRC_FILE
="$1"
590 test -n "${2}" && strstr
"${2}" =~ \
($
(getenv EXT_NAME
[lib
])|$
(getenv EXT_NAME
[dll
])\
)$
&& setenv DST_FILE
[1]="$2"
591 test -n "${3}" && strstr
"${3}" =~ \.dephdr$
&& setenv DST_FILE
[2]="$3"
592 test -n "${4}" && strstr
"${4}" =~ \.cgraph$
&& setenv DST_FILE
[3]="$4"
595 mkdir
-p $
(dirname ${DST_FILE})
598 loadarr srcfile
= "( $(envar SRC_FILE[@]) )"
599 DST_FILE
="$(echo "${DST_FILE}" | sed -E "s
/\.
[^\.
]*/.a
/g
")"
601 eval cmd
=\"$O2LIB_CMD_FMT\"
603 test $?
!= 0 && return $?
606 test $?
!= 0 && return $?
608 loadarr SRC_FILE
= "( $(envar srcfile[@]) )"
609 DST_FILE
="$(echo "${DST_FILE}" | sed -E "s
/\.
[^\.
]*/.so
/g
")"
611 eval cmd
=\"$O2DLL_CMD_FMT\"
615 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $(getenv DST_FILE[1])
622 # fdesc: .o files link to executables.
629 test -n "${1}" && strstr "${1}" =~ $(getenv EXT_NAME[obj])$ && SRC_FILE="$1"
630 # test -n "${2}" && strstr "${2}" =~ $(getenv EXT_NAME[exe])$ && DST_FILE="$2"
631 # test -n "${2}" && strstr "${2}" =~ \($(getenv EXT_NAME[lib])|$(getenv EXT_NAME[dll])\)$ &&
632 # DST_FILE="$
(eval echo "\"\${$2}\"")"
636 mkdir -p $(dirname ${DST_FILE})
638 eval cmd=\"$O2EXE_CMD_FMT\"
644 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $
(getenv DST_FILE
[1])
651 # fdesc: .o文件链接成elf格式linux的drv文件。
657 test -n "${1}" && strstr
"${1}" =~ $
(getenv EXT_NAME
[obj
])$
&& SRC_FILE
="$1"
658 test -n "${2}" && strstr
"${2}" =~ $
(getenv EXT_NAME
[drv
])$
&& setenv DST_FILE
[1]="$2"
659 test -n "${3}" && strstr
"${3}" =~ \.dephdr$
&& setenv DST_FILE
[2]="$3"
660 test -n "${4}" && strstr
"${4}" =~ \.cgraph$
&& setenv DST_FILE
[3]="$4"
663 mkdir
-p $
(dirname ${DST_FILE})
665 eval cmd
=\"$O2DRV_CMD_FMT\"
669 test "${OPT_OBJSIZE_INFO}" = 'Y' -o "${OPT_OBJSIZE_INFO}" = 'y' && eval ${SIZE} $(getenv DST_FILE[1])
674 #########################################
675 # build postage processing & info.
676 # size of .text/.data/.rodata/.bss.
677 # internal symbol of an executable file.
678 # export symbol of an executable file.
681 # nm -D <file>, dynamic symbol. U, imported; T, exported.
682 # nm -g <file>, global symbol, all symbol.
684 # objdump -t <file> | grep -e "\.text
", native code symbol.
685 # objdump -t <file> | grep -e "\.data
", initialized var symbol.
686 # objdump -t <file> | grep -e "\.rodata
", read only var symbol.
687 # objdump -t <file> | grep -e "\.bss
", uninitialized var symbol.
689 # size <file>, it display size info in .text/.data(.rodata)/.bss
690 #########################################
694 # fdesc: delete debug symbol info .etc .
702 test -n "${2}" || test -n "$DST_FILE" && DST_FILE="${OUTDIR}/$2"
704 # attention -lncurses paramter must be put after .o file,
705 # or it report err that symbol not found.
706 cmd="${STRIP} $
(envar DST_FILE
[@
])"
708 toolchain_dbgout -ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
711 output="$
( eval $cmd 2>&1; )"
714 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build-dbgout.log
715 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build.log
717 if test $ret == 0 || test -z "$output" ; then
718 toolchain_dbgout -ne " === ${cmd}\n"
720 toolchain_dbgout -ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
721 toolchain_dbgout "$output"
722 echo "$output" >> ${OUTDIR}/build-dbgout.log
725 if test $ret != 0 ; then
733 # fsyntax: prog_sizeinfo
734 # fdesc: size of .text/.data/.rodata/.bss.
744 test -z "$DST_FILE" && eval DST_FILE="${OUTDIR}/\
${${3}}"
747 # attention -lncurses paramter must be put after .o file,
748 # or it report err that symbol not found.
749 cmd="${SIZE} $
(basename ${DST_FILE})"
751 toolchain_dbgout -ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
754 cd $(dirname ${DST_FILE})
755 output="$
( eval ${cmd} 2>&1; )"
759 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build-dbgout.log
760 echo -ne " === ${cmd}\n" >> ${OUTDIR}/build.log
762 if test $ret == 0 || test -z "$output" ; then
763 toolchain_dbgout -ne " === ${cmd}\n"
766 toolchain_dbgout -ne "${CHIGHL} === ${cmd}${CNORMAL}\n"
768 echo "$output" >> ${OUTDIR}/build-dbgout.log
771 if test $ret != 0 ; then
779 # fsyntax: prog_symboals
780 # fdesc: output .text/.data/.rodata/.bss symbols in executables.
788 toolchain_dbgout "[$file]"
789 { ${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
/\.data
/var-i
/g
; s
/\.bss
/var
/g
; s
/\.rodata
/var-e
/g
;"
790 test $ret != 0 && break;
795 if test $ret != 0 ; then
805 # fsyntax: prog_inner_symbs
806 # fdesc: output internal symbols in executables.
814 test $SYMB_FILTER_SYS = 'y' && param="-v \"00000000\""
817 toolchain_dbgout "[$file]"
818 { ${OBJDUMP} -t $file; ret=$?; } | grep -o -e "\.text.
*"| grep -v $'[ |\t]'"\..
*" | sort | sed -e "s
/\.text
/func-i
/g
;"
823 if test $ret != 0 ; then
831 # fsyntax: prog_ext_symbs
832 # fdesc: output external symbols in executables.
840 toolchain_dbgout "[$file]"
841 { ${OBJDUMP} -t $file; ret=$?; } | grep -o -e "\
*UND\
*.
*"| grep -v $'[ |\t]'"\..
*" | grep -v \"00000000\" | sort | sed -e "s
/\
*UND\
*/func-e
/g
;;"
846 if test $ret != 0 ; then
854 # fsyntax: prog_func_symbs
855 # fdesc: output function symbols in executables.
863 toolchain_dbgout "[$file]"
864 { ${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
;"
869 if test $ret != 0 ; then
877 # fsyntax: prog_func_symbs
878 # fdesc: output function symbols in executables.
886 toolchain_dbgout "[$file]"
887 { ${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
;"
892 if test $ret != 0 ; then
900 #########################################
901 # bin/hex output and transform.
902 #########################################
907 # fdesc: bin二进制文件转换成hex字符串。
917 # fdesc: elf文件读取code/data的section,保存成bin文件。
924 { 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
;"
926 if test $ret != 0 ; then
935 # fdesc: bin二进制文件转换成hex字符串。
939 # hexdump -e '/1 "%02x
" '
940 xxd -ps -c 16 - 2>/dev/null
945 # fdesc: hex字符串转换成bin二进制数据文件。
953 # fsyntax: fbin2fhex <srcfile> <dst>
954 # fdesc: bin二进制文件转换成hex文件。
958 xxd -ps -c 16 $1 2>/dev/null > $2
963 # fdesc: hex文件转换成bin二进制数据文件。
975 echo "[error
]: cmd not defined.
look at the defination
in toolchain
/${TOOLCHAIN}.imi
, or use another toolchain.
" >&2
979 # syntax: without_pfx <pfx>
983 eval local varlist="\
${!${1}*}"
985 for var in ${varlist}; do
986 eval name="\
${var#$1}"
989 # name="$
(echo "$var" |
sed -E "s/$1//g"}"
990 # eval $name=\"\${$var}\"
1001 get_toolchain_info ()
1003 echo 'int main(){}' > /tmp/dummy.c
1007 # test the parameters setting in files.
1008 # use c2exe() instead of directly invoke, it can test for some 'GCC' cross-compiler.
1010 # gcc /tmp/dummy.c -I. -L/tmp/lib -Wl,-rpath,/tmp/lib -rdynamic -lpthread -v -Wl,--verbose &> /tmp/dummy.log
1011 LDFLAGS_EXT="-v -Wl,--verbose -lpthread" c2exe /tmp/dummy.c /tmp/dummy > /tmp/dummy.log
1012 test $? != 0 && echo "compile src
in get_toolchain_info
() error.
" >&2 && echo CMD_BAK=\"$CMD_BAK\" && cat /tmp/dummy.log && exit
1016 # get include paths for '#include <...>'
1018 # echo "===== get include path
====="
1019 loadarr INC_PATHS = "( `grep -B100 '^End of search list.' /tmp/dummy.log | grep -A100 '^#include <...>' | grep -v 'End of search list.' | grep -v '#include <...>'` )"
1021 # envar INC_PATHS[@]
1023 # /usr/lib/gcc/i686-linux-gnu/5/include
1024 # /usr/local/include
1025 # /usr/lib/gcc/i686-linux-gnu/5/include-fixed
1026 # /usr/include/i386-linux-gnu
1030 # get lib paths in linking
1032 # echo "===== get lib path
====="
1033 loadarr LIB_PATHS = "( `grep 'SEARCH.*/usr/lib' /tmp/dummy.log |sed 's|; |\n|g' | sed 's|SEARCH_DIR("=||g' | sed 's|")||g' | sed 's|;||g'` )"
1035 # envar LIB_PATHS[@]
1036 #/usr/local/lib/i386-linux-gnu
1037 #/lib/i386-linux-gnu
1038 #/usr/lib/i386-linux-gnu
1045 #/usr/i686-linux-gnu/lib32
1046 #/usr/i686-linux-gnu/lib
1049 # get lib libpthread linked in.
1051 # echo "===== get libs
====="
1052 loadarr 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'` )"
1054 # envar LINKED_LIBS[@]
1055 #/lib/i386-linux-gnu/libpthread.so.0
1056 #/usr/lib/i386-linux-gnu/libpthread_nonshared.a
1058 rm /tmp/dummy.c /tmp/dummy /tmp/dummy.log -f
1063 $1 -v 2>&1 | grep -oE "^gcc version
[[:alnum
:]_
+.
-]+ " | sed -E "s
/^gcc version
([[:alnum
:]_
+.
-]+) /\
1/g
"
1068 ######################
1069 # section: file tail
1070 ######################
1076 # fsyntax: toolchain_chk
1077 # fdesc: check toolchain if it can works in usual. save flags in
1087 # fsyntax: dev_env_chk
1088 # fdesc: check commands and build env.
1097 # fsyntax: dep_lib_chk
1098 # fdesc: check external lib file if it exist and can works.
1099 # save checking resualt into cmpl config file.
1108 # fsyntax: dep_syshdr_chk
1109 # fdesc: check system .h file if it exist.