voc icon indicating copy to clipboard operation
voc copied to clipboard

/bin/sh bias in the documentation

Open pascalecu opened this issue 9 months ago • 0 comments

As it currently stands, both the documentation and the installer assumes there is some sort of /bin/sh-derived shell on Unix (Bash and ksh by happenstance). export doesn't exist on csh and tcsh, and the incantation is set path = ( $path /usr/local/share/voc/bin ). Additionally, PowerShell instructions don't exist, since this project really favors having an Unix environment.

Ideally, the script would check $SHELL (in C, you could maybe use getpwuid(geteuid())->pw_shell, although I believe actually checking the SHELL env var is more reliable) and automatically determine the instructions for the final install. As far as I can see, the Makefile prints the export message within this file. I am not sure if this would cut it, but I believe you can do:

instructions: FORCE
	@printf '\nOberon build and test complete, result is in "$(ROOTDIR)/install".\n'
	@printf '\nYou can use the new compiler by running "$(ROOTDIR)/install/bin/$(ONAME)",\n'
	@printf 'or add it to your path as follows:\n'
	@printf 'For bash or zsh:\n'
	@printf '  export PATH="$(ROOTDIR)/install/bin:${PATH}"\n'
	@printf 'For csh or tcsh:\n'
	@printf '  setenv PATH $(ROOTDIR)/install/bin:$PATH\n'
	@printf 'For fish:\n'
	@printf '  set -gx PATH "$(ROOTDIR)/install/bin" $PATH\n'
	@printf '\n'

or for something smarter, use an external script (to my knowledge, all systems have a /bin/sh that isn't csh) like this:

#!/usr/bin/env sh
case "$SHELL" in
    */bash|*/zsh|*/ksh)
        echo 'export PATH="$(dirname "$0")/install/bin:$PATH"'
        ;;
    */fish)
        echo 'set -gx PATH "$(dirname "$0")/install/bin" $PATH'
        ;;
    */csh|*/tcsh)
        echo 'setenv PATH "$(dirname "$0")/install/bin" $PATH'
        ;;
    *)
        echo 'Unknown shell: $SHELL. Please set PATH manually.'
        ;;
esac

(I think this is the most portable way, I am not 100% sure) and then:

instructions: FORCE
	@SHELL=$(SHELL) ; \
	sh ./echo_path.sh ; \
	printf '\nOberon build and test complete, result is in "$(ROOTDIR)/install".\n'; \
	printf '\nYou can use the new compiler by running "$(ROOTDIR)/install/bin/$(ONAME)",\n'; \
	printf '\n'

pascalecu avatar Mar 12 '25 00:03 pascalecu