libk  Diff

Differences From Artifact [81c1265d8b]:

To Artifact [5f22a34160]:


    38     38   # APIs depending on the operating system.
    39     39   # presumably if the user is running a bash
    40     40   # script there is some degree of posix
    41     41   # support available, but we might still be
    42     42   # building for windows from within cygwin
    43     43   # or whatever
    44     44   case $os in
    45         -	lin|?bsd|and|dar|osx) posix=yes; unix=yes;;
           45  +	lin|?bsd|and|dar|osx|nix) posix=yes; unix=yes;;
    46     46   	hai) posix=yes; unix=no;;
    47     47   	*) posix=no; unix=no;;
    48     48   esac
    49     49   
    50     50   case $os.$bits in
    51     51   	win.32) bin_fmt=win32;;
    52     52   	win.64) bin_fmt=win64;;
................................................................................
    91     91   
    92     92   check cc "your C compiler of choice"
    93     93   check asm "an assembler that takes Intel syntax and nasm-style-macros"
    94     94   check m4 "the path to your m4 installation"
    95     95   
    96     96   export build=$(global/build-id.sh)
    97     97   
    98         -if test "$p_headers_syscall" = ""; then
    99         -	case $os in
   100         -		lin) headers_syscall_search=(
   101         -				/usr/include/asm/unistd_${bits}.h
   102         -				/usr/include/asm-generic/unistd.h
   103         -				/usr/include/*-linux-gnu/asm/unistd_${bits}.h
   104         -			);;
   105         -
   106         -		fbsd) p_headers_syscall_search=(
   107         -				/usr/include/sys/syscall.h
   108         -			);;
   109         -	esac
   110         -fi
   111         -
   112     98   if test "$p_headers_errno" = ""; then
   113     99   	case $os in
   114    100   		lin) p_headers_errno="${p_headers_errno:-/usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h}";;
   115    101   
   116    102   		fbsd) p_headers_errno="${p_headers_errno:-/usr/include/errno.h}";;
   117    103   	esac
   118    104   fi
   119    105   
   120         -for f in "${headers_syscall_search[@]}"; do
   121         -	test -e "$f" || continue
   122         -	p_headers_syscall="$f"
   123         -	say "using syscall headers at $f"
   124         -	break;
   125         -done
   126         -
   127         -check p_headers_syscall \
   128         -	'the location of a header defining your syscall numbers'
   129    106   check p_headers_errno \
   130    107   	'the location of a header defining the values of each errno symbol'
   131    108   
   132    109   macro_compile_env="-Datom_target_arch=$arch -Datom_target_os=$os -Dtarget_posix=$posix -Dtarget_unix=$unix"
   133    110   
   134    111   if test "$bits" != ""; then
   135    112   	macro_compile_env="$macro_compile_env -Datom_target_bits=$bits"
   136    113   fi
   137         -
   138    114   
   139    115   if test "$COLORTERM" != ""; then
   140    116   	announce() {
   141    117   		test "$verbose" = "silent" && return
   142    118   		color="$1" cmd="$2"; shift 2;
   143    119   		printf " → [38;5;$color;1m$cmd"
   144    120   		for a in "$@"; do
................................................................................
   162    138   comp_mac() {
   163    139   	local src=$1
   164    140   	local output=$2
   165    141   	local flags=$3
   166    142   	if test -e "$output"; then
   167    143   		if test ! "$output" -ot "$src"; then
   168    144   			return
   169         -		fi
          145  +		fi 
   170    146   	fi
   171         -	         $m4 $macro_compile_env -I "$gen" $flags "$src"  > "$output"
          147  +	             $m4 $macro_compile_env -I "$gen" $flags "$src"  > "$output"
   172    148   	announce 207 $m4 $macro_compile_env -I "$gen" $flags "$src" \> "$output"
   173    149   	# yes, this is incredibly stupid. if you know a better way, feel
   174    150   	# free to submit a fix. the problem is there's no way to pass >
   175    151   	# to report in such a way that it'll do the right thing, and if
   176    152   	# you just write > it redirects *report's* output, instead of
   177    153   	# m4's. piece of shit that it is, m4 doesn't have any way to emit
   178    154   	# output into a fille - stdout only apparently. tl;dr i hate bash.
................................................................................
   209    185   
   210    186   # get type data
   211    187   mkdir -p $gen
   212    188   $cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 
   213    189   $gen/typesize > gen/typesize.m
   214    190   
   215    191   # generate syscall tables
   216         -case $os in
   217         -	lin) grep -h "#define __NR_" $p_headers_syscall | sed 's;^#define __NR_;;' > $gen/calls.tbl;;
   218         -	fbsd) grep -h "#define	SYS_" $p_headers_syscall | sed 's;^#define	SYS_;;' | sed 's;[\t ]\+; ;' > $gen/calls.tbl;;
   219         -	*) noimpl 'system call table generation';;
   220         -esac
   221         -
   222         -cat $p_headers_syscall $gen/calls.tbl | cpp -P |
   223         -	awk -f arch/syscall.awk -v out=s >$gen/system_calls.s
   224         -cat $p_headers_syscall $gen/calls.tbl | cpp -P |
   225         -	awk -f arch/syscall.awk -v out=h >$gen/system_calls.h
          192  +if test $posix = yes; then
          193  +	# on posix, we simply abuse CPP to garner a list of syscalls;
          194  +	# the file arch/posix_syscalls contains a list of syscalls
          195  +	# we wish to import; we use sed to transform this into a form
          196  +	# that cpp will fill out for us, producing a table that the
          197  +	# awk scripts can handle and turn into a list of constants.
          198  +	echo '#include <sys/syscall.h>' > $gen/system_calls.t.1 # this is the magic part
          199  +	cat arch/posix_syscalls > $gen/system_calls.t.2
          200  +	sed -e 's;^\(.*\)$;\1 SYS_\1;' -i $gen/system_calls.t.2
          201  +	cat $gen/system_calls.t.1 $gen/system_calls.t.2 | cpp -P >$gen/system_calls.tbl
          202  +else
          203  +	case $os in
          204  +		# lin) grep -h "#define __NR_" $p_headers_syscall | sed 's;^#define __NR_;;' > $gen/system_calls.tbl;;
          205  +		# fbsd) grep -h "#define	SYS_" $p_headers_syscall | sed 's;^#define	SYS_;;' | sed 's;[\t ]\+; ;' > $gen/system_calls.tbl;;
          206  +		*) noimpl 'system call table generation';;
          207  +	esac
          208  +fi
          209  +# cat $p_headers_syscall $gen/system_calls.tbl | cpp -P |
          210  +awk -f arch/syscall.awk -v out=s <$gen/system_calls.tbl>$gen/system_calls.s
          211  +# cat $p_headers_syscall $gen/system_calls.tbl | cpp -P |
          212  +awk -f arch/syscall.awk -v out=h <$gen/system_calls.tbl>$gen/system_calls.h
   226    213   
   227    214   # generate errno tables
   228         -grep -h "#[ 	]*define[ 	]\+E" $p_headers_errno | sed 's;^#[\t ]*define[\t ]\+\(E[A-Z0-9]\+\).*$;k_platform_error_\1 \1;' > $gen/error_names.tbl
          215  +grep -h "#[ 	]*define[ 	]\+E" $p_headers_errno |
          216  +	sed 's;^#[\t ]*define[\t ]\+\(E[A-Z0-9]\+\).*$;k_platform_error_\1 \1;' >\
          217  +	$gen/error_names.tbl
   229    218   cat $p_headers_errno $gen/error_names.tbl | cpp -P >$gen/error_numbers.tbl
   230    219   awk -f arch/errtbl.awk <$gen/error_numbers.tbl >$gen/error_table.h
   231    220   
   232    221   # generate symbol tables for error handling functions
   233    222   mkdir -p "$out/k"
   234    223   awk -f global/gen-conds.awk <global/modules >$out/k/internal.egroup.h
   235    224   awk -f global/gen-ident.awk <global/modules >$gen/internal.ident.c