18 # fsyntax: construct_one_dest <dest-name>
19 # fdesc: construct one dest executables.
27 dbgoutd "############################\n"
28 dbgoutd "construct_one_dest(${1#*-})\n"
30 # init one dest cfg paramter
31 eval "DEST_GENERAL_CFG_DIR=\"${DEST_GENERAL_CFG_DIR_EVL}\""
33 one_dest_init dest-general
38 mkdir -p ${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/
40 dbgout_construct_param
42 # check src file list to be compiled.
43 check_and_get_src_compile_list
46 if [[ $? == 0 ]]; then
49 [[ $? != 0 ]] && dbgoutd "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx1\n" && return 1
52 # try to check dest and obj tp, it output OBJ_LIST.
54 [[ $? != 0 ]] && dbgoutd "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx2\n" && return 1
61 # fsyntax: construct_all_dest <dest-name>
62 # fdesc: construct all dest executables.
67 # load valid each dest.
69 if [[ -n $BUILD_DEST ]]; then
70 # BUILD_DEST="${BUILD_DEST//dest-/$'\ndest-'}"
71 for dest in $BUILD_DEST; do
72 # declare -g -A DEST_CFG_DIR[${dest#*dest.?-}]="${SRCPKG_TOPDIR}/build/$dest"
73 DEST_CFG_DIR_NAME="$dest"
74 construct_one_dest $dest
75 [[ $? != 0 ]] && err "${CHIGHL}[build-dest][${dest#*-}]: build dest file \"$dest\" err.${CNORMAL}" && return 1
77 # DEST_LIST=( ${DEST_CFG_DIR[@]} )
78 # echo DEST_CFG_DIR[@]=${DEST_CFG_DIR[@]}
80 err "no build dest defined in ${SRCPKG_TOPDIR}/build/dest/dest.list.\n"
85 #################################################
87 #################################################
88 eval "SRCPKG_TOPDIR=\"$SRCPKG_TOPDIR_EVAL\""
105 src_obj_map[asm]="obj"
106 #src_obj_map[c]="obj"
107 #src_obj_map[cpp]="obj"
110 # fsyntax: compile_src_file
111 # fdesc: compile each src file.
120 # DST_FILE[0]="output/test.o"
121 # DST_FILE[1]="output/test.dep"
130 # local C_SRC_LIST_FILE="dest/dest-libtui.so/c-src-file.list"
132 echo C_SRC_LIST_FILE=$C_SRC_LIST_FILE
133 if [[ -e $C_SRC_LIST_FILE ]]; then
135 C_SRC_LIST="${C_SRC_LIST//\.c/$'.c\n'}"
137 C_SRC_LIST_FILE="dest/dest-libtui.so/c-src-file.lst"
138 echo C_SRC_LIST_FILE=$C_SRC_LIST_FILE
139 [[ -e $C_SRC_LIST_FILE ]] && C_SRC_LIST=( $(cat $C_SRC_LIST_FILE | grep -v "^[[:space:]]*#" | sed -e "s/[[:space:]]*#.*$//g") )
144 # fsyntax: compile_src_list
145 # fdesc: compile each src file in src file list.
153 for file in $C_SRC_CMPL_LIST $CPP_SRC_CMPL_LIST; do
154 [[ -z "$file" ]] && continue
155 compile_src_file $file
156 [[ $? != 0 ]] && err "${CHIGHL}[build-compile]: compile file \"$file\" err.${CNORMAL}" && return 1
164 # fsyntax: check_and_get_src_compile_list
165 # fdesc: check if src file is newer then dest file in $obj,
167 check_and_get_src_compile_list ()
172 local SRC_LIST_N2B_CMPL=
174 #C_SRC_LIST="${C_SRC_LIST//.c/.c$'\n'}"
175 #echo C_SRC_LIST="${C_SRC_LIST}"
177 # check if no file to be compiled, and return 0.
178 [[ -z ${C_SRC_LIST[@]} && -z ${CPP_SRC_LIST[@]} ]] && echo no src file in src list. && return 0
183 if [[ -n "$C_SRC_LIST" ]]; then
184 # get compiled obj file list
185 OBJ_LIST_N2B_CPLE=`cd ${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/; ls ${C_SRC_LIST[@]//\.c/\.o} 2>/dev/null`
187 # test compiled obj file, to check if it need to be recompiled.
188 if [[ -n "$OBJ_LIST_N2B_CPLE" ]]; then
189 dbgoutd "OBJ_LIST_N2B_CPLE=${OBJ_LIST_N2B_CPLE}\n"
190 for obj in ${OBJ_LIST_N2B_CPLE}; do
191 srcfile="${obj//\.o/\.c}"
192 dstfile="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/${obj}"
194 # check if file does not need to be compiled.
195 if [[ "$dstfile" -nt "${srcfile}" ]]; then
196 SRC_LIST_N2B_CMPL+="${srcfile}"$'\n'
202 # filter compiled file.
203 # compare two list, delete lines in C_SRC_LIST list with that in SRC_LIST_N2B_CMPL.
204 # and store it to C_SRC_CMPL_LIST.
205 if [[ -n $SRC_LIST_N2B_CMPL ]]; then
206 C_SRC_CMPL_LIST="`comm <(echo "$C_SRC_LIST" | sort) <(echo "$SRC_LIST_N2B_CMPL" | sort) | sed -e "/^\t/d"`"
208 C_SRC_CMPL_LIST="$C_SRC_LIST"
211 echo C_SRC_CMPL_LIST="$C_SRC_CMPL_LIST"
217 if [[ -n "$CPP_SRC_LIST" ]]; then
218 # get compiled obj file list
219 OBJ_LIST_N2B_CPLE="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/${CPP_SRC_LIST[@]//\.c/\.o}"
221 # test compiled obj file, to check if it need to be recompiled.
222 if [[ -n "$OBJ_LIST_N2B_CPLE" ]]; then
223 # dbgoutd "OBJ_LIST_N2B_CPLE=${OBJ_LIST_N2B_CPLE}\n"
224 for obj in ${OBJ_LIST_N2B_CPLE}; do
225 srcfile="${obj//\.o/\.cpp}"
226 dstfile="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/${obj}"
228 # check if file does not need to be compiled.
229 if [[ "$dstfile" -nt "${srcfile}" ]]; then
230 SRC_LIST_N2B_CMPL+="${srcfile}"$'\n'
236 [[ -n $SRC_LIST_N2B_CMPL ]] && CPP_SRC_CMPL_LIST="`comm <(echo "$CPP_SRC_LIST" | sort) <(echo "$SRC_LIST_N2B_CMPL" | sort) | sed -e "/^\t/d"`"
237 echo CPP_SRC_CMPL_LIST="$CPP_SRC_CMPL_LIST"
244 # fsyntax: dest_link_check
245 # fdesc: check dest if it is not exist, or file in $obj is newer then dest,
253 #SRC_FILE=( ${DS3T_FILE[@]} )
254 DST_FILE[0]="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/$1"
256 # translate src file list to obj file list
257 #[[ -n "$C_SRC_LIST" ]] && OBJ_LIST=" ${C_SRC_LIST[@]//\.c/\.o} "
258 #[[ -n "$CPP_SRC_LIST" ]] && OBJ_LIST+=" ${CPP_SRC_LIST[@]//\.cpp/\.o} "
259 # translate to multi-line form.
260 #OBJ_LIST="$(echo ${OBJ_LIST[@]} | tr -s ' ' $'\n')"
262 #SRC_FILE=( `cd ${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/; ls ${C_SRC_LIST[@]//\.c/\.o} 2>/dev/null` )
263 SRC_FILE="${C_SRC_LIST[@]//\.c/\.o}"
264 SRC_FILE+=" ${CPP_SRC_LIST[@]//\.c/\.o}"
265 SRC_FILE="$(echo ${SRC_FILE} | tr '[\ |$'\\n']' ',')"
266 # if [[ ${SRC_FILE[@]: -1:1} == ',' ]]; then
267 # SRC_FILE="${SRC_FILE%,}"
269 SRC_FILE="ls ${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/{${SRC_FILE:0:-1}} 2>/dev/null"
272 #ls ${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/{${SRC_FILE:0:-1}} 2>/dev/null"
275 SRC_FILE="`eval $SRC_FILE`"
278 # echo === SRC_FILE="${SRC_FILE[@]}"
279 # echo === DST_FILE="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/${DST_FILE[@]}"
282 if [[ -f ${DST_FILE[0]} ]]; then
283 # dest is linked, check if obj to be compiled.
285 # do not use for loop here, especially in large number
286 # of file to be compiled.
287 # for obj in ${OBJ_LIST[@]}; do
289 file="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/${obj}"
291 [[ -f $file && $file -nt ${DST_FILE[0]} ]] && flag=compile
292 #OBJ_LIST+="$obj"$'\n';
293 done <<< "${SRC_FILE[@]}"
295 echo "OBJ_LIST=$OBJ_LIST"
297 [[ $flag == 'link' ]] && info "destination \"${DST_FILE[0]}\" has been existing." && return 1
299 # if dest is not exist, all file should try to be recompiled.
303 if [[ $flag == 'link' ]]; then
312 # fdesc: link .o files to an executable.
316 # SRC_FILE=( ${OBJ_LIST[@]} )
317 DST_FILE="${OUTPUT_DIR}/${DEST_CFG_DIR_NAME}/$1"
319 # echo === SRC_LIST[@] = ${SRC_LIST[@]}
320 # echo === DST_FILE[@] = ${DST_FILE[@]}
323 [[ $? != 0 ]] && err "${CHIGHL}[build-link]: link file \"$1\" err.${CNORMAL}" && return 1
330 # fsyntax: compile_src_list
331 # fdesc: compile each src file in src file list.
333 compile_src_list_bak ()
336 local C_SRC_LIST_FILE="dest/dest-libtui.so/c-src-file.list"
338 echo C_SRC_LIST_FILE=$C_SRC_LIST_FILE
339 if [[ -e $C_SRC_LIST_FILE ]]; then
341 C_SRC_LIST="${C_SRC_LIST//\.c/$'.c\n'}"
343 C_SRC_LIST_FILE="dest/dest-libtui.so/c-src-file.lst"
344 echo C_SRC_LIST_FILE=$C_SRC_LIST_FILE
345 [[ -e $C_SRC_LIST_FILE ]] && C_SRC_LIST=( $(cat $C_SRC_LIST_FILE | grep -v "^[[:space:]]*#" | sed -e "s/[[:space:]]*#.*$//g") )
348 [[ -z ${C_SRC_LIST[@]} ]] && echo no src file in src list. && return 0
350 echo C_SRC_LIST=${C_SRC_LIST[$i]}
353 [[ -z "$file" ]] && continue
356 compile_src_file $file
357 done < $C_SRC_LIST_FILE