20230310
[build-config.git] / build / tmp / constructor-tmp.shlib
blob0b84ffd34106a49e14b27a8c2e4766dc72927d18
4 # fsyntax: TASK_CMPL <srcfile> [<taskparam> ... ]
5 # fdesc: running compile task accroding srcfile sfx name.
6 #        it recognize srcfile, and invoke corresponding function.
8 TASK_CMPL ()
10         local srcfile="$1"
11         local ext="${srcfile##*.}"
12         local name="${ext^^}_SRC_CMPL"
14         declare -F $name >/dev/null 2>&1
15         [[ -v $name && $? == 0 ]] && ${!name} "$@"
19 # fsyntax: TASK_LINK <objlist> <dest>
20 # fdesc: compile obj list to dest accroding dest type.
22 TASK_LINK ()
24         :
28 # fsyntax: TASK_STEP_RUNNING <task-name-var> <taskparam>
29 # fdesc: running tasks by the name of var in arg.
31 TASK_STEP_RUNNING ()
33         local step=
34         local stepdef=( ${!1} )
36         for step in $stepdef; do
37                 declare -F $step >/dev/null 2>&1
38                 [[ $? == 0 ]] && shift 2; $step "$@"
39                 declare -F ${!step} >/dev/null 2>&1
40                 [[ -v $step && $? == 0 ]] && shift 2; ${!step} SRC_FILE "$@"
41         done
45 aslkffoo ()
47         declare -F $1 >/dev/null 2>&1
48         [[ $? == 0 ]] && shift 2; $1 "$@"
49         declare -F ${!1} >/dev/null 2>&1
50         [[ -v $1 && $? == 0 ]] && shift 2; ${!1} SRC_FILE "$@"
55 dest_build ()
57         # TBD: 
58         # dispose parameters, 
59         # build each dest.
60         local data=
61         local dest="${!1}"
63         info "..................... dest_build ($dest)\n"
65         if [[ -z $dest ]]; then
66                 warn "specified list var name '$1' is not valid.\n"
67                 return 2
68         fi
70         # init one dest cfg paramter
71         eval "DEST_GENERAL_CFG_DIR=\"${DEST_GENERAL_CFG_DIR_EVL}\""
72         dest_param_reset
73         one_dest_init dest-general
74         one_dest_init $1
75         
76         CFLAGS="$CFLAGS"
77         
78         mkdir -p ${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/
79         
80         dbgout_construct_param
81         
82         # check src file list to be compiled.
83         check_and_get_src_compile_list
85         # compile if needed.
86         if [[ $? == 0 ]]; then
87                 compile_src_list
88                 
89                 shift 1
90                 while read data; do
91                         [[ -z $data ]] && continue
92                         SRC_FILE=( $data )
93                         dbgoutd "SRC_FILE=${SRC_FILE[@]}\n"
94 #                       TASK_RUNNING $task SRC_FILE "$@"
95                         TASK_RUNNING STEP_DEFAULT_DEST $SRC_FILE "$@"
96                         # break tasklist running if one of them failed.
97                         [[ $? != 0 ]] && return 2
98                 done <<< "${!list}"
99                 
100                 [[ $? != 0 ]] && dbgoutd "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1\n" && return 2
101         fi
102         
103         
104         
105         
106         
107         
108         
109         return 0
112         DEST_CFG_DIR_NAME="$dest"
114         construct_one_dest $dest
115         [[ $? != 0 ]] && err "${CHIGHL}[build-dest][${dest#*-}]: build dest file \"$dest\" err.${CNORMAL}" && return 2
116         return 0
120 # fsyntax: construct_one_dest <dest-name>
121 # fdesc: construct one dest executables.
123 construct_one_dest ()
125         local dest=${dest#*-}
126         local step=
127         local ret=
129         dbgoutd "############################\n"
130         dbgoutd "construct_one_dest(${1#*-})\n"
132         
135         # try to check dest and obj tp, it output OBJ_LIST.
136         dest_link_check $dest
137         [[ $? != 0 ]] && dbgoutd "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2\n" && return 2
138         
139         link_dest $dest
140         return $?
144 # fsyntax: check_and_get_src_compile_list <lang-list-var>
145 # fdesc: check if src file is newer then dest file in $obj,
147 check_and_get_src_compile_list ()
149         local obj=
150         local srcfile=
151         local dstfile=
152         local SRC_LIST_N2B_CMPL=
153         local langlist=( $1 )
154         local lang=
155         local vname=
156         
157         #
158         # check ${lang}_SRC_LIST list.
159         #
160         for lang in ${langlist[@]} ; do
161                 vname="${lang}_SRC_LIST[@]"
162                 if [[ -z ${!vname} ]]; then
163                         eval ${lang}_SRC_CMPL_LIST=""
164                         task_info no src file in src list \'\${${lang}_SRC_LIST[@]}\'.
165                         continue
166                 fi
168                 # get obj file list that has been compiled.
169                 OBJ_LIST_N2B_CPLE=`cd ${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/; ls -1 ${!vname//\.c/\.o} 2>/dev/null`
170                 [[ -z "$OBJ_LIST_N2B_CPLE" ]] && eval ${lang}_SRC_CMPL_LIST=\"\${\!vname}\" && continue
172                 # test compiled obj file, to check if it need to be recompiled.
173 #               dbgoutd "OBJ_LIST_N2B_CPLE=${OBJ_LIST_N2B_CPLE}\n"
174                 for obj in ${OBJ_LIST_N2B_CPLE}; do
175                         srcfile="${obj//\.o/\.cpp}"
176                         dstfile="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/${obj}"
177                         
178                         # check if file does not need to be compiled.
179                         if [[ "${dstfile}" -nt "${srcfile}" ]]; then
180                                 # hdr file tp chk.
181                                 lang_src_hdrtpchk $dstfile
182                                 [[ $? == 0 ]] && SRC_LIST_N2B_CMPL+="${srcfile}"$'\n'
183                         fi
184                 done
185                 
186                 # get files to be compiled.
187                 if [[ -n $SRC_LIST_N2B_CMPL ]]; then
188                         flag=compile
189                         eval ${lang}_SRC_CMPL_LIST="`comm <(echo "${!vname}" | sort) <(echo "$SRC_LIST_N2B_CMPL" | sort) -1`"
190                         #  | sed -e "/^\t/d"
191                 fi
192                 eval task_info ${lang}_SRC_CMPL_LIST="\${${lang}_SRC_CMPL_LIST}"
193         done
194         
195         return 0
198 SYS_INC_LIST=
199 APP_INC_LIST=
201 full_lang_src_tpchk ()
203         local obj=
204         local srcfile=
205         local dstfile=
206         local SRC_LIST_N2B_CMPL=
207         local langlist=( $1 )
208         local lang=
209         local vname=
210         
211         info "lang_src_tpchk ($@)"
213         #
214         # check ${lang}_SRC list.
215         #
216         for lang in ${langlist[@]} ; do
217                 vname="${lang}_SRC_LIST[@]"
218                 if [[ -z ${!vname} ]]; then
219                         eval ${lang}_SRC_CMPL_LIST=""
220                         task_info "no src file in src list \'\${${lang}_SRC_LIST[@]}\'."
221                         continue
222                 fi
224                 # get obj file list that has been compiled.
225                 OBJ_LIST_N2B_CPLE=`cd ${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/; ls -1 ${!vname//\.c/\.o} 2>/dev/null`
226                 [[ -z "$OBJ_LIST_N2B_CPLE" ]] && eval ${lang}_SRC_CMPL_LIST=\"\${\!vname}\" && continue
228                 # test compiled obj file, to check if it need to be recompiled.
229 #               dbgoutd "OBJ_LIST_N2B_CPLE=${OBJ_LIST_N2B_CPLE}\n"
230                 for obj in ${OBJ_LIST_N2B_CPLE}; do
231                         srcfile="${obj//\.o/\.cpp}"
232                         dstfile="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/${obj}"
233                         
234                         # check if file does not need to be compiled.
235                         if [[ "${dstfile}" -nt "${srcfile}" ]]; then
236                                 # hdr file tp chk.
237                                 lang_src_hdrtpchk $dstfile
238                                 [[ $? == 0 ]] && SRC_LIST_N2B_CMPL+="${srcfile}"$'\n'
239                         fi
240                 done
241                 
242                 # get files to be compiled.
243                 if [[ -n $SRC_LIST_N2B_CMPL ]]; then
244                         flag=compile
245                         eval ${lang}_SRC_CMPL_LIST="`comm <(echo "${!vname}" | sort) <(echo "$SRC_LIST_N2B_CMPL" | sort) -1`"
246                         #  | sed -e "/^\t/d"
247                 fi
248                 eval task_info "${lang}_SRC_CMPL_LIST=\"\${${lang}_SRC_CMPL_LIST}\""
249         done
250         
251         return 0
255 # fsyntax: desttpchk <objlist-var> <dstfile-var>
256 # fdesc: chk tp between src-file and dest-file.
258 desttpchk ()
260         local extname="${DEST_EXTNAME}"
261         local srcfile=
262         local destfile="${!2}"
264         task_info "desttpchk ($@)"
265         task_info "destfile($2)=$destfile"
266         
267         srcfile="${1}[@]"
268         srcfile="${srcfile}"
269         [[ -z "$srcfile" ]] && err "input file list '${1}' does not have content" && return 2
270         [[ -z "$destfile" ]] && err "output file list '${2}' does not have content" && return 2
271     
272         [[ ! -f ${destfile} ]] && return 0
273         [[ ${srcfile} -nt ${destfile} ]] && return 2
277 # fsyntax: tpchk <srcfile> <dstfile>
278 # fdesc: chk tp between src-file and dest-file.
280 tpchk ()
282         local extname="${LANG_EXT_NAME[$2]}"
283         local srcfile="$1"
284         local destfile="${OUTPUT_DIR}/${3}/${1//\.${extname}/\.o}"
286         task_info "tpchk ($@)"
287         task_info "destfile=$destfile"
288         [[ ! -f ${destfile} ]] && return 0
289         [[ ${srcfile} -nt ${destfile} ]] && return 2
295 # fsyntax: src2exe <srcfile> <dstfile>
296 # fdesc: compile srcfile, and output exe file directly.
298 src2exe ()
300         [[ $1 -nt $2 ]] && return 2