5 # @ gen src list from a subdir, and compile
6 # @ compile a subdir by invoke build in subdir.
7 # @ compile & link for a target in target list.
18 O2LIB_CMD_EVL='${AR} ${ARFLAGS} ${outputfile}.a $(echo ${OBJ_LIST})'
21 OUTDIR_FMT='${PWD}/output/'
22 [[ -z $OUTDIR ]] && export OUTDIR="$PWD/output/" && echo XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX # it must have a '/' at last.
23 OBJDIR_FMT='${OUTDIR}obj/'
24 OBJDIR="${OUTDIR}obj/"
27 scriptversion=v0.1.0-231025
29 version="cmpl.sh $scriptversion
31 Copyright 2020 Free Software Foundation, Inc.
32 There is NO warranty. You may redistribute this software
33 under the terms of the GNU General Public License.
34 For more information about these matters, see the files named COPYING."
36 usage="Usage: $prog [OPTION]
38 It's a file of compile.
39 https://repo.or.cz/devutils.git
42 -f force to re-compile again even if code is compiled before.
47 clean clean output files.
48 bak clean and backup a tarball in the upper dir.
50 --help display help info in detail.
51 --version display version information in detail.
59 Email bug reports or enhancement requests to skeletone@126.com .
64 while test $# -gt 0; do
67 -v) shift; outdir=$1;;
68 -h) shift; dirargs="$dirargs -I '$1'"; dirs="$dirs $1";;
69 clean) echo cleaning ...; flag_clean=1;;
72 dir="$(basename $PWD)"
73 file="${dir}-$(date +%Y%m%d).zip"
78 [[ $BAKDIR != '../' && $BAKDIR != '..' ]] && mkdir -pv $BAKDIR && cp ../$file ${BAKDIR}/ -f
81 gz) echo TBD; exit 0;;
82 bz) echo TBD; exit 0;;
83 xz) echo TBD; exit 0;;
85 -v) echo "version: $scriptversion"; exit 0;;
86 -h) echo "$usage"; exit 0;;
88 --version) echo "$version"; exit 0;;
89 --help) echo "$usage"; exit 0;;
91 echo "$0: Unknown option \`$1'." >&2
92 echo "$0: Try \`--help' for more information." >&2
95 if test -z "$PACKAGE"; then
97 elif test -z "$MANUAL_TITLE"; then
100 echo "$0: extra non-option argument \`$1'." >&2
110 [[ ! -z $@ ]] && force=1
113 OBJDIR="$(eval echo ${OBJDIR_FMT})"
114 mkdir -pv $OUTDIR $OBJDIR
122 if [[ -n $line ]]; then
124 [[ -f "${line}_test.c" ]] && echo ${line}_test.c
133 [[ -z $SUB_SRCDIR_LIST ]] && return
135 for subdir in $SUB_SRCDIR_LIST; do
137 [[ ! -f "cmpl.sh" ]] && echo "err: there no cmpl.sh file exist in subdir '$subdir'." && exit -1
139 # running in subscript
141 [[ $? != 0 ]] && echo "err: builld dir $subdir failed." && exit -1
144 SLIB_LIST+=" ${OUTDIR}lib${subdir##*/}.a"
150 OBJDIR="$(eval echo ${OBJDIR_FMT})"
152 for srcfile in $SRC_LIST; do
153 objfile=${srcfile##*/}
154 objfile="${OBJDIR}${objfile//\.c/\.o}"
155 echo $srcfile gcc compile to $objfile ...
157 if [[ $srcfile -nt $objfile
158 # || cmpl.sh -nt $srcfile
160 || ! -f $objfile ]]; then
162 mkdir -p $(dirname $objfile)
163 $CC ${CFLAGS} -c $srcfile -o $objfile
164 [[ $? != 0 ]] && echo "gcc($CC) compile ($objfile) failed." && exit -1
171 for srcfile in $SRC_LIST; do
172 objfile=${srcfile##*/}
173 objfile="$OBJDIR${objfile//\.c/\.o}"
174 OBJ_LIST+=" $objfile"
180 OBJDIR="$(eval echo ${OBJDIR_FMT})"
182 if [[ "${DST_FMT}" == '${dst}' ]]; then
183 outputfile="${DST_LIST%%[[:blank:]]}"
184 outputfile="${OUTDIR}lib${outputfile#*[[:blank:]]}"
188 for srcfile in $SRC_LIST; do
189 objfile=${srcfile##*/}
190 objfile="${OBJDIR}${objfile//\.c/\.o}"
191 OBJ_LIST+=" $objfile"
192 [[ -z $flag_link && "$srcfile" -nt "$outputfile" ]] && flag_link=1 \
193 #&& echo $srcfile '-nt' $outputfile && ls -l $srcfile $outputfile
194 [[ -z $flag_link && "$objfile" -nt "$outputfile" ]] && flag_link=1 \
195 #&& echo $objfile '-nt' $outputfile && ls -l $objfile $outputfile
197 [[ $flag_link != 1 ]] && return
199 echo $outputfile gcc link ...
200 echo "########################################################################"
201 echo "$O2LIB_CMD_EVL"
202 eval O2LIB_CMD="\"$O2LIB_CMD_EVL\""
205 # $LINK $LDFLAGS -O2 $OBJ_LIST -o $outputfile
206 [[ $? != 0 ]] && echo "gcc link ($(echo $outputfile)) failed." && exit -1
208 ls -l ${outputfile}.a
216 OBJDIR="$(eval echo ${OBJDIR_FMT})"
218 if [[ "${DST_FMT}" == '${dst}' ]]; then
219 outputfile="${DST_LIST%%[[:blank:]]}"
220 outputfile="${OUTDIR}${outputfile#*[[:blank:]]}"
224 for srcfile in $SRC_LIST; do
225 objfile=${srcfile##*/}
226 objfile="${OBJDIR}${objfile//\.c/\.o}"
227 OBJ_LIST+=" $objfile"
228 [[ -z $flag_link && "$srcfile" -nt "$outputfile" ]] && flag_link=1 \
229 #&& echo $srcfile '-nt' $outputfile && ls -l $srcfile $outputfile
230 [[ -z $flag_link && "$objfile" -nt "$outputfile" ]] && flag_link=1 \
231 #&& echo $objfile '-nt' $outputfile && ls -l $objfile $outputfile
233 [[ $flag_link != 1 ]] && return
235 echo $outputfile gcc link ...
237 # echo "$LINK $LDFLAGS -O2 $SLIB_LIST $OBJ_LIST -o $outputfile"
238 $LINK $LDFLAGS -O2 $OBJ_LIST $SLIB_LIST -o $outputfile
239 [[ $? != 0 ]] && echo "gcc link ($(echo $outputfile)) failed." && exit -1
246 for dst in $DST_LIST; do
247 outputfile="${OUTDIR}$(eval echo ${DST_FMT})"
248 echo $outputfile gcc build ...
250 objfile1="${OBJDIR}${dst}.o"
251 objfile2="${OBJDIR}${dst}_test.o"
252 if [[ $outputfile -nt $objfile1 || $outputfile -nt $objfile2
253 || build.sh -nt $outputfile
255 || ! -f $outputfile ]]; then
256 echo "$LINK $LDFLAGS -O2 $SLIB_LIST $objfile1 $objfile2 -o $outputfile"
257 $LINK $LDFLAGS -O2 $SLIB_LIST $objfile1 $objfile2 -o $outputfile
258 [[ $? != 0 ]] && echo "gcc($CC) link ($outputfile) failed." && exit -1
266 CFLAGS="${MACRO_DEF} -O2 ${INC_PATHS} "
267 LDFLAGS="${INC_LIBS} ${MISC_LDFLAGS} "
272 OBJDIR="$(eval echo ${OBJDIR_FMT})"
274 rm $OBJ_LIST ${OBJDIR} $OUTDIR -rf
277 [[ -z $dst ]] && continue
278 eval echo rm "${OUTDIR}${DST_FMT}" -f
279 eval rm ${OUTDIR}${DST_FMT} -f