#!/bin/sh - # # @(#)$Id: mkconfig,v 1.6 2018/12/16 16:40:44 jan Exp $ # # Create appropriate "config.h" and "mkconfig.tmp" files. # ./configure runs this script on behalf of the user. # # Exit w/ a status of 0 on success. # Exit w/ a status of 1 on error. # -- # Jeffrey Allen Neitzel # CONFIG_H="config.h" BSDSTYLE_H="bsdstyle.h" rm -f $CONFIG_H $BSDSTYLE_H trap 'status=$? ; rm -f $CONFIG_H $BSDSTYLE_H ; exit $status' HUP INT QUIT TERM # # This function searches for the pathname of utility and defines # constant w/ the resulting value. If utility cannot be found, # constant is defined as the empty string. # # usage: definePathnameConstant constant utility # definePathnameConstant() { const="$1" ; util="$2" dirlist="/bin /sbin /usr/bin /usr/sbin /usr/libexec /usr/games" moderr=" Modify value in \"$CONFIG_H\" if this is incorrect." modout=" /* Modify value if incorrect. */" for dir in $dirlist ; do if test -f "$dir/$util" -a -x "$dir/$util" ; then pname="$dir/$util" ; break else pname="" fi done #echo "$PATH" >&2 wpname="`which $util /dev/null | grep -v 'not found'`" #echo "$wpname" >&2 if test X"$pname" != X -a \( \ X"$wpname" = X -o X"$wpname" = X"$pname" \ \) ; then (echo "$PROGNAME: $const == \"$pname\"";echo "$moderr") >&2 def="#define $const \"$pname\"$modout" elif test X"$wpname" != X ; then (echo "$PROGNAME: $const == \"$wpname\"";echo "$moderr") >&2 def="#define $const \"$wpname\"$modout" else # This should rarely be true, but it is possible. (echo "$PROGNAME: $const == \"\"";echo "$moderr") >&2 def="#define $const \"\"$modout" fi echo "$def" } # # Define the SYS & DOT file macros for etsh. # defineSysAndDotFiles() { in_ebn="$1" # # etsh no longer conflicts w/ omake & its osh, but we do not # want to install as "osh" anymore anyway; no worries. # if test -n "$in_ebn" ; then # install it as whatever was specified or etsh. echo '#define PATH_SYSTEM_LOGIN SYSCONFDIR/**/"'"/${in_ebn}.login"'"' echo '#define PATH_SYSTEM_ETSHRC SYSCONFDIR/**/"'"/${in_ebn}.${in_ebn}rc"'"' echo '#define FILE_DOT_LOGIN "'".${in_ebn}.login"'"' echo '#define FILE_DOT_ETSHRC "'".${in_ebn}rc"'"' echo '#define PATH_SYSTEM_LOGOUT SYSCONFDIR/**/"'"/${in_ebn}.logout"'"' echo '#define FILE_DOT_LOGOUT "'".${in_ebn}.logout"'"' else # default to etsh as a fallback. echo '#define PATH_SYSTEM_LOGIN SYSCONFDIR/**/"/etsh.login"' echo '#define PATH_SYSTEM_ETSHRC SYSCONFDIR/**/"/etsh.etshrc"' echo '#define FILE_DOT_LOGIN ".etsh.login"' echo '#define FILE_DOT_ETSHRC ".etshrc"' echo '#define PATH_SYSTEM_LOGOUT SYSCONFDIR/**/"/etsh.logout"' echo '#define FILE_DOT_LOGOUT ".etsh.logout"' fi # Exceptions: The names of the history & prompt files cannot change. echo '#define FILE_DOT_HISTORY ".etsh.history"' echo '#define FILE_DOT_PROMPT ".etsh.prompt"' # } # # Define the EBN, TBN, and related macros. # defineBinNameMacros() { in_ebn="$1" in_tbn="$2" if test -n "$in_ebn" ; then defineSysAndDotFiles "$in_ebn" else defineSysAndDotFiles fi # 1) ebn / tbn - all characters to lower-case equivalent ebn="`echo $in_ebn | awk '{ printf "%s\n", tolower($1); }'`" tbn="`echo $in_tbn | awk '{ printf "%s\n", tolower($1); }'`" # 2) ebn1 / tbn1 - capitalize - 1st character to upper-case equivalent ebn1="`echo $ebn | awk '{ ac = split($1, c, ""); for (i = 1; i <= ac; i++) { if (c[i] ~ /[0-9a-z]/ && i == 1) printf "%c", toupper(c[i]); else printf "%c", c[i]; }; printf "\n"; }'`" tbn1="`echo $tbn | awk '{ ac = split($1, c, ""); for (i = 1; i <= ac; i++) { if (c[i] ~ /[0-9a-z]/ && i == 1) printf "%c", toupper(c[i]); else printf "%c", c[i]; }; printf "\n"; }'`" # 3) ebnc / tbnc - all characters to upper-case equivalent ebnc="`echo $ebn | awk '{ printf "%s\n", toupper($1); }'`" tbnc="`echo $tbn | awk '{ printf "%s\n", toupper($1); }'`" if test $# -eq 2 -a X"$1" != X -a X"$2" != X ; then #echo debug: set macros as specified >&2 echo "EBN=$ebn EBN1=$ebn1 EBNC=$ebnc TBN=$tbn TBN1=$tbn1 TBNC=$tbnc" | tr ' ' '\n' >mkconfig.tmp else #echo debug: else >&2 #echo debug: set default macros >&2 echo 'EBN=etsh EBN1=Etsh EBNC=ETSH TBN=tsh TBN1=Tsh TBNC=TSH' | tr ' ' '\n' >mkconfig.tmp fi } # # Define HAVE_BSD_STYLE with a value of 1 or 0. # define_HAVE_BSD_STYLE() { if test X$CC = X ; then CC=/usr/bin/cc ; fi #echo debug: CC == $CC >&2 rm -f bsdstyle.c bsdstyle cat <bsdstyle.c #include "$BSDSTYLE_H" #include #include int main(void) { (void)printf("sizeof(u_char) == %zu\n", sizeof(u_char)); (void)printf("sizeof(u_int) == %zu\n", sizeof(u_int)); return 0; } EOI #echo 'debug: cat &2' >&2 ; cat &2 #echo 'debug: cat &2' >&2 ; cat &2 # -o bsdstyle bsdstyle.c >&2 #test $? -eq 0 && ./bsdstyle >&2 $CC -std=c99 -pedantic -Wall -Wextra \ -o bsdstyle bsdstyle.c >/dev/null 2>&1 test $? -eq 0 && ./bsdstyle >/dev/null 2>&1 test $? -eq 0 && echo '#define HAVE_BSD_STYLE 1' || echo '#define HAVE_BSD_STYLE 0' rm -f $BSDSTYLE_H bsdstyle.c bsdstyle } UNAME_S="`uname -s`" UNAME_SRM="`uname -srm`" PROGNAME="`basename $0`" if test $# -ne 0 -a $# -ne 2 ; then echo 'usage: $(SHELL) ./'"$PROGNAME"' [$(EBN) $(TBN)]' >&2 ; exit 1 ; fi if test X"$UNAME_S" = X -o X"$UNAME_SRM" = X ; then echo "$PROGNAME: Fatal uname(1) error" >&2 ; exit 1 fi cat <$CONFIG_H /* * etsh - an enhanced port of the Version 6 (V6) Thompson shell * tsh - an unenhanced port of the Version 6 (V6) Thompson shell */ /* * _XOPEN_SOURCE and/or _DEFAULT_SOURCE should be defined only if * needed to avoid compilation errors or warnings for the etsh package * on a given system. The systems where these feature test macros are * known to be needed are defined in the mkconfig script. * * This includes only Linux and SunOS (OpenIndiana) at the present time. * * Configured for: $UNAME_SRM */ #ifndef CONFIG_H #define CONFIG_H `definePathnameConstant PATH_LOGIN login` `definePathnameConstant PATH_NEWGRP newgrp` `defineBinNameMacros "$1" "$2"` #define ETSH_UNAME_SRM "$UNAME_SRM" EOI >$BSDSTYLE_H case "$UNAME_S" in *BSD|Darwin|DragonFly) echo "/* $UNAME_S: No need for _XOPEN_SOURCE or _DEFAULT_SOURCE */" >>$CONFIG_H >>$BSDSTYLE_H ;; Linux) # Check if building on Ubuntu 16.xx or 17.xx. egrep '^(DISTRIB_ID=Ubuntu|DISTRIB_RELEASE=(16\.(04|10)|17\.04))$' /etc/lsb-release 2>/dev/null | wc -l | tr -d ' ' | grep '^2$' >/dev/null if test $? -eq 0 ; then # Ubuntu 16.xx or Ubuntu 17.xx ( echo '#define CONFIG_BROKEN' ; echo ) >>$CONFIG_H fi ( echo '#define CONFIG_LINUX' ; echo ) >>$CONFIG_H echo '#define _XOPEN_SOURCE 700' >>$CONFIG_H echo '#define _DEFAULT_SOURCE' >>$CONFIG_H echo '#define _XOPEN_SOURCE 700' >>$BSDSTYLE_H echo '#define _DEFAULT_SOURCE' >>$BSDSTYLE_H ;; SunOS) echo '# for OpenIndiana' >>mkconfig.tmp ( echo '#define CONFIG_SUNOS' ; echo ) >>$CONFIG_H echo '#define _XOPEN_SOURCE 700' >>$CONFIG_H echo '#define _XOPEN_SOURCE 700' >>$BSDSTYLE_H CC=/usr/bin/gcc ( echo CC=$CC ; echo INSTALL=/usr/bin/ginstall ) >>mkconfig.tmp ;; *) # # This may or may not cause a compilation error. # Simply try it to see if it works or not. # echo "$PROGNAME: WARNING: Check \"$CONFIG_H\" if compilation fails." >&2 cat <>$CONFIG_H /* * WARNING: $UNAME_SRM: Unknown system * * Please report this result to the developer if possible. */ EOI ;; esac echo >>$CONFIG_H define_HAVE_BSD_STYLE >>$CONFIG_H echo >>$CONFIG_H echo '#endif /* !CONFIG_H */' >>$CONFIG_H