2 ############################################################
4 # author: CottonCandyOwner(CottonCandyOwner@126.com)
6 ############################################################
9 # file & dir name stored in envar for using. as an auxiliary
10 # method, arg param in func update to local envar for using.
11 # those var are store dir/file name for using.
13 # SRC_FILE[0], input src file name. in compile, it's xxx.c, in link, it's xxx.o
14 # DSTFILE/DST_FILE[0], output dst file name. lib/dll/exe
15 # OBJFILE/DST_FILE[1], output obj file name.
16 # DEPFILE/DST_FILE[2], output hdr dep file name.
17 # CGRAPHFILE/DST_FILE[3], output call graph file name.
19 # @ all dir defined without '/' surffix, but root dir.
20 # @ ext name with '.' prefix in envar.
21 # @ {} should be added for envar using.
22 # @ ${var} should be quoted with double quote.
24 # this copy of src can be used as a single file. it process
26 # @ public defination.
28 # @ param var, defined in .imi for config.
29 # DEST_NAME/DEST_TYPE/OUTDIR=
30 # @ *_EVL format define var, defined in this file.
31 # DSTDIR_EVL/OBJDIR_EVL/DSTFILE_FMT/OBJFILE_FMT/DEPFILE_FMT
33 # @ output var, generated in func in this file.
34 # DSTDIR/OBJDIR/DSTFILE/OBJFILE/DEPFILE/CGRAPHFILE/DST_FILE[]
36 ############################################################
46 ######################
47 # section: common comment info
48 ######################
51 ######################
52 # section: variable define
53 ######################
57 # TBD: those info should be defined in platform/toolchain/*.imi file as general info.
60 if [[ -z $OS ||
$OS == linux
]]; then
62 elif [[ $OS == win32 ||
$OS == cygwin || TOOLCHAIN
== vc
]]; then
67 echo "unkown build system."
70 if [[ -z $OS ||
$OS == cygwin || TOOLCHAIN
== gcc
]]; then
72 elif strstr
$VENDOR =~ GNU
; then
74 elif [[ $OS == win32 || TOOLCHAIN
== vc
]]; then
76 elif [[ TOOLCHAIN
== iar || TOOLCHAIN
== mdk
]]; then
83 setenv EXT_NAME
[null
]=""
86 # operating system relative
88 if [[ $BUILD_SYSTEM == linux
]]; then
99 elif [[ $BUILD_SYSTEM == win32
]]; then
109 EXT_NAME_exelist
=".exe"
111 echo "invalid OS type($BUILD_SYSTEM) info."
116 # arch/toolchain relative
118 if [[ $CMPLR == gcc
]]; then
119 EXT_NAME_objlist
=".o"
127 EXT_NAME_dephdr
=".dephdr"
128 EXT_NAME_cgraph
=".callgraph"
129 elif [[ $CMPLR == vc
]]; then
130 EXT_NAME_objlist
=".obj"
138 EXT_NAME_dephdr
=".dephdr"
139 EXT_NAME_cgraph
=".callgraph"
140 elif [[ $CMPLR == iar ||
$CMPLR == mdk
]]; then
141 EXT_NAME_objlist
=".obj"
149 EXT_NAME_dephdr
=".dephdr"
150 EXT_NAME_cgraph
=".callgraph"
152 echo "invalid toolchain($TOOLCHAIN) info."
156 EXT_NAME_texi
=".texi"
158 EXT_NAME_docbook
=".docbook"
166 EXT_NAME_info
=".info"
170 EXT_NAME_html
=".html"
180 # setenv LANG_EXT_NAME[c]="c"
181 # setenv LANG_EXT_NAME[sh]="sh"
182 #if [[ ${COMPILER_TYPE,,} == gcc ]]; then
183 # setenv LANG_EXT_NAME[cxx]="cc"
184 # setenv LANG_EXT_NAME[cpp]="cpp"
185 # setenv LANG_EXT_NAME[c++]="cpp"
186 # setenv LANG_EXT_NAME[asm]="S"
187 #elif [[ ${SYSTEM_TYPE,,} == mac ]]; then
188 # setenv LANG_EXT_NAME[cxx]="cc"
189 # setenv LANG_EXT_NAME[cpp]="cpp"
190 # setenv LANG_EXT_NAME[c++]="cpp"
191 # setenv LANG_EXT_NAME[asm]="asm"
195 setenv EXT_NAME
[drv
]="${EXT_NAME_drv}"
196 setenv EXT_NAME
[exe
]="${EXT_NAME_exe}"
197 setenv EXT_NAME
[dll
]="${EXT_NAME_dll}"
198 setenv EXT_NAME
[lib
]="${EXT_NAME_lib}"
199 setenv EXT_NAME
[exelist
]="${EXT_NAME_exelist}"
202 setenv EXT_NAME
[objlist
]="${EXT_NAME_objlist}"
203 setenv EXT_NAME
[asm
]="${EXT_NAME_asm}"
204 setenv EXT_NAME
[obj
]="${EXT_NAME_obj}"
206 setenv EXT_NAME
[sh
]="${EXT_NAME_sh}"
207 setenv EXT_NAME
[c
]="${EXT_NAME_c}"
208 setenv EXT_NAME
[cxx
]="${EXT_NAME_cxx}"
209 setenv EXT_NAME
[cpp
]="${EXT_NAME_cpp}"
210 setenv EXT_NAME
[dephdr
]="${EXT_NAME_dephdr}"
211 setenv EXT_NAME
[cgraph
]="${EXT_NAME_cgraph}"
214 setenv EXT_NAME
[texi
]="${EXT_NAME_texi}"
215 setenv EXT_NAME
[md
]="${EXT_NAME_md}"
216 setenv EXT_NAME
[docbook
]="${EXT_NAME_docbook}"
217 setenv EXT_NAME
[man1
]="${EXT_NAME_man1}"
218 setenv EXT_NAME
[man2
]="${EXT_NAME_man2}"
219 setenv EXT_NAME
[man3
]="${EXT_NAME_man3}"
220 setenv EXT_NAME
[man4
]="${EXT_NAME_man4}"
221 setenv EXT_NAME
[man5
]="${EXT_NAME_man5}"
222 setenv EXT_NAME
[man6
]="${EXT_NAME_man6}"
223 setenv EXT_NAME
[man7
]="${EXT_NAME_man7}"
224 setenv EXT_NAME
[info
]="${EXT_NAME_info}"
225 setenv EXT_NAME
[dvi
]="${EXT_NAME_dvi}"
226 setenv EXT_NAME
[ps
]="${EXT_NAME_ps}"
227 setenv EXT_NAME
[txt
]="${EXT_NAME_txt}"
228 setenv EXT_NAME
[html
]="${EXT_NAME_html}"
229 setenv EXT_NAME
[chm
]="${EXT_NAME_chm}"
230 setenv EXT_NAME
[pdf
]="${EXT_NAME_pdf}"
235 ######################
236 # section: private function
237 ######################
241 ######################
242 # section: public function
243 ######################
245 # syntax: fname_dstdir <ext-type> <fname>
248 echo -n "$2" |
sed -E "s/(.*)\..*/\1/g"
249 getenv EXT_NAME
[${1}]
252 # syntax: fname_dstdir
255 eval DSTDIR
="$DSTDIR_EVL"
258 # syntax: fname_objdir
261 eval OBJDIR
="$OBJDIR_EVL"
264 # syntax: fname_src2obj <src-file>
268 # append SRC_FILE as a local variable,
269 # it will not change global content.
271 test -n "$1" && local SRC_FILE
="$1"
272 test -z "${SRC_FILE}" && return -1
274 local tmp
="${SRC_FILE}"
275 SRC_FILE
="$(echo "${SRC_FILE}" | sed -E "s
/,.
*$
//g
")"
277 eval OBJFILE
="$OBJFILE_FMT"
279 setenv DST_FILE
[1]=$OBJFILE
282 # syntax: fname_src2dst <obj-file> <dst-type>
285 test -n "$1" && local SRC_FILE
="$1"
286 test -z "${SRC_FILE}" && return -1
288 local tmp
="${SRC_FILE}"
289 SRC_FILE
="$(echo "${SRC_FILE}" | sed -E "s
/,.
*$
//g
")"
291 eval DSTFILE
="$DSTFILE_FMT"
296 # syntax: fname_src2dep <src-file>
299 test -n "$1" && local SRC_FILE
="$1"
300 test -z "${SRC_FILE}" && return -1
302 local tmp
="${SRC_FILE}"
303 SRC_FILE
="$(echo "${SRC_FILE}" | sed -E "s
/,.
*$
//g
")"
305 eval DEPFILE
="$DEPFILE_FMT"
307 setenv DST_FILE
[2]=$DEPFILE
310 # fsyntax: fname_src2graph <src-file>
313 test -n "$1" && local SRC_FILE
="$1"
314 test -z "${SRC_FILE}" && return -1
316 local tmp
="${SRC_FILE}"
317 SRC_FILE
="$(echo "${SRC_FILE}" | sed -E "s
/,.
*$
//g
")"
319 eval CGRAPHFILE
="$CGRAPHFILE_FMT"
321 setenv DST_FILE
[3]=$CGRAPHFILE
324 fname_func_testing
()
326 echo "========================"
327 echo "= fname_func_testing()"
328 echo "========================"
332 export DEST_NAME
=bush
333 SRC_FILE
="src/lxrgmr/subst.c"
334 echo DEST_NAME
=$DEST_NAME
335 echo DEST_TYPE
=$DEST_TYPE
337 echo "SRC_FILE=${SRC_FILE}"
340 echo DSTDIR
="\"$DSTDIR\""
343 echo OBJDIR
="\"$OBJDIR\""
346 echo OBJFILE
="\"$OBJFILE\""
348 fname_obj2dst src
/runner
/xxx.c
349 echo DSTFILE
="\"$DSTFILE\""
351 fname_src2dep src
/var
/variable.c
352 echo DEPFILE
="\"$DEPFILE\""
354 echo CGRAPHFILE
="\"$CGRAPHFILE\""
357 ######################
359 ######################