Index: build.sh ================================================================== --- build.sh +++ build.sh @@ -49,19 +49,24 @@ # first, we establish the # parameters of the build has cc && _cc=cc has clang && _cc=clang -has gcc && _cc=gcc +has gcc && _cc=gcc # prefer gcc cc=${cc:-$_cc} has m4 && _m4=m4 m4=${m4:-$_m4} has nasm && asm=nasm -has yasm && asm=yasm +has yasm && asm=yasm # prefer yasm export gen=${gen:-gen} library=${libkind:-static} # {static|shared|both} +doc=${doc:-yes} +export doc_html=${doc_html:-yes} +export doc_pdf=${doc_pdf:-yes} +export doc_man=${doc_man:-yes} + case $library in static) build_static_library=yes build_shared_library=no;; shared) build_static_library=no @@ -131,11 +136,11 @@ 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 cat $p_headers_errno $gen/error_names.tbl | cpp -P >$gen/error_numbers.tbl awk -f arch/errtbl.awk <$gen/error_numbers.tbl >$gen/error_table.h # generate symbol tables for error handling functions -mkdir -p $out/k +mkdir -p "$out/k" awk -f global/gen-conds.awk $out/k/internal.egroup.h awk -f global/gen-ident.awk $gen/internal.ident.c comp_co $gen/internal.ident.c $out/internal.ident.o # first pass: copy all headers into place, @@ -155,21 +160,20 @@ done # second pass: generate manpage, html, and pdf # versions of the documentation from the md src -mkdir -p $out/doc/{man,html,pdf} -global/build-manpage.sh libk.md -for mod in ${modules[@]}; do - for doc in $(scan $mod '*.md'); do - base="$(basename $doc)" - stem="${base%%.md}" - global/build-manpage.sh "$doc" - global/build-html.sh "$doc" - global/build-pdf.sh "$doc" +if test "$doc" = "yes"; then + global/build-manpage.sh libk.md + for mod in ${modules[@]}; do + for doc in $(scan $mod '*.md'); do + base="$(basename $doc)" + stem="${base%%.md}" + global/build-manpage.sh "$doc" + done done -done +fi # third pass: compile sources and save the # resulting object files to $out, tracking # which is a runtime or function unit. exe's # will not be compiled until a later pass DELETED global/build-html.sh Index: global/build-html.sh ================================================================== --- global/build-html.sh +++ global/build-html.sh @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -(test -d global && test -f build.sh) || { - echo >&2 "($0) run $me from root of libk source directory" - exit 1 -} - -. global/common.sh -reqpack cmark "generate documentation" - -say "facility under construction" -exit 0 Index: global/build-manpage.sh ================================================================== --- global/build-manpage.sh +++ global/build-manpage.sh @@ -4,33 +4,40 @@ exit 1 } . global/common.sh reqpack cmark "generate documentation" - +check gen "a directory for generated build dependencies" file="$1" filename="$(basename "$file")" stem=${filename%%.md} -mandest="$out/doc/man" -section=${section:-4} -out="$mandest/$stem.$section" + +mandest=${out_manpage:-"$out/doc/man"} +htmldest=${out_html:-"$out/doc/html"} +pdfdest=${out_pdf:-"$out/doc/pdf"} + +section=${manual_section:-4} +man="$mandest/$stem.$section" +html="$htmldest/$stem.html" +pdf="$pdfdest/$stem.pdf" +fmt="$gen/$stem.tmp" + desc_rec="$(grep -m1 "^$stem:" global/modules)" if test "$desc_rec" != ""; then desc=" - $(echo $desc_rec | cut -d: -f4)" else desc="" fi date="$(date -r"$file" "+%d %A %Y")" -mkdir -p "$mandest" -echo >"$out" ".TH ${stem^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\"" +echo >"$fmt" ".TH ${stem^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\"" -echo >>"$out" ".SH NAME" -echo >>"$out" "$stem$desc" -echo >>"$out" ".SH SYNOPSIS" +echo >>"$fmt" ".SH NAME" +echo >>"$fmt" "$stem$desc" +echo >>"$fmt" ".SH SYNOPSIS" dhead=$(grep -m1 -n "^# description$" "$file") if test $? -eq 0; then descline=$(echo "$dhead" | cut -d: -f1) offset=1 @@ -37,17 +44,35 @@ else descline=$(grep -m2 -n "^#" "$file" | tail -n1 | cut -d: -f1) offset=0 fi -tail -n+2 $file | head -n$(expr $descline - 2) | cmark -t man >>"$out" +tail -n+2 $file | head -n$(expr $descline - 2) | cmark -t man >>"$fmt" + +echo >>"$fmt" ".SH DESCRIPTION" + +tail -n+$(expr $descline + $offset) "$file" | cmark -t man >> "$fmt" + +test "$doc_html" = "yes" && { + mkdir -p "$htmldest" + groff -Thtml -Kutf8 -m man "$fmt" > "$html" + say "wrote html page for $stem to $html" +} -echo >>"$out" ".SH DESCRIPTION" +test "$doc_pdf" = "yes" && { + mkdir -p "$pdfdest" + groff -Tpdf -Kutf8 -m man "$fmt" > "$pdf" + say "wrote pdf for $stem to $pdf" +} -tail -n+$(expr $descline + $offset) "$file" | cmark -t man >> "$out" +test "$doc_man" = "yes" && { + mkdir -p "$mandest" -if has gzip; then - gzip -f "$out" - out="$out.gz" -fi + if has gzip; then + man="$man.gz" + gzip -c -f "$fmt" > "$man" + else + mv "$fmt" "$man" + fi -say "wrote manpage for $stem to $out" + say "wrote manpage for $stem to $man" +} DELETED global/build-pdf.sh Index: global/build-pdf.sh ================================================================== --- global/build-pdf.sh +++ global/build-pdf.sh @@ -1,11 +0,0 @@ -#!/usr/bin/env bash -(test -d global && test -f build.sh) || { - echo >&2 "($0) run $me from root of libk source directory" - exit 1 -} - -. global/common.sh -reqpack cmark "generate documentation" - -say "facility under construction" -exit 0 Index: libk.md ================================================================== --- libk.md +++ libk.md @@ -1,10 +1,10 @@ # libk libk is intended as a modernized replacement *(not* reimplementation) for libc. -## manifesto +# manifesto normally, all C binaries (and binaries from other languages, depending on the platform) use a combination of libraries to get things done: POSIX libraries (interfaces common to UNIX-like operating systems) and libc, the C standard library. unlike POSIX, libc is part of the C language -- it's a standardized interface to various critical parts of the operating system, things like IO, system clock access, random number generation, and more. it's also a piece of shit. @@ -14,11 +14,11 @@ libk aims to offer a better, safer, and most importantly, less unpleasant foundation for modern code in C or any other language. it also aims to be much smaller, simpler, and faster than glibc to build so that there's no arduous bootstrapping process for new architectures. currently, the only dependency on libc in any form is `arch/typesize.c`, a small binary tool which uses libc IO routines to print type information it calculates; however, this could also be augmented to use POISX IO routines, or even potentially libk IO routines to remove any external dependency at all -- the work would be nontrivial, but fully feasible. further, the file it creates can also _in extremis_ be created by hand. the final compiled libc binaries and headers do not depend on or reference libc in any way; typesize is only a makedepend. -# goals +## goals libk's goals are far-reaching, and suggestions are welcome. note however that libk is *not* intended to be a kitchen-sink library like libiberty. it's meant to do one thing, and to it well: to provide an easy- and pleasant-to-use foundation for modern open source projects. below is a list of some of the project's major goals. 1. **IO.** libc's basic input/output mechanisms are dreadful, built at entirely the wrong level of abstraction. libk is intended to make many more primitives available to the user, and offer a sliding scale of abstraction so libk is suitable for a wide range of needs. 2. **file manipulation.** libc's file manipulation primitives are a relic of a bygone age and in dire need of upgrading. @@ -28,19 +28,20 @@ 6. **interprocess communication.** libc offers no useful IPC abstractions over the paltry array of tools POSIX &co. give us to work with. we can do better. 7. **tooling.** libk is intended as more than just a library. it's also intended to work with some basic tooling to automate tasks that current binary tooling is inadequate for -- for instance, embedding binary data into a program binary. (see module [kgraft](kgraft)) 8. **modularity.** libk is not part of the C specification and it isn't always going to be practical for developers to expect the entire library to be present on the end-user's computer. so libk is designed to be usable in many different ways -- as a traditional library, as a static library, in full form or with only components needed by the developer, to be distributed either on its own or as part of a binary. 9. **compatibility.** code that links against libk should be able to compile and run on any operating system. in the ideal case (Linux or FreeBSD) it will be able to do so without touching any other system libraries; for less ideal environments like Windows, libk will when necessary abstract over system libraries or libc itself. 10. **sane error-handling.** every time you type `errno` god murders a puppy. + 11. **ease of distribution.** libk should enable to user to create completely static binaries, free of any local dependency and trivial to distribute. # dependencies libk is designed to be as portable and depedency-free as possible. ideally, it will be possible to compile code against libk using nothing but libk itself. -compiling libk is also designed to be as easy as possible. it has only two external dependencies, the macro processor [m4], needed for compile-time header generation, and the [GNU make] utility, whose advanced features are needed to perform the relatively complex task of building all of libk from the ground up. +compiling libk is also designed to be as easy as possible. it has only two external dependencies, the macro processor [m4], needed for compile-time header generation, and optionally the [commonmark] compiler `cmark`, which is only needed if you wish to typeset the documentation in manpage, html, or pdf format. this process also requires `groff`, but `groff` is a standard part of most UNIX systems. [m4]: http://www.gnu.org/software/m4 - [GNU make]: http://www.gnu.org/software/make + [commonmark]: http://www.commonmark.org/ a different macro processor, gpp, was used in early versions of libk, however, it was so obscure and took so much overly fragile infrastructure to make it work that the cleaner syntax just wasn't worth it; i've since deleted the gpp infra and ported the macro files to m4. # naming conventions @@ -67,16 +68,15 @@ ## atoms libk uses the concept of "atoms" (small, regular strings of text) to standardize common references, such as operating systems or processor architectures. -### operating systems +**operating systems** these atoms will be used to reference operating systems. * Linux: `lin` - 1. aaaa * Haiku: `hai` * Android: `and` * FreeBSD: `fbsd` * NetBSD: `nbsd` * OpenBSD: `obsd` @@ -84,18 +84,18 @@ * MS-DOS: `dos` * FreeDOS: `fdos` * Windows: `win` * Windows MinGW: `mgw` -### file extensions +**file extensions** * C function implementations: `*.c` * C module headers: `*.h` * ancillary C headers: `*.inc.h` * assembly code: `*.s` -### arches +**arches** these atoms will be used to reference particular system architectures. these will mostly be used in the filenames of assembly code. * Intel/AMD x86: `x86` * ARM: `arm` (aarch64 is specified by `os=arm bits=64`) * MIPS: `mips` @@ -144,21 +144,44 @@ the repository root and each module may also contain the directory `misc`. this directory may be used to store miscellaneous data such as ABI references, developer discussions, and roadmaps. if the `misc` directory is deleted, this must not affect the library or build system's function in any way - that is, nothing outside a `misc` folder may reference a `misc` folder or anything inside it, including documentation. the `misc` directory should be removed when its contents are no longer needed. in most cases, the repository wiki and forum should be used instead of the `misc` folder. the folder `arch` in the root of the repository contains syscall tables and ABI implementations for various architectures. -## build sysem +# build system libk uses a very simple build system. the entire project is built with the `build.sh` script in the project root. `build.sh` need not be modified so long as all you're adding is functions, runtime stubs, headers, documentation files, or macro files in line with the standard naming convention. it will need to be modified to add or remove modules. it does not track dependencies, recompiling the entire project in one fell swoop. while in theory this could be slow and inefficient, in practice, it's not meaningfully slower on the average run than the old make-based system was. the shell-based build system was chosen for a number of reason. firstly, libk originally used a GNU make-based build system, but this was unwieldy and unreliably - make simply does not have the necessary capabilities to build a project of this nature. the original build system relied heavily on recursion, which is impossible to use while preserving idempotency. multithreaded building was likewise impossible. relying on make also had a number of subtler downsides. GNU make's capacities vary significantly across versions, and not all users will necessarily have access to the correct version in their repos. even a version as recent as make 4.1 couldn't build a project that build without issue in 4.2. given that libk is explicitly intended to be widely portable, this variance was alarming. make is also very indirect - it's a pain in the ass to tell it what to do sometimes, and it's well nigh on impossible to decipher the intricate way in which a sufficiently complex set of makefiles interlocks. this is both user- and developer-hostile. by contrast, a simple, linear build script with clearly delineated functions makes the build process much easier to understand, and therefore to tweak should a user need to modify some aspect of the process to compile `libk` on her system. finally, make simply has a smaller install base than `bash`. with the `build.sh` build system, more people can successfully build libk with less effort. -any time you make a change to the build script, always specify precisely what changed in your commit log and what affects this might have on the surrounding code. be sure to comment any new code as thoroughly as you can. the goal is that anyone who is familiar with bash should be able to learn the build process simply by reading `build.sh`. +any time you change build script, always specify precisely what changed in your commit log and what affects this might have on the surrounding code. be sure to comment any new code as thoroughly as you can. the goal is that anyone who is familiar with bash should be able to learn the build process simply by reading `build.sh`. + +## build process + +to build libk, you must invoke `build.sh` with the proper parameters. at minimum you must set the following environment variables: + + * `os={atom}` - an atom representing the operating system you are building libk for + * `arch={atom}` - an atom representing the processor architecture you are building libk for + * `bits={atom}` - if your processor has multiple variants with different word lengths (such as x86-32 vs. x86-64), specify the word length in this variable; otherwise, leave it unset. + +further optional variables may be set to control the build process and determine what targets it produces. + * `library=static {static|shared|both}` - this variable controls whether the build process will produce `libk.a`, `libk.so`, or both. + * `out=out {path}` - an alternate path to store build artifacts in + * `gen=gen {path}` - an alternate path to store generated source in + * `cc= {executable}` - the compiler to compile C sources with + * `m4= {executable}` - the m4 binary to compile the macro sources with + * `asm= {executable}` - the assembler to assemble the assembly listings with. it must take Intel-syntax input and handle nasm-style macros. only `yasm` and `nasm` are likely to be viable. + * `doc=yes {yes|no}` - whether to typeset the documentation (very slow with all three formats set to "yes") + * `doc_html=yes {yes|no}` - enable or disable html output of the documentation + * `doc_pdf=yes {yes|no}` - enable or disable pdf output of the documentation + * `doc_man=yes {yes|no}` - enable or disable manpage output of the documentation + +two other shell scripts complete the build system: + * `install.sh` - installs compiled libraries, objects, documentation, and headers into the appropriate directories. # design principles there are four overriding principles that guide the design of libk. @@ -184,49 +207,30 @@ rule_target_bourgeoisie }; this makes code much more legible and has the added benefit of making the definitions easier to expand at a later date if new functionality is needed without breaking the API or ABI. -## build process - -to build libk, you must invoke `build.sh` with the proper parameters. at minimum you must set the following environment variables: - - * `os={atom}` - an atom representing the operating system you are building libk for - * `arch={atom}` - an atom representing the processor architecture you are building libk for - * `bits={atom}` - if your processor has multiple variants with different word lengths (such as x86-32 vs. x86-64), specify the word length in this variable; otherwise, leave it unset. - -further optional variables may be set to control the build process and determine what targets it produces. - * `library=static {static|shared|both}` - this variable controls whether the build process will produce `libk.a`, `libk.so`, or both. - * `out=out {path}` - an alternate path to store build artifacts in - * `gen=gen {path}` - an alternate path to store generated source in - * `cc= {executable}` - the compiler to compile C sources with - * `m4= {executable}` - the m4 binary to compile the macro sources with - * `asm= {executable}` - the assembler to assemble the assembly listings with. it must take Intel-syntax input and handle nasm-style macros. only `yasm` and `nasm` are likely to be viable. - -two other shell scripts complete the build system: - * `install.sh` - installs compiled libraries, objects, documentation, and headers into the appropriate directories. - -## authors +# authors so far, this is a one-woman show. contributions are welcome however. * lexi hale -## caveats +# caveats the main coder, lexi hale, is first and foremost a writer, not a coder. this is a side-project of hers and will remain so unless it picks up a significant amount of attention. while MRs adding support for Windows, OS X, and other operating systems will be gratefully accepted, the maintainer is a Linux and FreeBSD developer, will not be writing such support infrastructure herself, and has limited ability even to vet code for those platforms. -## license +# license libk is released under the terms of the [GNU AGPLv3](LICENSE). contributors do not relinquish ownership of the code they contribute, but agree to release it under the same terms as the overall project license. the AGPL may seem like an inappropriately restrictive license for a project with such grandiose ambitions. it is an ideological choice. i selected it because libk is intended very specifically as a contribution to the *free software* community, a community that i hope will continue to grow at the expense of closed-source ecosystems. i have no interest in enabling people or corporations to profit from keeping secrets, especially not with my own free labor (or anyone else's, for that matter). if you disagree with this philosophy, you are welcome to continue using libc. -## what does the k stand for? +# what does the k stand for? nothing. it was chosen in reference to libc - the letter C was part of the original roman alphabet, while K was added later by analogy to the Greek kappa ‹κ›. in my native language, the older letter ‹c› can make a number of different sounds based on context, including [k] and [s], while ‹k› is fairly consistently used for the sound [k]. and for orthographical reasons, [k] is often represented by the digraph ‹ck› - that is, a C followed by a K. hopefully the analogies are obvious. this project has nothing to do with KDE.