2 ############################################################
4 # author: CottonCandyOwner(CottonCandyOwner@126.com)
6 ############################################################
7 # Copyright (C) 2022- Free Software Foundation, Inc.
8 # This configure script is free software; the Free Software
9 # Foundation gives unlimited permission to copy, distribute
11 ############################################################
13 # build all things in srcpkg, just like a Makefile.
14 # but does not contain develop operations.
15 # this program only do operation in output dir, and
16 # does not modify any thing in srcpkg.
17 ############################################################
27 # @ doc(man/info/um/html/pdf/md)
30 # @ debug/release build
34 # @ programs & opts & features trim
38 # # helper txt chk(dev/cmpl)
39 # # each feature for one opt, with one test-item
44 # @ <non>, main program & mandoc
45 # @ -dev-, dev lib for compile
47 # @ -intl-, multi-lang
48 # @ -test-, test program
53 # enable alias feature in script.
54 shopt -s expand_aliases
58 # source operation in codeblock of function or if statement,
59 # it will leading error.
61 source shlibinc
2>&1 >/dev
/null
63 alias include
>/dev
/null
2>&1
65 # put include code here if needed.
72 # code below include shlib in absolute name.
74 source tools
/build-srcpkg
/shlib
/incfile.shlib
76 loadimi tools
/build-srcpkg
/info
/SrcPkgDirs.imi
78 inc tools
/build-srcpkg
/shlib
/fname.shlib
79 inc tools
/build-srcpkg
/shlib
/toolchain.shlib
80 inc tools
/build-srcpkg
/shlib
/param-load.shlib
81 inc tools
/build-srcpkg
/shlib
/worklist.shlib
83 #inc build/shlib/pre_build.shlib
85 inc tools
/build-srcpkg
/shlib
/args.shlib
89 ##############################
90 # section: public comment info
91 ##############################
95 ##############################
96 # section: variable define
97 ##############################
100 # this comment is used for version id auto update.
107 readonly CMPL_VER_DATE
=20240201
110 readonly CMPL_PROG
=`basename $0`
112 readonly CMPL_PROG_VERSION
="v${CMPL_V1}.${CMPL_V2}\${CMPL_V3:+\".$CMPL_V3\"}\${CMPL_VEXT:+\"$CMPL_VEXT\"}\${CMPL_VER_DATE:+\"-$CMPL_VER_DATE\"}"
113 CMPL_PROG_VERSION_STR
="`eval echo $CMPL_PROG_VERSION`
114 Copyright (C) 2024- Free Software Foundation, Inc.
115 This configure script is free software; the Free Software
116 Foundation gives unlimited permission to copy, distribute
119 Writen by CottenCandyOwner(CottenCandyOwner@126.com).
122 CMPL_PROG_BANNER
="$CMPL_PROG $CMPL_PROG_VERSION_STR"
123 CMPL_PROG_SYNTAX
='Usage: $CMPL_PROG -[${p_shortparam//\|/}]'
124 CMPL_PROG_DESC
=" build all things in srcpkg, just like a Makefile.
127 CMPL_PROG_OTHER_DESC
="
129 @ standard cmd compatiable with Makefile.
135 @ seperated steps in cmpl all, and others.
143 CMPL_USAGE_FMT
='$CMPL_PROG_BANNER
147 $CMPL_PROG_OTHER_DESC'
151 # do not delete this comment, it is used for var define code intert.
153 ## args-var-define-begin
154 ## args-var-define-end
158 # PARAMETER DEFINE in DESCRIPTION STRING.
160 # this desc str would be referenced in script, consider about opt name space.
161 # @ desc-str can be defined more then one. and some of them maybe re-used
162 # for other program by 'source xxx --loadshlib'.
163 # @ '#' in desc-str is also supported as comment, and can be used to disable
164 # some option have not been implemented.
165 # @ =, param name for opt.
166 # @ %, var name if this opt is enabled.
167 # @ &, proc func if opt trigged.
170 |prog $0 'build all things in srcpkg, just like a Makefile.'
174 # still errors in multi-line.
177 |blank '[build check]'
178 |param |- |--envchk|---envchk |= |%<envchk> |&<on_envchk>
179 |'execute environment check for compile.'
180 |param |- |-- |---depchk |= |%<depchk> |&<on_depchk>
181 |'dependence inc file & lib file check.'
182 |param |- |-- |---buildep |= |%<buildep> |&<on_buildep>
183 |'dependence pkg download & build.'
185 |blank '[build misc]'
189 # TBD: envchk, depchk, buildep,
190 # doc, umdoc, mandoc, infodoc, tutorial, pdfdoc, htmldoc,
191 # genpkg, install, gendevpkg, devinstall,
192 # setting, release, debug,
195 # @ if there is a newline char in '' string, it will appears error, dispaly
196 # string append blanks in length of pname_with.
198 |blank '[build check]'
199 |param |- |-- |---envchk |= |%<envchk> |&<on_envchk> |'check compiling environment.'
200 |param |- |-- |---depchk |= |%<depchk> |&<on_depchk> |'dependent inc file & lib file check.'
201 |param |- |-- |---buildep |= |%<buildep> |&<on_buildep> |'dependent pkg download & build.'
203 |blank '[main build cmd]'
204 |param |- |-- |---srcbak |= |%<srcbak> |&<on_srcbak> |'distclean src pkg, and make an archive to backup dir. it is used for src code publish, or daily code backup.'
205 |param |- |-- |---clean |= |%<clean> |&<on_clean> |'clean files in compile procedure.'
206 |param |- |-- |---config |= |%<config> |&<on_config> |'feature config in src pkg.'
207 |param |- |-- |---all |= |%<all> |&<on_all> |'build in step of defconf, default, example, test, doc, umdoc, genpkg.'
208 |param |- |-- |---defconf |= |%<defconf> |&<on_defconf> |'set by default config.'
209 |param |- |-- |---default |= |%<default> |&<on_default> |'compile all dest in a src pkg.'
210 |param |- |-- |---example |= |%<example> |&<on_example> |'build example code if it exist.'
211 |param |- |-- |---test |= |%<test> |&<on_test> |'run test script for current src pkg.'
212 |param |- |-- |---doc |= |%<doc> |&<on_doc> |'build man and info helper doc.'
213 |param |- |-- |---umdoc |= |%<umdoc> |&<on_umdoc> |'build user manual doc in various kinds of doc type.'
214 |param |- |-- |---genpkg |=[pkgtype] |%<genpkg> |&<on_genpkg> |'build relative executables into a specified install pkg. if no pkgtype specified, it generate main/dev/umdoc/intl/test/eg pkgs.'
215 |param |- |-- |---install |=[pkgtype] |%<install> |&<on_install> |'install specified pkgs.'
217 |blank '[other build cmd]'
218 |param |- |-- |---dest |=[dest] |%<dest> |&<on_dest> |'build one of specified executables.'
219 |param |- |-- |---full |= |%<full> |&<on_full> |'compile all platform setted cpu platform in compiler toolchain.'
220 |param |- |-- |---setarch |=<arch> |%<setarch> |&<on_setarch> |'specified cross platform, and save.'
221 |param |- |-- |---cross |= |%<cross> |&<on_cross> |'build default cross platform setted '
222 |'insrc-pkg. it is setted by subcmd of setarch.'
223 |param |- |-- |---crosspkg |= |%<crosspkg> |&<on_crosspkg> |'build cross executables to a package.'
224 |param |- |-- |---gendevpkg |=[pkgname] |%<gendevpkg> |&<on_gendevpkg> |'generating pkg with dev lib.'
225 |param |- |-- |---devinstall |= |%<devinstall> |&<on_devinstall>|'install dev pkg.'
228 |param |- |-- |---mandoc |= |%<mandoc> |&<on_mandoc> |'build man doc.'
229 |param |- |-- |---infodoc |= |%<infodoc> |&<on_infodoc> |'build info doc.'
230 |param |- |-- |---tutorial |= |%<tutorial> |&<on_tutorial> |'build tutorial doc. it is an example guide doc.'
231 |param |- |-- |---pdfdoc |= |%<pdfdoc> |&<on_pdfdoc> |'build pdf user manual doc.'
232 |param |- |-- |---htmldoc |= |%<htmldoc> |&<on_htmldoc> |'build html user manual doc.'
234 |blank '[build src-pkg setting]'
235 |param |- |-- |---setting |= |%<setting> |&<on_setting> |'set src pkg build paramters.'
236 |param |- |-- |---release |= |%<release> |&<on_release> |'build release version.'
237 |param |- |-- |---debug |= |%<debug> |&<on_debug> |'build debug version, and genpkg with dev lib, install pkg by devinstall.'
242 cmpl_other_desc_str
="
244 |blank '[Version & Helper & Debug]'
245 |param |- |--version |---version |= |%<version> |&<on_version> |'output version info of this program.'
246 |param |-h |--help |---help |= |%<help> |&<on_help> |'this helper text doc.'
252 # application relative
254 SRCBAK_DIR
=${SRCBAK_DIR='../'}
257 load_shlib_on_build
()
259 # check if loaded, or not in root of srcpkg.
260 test ! -d "build" && test ! -d "tools/build-srcpkg" && test buildlib_loaded
= 1 &&
261 echo "'build' & 'tools/build-srcpkg' are not exist in current dir." &&
262 echo "is it the root dir of srcpkg?" >&2 &&
267 . tools
/build-srcpkg
/shlib
/incfile.shlib
269 #loadimi ${SRCPKG_DIR_FULL}/tools/build-srcpkg/info/SrcPkgDirs.imi
270 loadimi tools
/build-srcpkg
/info
/SrcPkgDirs.imi
272 inc tools
/build-srcpkg
/shlib
/worklist.shlib
274 # inc tools/build-srcpkg/shlib/cmdline.shlib
275 #inc build/shlib/pre_build.shlib
280 ##############################
281 # section: private function
282 ##############################
286 ############################################################################
288 ############################################################################
292 # fdesc: on envchk sub-cmd.
303 # fdesc: on depchk sub-cmd.
313 # fsyntax: on_buildep
314 # fdesc: on buildep sub-cmd.
324 # fdesc: on srcbak sub-cmd.
330 dir
="$(basename $PWD)"
331 file="${dir}-$(date +%Y%m%d).zip"
334 mkdir
-pv $
(dirname $file)
335 rm ${file} 2>/dev
/null
336 echo "zip -r ${file} ${dir}"
337 zip -r ${file} ${dir}
340 [[ $SRCBAK_DIR != '../' && $SRCBAK_DIR != '..' ]] && mkdir
-pv $SRCBAK_DIR && mv ..
/$file ${SRCBAK_DIR}/ -f
347 # fdesc: on help sub-cmd.
353 OBJDIR
="$(eval echo ${OBJDIR_FMT})"
355 rm $OBJ_LIST ${OBJDIR} $OUTDIR -rf
358 test -z $dst && continue
359 eval echo rm "${OUTDIR}${DST_FMT}" -rf
360 eval rm ${OUTDIR}${DST_FMT} -rf
368 # fdesc: on help sub-cmd.
372 test -f Config.
in ||
test -f Kconfig
&&
373 build-config
"$@" && return $?
379 # fdesc: on all sub-cmd. build with defconf, default, example, test,
380 # doc, umdoc, genpkg.
385 test $?
!= 0 && return $?
389 test $?
!= 0 && return $?
392 test $?
!= 0 && return $?
395 test $?
!= 0 && return $?
398 test $?
!= 0 && return $?
401 test $?
!= 0 && return $?
404 test $?
!= 0 && return $?
407 test $?
!= 0 && return $?
411 # fsyntax: on_defconf
412 # fdesc: on defconf sub-cmd.
416 test -e build
/default.config
&& cp build
/default.config .config
421 # fsyntax: on_default
422 # fdesc: on help sub-cmd.
430 # build src to executables
431 TASK_RUNNING
"STEP_BUILD_DEST"
432 test $?
!= 0 && return $?
436 # fsyntax: on_example
437 # fdesc: on help sub-cmd.
445 TASK_RUNNING
"STEP_EXAMPLE"
451 # fdesc: on test sub-cmd.
461 # fdesc: on doc sub-cmd.
469 TASK_RUNNING
"STEP_DOC"
475 # fdesc: on umdoc sub-cmd.
483 TASK_RUNNING
"STEP_UMDOC"
489 # fdesc: on genpkg sub-cmd.
497 TASK_RUNNING
"STEP_INSTPKG"
502 # fsyntax: on_install
503 # fdesc: on help sub-cmd.
513 # fdesc: on dest sub-cmd.
523 # fdesc: on help sub-cmd.
530 echo "##################################################"
531 echo "##################################################"
532 echo "# build for arch '$i' ..."
539 # fsyntax: on_setarch
540 # fdesc: on setarch sub-cmd.
544 echo "ARCH=$1" > build
/output
/arch.imi
549 # fdesc: on cross sub-cmd.
553 test -f build
/output
/arch.imi
&&
554 echo "[err] arch.imi does not existing. run 'cmpl setarch <arch>' first." >&2 &&
557 loadimi build
/output
/arch.imi
563 # fsyntax: on_crosspkg
564 # fdesc: on crosspkg sub-cmd.
568 test -f build
/output
/arch.imi
&&
569 echo "[err] arch.imi does not existing. run 'cmpl setarch <arch>' first." >&2 &&
572 loadimi build
/output
/arch.imi
578 # fsyntax: on_gendevpkg
579 # fdesc: on gendevpkg sub-cmd.
585 echo xxxxxxxxxxxx
"$@"
589 # fsyntax: on_devinstall
590 # fdesc: on devinstall sub-cmd.
600 # fdesc: on mandoc sub-cmd.
609 # fsyntax: on_infodoc
610 # fdesc: on help sub-cmd.
619 # fsyntax: on_tutorial
620 # fdesc: on help sub-cmd.
630 # fdesc: on help sub-cmd.
639 # fsyntax: on_htmldoc
640 # fdesc: on help sub-cmd.
649 # fsyntax: on_setting
650 # fdesc: on help sub-cmd.
659 # fsyntax: on_release
660 # fdesc: on help sub-cmd.
670 # fdesc: on help sub-cmd.
679 # fsyntax: on_version
680 # fdesc: on version sub-cmd.
684 eval echo "$CMPL_PROG_VERSION"
691 # fdesc: on help sub-cmd.
695 test -z $term_width && term_width
=80
697 helper
="$(opt_helper)"
699 eval CMPL_PROG_SYNTAX
="\"$CMPL_PROG_SYNTAX\""
700 eval echo -ne "\"$CMPL_USAGE_FMT\""
707 ############################################################################
709 ############################################################################
716 expr match
"$@" '--load' >/dev
/null
2>&1
717 test "$?" = 0 && return
720 # default operation just compile src code.
722 test $# = 0 && set -- "$@" default
727 # prog_opt_dispatch "$@"
728 opt_desc_str_dispatch cmpl_desc_hdr_str
729 opt_desc_str_dispatch cmpl_desc_str
730 opt_desc_str_dispatch cmpl_other_desc_str
733 # init_dbglogout 2 testing 20000
734 # set_output_prefix info ""
735 # set_auto_newline ""
738 # running action list function for options after init.
739 # the paramter for init will be effact, then execute the
747 ##############################
748 # section: public function
749 ##############################
752 expr match
"$@" '--debug' >/dev
/null
2>&1
753 if test "$?" = 0; then
756 # does not need to shift args if the --debug option is not the
757 # first option. it will be ignored in process.
761 expr match
"$@" '--loadshlib' >/dev
/null
2>&1
762 if test "$?" != 0; then
770 ##############################
772 ##############################
780 # copy code from term.shlib in shlib, do not use whole lib.
782 readonly CNORMAL
="\033[0m" # restore to normal mode
783 readonly FCGREEN
="\033[32m" # font green
784 readonly FCMAGENTA
="\033[35m" # font magenta
785 readonly FCRED
="\033[31m" # font red
786 readonly FCCYAN
="\033[36m" # font cyan
787 readonly CREV
="\033[7m" # reverse