first version.
[build-srcpkg.git] / bin / srcpkg
blobb755378ff92af04b1738e6e52492ea2bb59e56d8
1 #!/bin/bash
2 ############################################################
3 # source: srcpkg
4 # author: CottonCandyOwner(CottonCandyOwner@126.com)
5 # date: 2024-02-01
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
10 # and modify it.
11 ############################################################
12 # note:
13 # develop operation on srcpkg. this script is oriented
14 # srcpkg srcpkg.
15 # suppose there is a man does not doing coding work,
16 # put the operations here.
17 ############################################################
20 # todoļ¼š
21 # @
22 # @
25 . shlibinc
28 include stdio.shlib
29 include args.shlib
30 include build-srcpkg/srcpkg.shlib
32 #include gplib.shlib
33 #include term.shlib
34 #include paths.shlib
36 ##############################
37 # section: public comment info
38 ##############################
42 ##############################
43 # section: variable define
44 ##############################
49 # this comment is used for version id auto update.
51 # @{prog-ver-begin}
52 readonly SRCPKG_V1=0
53 readonly SRCPKG_V2=1
54 readonly SRCPKG_V3=0
55 readonly SRCPKG_VEXT=
56 readonly SRCPKG_VER_DATE=20240201
57 # @{prog-ver-end}
59 readonly SRCPKG_PROG=`basename $0`
61 readonly SRCPKG_PROG_VERSION="v${SRCPKG_V1}.${SRCPKG_V2}\${SRCPKG_V3:+\".$SRCPKG_V3\"}\${SRCPKG_VEXT:+\"$SRCPKG_VEXT\"}\${SRCPKG_VER_DATE:+\"-$SRCPKG_VER_DATE\"}"
62 SRCPKG_PROG_VERSION_STR="`eval echo $SRCPKG_PROG_VERSION`
63 Copyright (C) 2023- Free Software Foundation, Inc.
64 This configure script is free software; the Free Software
65 Foundation gives unlimited permission to copy, distribute
66 and modify it.
68 Writen by CottenCandyOwner(CottenCandyOwner@126.com).
71 SRCPKG_PROG_BANNER="$SRCPKG_PROG $SRCPKG_PROG_VERSION_STR"
72 SRCPKG_PROG_SYNTAX='Usage: $SRCPKG_PROG -[${p_shortparam//\|/}]'
73 SRCPKG_PROG_DESC=" develop operation on srcpkg. this script is oriented srcpkg srcpkg.
74 suppose there is a man does not doing coding work, put the operations here.
77 SRCPKG_PROG_OTHER_DESC="
78 EXAMPLES:
80 @ code generating and synchronizing:
82 srcpkg -y
83 s[y]nchronize code to output dir.
85 @ list catalog node:
88 SRCPKG_USAGE_FMT='$SRCPKG_PROG_BANNER
89 ${SRCPKG_PROG_SYNTAX}
90 $SRCPKG_PROG_DESC
91 ${helper}
92 $SRCPKG_PROG_OTHER_DESC'
96 # do not delete this comment, it is used for var define code intert.
98 # args-var-define-begin
99 # args-var-define-end
103 # desc-str for srcpkg
104 # @ every paramter desc-str-line start with 'param'.
105 # @ every colum start with '|', and seperated by blanks.
106 # @ '|blank' means a blank line dispalyed in helper.
107 # @ follow with a '' quoated string is the option category string.
108 # @ comment '#' in desc-str is also supported, and can be used to
109 # disable some option have not been implemented.
110 # @ desc-str can be in multiple var. and some of them maybe re-used
111 # for other program by 'source xxx --loadshlib'.
113 srcpkg_desc_hdr_str="
114 |prog $0 'operations in develop. it include srcpkg operation, code operation, project file operation, and other features beyound cmpl.'
117 # @ PARAMETER DEFINE.
118 # this desc str would be referenced in scripttest, consider about opt name space.
119 # =, param name for opt.
120 # %, var name if this opt is enabled.
121 # &, proc func if opt trigged.
122 srcpkg_desc_str="
123 |blank '[general]'
124 |param |- |-- |---devinfo |= |%<devinfo> |&<on_devinfo> |'developer info for developping.'
125 |param |- |-- |---mailreg |= |%<mailreg> |&<on_mailreg> |'register a mail by inf in devinfo.'
126 |param |- |-- |---devchk |= |%<devchk> |&<on_devchk> |'genral develop environment check.'
128 |param |- |-- |---author |=[author]|%<author> |&<on_author> |'list author, or switch to specified account.'
129 |param |- |-- |---org |=[org] |%<org> |&<on_org> |'list org, or switch to specified org.'
131 |blank '[package]'
132 |param |- |-- |---pkgwiz |= |%<pkgwiz> |&<on_pkgwiz> |'srcpkg info cli wizard, and save to .pkginfo.'
133 |param |- |-- |---pkgwizard |= |%<pkgwizard> |&<on_pkgwizard> |'srcpkg info TUI wizard, and save to .pkginfo.'
134 |param |- |-- |---pkginit |=[type] |%<pkginit> |&<on_pkginit> |'init srcpkg dir & files by .pkginfo file.'
135 |'install build-srcpkg/shlib/... into srcpkg, '
136 |'by specifying pkginit type.'
137 |param |- |--gen-dir |--- |= |%<gendir> |&<on_gendir> |'generate dir structure of srcpkg.'
138 |param |- |--instcmpl |--- |=[cmpl] |%<cmpl> |&<on_instcmpl> |'install builder for compile.'
139 |param |- |--initcmpl |--- |= |%<initcmpl> |&<on_initcmpl> |'init for compile dest.'
140 |param |- |--insttest |--- |=[ttype] |%<insttest> |&<on_insttest> |'install builder for compile.'
141 |param |- |--instoptgen |--- |= |%<instoptgen>|&<on_instoptgen>|'install builder for compile.'
142 |param |- |--instcfg |--- |= |%<instcfg> |&<on_instcfg> |'install builder for compile.'
143 |param |- |--instscripttest |--- |= |%<cmpl> |&<on_instscrt> |'install builder for compile.'
144 |param |- |--instfullcmpl |--- |= |%<fullcmpl> |&<on_instfullcmpl>|'install builder for compile.'
145 |param |- |-- |---pkgchk |= |%<pkgchk> |&<on_pkgchk> |'check dirs if it is a standard srcpkg.'
146 |param |- |-- |---pkgreg |= |%<pkgreg> |&<on_pkgreg> |'regist srcpkg on repo.or.cz with info in .pkginfo.'
147 |param |- |-- |---pkgrename |=<pkgname>|%<pkgrename>|&<on_pkgrename> |'rename package, not only pkg dir name, it modify names in all it is a text file.'
148 |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.'
150 |blank '[pkginfo]'
151 |param |- |-- |---pkginfo |= |%<pkginfo> |&<on_pkginfo> |'.pkginit to .pkginfo file.'
152 |param |- |-- |---listval |= |%<listval> |&<on_listval> |'list var & val in .pkginfo file.'
153 |param |- |-- |---getval |=<vname> |%<vname> |&<on_getval> |'get value for the var in .pkginfo.'
154 |param |- |-- |---setval |=<vname> |%<vname> |&<on_setval> |'set value to specified var in .pkginfo.'
156 |blank '[reporistry]'
157 |param |- |-- |---reposync |= |%<reposync> |&<on_reposync> |'pull code from src reporistray.'
158 |param |- |-- |---branch |=[name] |%<branch> |&<on_branch> |'make new branch for current src pkg, and save it with branch sfx name in upper dir. rename orignial src pkg dir with '-org' sfx. and create a link file to new branch code dir. at the same time, create branch in code reporistray.'
159 |param |- |-- |---combine |=<org|branch> |%<combine> |&<on_combine>|'combine code to specified dir manually, and delete branch dir. synchronize it in src reporistray.'
160 |param |- |-- |---commit |= |%<commit> |&<on_commit> |'push code to src reporistray.'
162 |blank '[publish]'
163 |param |- |-- |---incv1 |= |%<incv1> |&<on_incv1> |'increase major version code id.'
164 |param |- |-- |---incv2 |= |%<incv2> |&<on_incv2> |'increase minor version code id.'
165 |param |- |-- |---incv3 |= |%<incv3> |&<on_incv3> |'increase patching version code id.'
166 |param |- |-- |---decv1 |= |%<decv1> |&<on_decv1> |'decrease major version code id.'
167 |param |- |-- |---decv2 |= |%<decv2> |&<on_decv2> |'decrease minor version code id.'
168 |param |- |-- |---decv3 |= |%<decv3> |&<on_decv3> |'decrease patching version code id.'
169 |param |- |-- |---webpages |= |%<webpages> |&<on_webpages> |'generate web pages for home page.'
170 |param |- |-- |---publish |= |%<publish> |&<on_publish> |'bulid binary and docs, invoke commit, '
171 'invoke srcbak to backup src code, transfer'
172 'them to server space. invoke incvX, webpages,'
173 'webupdate, to update web pages.'
175 |blank '[publish]'
176 |param |- |--install-build |--- |= |%<incv1> |&<on_incv1> |'install build-srcpkg to current srcpkg.'
177 |param |- |--init-dir |--- |= |%<incv1> |&<on_incv1> |'initialize dir structure as a standard srcpkg.'
181 srcpkg_other_desc_str="
182 |blank
183 |blank 'Version & Helper & Debug:'
184 |param |- |-- |---version |= |%<version> |&<on_version> |'output version info of this program.'
185 |param |- |--help |---help |= |%<help> |&<on_help> |'this helper text doc.'
190 ##############################
191 # section: private function
192 ##############################
196 ##################################################################
197 # application func.
198 ##################################################################
202 # fsyntax: on_author
203 # fdesc: on author sub-cmd.
205 on_author ()
207 echo xxxxxxxxxxxxxxxxxxxxxxxx on_author "$@"
211 # fsyntax: on_org
212 # fdesc: on org sub-cmd.
214 on_org ()
216 echo xxxxxxxxxxxxxxxxxxxxxxxx on_org "$@"
220 # fsyntax: on_devinfo
221 # fdesc: on devinfo sub-cmd.
223 on_devinfo ()
225 echo xxxxxxxxxxxxxxxxxxxxxxxx on_devinfo "$@"
230 ##################################################################
231 # cmdline opt on_xxx() proc.
232 ##################################################################
235 # fsyntax: on_devinfo
236 # fdesc: on devinfo sub-cmd.
238 on_devinfo ()
240 echo xxxxxxxxxxxxxxxxxxxxxxxx on_devinfo "$@"
244 # fsyntax: on_mailreg
245 # fdesc: on mailreg sub-cmd.
247 on_mailreg ()
249 # create dir skeletone
251 # install build-srcpkg & create init
252 echo xxxxxxxxxxxxxxxxxxxxxxxx on_mailreg "($@)"
256 # fsyntax: on_pkgwiz
257 # fdesc: on pkgwiz sub-cmd.
259 on_pkgwiz ()
261 load_params
262 srcpkg_pkgwiz
266 # fsyntax: on_pkgwizard
267 # fdesc: on pkgwizard sub-cmd.
269 on_pkgwizard ()
271 # create dir skeletone
273 # install build-srcpkg & create init
274 echo xxxxxxxxxxxxxxxxxxxxxxxx on_pkgwizard "($@)"
278 # fsyntax: on_pkginfo
279 # fdesc: on pkginfo sub-cmd.
281 on_pkginfo ()
287 # fsyntax: on_listval
288 # fdesc: on listval sub-cmd.
290 on_listval ()
296 # fsyntax: on_getval
297 # fdesc: on getval sub-cmd.
299 on_getval ()
305 # fsyntax: on_setval
306 # fdesc: on setval sub-cmd.
308 on_setval ()
315 # fsyntax: on_gendir
316 # fdesc: on pkginit sub-cmd.
318 on_gendir ()
320 # load .pkginit & style param.
321 load_params
323 # echo Style = ${Style}
324 # echo CodingStyle = ${CodingStyle}
325 # echo CodingTmpl = ${CodingTmpl}
326 # echo NamingStyle = ${NamingStyle}
327 # echo TmplParam = ${TmplParam}
328 # echo SrcpkgStyle = ${SrcpkgStyle}
329 # echo InstpkgStyle = ${InstpkgStyle}
331 # create dir skeletone
332 srcpkg_gendir ./
334 # codegen if design/module-design.catalog existing.
335 [[ -e design/module-design.catalog ]] && codegen -y
336 [[ -e testing/testing.catalog ]] && scripttest -y
340 # fsyntax: on_instcmpl
341 # fdesc: on pkginit sub-cmd.
343 on_instcmpl ()
345 # load .pkginit & style param.
346 load_params
348 # install build-srcpkg
349 srcpkg_install_builder ./tools
353 # fsyntax: on_initcmpl
354 # fdesc: on pkginit sub-cmd.
356 on_initcmpl ()
358 # load .pkginit & style param.
359 load_params
361 # init build-srcpkg
362 srcpkg_init_builder
366 # fsyntax: on_insttest
367 # fdesc: on pkginit sub-cmd.
369 on_insttest ()
371 # load .pkginit & style param.
372 load_params
378 # fsyntax: on_instoptgen
379 # fdesc: on pkginit sub-cmd.
381 on_instoptgen ()
383 # load .pkginit & style param.
384 load_params
390 # fsyntax: on_instcfg
391 # fdesc: on pkginit sub-cmd.
393 on_instcfg ()
395 # load .pkginit & style param.
396 load_params
402 # fsyntax: on_instscrt
403 # fdesc: on pkginit sub-cmd.
405 on_instscrt ()
407 # load .pkginit & style param.
408 load_params
414 # fsyntax: on_instfullcmpl
415 # fdesc: on pkginit sub-cmd.
417 on_instfullcmpl ()
419 # load .pkginit & style param.
420 load_params
426 # fsyntax: on_pkginit
427 # fdesc: on pkginit sub-cmd.
429 on_pkginit ()
431 local pkgname=
432 local tmp=
434 echo xxxxxxxxxxxxxxxxxxxxxxxx on_pkginit "($@)"
436 on_gendir
438 on_instcmpl
439 on_initcmpl
440 exit
441 on_insttest
442 on_instoptgen
443 on_instcfg
444 on_instscrt
448 # fsyntax: on_pkgchk
449 # fdesc: on pkgchk sub-cmd.
451 on_pkgchk ()
453 # create dir skeletone
455 # install build-srcpkg & create init
456 echo xxxxxxxxxxxxxxxxxxxxxxxx on_pkgchk "($@)"
460 # fsyntax: on_pkgreg
461 # fdesc: on pkgreg sub-cmd.
463 on_pkgreg ()
465 # create dir skeletone
467 # install build-srcpkg & create init
468 echo xxxxxxxxxxxxxxxxxxxxxxxx on_pkgreg "($@)"
472 # fsyntax: on_pkgrename
473 # fdesc: on pkgrename sub-cmd.
475 on_pkgrename ()
477 # create dir skeletone
479 # install build-srcpkg & create init
480 echo xxxxxxxxxxxxxxxxxxxxxxxx on_pkgrename "($@)"
484 # fsyntax: on_srcbak
485 # fdesc: on srcbak sub-cmd.
487 on_srcbak ()
489 on_clean
491 dir="$(basename $PWD)"
492 file="${dir}-$(date +%Y%m%d).zip"
494 cd ..
495 mkdir -pv $(dirname $file)
496 rm ${file} 2>/dev/null
497 echo "zip -r ${file} ${dir}"
498 zip -r ${file} ${dir}
499 cd - 2>/dev/null
501 [[ $SRCBAK_DIR != '../' && $SRCBAK_DIR != '..' ]] && mkdir -pv $SRCBAK_DIR && mv ../$file ${SRCBAK_DIR}/ -f
503 exit 0
507 # fsyntax: on_reposync
508 # fdesc: on reposync sub-cmd.
510 on_reposync ()
512 # create dir skeletone
514 # install build-srcpkg & create init
515 echo xxxxxxxxxxxxxxxxxxxxxxxx on_reposync "($@)"
519 # fsyntax: on_branch
520 # fdesc: on branch sub-cmd.
522 on_branch ()
524 # create dir skeletone
526 # install build-srcpkg & create init
527 echo xxxxxxxxxxxxxxxxxxxxxxxx on_branch "($@)"
531 # fsyntax: on_combine
532 # fdesc: on combine sub-cmd.
534 on_combine ()
536 # create dir skeletone
538 # install build-srcpkg & create init
539 echo xxxxxxxxxxxxxxxxxxxxxxxx on_combine "($@)"
543 # fsyntax: on_commit
544 # fdesc: on commit sub-cmd.
546 on_commit ()
548 # create dir skeletone
550 # install build-srcpkg & create init
551 echo xxxxxxxxxxxxxxxxxxxxxxxx on_commit "($@)"
554 on_incv1 ()
556 PRJ_NAME=`ls *.pc | sed -e "s/\.pc.*$$//g"`
557 sed -e "s/Version:.*$$/Version: $1/g" -i $$PRJ_NAME.pc
561 # fsyntax: on_incv1
562 # fdesc: on incv1 sub-cmd.
564 on_incv1 ()
566 echo xxxxxxxxxxxxxxxxxxxxxxxx on_incv1 "($@)"
568 SRCPKG_NAME=`ls *.pc | sed -e "s/\.pc.*$$//g"`
569 VERSION=`cat $SRCPKG_NAME.pc | grep -e "Version:" | sed -e "s/Version: //g"`
570 VER1=`echo $VERSION | cut -d "." -f1`
571 VER1=`expr $VER1 + 1`
572 VER2=0
573 VER3=0
574 echo $$VER1.$$VER2.$$VER3
575 set_prj_version "$VER1" "$VER2" "$VER3"
579 # fsyntax: on_incv2
580 # fdesc: on incv2 sub-cmd.
582 on_incv2 ()
584 echo xxxxxxxxxxxxxxxxxxxxxxxx on_incv2 "($@)"
586 SRCPKG_NAME=`ls *.pc | sed -e "s/\.pc.*$$//g"`
587 VERSION=`cat SRCPKG_NAME.pc | grep -e "Version:" | sed -e "s/Version: //g"`
588 VER1=`echo $VERSION | cut -d "." -f1`
589 VER2=`echo $VERSION | cut -d "." -f2`
590 VER2=`expr $VER2 + 1`
591 VER3=0
592 echo $VER1.$VER2.$VER3
593 set_prj_version "$VER1" "$VER2" "$VER3"
597 # fsyntax: on_incv3
598 # fdesc: on incv3 sub-cmd.
600 on_incv3 ()
602 echo xxxxxxxxxxxxxxxxxxxxxxxx on_incv3 "($@)"
604 SRCPKG_NAME=`ls *.pc | sed -e "s/\.pc.*$$//g"`
605 VERSION=`cat $PRJ_NAME.pc | grep -e "Version:" | sed -e "s/Version: //g"`
606 VER1=`echo $VERSION | cut -d "." -f1`
607 VER2=`echo $VERSION | cut -d "." -f2`
608 VER3=`echo $VERSION | cut -d "." -f3`
609 VER3=`expr $VER3 + 1`
610 echo $VER1.$VER2.$VER3
611 set_prj_version "$VER1" "$VER2" "$VER3"
615 # fsyntax: on_decv1
616 # fdesc: on decv1 sub-cmd.
618 on_decv1 ()
620 # create dir skeletone
622 # install build-srcpkg & create init
623 echo xxxxxxxxxxxxxxxxxxxxxxxx on_decv1 "($@)"
627 # fsyntax: on_decv2
628 # fdesc: on decv2 sub-cmd.
630 on_decv2 ()
632 # create dir skeletone
634 # install build-srcpkg & create init
635 echo xxxxxxxxxxxxxxxxxxxxxxxx on_decv2 "($@)"
639 # fsyntax: on_decv3
640 # fdesc: on decv3 sub-cmd.
642 on_decv3 ()
644 # TBD:
645 echo xxxxxxxxxxxxxxxxxxxxxxxx on_decv3 "($@)"
649 # fsyntax: on_webpages
650 # fdesc: on webpages sub-cmd.
652 on_webpages ()
654 echo xxxxxxxxxxxxxxxxxxxxxxxx on_webpages "($@)"
656 gendocs.sh --email bug-gnu-emacs@gnu.org emacs "GNU Emacs Manual"
660 # fsyntax: on_publish
661 # fdesc: on publish sub-cmd.
663 on_publish ()
665 echo xxxxxxxxxxxxxxxxxxxxxxxx on_publish "($@)"
667 # update webpages generated in build/output/doc/
668 gnu-web-doc-update
672 # fsyntax: on_version
673 # fdesc: on version sub-cmd.
675 on_version ()
677 eval echo "$CMPL_PROG_VERSION"
679 exit
683 # fsyntax: on_help
684 # fdesc: on help sub-cmd.
686 on_help ()
688 [[ -z $term_width ]] && term_width=80
690 helper="$(opt_helper)"
691 eval SRCPKG_PROG_SYNTAX="\"$SRCPKG_PROG_SYNTAX\""
692 eval echo -ne "\"$SRCPKG_USAGE_FMT\""
694 exit
699 ##############################
700 # section: public function
701 ##############################
705 main_srcpkg ()
707 [[ "$@" =~ '--load' ]] && return
710 # args parsing
712 # prog_opt_dispatch "$@"
713 opt_desc_str_dispatch srcpkg_desc_hdr_str
714 opt_desc_str_dispatch srcpkg_desc_str
715 opt_desc_str_dispatch srcpkg_other_desc_str
716 prog_opt_proc "$@"
718 init_dbglogout 2 testing 20000
719 # set_output_prefix info ""
720 set_auto_newline ""
722 # SRCPKG_DIR="$(pwd)"
723 # TEST_DIR_STR_FMT="$(attr_get catalog::testdir::STR_FMT)"
724 # ALIGN=' '
727 # running action list function for options after init.
728 # the paramter for init will be effact, then execute the
729 # action function.
731 action_list_exec
734 if [[ "$@" =~ "--debug" ]]; then
735 declare -g DBGOUTD_OUTPUT=1
737 # does not need to shift args if the --debug option is not the
738 # first option. it will be ignore in process.
739 # shift
742 if [[ $1 != "--loadshlib" ]]; then
743 # main "$@"
744 main_srcpkg "$@"
745 else
746 shift
750 ##############################
751 # section: file tail
752 ##############################