diff options
author | P. J. McDermott <pj@pehjota.net> | 2015-12-07 12:07:15 (EST) |
---|---|---|
committer | P. J. McDermott <pj@pehjota.net> | 2015-12-07 12:07:15 (EST) |
commit | 34a77f7822126263fed5c72aedaa65b58fee94ac (patch) | |
tree | a3404e611672f64126298e2f0f6d3398b014851e | |
parent | 84f3cccfb57fc8270b2ae14f0adf2c2ff24cc69b (diff) | |
parent | 41f638c961d5c7832e2b18a9f2e45a09b54dc53e (diff) |
Merge branch 'feature/use-shld'
-rw-r--r-- | .gitignore | 10 | ||||
-rw-r--r-- | Makefile.am | 110 | ||||
-rw-r--r-- | config.sh.in | 2 | ||||
-rw-r--r-- | configure.ac | 3 | ||||
-rw-r--r-- | lib/cmd/local.mk | 8 | ||||
-rw-r--r-- | lib/local.mk | 22 | ||||
-rw-r--r-- | lib/package/local.mk | 2 | ||||
-rw-r--r-- | lib/profile/local.mk | 2 | ||||
-rw-r--r-- | src/archplat.sh (renamed from lib/archplat.sh) | 3 | ||||
-rw-r--r-- | src/block.sh (renamed from lib/block.sh) | 6 | ||||
-rw-r--r-- | src/cmd.sh (renamed from lib/cmd.sh) | 23 | ||||
-rw-r--r-- | src/cmd/build.sh (renamed from lib/cmd/build.sh) | 13 | ||||
-rw-r--r-- | src/cmd/help.sh (renamed from lib/cmd/help.sh) | 6 | ||||
-rw-r--r-- | src/cmd/install.sh (renamed from lib/cmd/install.sh) | 12 | ||||
-rw-r--r-- | src/cmd/installer-pc.sh (renamed from lib/cmd/installer-pc.sh) | 12 | ||||
-rw-r--r-- | src/cmd/local.mk | 8 | ||||
-rw-r--r-- | src/cmd/opkg.sh (renamed from lib/cmd/opkg.sh) | 11 | ||||
-rw-r--r-- | src/cmd/shell.sh (renamed from lib/cmd/shell.sh) | 10 | ||||
-rw-r--r-- | src/cmd/version.sh (renamed from lib/cmd/version.sh) | 6 | ||||
-rw-r--r-- | src/control.sh (renamed from lib/control.sh) | 6 | ||||
-rw-r--r-- | src/deps.sh (renamed from lib/deps.sh) | 5 | ||||
-rw-r--r-- | src/dir.sh (renamed from lib/dir.sh) | 3 | ||||
-rw-r--r-- | src/fd.sh (renamed from lib/fd.sh) | 6 | ||||
-rw-r--r-- | src/feed.sh (renamed from lib/feed.sh) | 6 | ||||
-rw-r--r-- | src/getopt.sh (renamed from lib/getopt.sh) | 3 | ||||
-rw-r--r-- | src/install.sh (renamed from lib/install.sh) | 8 | ||||
-rw-r--r-- | src/local.mk | 29 | ||||
-rw-r--r-- | src/locale.sh (renamed from lib/locale.sh) | 9 | ||||
-rw-r--r-- | src/main.sh (renamed from src/prokit.sh) | 38 | ||||
-rw-r--r-- | src/mutex.sh (renamed from lib/mutex.sh) | 3 | ||||
-rw-r--r-- | src/opkg.sh (renamed from lib/opkg.sh) | 5 | ||||
-rw-r--r-- | src/output.sh (renamed from lib/output.sh) | 3 | ||||
-rw-r--r-- | src/package.sh (renamed from lib/package.sh) | 6 | ||||
-rw-r--r-- | src/package/2.sh (renamed from lib/package/2.sh) | 7 | ||||
-rw-r--r-- | src/package/local.mk | 2 | ||||
-rw-r--r-- | src/pkg.sh (renamed from lib/pkg.sh) | 3 | ||||
-rw-r--r-- | src/profile.sh (renamed from lib/profile.sh) | 18 | ||||
-rw-r--r-- | src/profile/local.mk | 2 | ||||
-rw-r--r-- | src/profile/proteanos.sh (renamed from lib/profile/proteanos.sh) | 9 | ||||
-rw-r--r-- | src/rand.sh (renamed from lib/rand.sh) | 6 | ||||
-rw-r--r-- | src/session.sh (renamed from lib/session.sh) | 9 | ||||
-rw-r--r-- | src/substvars.sh (renamed from lib/substvars.sh) | 3 | ||||
-rw-r--r-- | src/vardata.sh (renamed from lib/vardata.sh) | 4 | ||||
-rwxr-xr-x | tests/arch_is_concerned.sh | 93 | ||||
-rw-r--r-- | tests/common.sh | 15 | ||||
-rw-r--r-- | tests/local.mk | 51 | ||||
-rwxr-xr-x | tests/match_arch.sh | 33 | ||||
-rwxr-xr-x | tests/match_plat.sh | 25 | ||||
-rwxr-xr-x | tests/parse_control.basic.sh | 2 | ||||
-rw-r--r-- | tests/parse_control.common.sh | 20 | ||||
-rwxr-xr-x | tests/plat_is_concerned.sh | 85 | ||||
-rwxr-xr-x | tests/reduce_deps.sh | 66 | ||||
-rwxr-xr-x | tests/resolve_deps.basic.sh | 23 | ||||
-rwxr-xr-x | tools/shld.sh | 157 | ||||
-rwxr-xr-x | tools/shpp.sh | 165 |
55 files changed, 687 insertions, 510 deletions
@@ -17,14 +17,18 @@ Makefile.in config.log config.status Makefile +config.sh # Files generated by Makefile -src/*[^.]?? -lib/*.sm -lib/*/*.sm +*.sho +prokit locale/*.ms man/*.[18] man/*.[18].mdwn *-*/ *-*.tar* .builddirstamp +tests/*[^.]?? +tests/*.log +tests/*.trs +test-suite.log diff --git a/Makefile.am b/Makefile.am index 83c0127..f8cdfa8 100644 --- a/Makefile.am +++ b/Makefile.am @@ -18,81 +18,48 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -include $(top_srcdir)/src/local.mk -include $(top_srcdir)/lib/local.mk -include $(top_srcdir)/lib/cmd/local.mk -include $(top_srcdir)/lib/profile/local.mk -include $(top_srcdir)/lib/package/local.mk -include $(top_srcdir)/man/local.mk -include $(top_srcdir)/locale/local.mk -include $(top_srcdir)/tests/local.mk - MANUAL = ProteanOS Development Kit Manual +TEXTDOMAIN = $$(printf '%s\n' '$(PACKAGE)' | sed -e 's|-|_|g') + +SUFFIXES = .sh .sho .ms .1in .1 .8in .8 +LINK = '$(srcdir)/tools/shld.sh' -I '$(SH)' -o $@ config.sh + +bin_PROGRAMS = prokit + +prokit_SOURCES = +prokit_SHPPFLAGS = \ + -DPKGDATADIR="$(pkgdatadir)" \ + -DLOCALEDIR="$(localedir)" \ + -DPKGLOCALSTATEDIR="$(pkglocalstatedir)" \ + -DTEXTDOMAIN="$(TEXTDOMAIN)" +prokit_LDADD = $(prokit_SOURCES:.sh=.sho) + +locale_MESSAGES = $(locale_sources:.sh=.ms) -bin_SCRIPTS = $(bin_sources:.sh=) -pkgdata_SCRIPTS = $(pkgdata_sources:.sh=.sm) -pkgdatacmd_SCRIPTS = $(pkgdatacmd_sources:.sh=.sm) -pkgdataprofile_SCRIPTS = $(pkgdataprofile_sources:.sh=.sm) -pkgdatapackage_SCRIPTS = $(pkgdatapackage_sources:.sh=.sm) man1_MANS = $(man1_sources:.1in=.1) man8_MANS = $(man8_sources:.8in=.8) -locale_MESSAGES = $(locale_sources:.sh=.ms) +do_subst = sed \ + -e 's|[@]PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' \ + -e 's|[@]PACKAGE_VERSION[@]|$(PACKAGE_VERSION)|g' \ + -e 's|[@]MANUAL[@]|$(MANUAL)|g' + noinst_DATA = $(locale_MESSAGES) .builddirstamp CLEANFILES = \ - $(bin_SCRIPTS) \ - $(pkgdata_SCRIPTS) \ - $(pkgdatacmd_SCRIPTS) \ - $(pkgdataprofile_SCRIPTS) \ - $(pkgdatapackage_SCRIPTS) \ + $(locale_MESSAGES) \ $(man1_MANS) \ $(man8_MANS) \ - $(locale_MESSAGES) \ .builddirstamp -pkgdatacmddir = $(pkgdatadir)/cmd -pkgdataprofiledir = $(pkgdatadir)/profile -pkgdatapackagedir = $(pkgdatadir)/package uninstall_dirs = \ '$(DESTDIR)$(pkglocalstatedir)/mount' \ - '$(DESTDIR)$(pkglocalstatedir)' \ - '$(DESTDIR)$(pkgdatapackagedir)' \ - '$(DESTDIR)$(pkgdataprofiledir)' \ - '$(DESTDIR)$(pkgdatacmddir)' \ - '$(DESTDIR)$(pkgdatadir)' -sources = \ - $(bin_sources) \ - $(pkgdata_sources) \ - $(pkgdatacmd_sources) \ - $(pkgdataprofile_sources) \ - $(pkgdatapackage_sources) \ - $(man1_sources) \ - $(man8_sources) \ - $(locale_sources) \ - $(TESTS) \ - tests/common.sh \ - tests/parse_control.common.sh + '$(DESTDIR)$(pkglocalstatedir)' EXTRA_DIST = \ autogen.sh \ - $(sources) \ - scripts/announce-release.sh - -SUFFIXES = .sh .sm .1in .1 .8in .8 .ms - -cmds = $$(printf '%s ' $(pkgdatacmd_SCRIPTS) | \ - sed -e 's|[^ ]*/\([^ ]*\)\.sm |\1 |g') -profiles = $$(printf '%s ' $(pkgdataprofile_SCRIPTS) | \ - sed -e 's|[^ ]*/\([^ ]*\)\.sm |\1 |g') -textdomain = $$(printf '%s\n' '$(PACKAGE)' | sed -e 's|-|_|g') -do_subst = sed \ - -e 's|[@]PACKAGE_NAME[@]|$(PACKAGE_NAME)|g' \ - -e 's|[@]PACKAGE_VERSION[@]|$(PACKAGE_VERSION)|g' \ - -e 's|[@]MANUAL[@]|$(MANUAL)|g' \ - -e 's|[@]SH[@]|$(SH)|g' \ - -e 's|[@]pkgdatadir[@]|$(pkgdatadir)|g' \ - -e 's|[@]localedir[@]|$(localedir)|g' \ - -e 's|[@]pkglocalstatedir[@]|$(pkglocalstatedir)|g' \ - -e "s|[@]cmds[@]|$(cmds)|g" \ - -e "s|[@]profiles[@]|$(profiles)|g" \ - -e "s|[@]textdomain[@]|$(textdomain)|g" + $(locale_sources) \ + $(man1_sources) \ + $(man8_sources) \ + scripts/announce-release.sh \ + tools/shpp.sh \ + tools/shld.sh AM_TESTS_ENVIRONMENT = srcdir=$(top_srcdir) COLOR_TEST_LOGS=$(COLOR_TEST_LOGS) @@ -114,7 +81,7 @@ todo: printf '\n'; \ printf 'Code comments:\n'; \ printf '==============\n\n'; \ - for f in $(sources); do \ + for f in $$(printf '%s\n' $(SOURCES) | sort -u); do \ printed=false; \ sed '=' "$(top_srcdir)/$${f}" | sed 'N; s/\n/ ./' | sed -n \ '$(todo_script)' | while read -r lineno line; do \ @@ -213,14 +180,14 @@ release: '$(srcdir)/scripts/announce-release.sh' \ $(PACKAGE) $(VERSION) '$(PACKAGE_NAME)' -.sh: +.sh.sho: $(AM_V_GEN)$(MKDIR_P) "$$(dirname $@)" - $(AM_V_at)$(do_subst) $< >$@ - $(AM_V_at)chmod a+x $@ + $(AM_V_at)$(SH) -n $< + $(AM_V_at)'$(srcdir)/tools/shpp.sh' $(prokit_SHPPFLAGS) $< $@ -.sh.sm: +.sh.ms: $(AM_V_GEN)$(MKDIR_P) "$$(dirname $@)" - $(AM_V_at)$(do_subst) $< >$@ + $(AM_V_at)cp $< $@ .1in.1: $(AM_V_GEN)$(MKDIR_P) "$$(dirname $@)" @@ -230,6 +197,7 @@ release: $(AM_V_GEN)$(MKDIR_P) "$$(dirname $@)" $(AM_V_at)$(do_subst) $< >$@ -.sh.ms: - $(AM_V_GEN)$(MKDIR_P) "$$(dirname $@)" - $(AM_V_at)cp $< $@ +include $(top_srcdir)/src/local.mk +include $(top_srcdir)/locale/local.mk +include $(top_srcdir)/man/local.mk +include $(top_srcdir)/tests/local.mk diff --git a/config.sh.in b/config.sh.in new file mode 100644 index 0000000..cf4a26d --- /dev/null +++ b/config.sh.in @@ -0,0 +1,2 @@ +PACKAGE_NAME='@PACKAGE_NAME@' +PACKAGE_VERSION='@PACKAGE_VERSION@' diff --git a/configure.ac b/configure.ac index b0e27e1..75d216a 100644 --- a/configure.ac +++ b/configure.ac @@ -22,7 +22,7 @@ AC_INIT([ProteanOS Development Kit], [1.2.0], [mailto:proteanos-dev@lists.proteanos.com], [prokit], [http://www.proteanos.com/dev/prokit/]) AC_CONFIG_AUX_DIR([build-aux]) -AC_CONFIG_SRCDIR([src/prokit.sh]) +AC_CONFIG_SRCDIR([src/main.sh]) AM_INIT_AUTOMAKE([gnu check-news dist-bzip2 dist-xz subdir-objects]) AM_SILENT_RULES([yes]) @@ -71,4 +71,5 @@ AC_ARG_WITH( ) AC_CONFIG_FILES([Makefile]) +AC_CONFIG_FILES([config.sh]) AC_OUTPUT() diff --git a/lib/cmd/local.mk b/lib/cmd/local.mk deleted file mode 100644 index dc6e2ae..0000000 --- a/lib/cmd/local.mk +++ /dev/null @@ -1,8 +0,0 @@ -pkgdatacmd_sources = \ - lib/cmd/help.sh \ - lib/cmd/version.sh \ - lib/cmd/install.sh \ - lib/cmd/shell.sh \ - lib/cmd/opkg.sh \ - lib/cmd/build.sh \ - lib/cmd/installer-pc.sh diff --git a/lib/local.mk b/lib/local.mk deleted file mode 100644 index a202aad..0000000 --- a/lib/local.mk +++ /dev/null @@ -1,22 +0,0 @@ -pkgdata_sources = \ - lib/output.sh \ - lib/locale.sh \ - lib/getopt.sh \ - lib/fd.sh \ - lib/dir.sh \ - lib/vardata.sh \ - lib/archplat.sh \ - lib/deps.sh \ - lib/substvars.sh \ - lib/control.sh \ - lib/feed.sh \ - lib/pkg.sh \ - lib/mutex.sh \ - lib/session.sh \ - lib/block.sh \ - lib/opkg.sh \ - lib/rand.sh \ - lib/cmd.sh \ - lib/profile.sh \ - lib/package.sh \ - lib/install.sh diff --git a/lib/package/local.mk b/lib/package/local.mk deleted file mode 100644 index aee6eca..0000000 --- a/lib/package/local.mk +++ /dev/null @@ -1,2 +0,0 @@ -pkgdatapackage_sources = \ - lib/package/2.sh diff --git a/lib/profile/local.mk b/lib/profile/local.mk deleted file mode 100644 index 2ebbca8..0000000 --- a/lib/profile/local.mk +++ /dev/null @@ -1,2 +0,0 @@ -pkgdataprofile_sources = \ - lib/profile/proteanos.sh diff --git a/lib/archplat.sh b/src/archplat.sh index d7b1424..b8324a0 100644 --- a/lib/archplat.sh +++ b/src/archplat.sh @@ -18,9 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_ARCHPLAT_SM+set}" = 'xset' ] && return 0 -_ARCHPLAT_SM=1 - match_arch() { local arch="${1}" diff --git a/lib/block.sh b/src/block.sh index ef1eed9..f056305 100644 --- a/lib/block.sh +++ b/src/block.sh @@ -18,12 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_BLOCK_SM+set}" = 'xset' ] && return 0 -_BLOCK_SM=1 - -use rand -use vardata - is_block() { local dev="${1}" @@ -18,24 +18,17 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_CMD_SM+set}" = 'xset' ] && return 0 -_CMD_SM=1 - -use output -use locale - -CMDS='@cmds@' - +cmds=' ' running_cmd= running_cmd_clean= -load_cmds() +register_cmd() { - local cmd= + local cmd="${1}" + shift 1 - for cmd in ${CMDS}; do - use "cmd/${cmd}" - done + cmds="${cmds}${cmd} " + return 0 } print_opt_summaries() @@ -75,7 +68,7 @@ print_cmd_summaries() local summary= padding="$(printf '%24s' '')" - for cmd in ${CMDS}; do + for cmd in ${cmds}; do if [ ${#cmd} -gt 20 ]; then printf ' %s\n%24s' "${cmd}" '' else @@ -106,7 +99,7 @@ is_cmd() { local cmd="${1}" - [ "x$(printf '%s\n' ${CMDS} | grep "^${cmd}$")" = "x${cmd}" ] + [ "x$(printf '%s\n' ${cmds} | grep "^${cmd}$")" = "x${cmd}" ] } run_cmd() diff --git a/lib/cmd/build.sh b/src/cmd/build.sh index d22fa1e..8d12691 100644 --- a/lib/cmd/build.sh +++ b/src/cmd/build.sh @@ -18,13 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -use block -use profile -use session -use rand -use package -use control - cmd_build_root= cmd_build_pkg_dir= cmd_build_build_deps= @@ -151,3 +144,9 @@ cmd_build_fini() mv "${f}" "${cmd_build_pkg_dir}/.." done } + +cmd_build_register() +{ + register_cmd 'build' +} +__init cmd_build_register diff --git a/lib/cmd/help.sh b/src/cmd/help.sh index 7515fdb..c699c73 100644 --- a/lib/cmd/help.sh +++ b/src/cmd/help.sh @@ -39,3 +39,9 @@ cmd_help_main() printf "$(get_msg 'cmd_help_summary_head')\n" print_cmd_summaries } + +cmd_help_register() +{ + register_cmd 'help' +} +__init cmd_help_register diff --git a/lib/cmd/install.sh b/src/cmd/install.sh index d983e28..e0bdc4e 100644 --- a/lib/cmd/install.sh +++ b/src/cmd/install.sh @@ -18,12 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -use getopt -use feed -use profile -use block -use install - cmd_install_optstring='a:p:m:F' cmd_install_main() @@ -79,3 +73,9 @@ cmd_install_main() block_umount "${chroot}" fi } + +cmd_install_register() +{ + register_cmd 'install' +} +__init cmd_install_register diff --git a/lib/cmd/installer-pc.sh b/src/cmd/installer-pc.sh index 69381d0..dd01506 100644 --- a/lib/cmd/installer-pc.sh +++ b/src/cmd/installer-pc.sh @@ -18,12 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -use getopt -use profile -use block -use install -use session - cmd_installer_pc_optstring='a:p:m:' cmd_installer_pc_main() @@ -99,3 +93,9 @@ cmd_installer_pc_make_partition_and_fs() printf 'n\np\n1\n\n\nt\n83\na\n1\nw\n' | fdisk "${dev}" mke2fs -t ext4 "${dev}1" } + +cmd_installer_pc_register() +{ + register_cmd 'installer-pc' +} +__init cmd_installer_pc_register diff --git a/src/cmd/local.mk b/src/cmd/local.mk new file mode 100644 index 0000000..a6dd3bd --- /dev/null +++ b/src/cmd/local.mk @@ -0,0 +1,8 @@ +prokit_SOURCES += \ + src/cmd/help.sh \ + src/cmd/version.sh \ + src/cmd/install.sh \ + src/cmd/shell.sh \ + src/cmd/opkg.sh \ + src/cmd/build.sh \ + src/cmd/installer-pc.sh diff --git a/lib/cmd/opkg.sh b/src/cmd/opkg.sh index 51b90dc..e1fc8ce 100644 --- a/lib/cmd/opkg.sh +++ b/src/cmd/opkg.sh @@ -18,11 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -use block -use profile -use session -use rand - cmd_opkg_opks= cmd_opkg_main() @@ -109,3 +104,9 @@ cmd_opkg_fini() ;; esac } + +cmd_opkg_register() +{ + register_cmd 'opkg' +} +__init cmd_opkg_register diff --git a/lib/cmd/shell.sh b/src/cmd/shell.sh index b5b6d69..468da0f 100644 --- a/lib/cmd/shell.sh +++ b/src/cmd/shell.sh @@ -18,10 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -use block -use profile -use session - cmd_shell_main() { local root= @@ -58,3 +54,9 @@ cmd_shell_main() block_umount "${root}" fi } + +cmd_shell_register() +{ + register_cmd 'shell' +} +__init cmd_shell_register diff --git a/lib/cmd/version.sh b/src/cmd/version.sh index cc40b4b..0105f20 100644 --- a/lib/cmd/version.sh +++ b/src/cmd/version.sh @@ -25,3 +25,9 @@ cmd_version_main() printf "$(get_msg 'cmd_version_copyright')\n" \ '2012, 2013, 2014' 'Patrick "P. J." McDermott' } + +cmd_version_register() +{ + register_cmd 'version' +} +__init cmd_version_register diff --git a/lib/control.sh b/src/control.sh index 3dcb06c..b25d00b 100644 --- a/lib/control.sh +++ b/src/control.sh @@ -18,12 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_CONTROL_SM+set}" = 'xset' ] && return 0 -_CONTROL_SM=1 - -use output -use locale - control_file= control_line_nr= diff --git a/lib/deps.sh b/src/deps.sh index 7800cad..862caff 100644 --- a/lib/deps.sh +++ b/src/deps.sh @@ -18,11 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_DEPS_SM+set}" = 'xset' ] && return 0 -_DEPS_SM=1 - -use archplat - parse_dep() { local dep="${1}" @@ -18,9 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_DIR_SM+set}" = 'xset' ] && return 0 -_DIR_SM=1 - dir_is_empty() { local dir="${1}" @@ -18,12 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_FD_SM+set}" = 'xset' ] && return 0 -_FD_SM=1 - -use output -use locale - _FD_MIN=3 # Shells and the file descriptors they reserve for the user: # * Debian Almquist Shell diff --git a/lib/feed.sh b/src/feed.sh index 8d29640..4288c2a 100644 --- a/lib/feed.sh +++ b/src/feed.sh @@ -18,12 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_FEED_SM+set}" = 'xset' ] && return 0 -_FEED_SM=1 - -use fd -use control - feed_dep_fields= feed_pkg_cb= feed_deps_cb= diff --git a/lib/getopt.sh b/src/getopt.sh index b8d90fb..07769e7 100644 --- a/lib/getopt.sh +++ b/src/getopt.sh @@ -18,9 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_GETOPT_SM+set}" = 'xset' ] && return 0 -_GETOPT_SM=1 - get_options() { local optstring= diff --git a/lib/install.sh b/src/install.sh index b7ca485..e1e93df 100644 --- a/lib/install.sh +++ b/src/install.sh @@ -18,14 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_INSTALL_SM+set}" = 'xset' ] && return 0 -_INSTALL_SM=1 - -use profile -use dir -use fd -use pkg - install_deps= install_fnames= install_md5sums= diff --git a/src/local.mk b/src/local.mk index d989dbf..dae4309 100644 --- a/src/local.mk +++ b/src/local.mk @@ -1,2 +1,27 @@ -bin_sources = \ - src/prokit.sh +prokit_SOURCES += \ + src/main.sh \ + src/output.sh \ + src/locale.sh \ + src/getopt.sh \ + src/fd.sh \ + src/dir.sh \ + src/vardata.sh \ + src/archplat.sh \ + src/deps.sh \ + src/substvars.sh \ + src/control.sh \ + src/feed.sh \ + src/pkg.sh \ + src/mutex.sh \ + src/session.sh \ + src/block.sh \ + src/opkg.sh \ + src/rand.sh \ + src/cmd.sh \ + src/profile.sh \ + src/package.sh \ + src/install.sh + +include $(top_srcdir)/src/cmd/local.mk +include $(top_srcdir)/src/profile/local.mk +include $(top_srcdir)/src/package/local.mk diff --git a/lib/locale.sh b/src/locale.sh index 59390f8..76d2d9b 100644 --- a/lib/locale.sh +++ b/src/locale.sh @@ -18,12 +18,7 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_LOCALE_SM+set}" = 'xset' ] && return 0 -_LOCALE_SM=1 - -LOCALEDIR='@localedir@' DEFAULT_LOCALE='en_US' -TEXT_DOMAIN='@textdomain@' load_locale() { @@ -66,7 +61,7 @@ get_msg() { local msgid="${1}" - eval "printf '%s' \"\${msg_${TEXT_DOMAIN}_${msgid}}\"" + eval "printf '%s' \"\${msg_${TEXTDOMAIN}_${msgid}}\"" return 0 } @@ -77,7 +72,7 @@ _try_load_locale() local locale="${2}" local ms= - for ms in "${localedir}/${locale}/LC_MESSAGES/${TEXT_DOMAIN}.ms" \ + for ms in "${localedir}/${locale}/LC_MESSAGES/${TEXTDOMAIN}.ms" \ "${localedir}/${locale}.ms"; do if [ -f "${ms}" ]; then . "${ms}" diff --git a/src/prokit.sh b/src/main.sh index 5cfdb53..d0ca8f7 100644 --- a/src/prokit.sh +++ b/src/main.sh @@ -1,5 +1,3 @@ -#!@SH@ -# # Main program file # # Copyright (C) 2013, 2014 Patrick "P. J." McDermott @@ -26,52 +24,24 @@ set -u HT=' ' LF=' ' -PACKAGE_NAME='@PACKAGE_NAME@' -PACKAGE_VERSION='@PACKAGE_VERSION@' -PKGDATADIR='@pkgdatadir@' OPTSTRING='hV' if [ -f "${0%/*}/../.builddirstamp" ]; then in_place=true builddir="${0%/*}/.." +elif [ -f "${0%/*}/.builddirstamp" ]; then + in_place=true + builddir="${0%/*}" else in_place=false builddir='' fi -# use() must be defined inline so it can be used to load other modules. -use() -{ - local module="${1}" - local dir= - - if ${in_place}; then - dir="${builddir}/lib" - else - dir="${PKGDATADIR}" - fi - - if [ -f "${dir}/${module}.sm" ]; then - . "${dir}/${module}.sm" - else - printf '%s: Error: Failed to load module "%s": %s\n' \ - "${0##*/}" "${module}" 'no such file or directory' >&2 - exit 2 - fi -} - -use locale -use cmd -use vardata -use getopt -use rand - main() { local cmd= load_locale - load_cmds init_vardata if ! get_options "${@}"; then @@ -121,5 +91,3 @@ check_uid() return 0 } - -main "${@}" diff --git a/lib/mutex.sh b/src/mutex.sh index fb96e66..cd4a365 100644 --- a/lib/mutex.sh +++ b/src/mutex.sh @@ -18,9 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_MUTEX_SM+set}" = 'xset' ] && return 0 -_MUTEX_SM=1 - mutex_trylock() { local mutex="${1}" diff --git a/lib/opkg.sh b/src/opkg.sh index 2b942d3..9e5c3c4 100644 --- a/lib/opkg.sh +++ b/src/opkg.sh @@ -18,11 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_OPKG_SM+set}" = 'xset' ] && return 0 -_OPKG_SM=1 - -use session - opkg_install_all() { local root="${1}" diff --git a/lib/output.sh b/src/output.sh index 877c7fc..62d2095 100644 --- a/lib/output.sh +++ b/src/output.sh @@ -18,9 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_OUTPUT_SM+set}" = 'xset' ] && return 0 -_OUTPUT_SM=1 - error() { local status=${1} diff --git a/lib/package.sh b/src/package.sh index 5c494ba..3175202 100644 --- a/lib/package.sh +++ b/src/package.sh @@ -18,12 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_PACKAGE_SM+set}" = 'xset' ] && return 0 -_PACKAGE_SM=1 - -use locale -use output - package_dir= package_format= diff --git a/lib/package/2.sh b/src/package/2.sh index 335fec3..fc4c77d 100644 --- a/lib/package/2.sh +++ b/src/package/2.sh @@ -18,13 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_PACKAGE_2_SM+set}" = 'xset' ] && return 0 -_PACKAGE_2_SM=1 - -use control -use deps -use substvars - package_2_build_deps= package_2_get_build_deps() diff --git a/src/package/local.mk b/src/package/local.mk new file mode 100644 index 0000000..9ec2158 --- /dev/null +++ b/src/package/local.mk @@ -0,0 +1,2 @@ +prokit_SOURCES += \ + src/package/2.sh @@ -18,9 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_PKG_SM+set}" = 'xset' ] && return 0 -_PKG_SM=1 - resolve_deps() { local new_pkgs="${1}" diff --git a/lib/profile.sh b/src/profile.sh index 44c58a2..f64a0d8 100644 --- a/lib/profile.sh +++ b/src/profile.sh @@ -18,21 +18,23 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_PROFILE_SM+set}" = 'xset' ] && return 0 -_PROFILE_SM=1 - -use output -use locale +profiles=' ' +profile= -PROFILES=' @profiles@ ' +register_profile() +{ + local profile="${1}" + shift 1 -profile= + profiles="${profiles}${profile} " + return 0 +} is_profile() { local prof="${1}" - [ "x${PROFILES# ${prof} }" != "x${PROFILES}" ] + [ "x${profiles# ${prof} }" != "x${profiles}" ] } profile_set() diff --git a/src/profile/local.mk b/src/profile/local.mk new file mode 100644 index 0000000..c303390 --- /dev/null +++ b/src/profile/local.mk @@ -0,0 +1,2 @@ +prokit_SOURCES += \ + src/profile/proteanos.sh diff --git a/lib/profile/proteanos.sh b/src/profile/proteanos.sh index 272282a..0e146ee 100644 --- a/lib/profile/proteanos.sh +++ b/src/profile/proteanos.sh @@ -18,9 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -use rand -use opkg - prof_proteanos_fstab_linux="\ proc /proc proc defaults sys /sys sysfs defaults @@ -253,3 +250,9 @@ prof_proteanos_configure_system_foreign() [ -e "${root}/etc/group" ] || printf \ 'root:x:0:\n' >"${root}/etc/group" } + +prof_proteanos_register() +{ + register_profile 'proteanos' +} +__init prof_proteanos_register diff --git a/lib/rand.sh b/src/rand.sh index 18d7749..872d3fb 100644 --- a/lib/rand.sh +++ b/src/rand.sh @@ -18,12 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_RAND_SM+set}" = 'xset' ] && return 0 -_RAND_SM=1 - -use output -use locale - rand_x=1 srand() diff --git a/lib/session.sh b/src/session.sh index 05fecc4..6453fae 100644 --- a/lib/session.sh +++ b/src/session.sh @@ -18,15 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_SESSION_SM+set}" = 'xset' ] && return 0 -_SESSION_SM=1 - -use rand -use mutex -use output -use locale -use profile - session_id= session_root= session_arch= diff --git a/lib/substvars.sh b/src/substvars.sh index d69c693..c2bc3f8 100644 --- a/lib/substvars.sh +++ b/src/substvars.sh @@ -18,9 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_SUBSTVARS_SM+set}" = 'xset' ] && return 0 -_SUBSTVARS_SM=1 - substvars_max_depth=50 set_substvar() diff --git a/lib/vardata.sh b/src/vardata.sh index 8800003..0c68d67 100644 --- a/lib/vardata.sh +++ b/src/vardata.sh @@ -18,10 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -[ "x${_VARDATA_SM+set}" = 'xset' ] && return 0 -_VARDATA_SM=1 - -PKGLOCALSTATEDIR='@pkglocalstatedir@' VARDATA_DIRS='mount' vardatadir= diff --git a/tests/arch_is_concerned.sh b/tests/arch_is_concerned.sh index 5358b73..c6c1d17 100755 --- a/tests/arch_is_concerned.sh +++ b/tests/arch_is_concerned.sh @@ -20,10 +20,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -. "${srcdir}/tests/common.sh" - -use archplat - do_test() { local host_arch="${1}" @@ -47,50 +43,45 @@ do_test() fi } -# Architecture: all - -do_test 'amd64-linux-glibc' 'all' false - -do_test 'i686-linux-glibc' 'all' false - -do_test 'all' 'all' true - -# Architecture: any - -do_test 'amd64-linux-glibc' 'any' true - -do_test 'i686-linux-glibc' 'any' true - -do_test 'all' 'any' false - -# Architecture: amd64-linux-glibc - -do_test 'amd64-linux-glibc' 'amd64-linux-glibc' true - -do_test 'i686-linux-glibc' 'amd64-linux-glibc' false - -do_test 'all' 'amd64-linux-glibc' false - -# Architecture: !amd64-linux-glibc - -do_test 'amd64-linux-glibc' '!amd64-linux-glibc' false - -do_test 'i686-linux-glibc' '!amd64-linux-glibc' true - -do_test 'all' '!amd64-linux-glibc' false - -# Architecture: amd64-linux-glibc cortexa8-linux-glibc - -do_test 'amd64-linux-glibc' 'amd64-linux-glibc cortexa8-linux-glibc' true - -do_test 'i686-linux-glibc' 'amd64-linux-glibc cortexa8-linux-glibc' false - -do_test 'all' 'amd64-linux-glibc cortexa8-linux-glibc' false - -# Architecture: amd64-linux-glibc all - -do_test 'amd64-linux-glibc' 'amd64-linux-glibc all' true - -do_test 'i686-linux-glibc' 'amd64-linux-glibc all' false - -do_test 'all' 'amd64-linux-glibc all' true +main() +{ + local arches= + + # Architecture: all + arches='all' + do_test 'amd64-linux-glibc' "${arches}" false + do_test 'i686-linux-glibc' "${arches}" false + do_test 'all' "${arches}" true + + # Architecture: any + arches='any' + do_test 'amd64-linux-glibc' "${arches}" true + do_test 'i686-linux-glibc' "${arches}" true + do_test 'all' "${arches}" false + + # Architecture: amd64-linux-glibc + arches='amd64-linux-glibc' + do_test 'amd64-linux-glibc' "${arches}" true + do_test 'i686-linux-glibc' "${arches}" false + do_test 'all' "${arches}" false + + # Architecture: !amd64-linux-glibc + arches='!amd64-linux-glibc' + do_test 'amd64-linux-glibc' "${arches}" false + do_test 'i686-linux-glibc' "${arches}" true + do_test 'all' "${arches}" false + + # Architecture: amd64-linux-glibc cortexa8-linux-glibc + arches='amd64-linux-glibc cortexa8-linux-glibc' + do_test 'amd64-linux-glibc' "${arches}" true + do_test 'i686-linux-glibc' "${arches}" false + do_test 'all' "${arches}" false + + # Architecture: amd64-linux-glibc all + arches='amd64-linux-glibc all' + do_test 'amd64-linux-glibc' "${arches}" true + do_test 'i686-linux-glibc' "${arches}" false + do_test 'all' "${arches}" true + + return 0 +} diff --git a/tests/common.sh b/tests/common.sh index b883a51..293dc7d 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -33,21 +33,6 @@ trap atexit EXIT in_place=true builddir='.' -use() -{ - local module="${1}" - local dir= - - dir='lib' - - if [ -f "${dir}/${module}.sm" ]; then - . "${dir}/${module}.sm" - else - printf '%s: Error: Failed to load module "%s": %s\n' \ - "${0##*/}" "${module}" 'no such file or directory' >&2 - exit 2 - fi -} assert() { diff --git a/tests/local.mk b/tests/local.mk index 023eae1..4c54bc8 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -1,8 +1,55 @@ -TESTS = \ +check_PROGRAMS = \ + tests/parse_control.basic \ + tests/resolve_deps.basic \ + tests/match_arch \ + tests/match_plat \ + tests/arch_is_concerned \ + tests/plat_is_concerned \ + tests/reduce_deps + +TESTS = $(check_PROGRAMS) + +tests_parse_control_basic_SOURCES = \ tests/parse_control.basic.sh \ + tests/parse_control.common.sh \ + tests/common.sh \ + src/output.sh \ + src/control.sh +tests_parse_control_basic_LDADD = $(tests_parse_control_basic_SOURCES:.sh=.sho) + +tests_resolve_deps_basic_SOURCES = \ tests/resolve_deps.basic.sh \ + tests/common.sh \ + src/pkg.sh +tests_resolve_deps_basic_LDADD = $(tests_resolve_deps_basic_SOURCES:.sh=.sho) + +tests_match_arch_SOURCES = \ tests/match_arch.sh \ + tests/common.sh \ + src/archplat.sh +tests_match_arch_LDADD = $(tests_match_arch_SOURCES:.sh=.sho) + +tests_match_plat_SOURCES = \ tests/match_plat.sh \ + tests/common.sh \ + src/archplat.sh +tests_match_plat_LDADD = $(tests_match_plat_SOURCES:.sh=.sho) + +tests_arch_is_concerned_SOURCES = \ tests/arch_is_concerned.sh \ + tests/common.sh \ + src/archplat.sh +tests_arch_is_concerned_LDADD = $(tests_arch_is_concerned_SOURCES:.sh=.sho) + +tests_plat_is_concerned_SOURCES = \ tests/plat_is_concerned.sh \ - tests/reduce_deps.sh + tests/common.sh \ + src/archplat.sh +tests_plat_is_concerned_LDADD = $(tests_plat_is_concerned_SOURCES:.sh=.sho) + +tests_reduce_deps_SOURCES = \ + tests/reduce_deps.sh \ + tests/common.sh \ + src/deps.sh \ + src/archplat.sh +tests_reduce_deps_LDADD = $(tests_reduce_deps_SOURCES:.sh=.sho) diff --git a/tests/match_arch.sh b/tests/match_arch.sh index f9b8a22..35f943b 100755 --- a/tests/match_arch.sh +++ b/tests/match_arch.sh @@ -20,10 +20,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -. "${srcdir}/tests/common.sh" - -use archplat - do_test() { local arch="${1}" @@ -47,26 +43,31 @@ do_test() fi } -do_test all 'all' true +main() +{ + do_test all 'all' true -do_test foo-bar-baz 'any' true + do_test foo-bar-baz 'any' true -do_test foo-bar-baz 'any all' true + do_test foo-bar-baz 'any all' true -do_test all 'any all' true + do_test all 'any all' true -do_test foo-bar-baz 'foo-bar-baz' true + do_test foo-bar-baz 'foo-bar-baz' true -do_test foo-bar-baz 'foo-any-any' true + do_test foo-bar-baz 'foo-any-any' true -do_test foo-bar-baz 'foo-bar-qux' false + do_test foo-bar-baz 'foo-bar-qux' false -do_test foo-bar-baz 'any-qux-any any-bar-any' true + do_test foo-bar-baz 'any-qux-any any-bar-any' true -do_test foo-bar-baz 'any-qux-any any-quux-any' false + do_test foo-bar-baz 'any-qux-any any-quux-any' false -do_test all 'any' false + do_test all 'any' false -do_test any 'all' false + do_test any 'all' false -do_test all 'foo-any-any' false + do_test all 'foo-any-any' false + + return 0 +} diff --git a/tests/match_plat.sh b/tests/match_plat.sh index 775e203..9074362 100755 --- a/tests/match_plat.sh +++ b/tests/match_plat.sh @@ -20,10 +20,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -. "${srcdir}/tests/common.sh" - -use archplat - do_test() { local plat="${1}" @@ -47,18 +43,23 @@ do_test() fi } -do_test all 'all' true +main() +{ + do_test all 'all' true -do_test dev 'any' true + do_test dev 'any' true -do_test dev 'any all' true + do_test dev 'any all' true -do_test all 'any all' true + do_test all 'any all' true -do_test dev 'dev' true + do_test dev 'dev' true -do_test dev 'ao751h' false + do_test dev 'ao751h' false -do_test all 'any' false + do_test all 'any' false -do_test any 'all' false + do_test any 'all' false + + return 0 +} diff --git a/tests/parse_control.basic.sh b/tests/parse_control.basic.sh index f8df181..98d3c83 100755 --- a/tests/parse_control.basic.sh +++ b/tests/parse_control.basic.sh @@ -39,5 +39,3 @@ Package bar Version 2.0 ¶ " - -. "${srcdir}/tests/parse_control.common.sh" diff --git a/tests/parse_control.common.sh b/tests/parse_control.common.sh index 1549ae0..9eee27b 100644 --- a/tests/parse_control.common.sh +++ b/tests/parse_control.common.sh @@ -18,11 +18,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -. "${srcdir}/tests/common.sh" - -use output -use control - load_locale HT=' ' @@ -41,10 +36,15 @@ para() test_results="${test_results}¶${LF}" } -parse_control - field para "${req_fields}" <<-EOF - ${packages} - EOF +main() +{ + parse_control - field para "${req_fields}" <<-EOF + ${packages} + EOF -printf 'Required fields: %s\n\n' "${req_fields}" + printf 'Required fields: %s\n\n' "${req_fields}" -test_diff "${results}" "${test_results}" + test_diff "${results}" "${test_results}" + + return 0 +} diff --git a/tests/plat_is_concerned.sh b/tests/plat_is_concerned.sh index 2bc808b..126e36a 100755 --- a/tests/plat_is_concerned.sh +++ b/tests/plat_is_concerned.sh @@ -20,10 +20,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -. "${srcdir}/tests/common.sh" - -use archplat - do_test() { local host_plat="${1}" @@ -47,50 +43,37 @@ do_test() fi } -# Platform: all - -do_test dev 'all' false - -do_test ao751h 'all' false - -do_test all 'all' true - -# Platform: any - -do_test dev 'any' true - -do_test ao751h 'any' true - -do_test all 'any' false - -# Platform: dev - -do_test dev 'dev' true - -do_test ao751h 'dev' false - -do_test all 'dev' false - -# Platform: !dev - -do_test dev '!dev' false - -do_test ao751h '!dev' true - -do_test all '!dev' false - -# Platform: dev dimension2400 - -do_test 'dev' 'dev dimension2400' true - -do_test 'ao751h' 'dev dimension2400' false - -do_test 'all' 'dev dimension2400' false - -# Platform: dev all - -do_test 'dev' 'dev all' true - -do_test 'ao751h' 'dev all' false - -do_test 'all' 'dev all' true +main() +{ + # Platform: all + do_test dev 'all' false + do_test ao751h 'all' false + do_test all 'all' true + + # Platform: any + do_test dev 'any' true + do_test ao751h 'any' true + do_test all 'any' false + + # Platform: dev + do_test dev 'dev' true + do_test ao751h 'dev' false + do_test all 'dev' false + + # Platform: !dev + do_test dev '!dev' false + do_test ao751h '!dev' true + do_test all '!dev' false + + # Platform: dev dimension2400 + do_test 'dev' 'dev dimension2400' true + do_test 'ao751h' 'dev dimension2400' false + do_test 'all' 'dev dimension2400' false + + # Platform: dev all + do_test 'dev' 'dev all' true + do_test 'ao751h' 'dev all' false + do_test 'all' 'dev all' true + + return 0 +} diff --git a/tests/reduce_deps.sh b/tests/reduce_deps.sh index 569a16c..0e5f7da 100755 --- a/tests/reduce_deps.sh +++ b/tests/reduce_deps.sh @@ -20,10 +20,6 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -. "${srcdir}/tests/common.sh" - -use deps - do_test() { local deps="${1}" @@ -45,38 +41,30 @@ do_test() fi } -# Normal and union AND-lists. - -do_test 'foo, bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' - -do_test 'foo,bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' - -do_test 'foo, bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' - -do_test 'foo, bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' - -do_test 'foo,bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' - -do_test 'foo, bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' - -# Normal and union OR-lists. - -do_test 'foo | bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' - -do_test 'foo|bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' - -do_test 'foo | bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' - -# Normal and union AND-lists with arch specs. - -do_test 'foo [amd64-linux-glibc], bar [!amd64-linux-glibc]' false \ - 'amd64-linux-glibc' 'dev' 'foo' - -do_test 'foo [amd64-linux-glibc], bar [!amd64-linux-glibc]' true \ - 'amd64-linux-glibc' 'dev' 'foo' - -# Normal and union AND-lists with plat specs. - -do_test 'foo <dev>, bar <!dev>' false 'amd64-linux-glibc' 'dev' 'foo' - -do_test 'foo <dev>, bar <!dev>' true 'amd64-linux-glibc' 'dev' 'foo' +main() +{ + # Normal and union AND-lists. + do_test 'foo, bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' + do_test 'foo,bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' + do_test 'foo, bar' false 'amd64-linux-glibc' 'dev' 'foo, bar' + do_test 'foo, bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' + do_test 'foo,bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' + do_test 'foo, bar' true 'amd64-linux-glibc' 'dev' 'foo, bar' + + # Normal and union OR-lists. + do_test 'foo | bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' + do_test 'foo|bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' + do_test 'foo | bar' false 'amd64-linux-glibc' 'dev' 'foo | bar' + + # Normal and union AND-lists with arch specs. + do_test 'foo [amd64-linux-glibc], bar [!amd64-linux-glibc]' false \ + 'amd64-linux-glibc' 'dev' 'foo' + do_test 'foo [amd64-linux-glibc], bar [!amd64-linux-glibc]' true \ + 'amd64-linux-glibc' 'dev' 'foo' + + # Normal and union AND-lists with plat specs. + do_test 'foo <dev>, bar <!dev>' false 'amd64-linux-glibc' 'dev' 'foo' + do_test 'foo <dev>, bar <!dev>' true 'amd64-linux-glibc' 'dev' 'foo' + + return 0 +} diff --git a/tests/resolve_deps.basic.sh b/tests/resolve_deps.basic.sh index b0c506c..b0b938e 100755 --- a/tests/resolve_deps.basic.sh +++ b/tests/resolve_deps.basic.sh @@ -20,23 +20,26 @@ # along with the ProteanOS Development Kit. If not, see # <http://www.gnu.org/licenses/>. -. "${srcdir}/tests/common.sh" - -use pkg - pkgs='foo bar' deps="\ foo: baz bar: qux baz: quux " -results='foo bar baz qux quux' -test_results="$(resolve_deps "${pkgs}" "${deps}")" +main() +{ + local results= + local test_results= -test_diff "${results}" "${test_results}" + results='foo bar baz qux quux' + test_results="$(resolve_deps "${pkgs}" "${deps}")" + test_diff "${results}" "${test_results}" -results="$(printf '%s\n' ${results} | sort)" -test_results="$(printf '%s\n' $(resolve_deps "${pkgs}" "${deps}") | sort)" + results="$(printf '%s\n' ${results} | sort)" + test_results="$(printf '%s\n' $(resolve_deps "${pkgs}" "${deps}") | \ + sort)" + test_diff "${results}" "${test_results}" -test_diff "${results}" "${test_results}" + return 0 +} diff --git a/tools/shld.sh b/tools/shld.sh new file mode 100755 index 0000000..88973ed --- /dev/null +++ b/tools/shld.sh @@ -0,0 +1,157 @@ +#!/bin/sh +# +# Shell command language linker +# +# Copyright (C) 2015 Patrick "P. J." McDermott +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +set -u + +VERSION='0.1.0' + +output='out.sh' +make_executable=true +interpreter='/bin/sh' +entry_point='main' + +die() +{ + local fmt="${1}" + shift 1 + + printf "shld: ${fmt}\n" "${@}" + exit 2 +} + +link() +{ + local input= + + # Open output file. + if ! exec 3>"${output}~"; then + die 'Cannot open file "%s"' "${output}~" + fi + + # Write magic number and interpreter path. + if ${make_executable}; then + printf '#!%s\n' "${interpreter}" >&3 + fi + + # Write __init() function. + cat >&3 <<-'EOF' + __init_funcs='' + __init() + { + __init_funcs="${__init_funcs} ${1}" + } + EOF + + # Read input files. + for input in "${@}"; do + if ! cat "${input}" >&3; then + die 'Cannot read file "%s"' "${input}" + fi + done + + # Add call to init functions. + cat >&3 <<-'EOF' + for __func in ${__init_funcs}; do + ${__func} + done + EOF + + # Add call to entry point. + if ${make_executable}; then + printf '%s "${@}"\n' "${entry_point}" >&3 + fi + + # Close output file, make it executable, and set its name. + exec 3>&- + if ${make_executable}; then + if ! chmod a+x "${output}~"; then + die 'Cannot set mode of file "%s"' "${output}~" + fi + fi + if ! mv "${output}~" "${output}"; then + die 'Cannot rename file to "%s"' "${output}" + fi +} + +usage() +{ + printf 'Usage: %s [option ...] <file>...\n' "${0}" +} + +help() +{ + usage + cat <<EOF +Options: + -h Display this information + -V Display linker version information + -I <interp> Use <interp> as the interpreter for your program, instead of the + default of "/bin/sh" + -e <entry> Use <entry> as the function for beginning execution of your + program, instead of the default of "main" + -o <output> Use <output> as the name of the program produced by shld, instead + of the default of "out.sh" +EOF +} + +version() +{ + cat <<EOF +shld ${VERSION} +Copyright (C) 2015 Patrick "P. J." McDermott +License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +EOF +} + +main() +{ + while getopts 'hVI:e:o:' opt; do + case "${opt}" in + 'h') + help + exit + ;; + 'V') + version + exit + ;; + 'I') + interpreter="${OPTARG}" + ;; + 'e') + entry_point="${OPTARG}" + ;; + 'o') + output="${OPTARG}" + ;; + esac + done + shift $(($OPTIND - 1)) + + if [ ${#} -lt 1 ]; then + usage >&2 + exit 1 + fi + + link "${@}" +} + +main "${@}" diff --git a/tools/shpp.sh b/tools/shpp.sh new file mode 100755 index 0000000..c54c7b7 --- /dev/null +++ b/tools/shpp.sh @@ -0,0 +1,165 @@ +#!/bin/sh +# +# Shell command language preprocessor +# +# Copyright (C) 2015 Patrick "P. J." McDermott +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +set -u + +VERSION='0.1.0' +FS="$(printf '\034')" + +die() +{ + local fmt="${1}" + shift 1 + + printf "shpp: ${fmt}\n" "${@}" + exit 2 +} + +preprocess() +{ + local vars="${1}" + local input="${2}" + local output="${3}" + local def= + local var= + local val= + + # Open output file. + if [ "x${output}" = 'x-' ]; then + if ! exec 3>&1; then + die 'Cannot duplicate output file descriptor' + fi + else + if ! exec 3>"${outfile}~"; then + die 'Cannot open file "%s"' "${output}~" + fi + fi + + IFS="${FS}" + for def in ${vars}; do + case "${def}" in + *=*) + var="${def%%=*}" + val="${def#*=}" + ;; + *) + var="${def%%=*}" + val='true' + ;; + esac + case "${var}" in + *[!A-Za-z0-9_]*) + error 'Invalid variable name "%s"' "${var}" + continue + ;; + [0-9]*) + error 'Invalid variable name "%s"' "${var}" + continue + ;; + esac + printf "%s='" "${var}" >&3 + printf '%s' "${val}" | sed "s/'/'\\\\''/g" >&3 + printf "'\n" >&3 + done + unset IFS + + # Read input file. + if ! cat "${input}" >&3; then + die 'Cannot read file "%s"' "${input}" + fi + + # Close output file, make it executable, and set its name. + if ! [ "x${output}" = 'x-' ]; then + exec 3>&- + if ! mv "${output}~" "${output}"; then + die 'Cannot rename file to "%s"' "${output}" + fi + fi +} + +usage() +{ + printf 'Usage: %s [option ...] <infile> [<outfile>]\n' "${0}" +} + +help() +{ + usage + cat <<EOF +Options: + -h Display this information + -V Display preprocessor version information + -D <var>[=<val>] Predefine <var> as a variable with value <val> (default + "true") +EOF +} + +version() +{ + cat <<EOF +shpp ${VERSION} +Copyright (C) 2015 Patrick "P. J." McDermott +License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>. +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law. +EOF +} + +main() +{ + local opt= + local vars= + local infile= + local outfile= + + while getopts 'hVD:' opt; do + case "${opt}" in + 'h') + help + exit + ;; + 'V') + version + exit + ;; + 'D') + vars="${vars}${OPTARG}${FS}" + ;; + esac + done + shift $(($OPTIND - 1)) + + case ${#} in + 1) + infile="${1}" + outfile='-' + ;; + 2) + infile="${1}" + outfile="${2}" + ;; + *) + usage >&2 + exit 1 + esac + + preprocess "${vars}" "${infile}" "${outfile}" +} + +main "${@}" |