improve of cmpl.
[bush.git] / tools / build-srcpkg-bak-20240503 / shlib / fname.shlib
blob053ba79e033c33ea80236582b915523d220deb8f
1 #!/bin/bash
2 ############################################################
3 # source: toolchain.shlib
4 # author: devenkong(18151155@qq.com)
5 # date: 2023-02-15
6 ############################################################
7 # note:
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
25 # with vars below.
26 # @ public defination.
27 # EXT_NAME[]
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
32 # /CGRAPHFILE_FMT
33 # @ output var, generated in func in this file.
34 # DSTDIR/OBJDIR/DSTFILE/OBJFILE/DEPFILE/CGRAPHFILE/DST_FILE[]
36 ############################################################
41 # todo£º
42 # @
43 # @
46 ######################
47 # section: common comment info
48 ######################
50 ######################
51 # section: variable define
52 ######################
55 # XXX: dir param _EVL defined in info/SrcPkgDirs.imi & info/extname.imi
60 ######################
61 # section: private function
62 ######################
66 ######################
67 # section: public function
68 ######################
70 # syntax: fname_dstdir
71 fname_dstdir ()
73 eval DSTDIR="$DSTDIR_EVL"
76 # syntax: fname_objdir
77 fname_objdir ()
79 eval OBJDIR="$OBJDIR_EVL"
82 # syntax: fname_src2obj <src-file>
83 fname_src2obj ()
86 # append SRC_FILE as a local variable,
87 # it will not change global content.
89 [[ -n "$1" ]] && local SRC_FILE[0]="$1"
90 [[ -z ${SRC_FILE[0]} ]] && return -1
92 local tmp="${SRC_FILE}"
93 SRC_FILE="${SRC_FILE%%\,*}"
95 eval OBJFILE="$OBJFILE_FMT"
96 SRC_FILE="$tmp"
97 DST_FILE[1]=$OBJFILE
100 # syntax: fname_src2dst <obj-file> <dst-type>
101 fname_src2dst ()
103 [[ -n "$1" ]] && local SRC_FILE[0]="$1"
104 [[ -z ${SRC_FILE[0]} ]] && return -1
106 local tmp="${SRC_FILE}"
107 SRC_FILE="${SRC_FILE%%\,*}"
109 eval DSTFILE="$DSTFILE_FMT"
110 SRC_FILE="$tmp"
111 DST_FILE[0]=$DSTFILE
114 # syntax: fname_src2dep <src-file>
115 fname_src2dep ()
117 [[ -n "$1" ]] && local SRC_FILE[0]="$1"
118 [[ -z ${SRC_FILE[0]} ]] && return -1
120 local tmp="${SRC_FILE}"
121 SRC_FILE="${SRC_FILE%%\,*}"
123 eval DEPFILE="$DEPFILE_FMT"
124 SRC_FILE="$tmp"
125 DST_FILE[2]=$DEPFILE
128 # fsyntax: fname_src2graph <src-file>
129 fname_src2graph ()
131 [[ -n "$1" ]] && local SRC_FILE[0]="$1"
132 [[ -z ${SRC_FILE[0]} ]] && return -1
134 local tmp="${SRC_FILE}"
135 SRC_FILE="${SRC_FILE%%\,*}"
137 eval CGRAPHFILE="$CGRAPHFILE_FMT"
138 SRC_FILE="$tmp"
139 DST_FILE[3]=$CGRAPHFILE
142 fname_func_testing ()
144 echo "========================"
145 echo "= fname_func_testing()"
146 echo "========================"
148 export OUTDIR=build
149 export DEST_TYPE=exe
150 export DEST_NAME=bush
151 SRC_FILE[0]="src/lxrgmr/subst.c"
152 echo DEST_NAME=$DEST_NAME
153 echo DEST_TYPE=$DEST_TYPE
154 echo OUTDIR=$OUTDIR
155 echo "SRC_FILE[0]=${SRC_FILE[0]}"
157 fname_dstdir
158 echo DSTDIR="\"$DSTDIR\""
160 fname_objdir
161 echo OBJDIR="\"$OBJDIR\""
163 fname_src2obj
164 echo OBJFILE="\"$OBJFILE\""
166 fname_obj2dst src/runner/xxx.c
167 echo DSTFILE="\"$DSTFILE\""
169 fname_src2dep src/var/variable.c
170 echo DEPFILE="\"$DEPFILE\""
171 fname_src2graph
172 echo CGRAPHFILE="\"$CGRAPHFILE\""
175 ######################
176 # section: file tail
177 ######################