libk  Check-in [34c625a47b]

Overview
Comment:switch over to new build mechanism and formally deprecate makefiles
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 34c625a47b56572efa5b2f4f599318d63c7d6e47bfa08f5b6eed8cc54a8f917c
User & Date: lexi on 2019-08-19 05:42:02
Other Links: manifest | tags
Context
2019-08-19
22:40
add documentation compilation check-in: 8d6d792515 user: lexi tags: trunk
05:42
switch over to new build mechanism and formally deprecate makefiles check-in: 34c625a47b user: lexi tags: trunk
04:51
begin move away from legacy build system check-in: 26c340d29e user: lexi tags: trunk
Changes

Modified build.sh from [75da38cbfd] to [e19ff3649f].

     1      1   #!/usr/bin/env bash
            2  +export out=${out:-out}
     2      3   . global/common.sh
     3      4   noimpl() {
     4      5   	say "$1 is not currently implemented on your system. an exciting chance for you to contribute, no?"
     5      6   	exit 1
     6      7   }
            8  +timestamp() { date "+%H:%M:%S %A"; }
     7      9   
     8     10   if test "$os$arch$bits" = ""; then
     9     11   	say "set the following environment variables to the appropriate atoms describing your system. for help determining the appropriate atoms, see libk.md"
    10     12   	say ' - $os={lin|fbsd|hai|osx…}'
    11     13   	say ' - $arch={x86|arm|ia64|mips…}'
    12     14   	say ' - $bits={|32|64…}'
    13     15   	exit 1
    14     16   fi
           17  +
           18  +if test "$1" = "-C"; then
           19  +	say "precleaning repo"
           20  +	./clean.sh
           21  +fi
    15     22   
    16     23   # TODO: make it possible for user to change
    17     24   #       default set with environment vars
    18     25   modules=(kcore kmem kstr kio kgraft kfile)
    19     26   
    20     27   target=$arch.$os
    21     28   if test "$bits" != ""; then
................................................................................
    31     38   case $os.$bits in
    32     39   	win.32) bin_fmt=win32;;
    33     40   	win.64) bin_fmt=win64;;
    34     41   	osx.32|dar.32) bin_fmt=macho32;;
    35     42   	osx.64|dar.64) bin_fmt=macho64;;
    36     43   	dos.*) bin_fmt=dosexe;;
    37     44   	none.*) bin_fmt=bin;;
    38         -	32) bin_fmt=elf32;;
    39         -	64) bin_fmt=elf64;;
           45  +	*.32) bin_fmt=elf32;;
           46  +	*.64) bin_fmt=elf64;;
           47  +	*) say "cannot determine correct binary format to use for target $target"; exit 1;;
    40     48   esac
    41     49   
    42     50   # first, we establish the
    43     51   # parameters of the build
    44         -has gcc && _cc=gcc
    45         -has clang && _cc=clang
    46     52   has cc && _cc=cc
           53  +has clang && _cc=clang 
           54  +has gcc && _cc=gcc
    47     55   cc=${cc:-$_cc}
    48     56   has m4 && _m4=m4
    49     57   m4=${m4:-$_m4}
    50         -has yasm && asm=yasm
    51     58   has nasm && asm=nasm
    52         -export out=${out:-out}
           59  +has yasm && asm=yasm
    53     60   export gen=${gen:-gen}
    54     61   library=${libkind:-static} # {static|shared|both}
    55     62   
    56     63   case $library in
    57     64   	static) build_static_library=yes
    58     65   	        build_shared_library=no;;
    59     66   
................................................................................
    85     92   
    86     93   macro_compile_env="-Datom_target_arch=$arch -Datom_target_os=$os -Dtarget_posix=$posix -Dtarget_unix=$unix"
    87     94   
    88     95   if test "$bits" != ""; then
    89     96   	macro_compile_env="$macro_compile_env -Datom_target_bits=$bits"
    90     97   fi
    91     98   
    92         -for mod in ${modules[@]}; do
    93         -	say "building libk with $mod"
    94         -done
    95     99   
    96    100   comp_mac() { $m4 $macro_compile_env -I "$gen" $3 "$1" > "$2"; }
    97         -comp_asm() { $asm "-f$bin_fmt" "-i$gen" $1 -o "$2"; }
    98         -comp_co()  { comp_clib $1 $2 -c; }
    99         -comp_clib(){
          101  +comp_asm() { $asm "-f$bin_fmt" -i "$gen" $1 -o "$2"; }
          102  +comp_co()  { comp_c $1 $2 "-c -fPIC"; }
          103  +comp_c(){
   100    104   	src=$1
   101    105   	output=$2
   102    106   	flags=$3
   103         -	$cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -fPIC -nostdlib "-L$out" "-o$output"
          107  +	$cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -nostdlib "-L$out" "-o$output"
   104    108   }
   105    109   
   106    110   scan() { find "$1" -name "$2"; }
   107    111   
   108         -# now we make sure all the appropriate
   109         -# directories exist
   110         -
          112  +say "commencing libk build $build at $(timestamp)"
   111    113   set -x
   112    114   
   113    115   # get type data
   114    116   mkdir -p $gen
   115    117   $cc -D_emit_m4_include arch/typesize.c -o $gen/typesize 
   116    118   $gen/typesize > gen/typesize.m
   117    119   
................................................................................
   132    134   
   133    135   # generate symbol tables for error handling functions
   134    136   mkdir -p $out/k
   135    137   awk -f global/gen-conds.awk <global/modules >$out/k/internal.egroup.h
   136    138   awk -f global/gen-ident.awk <global/modules >$gen/internal.ident.c
   137    139   comp_co $gen/internal.ident.c $out/internal.ident.o
   138    140   
   139         -# first pass: copy all raw headers into place
          141  +# first pass: copy all headers into place,
          142  +# including ones we need to generate
          143  +
   140    144   for mod in ${modules[@]}; do
   141    145   	for h in $(scan $mod '*.h'); do
   142    146   		base=$(basename $h)
   143    147   		cp "$h" "$out/k/$base"
   144    148   	done
   145         -done
   146    149   
   147         -# second pass: run macro headers through m4 and
   148         -# copy the resulting file into place
   149         -
   150         -for mod in ${modules[@]}; do
   151    150   	for h in $(scan $mod '*.h.m'); do
   152    151   		base=$(basename $h)
   153    152   		dest=${base%%.m}
   154    153   		comp_mac "$h" "$out/k/$dest"
   155    154   	done
   156    155   done
   157    156   
   158         -# third pass: generate manpage, html, and pdf
          157  +# second pass: generate manpage, html, and pdf
   159    158   # versions of the documentation from the md src
   160    159   
   161    160   mkdir -p $out/doc/{man,html,pdf}
   162    161   global/build-manpage.sh libk.md
   163    162   for mod in ${modules[@]}; do
   164    163   	for doc in $(scan $mod '*.md'); do
   165    164   		base="$(basename $doc)"
   166    165   		stem="${base%%.md}"
   167    166   		global/build-manpage.sh "$doc"
   168         -		# TODO html
   169         -		# TODO pdf
          167  +		global/build-html.sh "$doc"
          168  +		global/build-pdf.sh "$doc"
   170    169   	done
   171    170   done
   172    171   
   173         -# fourth pass: compile sources and save the
          172  +# third pass: compile sources and save the
   174    173   # resulting object files to $out, tracking
   175    174   # which is a runtime or function unit. exe's
   176    175   # will not be compiled until a later pass
   177    176   
   178    177   fn_objects=()
   179    178   rt_objects=()
   180    179   data_objects=( $out/internal.ident.o )
   181    180   for mod in ${modules[@]}; do
   182    181   	for fn in $(scan $mod '*.fn.c'); do
   183    182   		base="$(basename $fn)"
   184    183   		dest="$out/$mod.${base%%.c}.o"
   185    184   		comp_co "$fn" "$dest"
   186         -		fn_objects+="$dest"
          185  +		fn_objects+=("$dest")
   187    186   	done
   188    187   
   189    188   	for rt in $(scan $mod '*.rt.c'); do
   190    189   		base="$(basename $rt)"
   191    190   		dest="$out/$mod.${base%%.c}.o"
   192    191   		comp_co "$rt" "$dest"
   193         -		rt_objects+="$dest"
          192  +		rt_objects+=("$dest")
   194    193   	done
   195    194   
   196    195   	for fn in $(scan $mod "*.fn.$target.s"); do
   197    196   		base="$(basename $fn)"
   198    197   		dest="$out/$mod.${base%%.s}.o"
   199    198   		comp_asm "$fn" "$dest"
   200         -		fn_objects+="$dest"
          199  +		fn_objects+=("$dest")
   201    200   	done
   202    201   
   203    202   	for rt in $(scan $mod "*.rt.$target.s"); do
   204    203   		base="$(basename $rt)"
   205    204   		dest="$out/$mod.${base%%.s}.o"
   206    205   		comp_asm "$rt" "$dest"
   207         -		rt_objects+="$dest"
          206  +		rt_objects+=("$dest")
          207  +	done
          208  +done
          209  +
          210  +# fourth pass: link the libraries that are
          211  +# configured to be built
          212  +
          213  +if test $build_static_library == yes; then
          214  +	for obj in ${fn_objects[@]} ${rt_objects[@]} ${data_objects[@]}; do
          215  +		ar rc $out/libk.a $obj
          216  +	done
          217  +	ranlib $out/libk.a
          218  +fi
          219  +
          220  +if test $build_shared_library == yes; then
          221  +	ld -r ${rt_objects[@]} -o $out/boot.o
          222  +	ld -shared ${fn_objects[@]} -o $out/libk.so
          223  +fi
          224  +
          225  +# fifth pass: compile the executable tools
          226  +# against the libraries created in pass 5
          227  +
          228  +for mod in ${modules[@]}; do
          229  +	for exe in $(scan $mod '*.exe.c'); do
          230  +		base="$(basename $exe)"
          231  +		dest="$out/$mod.${base%%.exe.c}"
          232  +		if test $build_shared_library == yes; then
          233  +			comp_c "$out/boot.o $exe" "$dest" -lk
          234  +		else
          235  +			comp_c "$exe" "$dest" -lk
          236  +		fi
   208    237   	done
   209    238   done
   210    239   
   211         -echo fns: ${fn_objects[@]}
   212         -echo rts: ${rt_objects[@]}
          240  +set +x
          241  +say "all passes finished; build $build complete at $(timestamp)"

Modified clean.sh from [61a9f12cd8] to [67375a0380].

     1      1   #!/usr/bin/env bash
     2         -. global/common.sh
     3         -
     4      2   out=${out:-out}
     5      3   gen=${gen:-gen}
            4  +. global/common.sh
     6      5   
     7      6   say "cleaning libk build artifacts"
     8      7   
     9      8   set -x
    10      9   rm -r $out
    11     10   rm -r $gen

Added global/build-html.sh version [045bd446a1].

            1  +#!/usr/bin/env bash
            2  +(test -d global && test -f build.sh) || {
            3  +	echo >&2 "($0) run $me from root of libk source directory"
            4  +	exit 1
            5  +}
            6  +
            7  +. global/common.sh
            8  +reqpack cmark "generate documentation"
            9  +
           10  +say "facility under construction"
           11  +exit 0

Modified global/build-manpage.sh from [fbe8d4ad27] to [b795aa8a1c].

     1      1   #!/usr/bin/env sh
     2      2   (test -d global && test -f build.sh) || {
     3      3   	echo >&2 "($0) run $me from root of libk source directory"
     4      4   	exit 1
     5      5   }
     6      6   
     7      7   . global/common.sh
     8         -test "$out" = "" && {
     9         -	say "\$out environment variable must be set to your build directory - are you running this script by hand? run make doc in the root directory instead!"
    10         -	exit 2
    11         -}
    12         -
    13         -if ! has cmark; then
    14         -	say "to generate documentation for libk, install the cmark package and try again"
    15         -	exit 3
    16         -fi
            8  +reqpack cmark "generate documentation"
    17      9   
    18     10   
    19     11   file="$1"
    20     12   filename="$(basename "$file")"
    21     13   stem=${filename%%.md}
    22     14   mandest="$out/doc/man"
    23     15   section=${section:-4}
    24     16   out="$mandest/$stem.$section"
    25         -desc_rec="$(grep -m1 "^$name:" global/modules)"
    26         -if test $? -eq 0; then
           17  +desc_rec="$(grep -m1 "^$stem:" global/modules)"
           18  +if test "$desc_rec" != ""; then
    27     19   	desc=" - $(echo $desc_rec | cut -d: -f4)"
    28     20   else
    29     21   	desc=""
    30     22   fi
    31     23   date="$(date -r"$file" "+%d %A %Y")"
    32     24   
    33     25   mkdir -p "$mandest"
    34     26   
    35         -echo  >"$out" ".TH ${name^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\""
           27  +echo  >"$out" ".TH ${stem^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\""
    36     28   
    37     29   echo >>"$out" ".SH NAME"
    38     30   echo >>"$out" "$stem$desc"
    39     31   echo >>"$out" ".SH SYNOPSIS" 
    40     32   
    41     33   dhead=$(grep -m1 -n "^# description$" "$file")
    42     34   if test $? -eq 0; then

Added global/build-pdf.sh version [045bd446a1].

            1  +#!/usr/bin/env bash
            2  +(test -d global && test -f build.sh) || {
            3  +	echo >&2 "($0) run $me from root of libk source directory"
            4  +	exit 1
            5  +}
            6  +
            7  +. global/common.sh
            8  +reqpack cmark "generate documentation"
            9  +
           10  +say "facility under construction"
           11  +exit 0

Modified global/common.sh from [4d96b9fc79] to [85eaa3b261].

     3      3   has() { which $1 >/dev/null 2>&1; return $?; }
     4      4   check() {
     5      5   	var=$1
     6      6   	test "${!var}" == "" || return 0
     7      7   	say "we were not able to detect a default value for the configuration variable \$$var. please set this variable to $2 and try again."
     8      8   	exit 1
     9      9   }
           10  +
           11  +test "$out" = "" && {
           12  +	say "\$out environment variable must be set to your build directory - are you running this script by hand? run ./build.sh in the root directory instead!"
           13  +	exit 2
           14  +}
           15  +
           16  +reqpack() {
           17  +	if ! has "$1"; then
           18  +		say "to $2 for libk, install the $1 package and try again"
           19  +		exit 3
           20  +	fi
           21  +}

Name change from arch/makefile to legacy/arch.makefile.


Name change from kbuild/makefile to legacy/kbuild.makefile.


Name change from kconf/makefile to legacy/kconf.makefile.


Name change from kcore/makefile to legacy/kcore.makefile.


Name change from kdb/makefile to legacy/kdb.makefile.


Name change from kdbg/makefile to legacy/kdbg.makefile.


Name change from kfile/makefile to legacy/kfile.makefile.


Name change from kgraft/makefile to legacy/kgraft.makefile.


Name change from kio/makefile to legacy/kio.makefile.


Name change from kmem/makefile to legacy/kmem.makefile.


Name change from kmsg/makefile to legacy/kmsg.makefile.


Name change from knet/makefile to legacy/knet.makefile.


Name change from knum/makefile to legacy/knum.makefile.


Name change from kproc/makefile to legacy/kproc.makefile.


Name change from kstr/makefile to legacy/kstr.makefile.


Name change from kterm/makefile to legacy/kterm.makefile.


Name change from legacy/makefile to legacy/legacy.makefile.