improve of cmpl.
[bush.git] / tools / build-srcpkg-bak-20240503 / shlib / param-load.shlib
blob019598a69e3911c9cac7bdb0e34111c89a84b19d
1 #!/bin/bash
2 ############################################################
3 # source: param-load.shlib
4 # author: devenkong(18151155@qq.com)
5 # date: 2023-02-15
6 ############################################################
7 # note:
8 # this file is used to load param defined in
9 # build/dest/dest-<dest>/*.
10 # before using func in toolchain.shlib, inc this file,
11 # and invoke one_dest_init() to load parameters in config
12 # dir.
13 ############################################################
16 # todo£º
20 # TBD:
22 # @
26 ######################
27 # section: common comment info
28 ######################
30 ######################
31 # section: variable define
32 ######################
36 ######################
37 # section: private function
38 ######################
40 buildimilist_dbgout ()
42 return
43 echo "$@"
47 # fsyntax: buildparam_dbgout <output-string>
48 # fdesc: output string by dbgout switch.
50 buildparam_dbgout ()
52 if [[ ! "${dbgout_opt}" =~ buildparam_dbgout ]]; then
53 return
56 echo -ne "$@"
57 echo -ne "$@" >> ${OUTDIR}/buildparam.log
58 echo -ne "$@" >> ${OUTDIR}/buildinfo.log
61 err ()
63 echo $@ >&2
64 exit -1
67 ######################
68 # section: public function
69 ######################
72 # fsyntax: dbgout_construct_param
73 # fdesc:
75 dest_param_reset ()
77 local name=
78 local namelist=
80 C_SRC_LIST_Y=""
81 CXX_SRC_LIST_Y=""
82 CPP_SRC_LIST_Y=""
83 ASM_SRC_LIST_Y=""
84 SH_SRC_LIST_Y=""
85 STATIC_LIB_LIST_Y=""
87 namelist="${!FLAGS*}"
88 for name in $namelist; do
89 eval $name=""
90 done
92 namelist="${!ASFLAGS*}"
93 for name in $namelist; do
94 eval $name=""
95 done
97 namelist="${!CFLAGS*}"
98 for name in $namelist; do
99 eval $name=""
100 done
102 namelist="${!CXXFLAGS*}"
103 for name in $namelist; do
104 eval $name=""
105 done
107 namelist="${!CPPFLAGS*}"
108 for name in $namelist; do
109 eval $name=""
110 done
112 namelist="${!ARFLAGS*}"
113 for name in $namelist; do
114 eval $name=""
115 done
117 namelist="${!LDFLAGS*}"
118 for name in $namelist; do
119 eval $name=""
120 done
122 INC_PKG=""
128 dest_info_init ()
130 [[ "$DEST_NAME" == general ]] && DEST_TYPE=null && return
132 # load dest.imi
133 eval "DEST_CFG_DIR_NAME=\"${DEST_CFG_DIR_NAME_EVL}\""
134 eval "DEST_IMI_FILE=\"${DEST_IMI_FILE_EVL}\""
135 loadimi $DEST_IMI_FILE
137 if [[ -z "${DEST_TYPE}" ]]; then
138 echo "[error] DEST_TYPE is NULL in $DEST_IMI_FILE."
139 exit
142 # append [] on DEST_TYPE just for good looking.
143 if [[ "${DEST_TYPE:0:1}" == \[ && "${DEST_TYPE: -1:1}" == \] ]]; then
144 DEST_TYPE="${DEST_TYPE:1:-1}"
149 # fsyntax: one_dest_cflags_init <dest-name>
150 # fdesc: specified dest paramter load
152 one_dest_cflags_init ()
154 local dir=`pwd`
155 local filelist=
157 cd build/dest/dest-$1
159 filelist=$(ls -1 FLAGS* 2>/dev/null)
160 for file in $filelist; do
161 # echo load file $file
162 if [[ "${file}" =~ \.imi$ ]]; then
163 loadimi ${file}
164 else
165 loadlist ${file}
167 done
169 filelist=$(ls -1 ASFLAGS* 2>/dev/null)
170 for file in $filelist; do
171 # echo load file $file
172 if [[ "${file}" =~ \.imi$ ]]; then
173 loadimi ${file}
174 else
175 loadlist ${file}
177 done
179 filelist=$(ls -1 CFLAGS* 2>/dev/null)
180 for file in $filelist; do
181 # echo load file $file
182 if [[ "${file}" =~ \.imi$ ]]; then
183 loadimi ${file}
184 else
185 loadlist ${file}
187 done
189 filelist=$(ls -1 CXXFLAGS* 2>/dev/null)
190 for file in $filelist; do
191 # echo load file $file
192 if [[ "${file}" =~ \.imi$ ]]; then
193 loadimi ${file}
194 else
195 loadlist ${file}
197 done
199 filelist=$(ls -1 CPPFLAGS* 2>/dev/null)
200 for file in $filelist; do
201 # echo load file $file
202 if [[ "${file}" =~ \.imi$ ]]; then
203 loadimi ${file}
204 else
205 loadlist ${file}
207 done
209 cd $dir 2>/dev/null
211 buildparam_dbgout "CFLAGS=$CFLAGS\n"
215 # fsyntax: one_dest_ldflags_init <dest-name>
216 # fdesc: specified dest paramter load
218 one_dest_ldflags_init ()
220 local dir=`pwd`
221 local filelist=
223 cd build/dest/dest-$1
225 filelist=$(ls -1 ARFLAGS* 2>/dev/null)
226 for file in $filelist; do
227 # echo load file $file
228 if [[ "${file}" =~ \.imi$ ]]; then
229 loadimi ${file}
230 else
231 loadlist ${file}
233 done
235 filelist=$(ls -1 LDFLAGS* 2>/dev/null)
236 for file in $filelist; do
237 # echo load file $file
238 if [[ "${file}" =~ \.imi$ ]]; then
239 loadimi ${file}
240 else
241 loadlist ${file}
243 done
245 cd $dir 2>/dev/null
247 buildparam_dbgout "LDFLAGS=$LDFLAGS\n"
251 # fsyntax: one_dest_cfg <dest-name>
252 # fdesc: specified dest paramter load
254 one_dest_cfg ()
256 buildparam_dbgout "###################################\n"
257 buildparam_dbgout "###################################\n"
258 buildparam_dbgout "one_dest_cfg($1)\n"
260 DEST_CFG_DIR_NAME="dest-$1"
261 eval "DEST_CFG_DIR=\"${DEST_CFG_DIR_EVL}\""
263 unset DST_FILE
264 declare -g -a DST_FILE
265 unset SRC_FILE
266 declare -g -a SRC_FILE
268 one_dest_cflags_init "$@"
269 buildparam_dbgout "===================== CFLAGS_DEF_LIST_Y=\"$CFLAGS_DEF_LIST_Y\"\n"
271 one_dest_ldflags_init "$@"
273 buildparam_dbgout "+++++++++++++++++++++ CFLAGS_DEF_LIST_Y=\"$CFLAGS_DEF_LIST_Y\"\n"
274 buildparam_dbgout "===================== CFLAGS=\"$CFLAGS\"\n"
276 buildparam_dbgout "+++++++++++++++++++++ CFLAGS=\"$CFLAGS\"\n"
280 # fsyntax: one_dest_srclist_init <dest-name>
281 # fdesc: specified dest paramter load
283 one_dest_srclist_init ()
285 # TBD: disable src-list load in init. load it before corresponding
286 # program language src file list compile.
287 if true; then
288 # load src list files
289 # -src-file and -src-dir can be included in this loading.
290 while read file; do
291 [[ ! ${file} =~ .+-src-.+ ]] && continue
292 echo loadlist $file
293 loadlist $file
294 done < <(ls -d -1 -f $DEST_CFG_DIR/{*.lst,*.list} 2>/dev/null)
297 # load LDFLAGS_LIBPATH.list
298 eval "STATIC_LIB_FILE_LIST=\"${STATIC_LIB_FILE_LIST_FILE_EVL}\""
299 # buildparam_dbgout "STATIC_LIB_FILE_LIST=$STATIC_LIB_FILE_LIST\n"
300 loadlist $STATIC_LIB_FILE_LIST
304 # fsyntax: load_param_imi <dest>
305 # fdesc: this func should be invoked after one_dest_cfg().
307 load_param_imi ()
309 local tmp=
310 local DEST_CFG_DIR_NAME=
312 # load global param define
313 loadimi tools/build-srcpkg/info/paramters.imi
315 # load general param define in srcpkg
316 DEST_CFG_DIR_NAME=dest-general
317 eval PARAMTERS_IMI_FILE="\"$PARAMTERS_IMI_FILE_EVL\""
318 [[ -e $PARAMTERS_IMI_FILE ]] && loadimi $PARAMTERS_IMI_FILE
320 # load one dest param define in srcpkg
321 DEST_CFG_DIR_NAME="dest-$1"
322 [[ -e $PARAMTERS_IMI_FILE ]] && loadimi $PARAMTERS_IMI_FILE
326 set_cmplr ()
328 local cmdlist="
332 LINK
333 SLIB
334 DLIB
335 RANLIB
337 STRIP
338 OBJDUMP
339 OBJCOPY
340 READELF
342 SIZE
343 GCOV
345 GPROF
346 ADDR2LINE"
348 local PFX=
350 if [[ ${1} == 'TARGET' || ${1} == 'BUILD' || ${1} == 'HOST' ]]; then
351 PFX=$1
352 else
353 return
356 for cmd in $cmdlist; do
357 eval ${cmd}=\${${PFX}_${cmd}}
358 done
362 # fsyntax: one_dest_init <dest-name>
363 # fdesc: specified dest paramter load
365 one_dest_init ()
367 [[ -z "$1" ]] && err "specify the dest name to be init."
369 DEST_NAME=${1#*-}
372 # TBD:
373 # some param in .imi file should be defined as _SYNTAX suffix.
377 # load general parameter files.
379 # loadimi ${SRCPKG_DIR_FULL}/tools/build-srcpkg/info/ParamFiles.imi
380 # loadimi ${SRCPKG_DIR_FULL}/tools/build-srcpkg/info/SrcPkgDirs.imi
383 # init toolchain in auto, for compiler cmd infos in host/target.
385 toolchain_init
387 echo =========================== 1 MACHTYPE=$MACHTYPE
390 # create $OUTDIR & $OBJDIR for compile.
392 mkdir -p $OUTDIR $OBJDIR
393 dest_param_reset
396 # load parameter files in one dest, .imi & .list.
398 dest_info_init
401 # update extname info if dest build type changed.
403 inc ${SRCPKG_DIR_FULL}/tools/build-srcpkg/info/extname.imi
404 loadimi tools/build-srcpkg/info/SrcPkgDirs.imi
406 one_dest_cfg general
407 one_dest_cfg $1
408 load_param_imi $1
409 one_dest_srclist_init $1
411 # update toolchain cmd lnfo by Dest.imi
412 # set build type for compiler cross prefix.
413 [[ -n $DEST_BUILDTYPE ]] && set_cmplr $DEST_BUILDTYPE
415 buildparam_dbgout "==================== DEST_BUILDTYPE=$DEST_BUILDTYPE\n"
416 buildparam_dbgout "==================== CC=$CC\n"
420 ######################
421 # section: file tail
422 ######################
424 return
446 param_imi_list="PARAMTERS_IMI_FILE"
448 cflag_param_list="
449 ARFLAGS_MISC_IMI_FILE
450 CFLAGS_DEF_LIST_FILE_Y
451 CFLAGS_INCPATH_LIST_FILE_Y
452 CFLAGS_MISC_IMI_FILE"
454 ldflag_param_list="
455 DEP_PKG_LIST_FILE
456 LDFLAGS_LIB_LIST_FILE
457 LDFLAGS_LIBPATH_LIST_FILE_Y
458 LDFLAGS_MISC_IMI_FILE"
461 # fsyntax: load_param_file_list <file-name-list-envar>
462 # fdesc: specified dest paramter load
464 load_param_file_list ()
466 # echo "load_param_file_list(${!1})"
467 for name in ${!1}; do
468 if [[ -z $name || $name =~ ^[[:blank:]][#] ]]; then
469 continue;
472 # echo name=$name
473 # echo $name=${!name}
474 eval "local $name=\"\${${name}_EVL}\""
475 # buildparam_dbgout "param: $name=${!name}\n"
476 eval "$name=\"${!name}\""
477 # buildparam_dbgout "$name=${!name}\n"
479 [[ -z "${!name}" ]] && continue
481 if [[ "${!name}" =~ \.imi$ ]]; then
482 loadimi ${!name}
483 else
484 loadlist ${!name}
486 done