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 |- |-- |---clean |= |%<clean> |&<on_clean> |'clean files in compile procedure.'
205 |param |- |-- |---config |= |%<config> |&<on_config> |'feature config in src pkg.'
206 |param |- |-- |---all |= |%<all> |&<on_all> |'build in step of defconf, default, example, test, doc, umdoc, genpkg.'
207 |param |- |-- |---defconf |= |%<defconf> |&<on_defconf> |'set by default config.'
208 |param |- |-- |---default |= |%<default> |&<on_default> |'compile all dest in a src pkg.'
209 |param |- |-- |---example |= |%<example> |&<on_example> |'build example code if it exist.'
210 |param |- |-- |---test |= |%<test> |&<on_test> |'run test script for current src pkg.'
211 |param |- |-- |---doc |= |%<doc> |&<on_doc> |'build man and info helper doc.'
212 |param |- |-- |---umdoc |= |%<umdoc> |&<on_umdoc> |'build user manual doc in various kinds of doc type.'
213 |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.'
214 |param |- |-- |---install |=[pkgtype] |%<install> |&<on_install> |'install specified pkgs.'
216 |blank '[other build cmd]'
217 |param |- |-- |---dest |=[dest] |%<dest> |&<on_dest> |'build one of specified executables.'
218 |param |- |-- |---full |= |%<full> |&<on_full> |'compile all platform setted cpu platform in compiler toolchain.'
219 |param |- |-- |---setarch |=<arch> |%<setarch> |&<on_setarch> |'specified cross platform, and save.'
220 |param |- |-- |---cross |= |%<cross> |&<on_cross> |'build default cross platform setted '
221 |'insrc-pkg. it is setted by subcmd of setarch.'
222 |param |- |-- |---crosspkg |= |%<crosspkg> |&<on_crosspkg> |'build cross executables to a package.'
223 |param |- |-- |---gendevpkg |=[pkgname] |%<gendevpkg> |&<on_gendevpkg> |'generating pkg with dev lib.'
224 |param |- |-- |---devinstall |= |%<devinstall> |&<on_devinstall>|'install dev pkg.'
227 |param |- |-- |---mandoc |= |%<mandoc> |&<on_mandoc> |'build man doc.'
228 |param |- |-- |---infodoc |= |%<infodoc> |&<on_infodoc> |'build info doc.'
229 |param |- |-- |---tutorial |= |%<tutorial> |&<on_tutorial> |'build tutorial doc. it is an example guide doc.'
230 |param |- |-- |---pdfdoc |= |%<pdfdoc> |&<on_pdfdoc> |'build pdf user manual doc.'
231 |param |- |-- |---htmldoc |= |%<htmldoc> |&<on_htmldoc> |'build html user manual doc.'
233 |blank '[build src-pkg setting]'
234 |param |- |-- |---setting |= |%<setting> |&<on_setting> |'set src pkg build paramters.'
235 |param |- |-- |---release |= |%<release> |&<on_release> |'build release version.'
236 |param |- |-- |---debug |= |%<debug> |&<on_debug> |'build debug version, and genpkg with dev lib, install pkg by devinstall.'
241 cmpl_other_desc_str
="
243 |blank '[Version & Helper & Debug]'
244 |param |- |--version |---version |= |%<version> |&<on_version> |'output version info of this program.'
245 |param |-h |--help |---help |= |%<help> |&<on_help> |'this helper text doc.'
251 # application relative
253 SRCBAK_DIR
=${SRCBAK_DIR='../'}
256 load_shlib_on_build
()
258 # check if loaded, or not in root of srcpkg.
259 test ! -d "build" && test ! -d "tools/build-srcpkg" && test buildlib_loaded
= 1 &&
260 echo "'build' & 'tools/build-srcpkg' are not exist in current dir." &&
261 echo "is it the root dir of srcpkg?" >&2 &&
266 . tools
/build-srcpkg
/shlib
/incfile.shlib
268 #loadimi ${SRCPKG_DIR_FULL}/tools/build-srcpkg/info/SrcPkgDirs.imi
269 loadimi tools
/build-srcpkg
/info
/SrcPkgDirs.imi
271 inc tools
/build-srcpkg
/shlib
/worklist.shlib
273 inc tools
/build-srcpkg
/shlib
/cmdline.shlib
274 #inc build/shlib/pre_build.shlib
279 ##############################
280 # section: private function
281 ##############################
285 ############################################################################
287 ############################################################################
291 # fdesc: on envchk sub-cmd.
302 # fdesc: on depchk sub-cmd.
312 # fsyntax: on_buildep
313 # fdesc: on buildep sub-cmd.
323 # fdesc: on help sub-cmd.
329 OBJDIR
="$(eval echo ${OBJDIR_FMT})"
331 rm $OBJ_LIST ${OBJDIR} $OUTDIR -rf
334 test -z $dst && continue
335 eval echo rm "${OUTDIR}${DST_FMT}" -rf
336 eval rm ${OUTDIR}${DST_FMT} -rf
344 # fdesc: on help sub-cmd.
348 test -f Config.
in ||
test -f Kconfig
&&
349 build-config
"$@" && return $?
355 # fdesc: on all sub-cmd. build with defconf, default, example, test,
356 # doc, umdoc, genpkg.
361 test $?
!= 0 && return $?
365 test $?
!= 0 && return $?
368 test $?
!= 0 && return $?
371 test $?
!= 0 && return $?
374 test $?
!= 0 && return $?
377 test $?
!= 0 && return $?
380 test $?
!= 0 && return $?
383 test $?
!= 0 && return $?
387 # fsyntax: on_defconf
388 # fdesc: on defconf sub-cmd.
392 test -e build
/default.config
&& cp build
/default.config .config
397 # fsyntax: on_default
398 # fdesc: on help sub-cmd.
406 # build src to executables
407 TASK_RUNNING
"STEP_BUILD_DEST"
408 test $?
!= 0 && return $?
412 # fsyntax: on_example
413 # fdesc: on help sub-cmd.
421 TASK_RUNNING
"STEP_EXAMPLE"
427 # fdesc: on test sub-cmd.
437 # fdesc: on doc sub-cmd.
445 TASK_RUNNING
"STEP_DOC"
451 # fdesc: on umdoc sub-cmd.
459 TASK_RUNNING
"STEP_UMDOC"
465 # fdesc: on genpkg sub-cmd.
473 TASK_RUNNING
"STEP_INSTPKG"
478 # fsyntax: on_install
479 # fdesc: on help sub-cmd.
489 # fdesc: on dest sub-cmd.
499 # fdesc: on help sub-cmd.
506 echo "##################################################"
507 echo "##################################################"
508 echo "# build for arch '$i' ..."
515 # fsyntax: on_setarch
516 # fdesc: on setarch sub-cmd.
520 echo "ARCH=$1" > build
/output
/arch.imi
525 # fdesc: on cross sub-cmd.
529 test -f build
/output
/arch.imi
&&
530 echo "[err] arch.imi does not existing. run 'cmpl setarch <arch>' first." >&2 &&
533 loadimi build
/output
/arch.imi
539 # fsyntax: on_crosspkg
540 # fdesc: on crosspkg sub-cmd.
544 test -f build
/output
/arch.imi
&&
545 echo "[err] arch.imi does not existing. run 'cmpl setarch <arch>' first." >&2 &&
548 loadimi build
/output
/arch.imi
554 # fsyntax: on_gendevpkg
555 # fdesc: on gendevpkg sub-cmd.
561 echo xxxxxxxxxxxx
"$@"
565 # fsyntax: on_devinstall
566 # fdesc: on devinstall sub-cmd.
576 # fdesc: on mandoc sub-cmd.
585 # fsyntax: on_infodoc
586 # fdesc: on help sub-cmd.
595 # fsyntax: on_tutorial
596 # fdesc: on help sub-cmd.
606 # fdesc: on help sub-cmd.
615 # fsyntax: on_htmldoc
616 # fdesc: on help sub-cmd.
625 # fsyntax: on_setting
626 # fdesc: on help sub-cmd.
635 # fsyntax: on_release
636 # fdesc: on help sub-cmd.
646 # fdesc: on help sub-cmd.
655 # fsyntax: on_version
656 # fdesc: on version sub-cmd.
660 eval echo "$CMPL_PROG_VERSION"
667 # fdesc: on help sub-cmd.
671 test -z $term_width && term_width
=80
673 helper
="$(opt_helper)"
675 eval CMPL_PROG_SYNTAX
="\"$CMPL_PROG_SYNTAX\""
676 eval echo -ne "\"$CMPL_USAGE_FMT\""
683 ############################################################################
685 ############################################################################
692 expr match
"$@" '--load' >/dev
/null
2>&1
693 test "$?" = 0 && return
696 # default operation just compile src code.
698 test $# = 0 && set -- "$@" default
703 # prog_opt_dispatch "$@"
704 opt_desc_str_dispatch cmpl_desc_hdr_str
705 opt_desc_str_dispatch cmpl_desc_str
706 opt_desc_str_dispatch cmpl_other_desc_str
709 # init_dbglogout 2 testing 20000
710 # set_output_prefix info ""
711 # set_auto_newline ""
714 # running action list function for options after init.
715 # the paramter for init will be effact, then execute the
723 ##############################
724 # section: public function
725 ##############################
728 expr match
"$@" '--debug' >/dev
/null
2>&1
729 if test "$?" = 0; then
732 # does not need to shift args if the --debug option is not the
733 # first option. it will be ignored in process.
737 expr match
"$@" '--loadshlib' >/dev
/null
2>&1
738 if test "$?" != 0; then
746 ##############################
748 ##############################
756 # copy code from term.shlib in shlib, do not use whole lib.
758 readonly CNORMAL
="\033[0m" # restore to normal mode
759 readonly FCGREEN
="\033[32m" # font green
760 readonly FCMAGENTA
="\033[35m" # font magenta
761 readonly FCRED
="\033[31m" # font red
762 readonly FCCYAN
="\033[36m" # font cyan
763 readonly CREV
="\033[7m" # reverse