Initial import

This commit is contained in:
Justine Tunney 2020-06-15 07:18:57 -07:00
commit c91b3c5006
14915 changed files with 590219 additions and 0 deletions

28
build/actuallynice Executable file
View file

@ -0,0 +1,28 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# SYNOPSIS
#
# Program Deprioritizer
#
# OVERVIEW
#
# This is a drop-in replacement for the traditional Unix `nice`
# command that also invokes `ionice`, which is important, since
# network and traffic is usually what clobber the system.
if [ -z "$IONICE" ]; then
if IONICE=$(command -v ionice 2>/dev/null); then
IONICE="$IONICE -c3"
fi
fi
if [ -z "$NICE" ]; then
NICE=$(command -v nice 2>/dev/null)
fi
if [ -z "$IONICE$NICE" ]; then
echo "error: can't be nice" >&2
fi
exec $IONICE $NICE "$@"

80
build/archive Executable file
View file

@ -0,0 +1,80 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# GNU Archiver Veneer
#
# DESCRIPTION
#
# This script wraps normal archive commands that're transparently
# passed-through. It adds value too, by addressing difficulties
# that would normally cause a developer to need `make clean`.
#
# EXAMPLE
#
# build/archive ar rcsD library.a foo.o ...
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
fi
export LC_ALL=C
RM=${RM:-$(command -v rm) -f} || exit
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
AR=$1
ARFLAGS=$2
OUT=$3
shift 3
# remove directory arguments (having .a targets depend on dirs is what
# lets them be invalidated by deleted files)
FIRST=1
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
fi
if [ -d "$x" ]; then
if [ -f "$OUT" ] && [ "$x" -nt "$OUT" ]; then
$RM "$OUT"
fi
continue
fi
if [ "$x" != "${x%.o}" ]; then
set -- "$@" "$x"
fi
done
set -- "$AR" "$ARFLAGS" "$OUT" "$@"
OUTDIR="${OUT%/*}"
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
$MKDIR "$OUTDIR" || exit 2
fi
printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
# if [ "$SILENT" = "0" ]; then
# # some of these windows nt archives are quite huge
# COLUMNS=${COLUMNS:-80}
# COLUMNS=$((COLUMNS - 4))
# printf "%s\n" "$*" |
# /usr/bin/fold -s -w $COLUMNS |
# sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
# else
# printf "$LOGFMT" "${ACTION:-ARCHIVE.a}" "$OUT" >&2
# fi
REASON=failed
trap REASON=interrupted INT
"$@" >/dev/null && exit
if [ "$TERM" = "dumb" ]; then
f='%s %s\r\n\r\n'
else
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
fi
printf "$f" "archive $REASON:" "$*" >&2
exit 1

49
build/assemble Executable file
View file

@ -0,0 +1,49 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# GNU Assembler Veneer
#
# DESCRIPTION
#
# This script wraps normal assembler commands that're transparently
# passed-through. It adds ephemeral logging and directory creation.
#
# EXAMPLE
#
# TARGET=program build/assemble as -o program program.o
#
# SEE ALSO
#
# https://justine.storage.googleapis.com/perm/as.pdf
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
fi
export LC_ALL=C
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
if [ "$SILENT" = "0" ]; then
printf "%s\n" "$*" >&2
else
printf "$LOGFMT" "${ACTION:-OBJECTIFY.s}" "$TARGET" >&2
fi
if [ "$TARGET" ]; then
TARGETDIR="${TARGET%/*}"
if [ "$TARGETDIR" != "$TARGET" ] && [ ! -d "$TARGETDIR" ]; then
$MKDIR "$TARGETDIR" || exit 2
fi
fi
"$@" && exit
if [ "$TERM" = "dumb" ]; then
f='%s %s\r\n\r\n'
else
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
fi
printf "$f" "assemble failed:" "$*" >&2
exit 1

8
build/bochs-debugger Executable file
View file

@ -0,0 +1,8 @@
# -*- mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8 -*-
# vi: set net ft=sh ts=2 sts=2 sw=2 fenc=utf-8 :vi
echo c |
bochs \
-q \
-f ape/etc/bochsrc.dbg \
floppya:1_44=$1,status=inserted

51
build/bochs-scriptable Executable file
View file

@ -0,0 +1,51 @@
#!/bin/sh
# -*- mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8 -*-
# vi: set net ft=sh ts=2 sts=2 sw=2 fenc=utf-8 :vi
#
# bochs-scriptable executes a disk with serial uart stdio.
#
# USAGE
#
# build/bochs-scriptable IMAGE...
#
# DESCRIPTION
#
# This script is useful for end-to-end testing metal apps in <100ms.
#
# SEE ALSO
#
# build/boot(1)
while getopts h X; do
case $X in
h) exec less "$0" ;;
\?) echo "$0: bad arg" >&2; exit 1 ;;
esac
done
shift $((OPTIND - 1))
trap '' INT
IMG=$1
OUT=/tmp/$USER.$$.bochs.stdout
ERR=/tmp/$USER.$$.bochs.stderr
mkfifo $OUT || exit
cat <$OUT &
CAT=$!
exec 4>$OUT
rm -f $OUT
echo c |
bochs \
-q \
-f ape/etc/bochsrc.ffs \
display_library:nogui \
floppya:1_44=$1,status=inserted \
>>$ERR 2>>$ERR
RC=$?
kill $CAT
exec 4>&-
rm -f $ERR

BIN
build/bootstrap/mkdeps.com Executable file

Binary file not shown.

Binary file not shown.

Binary file not shown.

BIN
build/bootstrap/package.com Executable file

Binary file not shown.

BIN
build/bootstrap/zipobj.com Executable file

Binary file not shown.

20
build/catcode Executable file
View file

@ -0,0 +1,20 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# Source File Concatenation Tool
#
# DESCRIPTION
#
# This program is the same as cat, but inserts preprocessor directives
# that allow compiler errors to point back to the original lines.
if [ $# -eq 0 ]; then
cat
else
for x; do
printf '# 1 "%s"\n' "$x"
cat "$x"
done
fi

279
build/compile Executable file
View file

@ -0,0 +1,279 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# GNU/LLVM Compiler Frontend Frontend
#
# DESCRIPTION
#
# This wrapper script filters out certain flags so the compiler won't
# whine, and passes extra information to the preprocessor.
#
# EXAMPLE
#
# build/compile cc -o program program.c
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
fi
if [ "$1" = "clang-10" ]; then
if ! command -v clang-10 >/dev/null; then
shift
set -- o/third_party/gcc/bin/x86_64-linux-musl-gcc "$@"
fi
fi
if [ "$1" = "clang++-10" ]; then
if ! command -v clang++-10 >/dev/null; then
shift
set -- o/third_party/gcc/bin/x86_64-linux-musl-g++ "$@"
fi
fi
export LC_ALL=C
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
GZME=
PLAT="${1%% *}"
FDIAGNOSTIC_COLOR=
CCNAME=${CCNAME:-gcc}
CCVERSION=${CCVERSION:-4}
COUNTERMAND=
# The GNU Compiler Collection passes a lot of CFLAGS to the preprocessor
# (which we call CCFLAGS) but it should pass more; and we do just that.
FIRST=1
OUTARG=0
INVISIBLE=0
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
fi
if [ $OUTARG -eq 1 ]; then
OUTARG=0
OUT="$x"
fi
case "$x" in
-o)
set -- "$@" "$x"
OUTARG=1
;;
-w)
set -- "$@" "$x" -D__W__
;;
-pg)
if [ $INVISIBLE -eq 0 ]; then
set -- "$@" "$x" -D__PG__ # @see libc/macros.h
fi
;;
-mfentry)
if [ $INVISIBLE -eq 0 ]; then
set -- "$@" "$x" -D__MFENTRY__
fi
;;
-fomit-frame-pointer)
INVISIBLE=1
set -- "$@" "$x"
;;
-mno-vzeroupper)
set -- "$@" "$x" -Wa,-msse2avx -D__MNO_VZEROUPPER__
;;
-fsanitize=undefined)
set -- "$@" "$x" -D__FSANITIZE_UNDEFINED__
COUNTERMAND="$COUNTERMAND -fno-data-sections" # sqlite.o
;;
-mnop-mcount)
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
set -- "$@" "$x" -D__MNOP_MCOUNT__
fi
;;
-mrecord-mcount)
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
set -- "$@" "$x" -D__MRECORD_MCOUNT__
fi
;;
-fsanitize=implicit*integer*)
if ! [ "$CCNAME" = "gcc" ]; then
set -- "$@" "$x"
fi
;;
-f*sanitize*|-gz*|-*stack-protector*|-fvect-cost*|-mstringop*)
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 6 ]; then
set -- "$@" "$x"
fi
;;
-freorder-blocks-and-partition|-fstack-clash-protection)
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 8 ]; then
set -- "$@" "$x"
fi
;;
-fdiagnostic-color=*)
FDIAGNOSTIC_COLOR=$x
;;
-fopt-info*=*.optinfo)
if [ "$CCNAME" = "gcc" ] && [ "$CCVERSION" -ge 9 ]; then
GZME="$GZME ${x##*=}"
set -- "$@" "$x"
fi
;;
-R*) # e.g. clang's -Rpass-missed=all
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
set -- "$@" "$x"
fi
;;
-fsave-optimization-record) # clang only
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
set -- "$@" "$x"
fi
;;
*)
set -- "$@" "$x"
;;
esac
done
if [ -z "$FDIAGNOSTIC_COLOR" ] && [ "$TERM" != "dumb" ]; then
FDIAGNOSTIC_COLOR=-fdiagnostics-color=always
fi
if [ "${PLAT#*clang}" != "${PLAT}" ]; then
FIRST=1
for x; do
# clang's assembler isn't complete yet
if [ $FIRST -eq 1 ]; then
set -- \
"$x" \
-fno-integrated-as \
-Wno-unused-command-line-argument \
-Wno-incompatible-pointer-types-discards-qualifiers
FIRST=0
continue
fi
# removes flags clang whines about
case "$x" in
-gstabs) ;;
-ffixed-*) ;;
-fcall-saved*) ;;
-fsignaling-nans) ;;
-fcx-limited-range) ;;
-fno-fp-int-builtin-inexact) ;;
-Wno-unused-but-set-variable) ;;
-Wunsafe-loop-optimizations) ;;
-ftracer) ;;
-frounding-math) ;;
-fmerge-constants) ;;
-fmodulo-sched) ;;
-msse2avx)
set -- "$@" -Wa,-msse2avx
;;
-fopt-info-vec) ;;
-fopt-info-vec-missed) ;;
-fmodulo-sched-allow-regmoves) ;;
-fgcse-*) ;;
-freschedule-modulo-scheduled-loops) ;;
-freschedule-modulo-scheduled-loops) ;;
-fipa-pta) ;;
-fsched2-use-superblocks) ;;
-fbranch-target-load-optimize) ;;
-fdelete-dead-exceptions) ;;
-funsafe-loop-optimizations) ;;
-fcall-used*) ;;
-mmitigate-rop) ;;
-mnop-mcount) ;;
-fno-align-jumps) ;;
-fno-align-labels) ;;
-fno-align-loops) ;;
-fivopts) ;;
-fschedule-insns) ;;
-fno-semantic-interposition) ;;
-mno-fentry) ;;
-f*schedule-insns2) ;;
-fvect-cost-model=*) ;;
-fsimd-cost-model=*) ;;
-fversion-loops-for-strides) ;;
-fopt-info*) ;;
-f*var-tracking-assignments) ;;
-femit-struct-debug-baseonly) ;;
-ftree-loop-vectorize) ;;
-gdescribe-dies) ;;
-flimit-function-alignment) ;;
-ftree-loop-im) ;;
-fno-instrument-functions) ;;
-fstack-clash-protection) ;;
-mstringop-strategy=*) ;;
-mpreferred-stack-boundary=*) ;;
-*stack-protector*) ;; # clang requires segmented memory for this
-f*gnu-unique) ;;
-Wframe-larger-than=*) ;;
-f*whole-program) ;;
-Wa,--size-check=*) ;;
-Wa,--listing*) ;;
-mfpmath=sse+387) ;;
-Wa,--noexecstack) ;;
-freg-struct-return) ;;
-mcall-ms2sysv-xlogues) ;;
-mno-vzeroupper)
set -- "$@" -mllvm -x86-use-vzeroupper=0
;;
-Wa,-a*)
x="${x#*=}"
if [ "$x" ] && [ -p "$x" ]; then
printf '' >"$x"
fi
;;
*)
set -- "$@" "$x"
;;
esac
done
else
# removes flags only clang supports
FIRST=1
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
fi
case "$x" in
-Oz) set -- "$@" -Os ;;
*) set -- "$@" "$x" ;;
esac
done
fi
set -- "$@" -no-canonical-prefixes $FDIAGNOSTIC_COLOR $COUNTERMAND
if [ "$SILENT" = "0" ]; then
printf "%s\n" "$*" >&2
else
printf "$LOGFMT" "${ACTION:-COMPILE}" "${TARGET:-$OUT}" >&2
fi
OUTDIR="${OUT%/*}"
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
$MKDIR "$OUTDIR" || exit 2
fi
REASON=failed
trap REASON=interrupted INT
if "$@"; then
for f in $GZME; do
if GZ=${GZ:-$(command -v gzip)}; then
if [ -f "$f" ]; then
build/actuallynice $GZ $ZFLAGS -qf $f &
fi
fi
done
exit 0
fi
if [ "$TERM" = "dumb" ]; then
f='%s %s\r\n\r\n'
else
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
fi
printf "$f" "$CCNAME $CCVERSION: compile $REASON:" "$*" >&2
exit 1

152
build/config.mk Normal file
View file

@ -0,0 +1,152 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
# Default Mode
#
# - `make`
# - Backtraces
# - Function tracing
# - Reasonably small
# - Reasonably optimized
# - Reasonably debuggable
ifeq ($(MODE),)
CONFIG_CCFLAGS += \
$(BACKTRACES) \
$(FTRACE) \
-Og
TARGET_ARCH ?= \
-msse3
RAGELFLAGS ?= -G2
endif
# Optimized Mode
#
# - `make MODE=opt`
# - Backtraces
# - More optimized
# - Reasonably small
# - No memory corruption detection
# - assert() / CHECK_xx() may leak code into binary for debuggability
# - GCC 8+ hoists check fails into .text.cold, thus minimizing impact
ifeq ($(MODE), opt)
CONFIG_CPPFLAGS += \
-DNDEBUG \
-msse2avx \
-Wa,-msse2avx
CONFIG_CCFLAGS += \
$(BACKTRACES) \
-O3
TARGET_ARCH ?= \
-march=native
RAGELFLAGS ?= -G2
endif
# Release Mode
#
# - `make MODE=rel`
# - More optimized
# - Reasonably small
# - Numeric backtraces
# - Toilsome debuggability
# - assert() statements removed
# - DCHECK_xx() statements removed
# - No memory corruption detection
# - CHECK_xx() won't leak strings into binary
ifeq ($(MODE), rel)
CONFIG_CPPFLAGS += \
-DNDEBUG
CONFIG_CCFLAGS += \
$(BACKTRACES) \
-O3
#TARGET_ARCH ?= \
-msse3
RAGELFLAGS = -G2
endif
# Debug Mode
#
# - `make MODE=dbg`
# - Backtraces
# - Zero optimization
# - Enables sanitization
# - Enables stack canaries
# - Enormous binaries (b/c ubsan suboptimalities)
ifeq ($(MODE), dbg)
CONFIG_CPPFLAGS += \
-DMODE_DBG
CONFIG_CCFLAGS += \
$(BACKTRACES) \
$(FTRACE) \
-fno-inline
CONFIG_COPTS += \
$(SECURITY_BLANKETS) \
$(SANITIZER)
OVERRIDE_CCFLAGS += \
-fno-pie
endif
# Tiny Mode
#
# - `make MODE=tiny`
# - No checks
# - No asserts
# - No canaries
# - No paranoia
# - No avx hooks
# - No backtraces
# - No algorithmics
# - YOLO
ifeq ($(MODE), tiny)
CONFIG_CPPFLAGS += \
-DTINY \
-DNDEBUG \
-DTRUSTWORTHY
CONFIG_CCFLAGS += \
-Os \
-fno-align-functions \
-fno-align-jumps \
-fno-align-labels \
-fno-align-loops
TARGET_ARCH ?= \
-msse3
endif
# ANSI Mode
#
# Folks who want it deserve to get it, good and hard.
ifeq ($(MODE), ansi)
CONFIG_CCFLAGS += \
-std=c11 \
-Og
endif

357
build/definitions.mk Normal file
View file

@ -0,0 +1,357 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
#
# SYNOPSIS
#
# Cosmopolitan Core Build Definitions
#
# DESCRIPTION
#
# Nearly all compiler flag tuning is done within this one file. Flags
# may be customized with environment variables. We also use this file
# to compute expensive values once per build.
#
# When tuning the variables below, please note they're interpreted in
# the strictest sense. For example, we don't pass CFLAGS to gcc if we
# know it's compiling a .S file. This allows our `make SILENT=0` logs
# to be succinct and informative, at the cost of being less forgiving.
#
# Further note that link order is equally unforgiving in repositories
# of this scale. We approach that by over-specifying dependencies, in
# packages that're broken down usually on a per-directory basis. This
# is aided by the checkdeps and functional programming tools which in
# most cases should be able to deduce correct ordering automatically.
#
# Concerning our approach to flag tuning, most of it is non-essential
# and largely serves to turn features off. Particularly features that
# would otherwise lock us in to a particular platform or legal terms.
# Other flags will usually be the ones that provide us marginal gains
# in terms of performance and code size, but the world won't end when
# they aren't used. Flags that play a critical role in source working
# correctly will usually be specified on a target-by-target basis, in
# their respective packages.
#
# NOTE might have gotten the per-target override flag flow wrong since
# flags defined that way might flow quadratically opposite blaze.
#
# VARIABLES
#
# CCFLAGS gcc frontend flags (.i, .c, .cc, .f, .S, .lds, etc.)
# CPPFLAGS preprocessor flags (.h, .c, .cc, .S, .inc, .lds, etc.)
# CFLAGS c flags (.c only)
# CXXFLAGS c++ flags (.cc only)
# COPTS c/c++ flags (.c, .cc)
# LDFLAGS linker flags (don't use -Wl, frontend prefix)
# ASFLAGS assembler flags (don't use -Wa, frontend prefix)
# TARGET_ARCH microarchitecture flags (e.g. -march=native)
SHELL = /bin/sh
DD ?= /bin/dd
CP ?= /bin/cp -f
RM ?= /bin/rm -f
SED ?= /bin/sed
MKDIR ?= /bin/mkdir -p
TAGS ?= ctags
ARFLAGS = rcsD
TAGSFLAGS ?= -e -a --if0=no --langmap=c:.c.h.i --line-directives=yes
SILENT ?= 1
ZFLAGS ?= -4 --rsyncable
XARGS ?= xargs -P4 -rs8000
NICE ?= build/actuallynice
RAGEL ?= ragel
DOT ?= dot
GZ ?= gzip
CLANG = clang-11
FC = gfortran #/opt/cross9f/bin/x86_64-linux-musl-gfortran
# see build/compile, etc. which run third_party/gcc/unbundle.sh
AS = o/third_party/gcc/bin/x86_64-linux-musl-as
CC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
CXX = o/third_party/gcc/bin/x86_64-linux-musl-g++
LD = o/third_party/gcc/bin/x86_64-linux-musl-ld.bfd
AR = o/third_party/gcc/bin/x86_64-linux-musl-ar
NM = o/third_party/gcc/bin/x86_64-linux-musl-nm
GCC = o/third_party/gcc/bin/x86_64-linux-musl-gcc
STRIP = o/third_party/gcc/bin/x86_64-linux-musl-strip
OBJCOPY = o/third_party/gcc/bin/x86_64-linux-musl-objcopy
ADDR2LINE = o/third_party/gcc/bin/x86_64-linux-musl-addr2line
COMMA := ,
PWD := $(shell pwd)
IMAGE_BASE_VIRTUAL ?= 0x400000
TMPDIR := $(shell build/findtmp)
LOGFMT := $(shell build/getlogfmt)
CCNAME := $(shell build/getccname $(CC))
CCVERSION := $(shell build/getccversion $(CC))
BLAH1 := $(shell build/zipobj 2>/dev/null)
BLAH2 := $(shell build/package 2>/dev/null)
export ADDR2LINE
export CCNAME
export CCVERSION
export CP
export DD
export GZ
export IMAGE_BASE_VIRTUAL
export LOGFMT
export MKDIR
export MODE
export RM
export SED
export SILENT
export TMPDIR
export ZFLAGS
FTRACE = \
-pg
SANITIZER = \
-fsanitize=undefined \
-fsanitize=leak \
-fsanitize=implicit-signed-integer-truncation \
-fsanitize=implicit-integer-sign-change
NO_MAGIC = \
-mno-fentry \
-fno-stack-protector \
-fno-sanitize=all
OLD_CODE = \
-fno-strict-aliasing \
-fno-strict-overflow
TRADITIONAL = \
-Wno-implicit-int \
-Wno-return-type \
-Wno-pointer-sign
DEFAULT_CCFLAGS = \
-Wall \
-Werror \
-fmerge-all-constants \
-fdebug-prefix-map="$(PWD)"= \
-frecord-gcc-switches
DEFAULT_OFLAGS = \
-g \
-gdescribe-dies
DEFAULT_COPTS = \
-fno-math-errno \
-fno-trapping-math \
-fno-fp-int-builtin-inexact \
-fno-ident \
-fno-common \
-fno-gnu-unique \
-fmerge-constants \
-fstrict-aliasing \
-fstrict-overflow \
-fno-omit-frame-pointer \
-fno-optimize-sibling-calls \
-mno-omit-leaf-frame-pointer
DEFAULT_CPPFLAGS = \
-DIMAGE_BASE_VIRTUAL=$(IMAGE_BASE_VIRTUAL) \
-nostdinc \
-iquote . \
-include libc/integral/normalize.inc
DEFAULT_CFLAGS = \
-std=gnu2x
DEFAULT_CXXFLAGS = \
-std=gnu++11 \
-fno-rtti \
-fno-exceptions \
-fuse-cxa-atexit \
-fno-threadsafe-statics
DEFAULT_ASFLAGS = \
-W \
-I. \
--noexecstack
DEFAULT_LDFLAGS = \
-h \
-static \
--relax \
-nostdlib \
-m elf_x86_64 \
--gc-sections \
--build-id=none \
--cref -Map=$@.map \
--no-dynamic-linker \
-Ttext-segment=$(IMAGE_BASE_VIRTUAL)
ASONLYFLAGS = \
-g \
--debug-prefix-map="$(PWD)"=
DEFAULT_LDLIBS =
MCA = llvm-mca-10 \
-mtriple=x86_64-pc-linux-gnu \
-iterations=3 \
-instruction-info \
-iterations=3 \
-all-stats \
-all-views \
-timeline
cc.flags = \
$(DEFAULT_CCFLAGS) \
$(CONFIG_CCFLAGS) \
$(CCFLAGS) \
$(OVERRIDE_CCFLAGS) \
-D__SAUCE__=\"$<\"
o.flags = \
$(DEFAULT_OFLAGS) \
$(CONFIG_OFLAGS) \
$(OFLAGS) \
$(OVERRIDE_OFLAGS)
cpp.flags = \
$(DEFAULT_CPPFLAGS) \
$(CONFIG_CPPFLAGS) \
$(CPPFLAGS) \
$(OVERRIDE_CPPFLAGS)
copt.flags = \
$(TARGET_ARCH) \
$(DEFAULT_COPTS) \
$(CONFIG_COPTS) \
$(COPTS) \
$(OVERRIDE_COPTS)
f.flags = \
$(DEFAULT_FFLAGS) \
$(CONFIG_FFLAGS) \
$(FFLAGS) \
$(OVERRIDE_FFLAGS)
c.flags = \
$(DEFAULT_CFLAGS) \
$(CONFIG_CFLAGS) \
$(CFLAGS) \
$(OVERRIDE_CFLAGS)
cxx.flags = \
$(DEFAULT_CXXFLAGS) \
$(CONFIG_CXXFLAGS) \
$(CXXFLAGS) \
$(OVERRIDE_CXXFLAGS)
s.flags = \
$(DEFAULT_ASFLAGS) \
$(CONFIG_ASFLAGS) \
$(ASFLAGS) \
$(OVERRIDE_ASFLAGS)
S.flags = $(addprefix -Wa$(COMMA),$(s.flags))
LD.libs = \
$(LDLIBS) \
$(LOADLIBES) \
$(DEFAULT_LDLIBS) \
$(CONFIG_LDLIBS) \
$(LDLIBS) \
$(DEFAULT_LIBS) \
$(CONFIG_LIBS) \
$(LIBS)
COMPILE.c.flags = $(cc.flags) $(cpp.flags) $(copt.flags) $(c.flags)
COMPILE.cxx.flags = $(cc.flags) $(cpp.flags) $(copt.flags) $(cxx.flags)
COMPILE.f.flags = $(cc.flags) $(copt.flags) $(f.flags)
COMPILE.F.flags = $(cc.flags) $(cpp.flags) $(copt.flags) $(f.flags)
COMPILE.i.flags = $(cc.flags) $(copt.flags) $(c.flags)
COMPILE.ii.flags = $(cc.flags) $(copt.flags) $(cxx.flags)
LINK.flags = $(DEFAULT_LDFLAGS) $(CONFIG_LDFLAGS) $(LDFLAGS)
OBJECTIFY.c.flags = $(OBJECTIFY.S.flags) $(copt.flags) $(c.flags)
OBJECTIFY.cxx.flags = $(OBJECTIFY.S.flags) $(copt.flags) $(cxx.flags)
OBJECTIFY.s.flags = $(ASONLYFLAGS) $(s.flags)
OBJECTIFY.S.flags = $(copt.flags) $(cc.flags) $(o.flags) $(cpp.flags) $(S.flags)
OBJECTIFY.f.flags = $(copt.flags) $(cc.flags) $(o.flags) $(copt.flags) $(S.flags) $(f.flags)
OBJECTIFY.F.flags = $(OBJECTIFY.f.flags) $(cpp.flags)
PREPROCESS.flags = -E $(copt.flags) $(cc.flags) $(cpp.flags)
PREPROCESS.lds.flags = -D__LINKER__ $(filter-out -g%,$(PREPROCESS.flags)) -P -xc
COMPILE.c = $(CC) -S $(COMPILE.c.flags)
COMPILE.i = $(CC) -S $(COMPILE.i.flags)
COMPILE.f = $(FC) -S $(COMPILE.f.flags)
COMPILE.F = $(FC) -S $(COMPILE.F.flags)
OBJECTIFY.s = $(AS) $(OBJECTIFY.s.flags)
OBJECTIFY.S = $(CC) $(OBJECTIFY.S.flags) -c
OBJECTIFY.f = $(FC) $(OBJECTIFY.f.flags) -c
OBJECTIFY.F = $(FC) $(OBJECTIFY.F.flags) -c
OBJECTIFY.c = $(CC) $(OBJECTIFY.c.flags) -c
OBJECTIFY.cxx = $(CXX) $(OBJECTIFY.cxx.flags) -c
PREPROCESS = $(CC) $(PREPROCESS.flags)
PREPROCESS.lds = $(CC) $(PREPROCESS.lds.flags)
LINK = build/link $(LD) $(LINK.flags)
ELF = o/libc/elf/elf.lds
ELFLINK = ACTION=LINK.elf $(LINK) $(LINKARGS) $(OUTPUT_OPTION)
ARCHIVE = build/archive $(AR) $(ARFLAGS)
LINKARGS = $(patsubst %.lds,-T %.lds,$(call uniqr,$(LD.libs) $(filter-out %.pkg,$^)))
LOLSAN = build/lolsan -b $(IMAGE_BASE_VIRTUAL)
# The compiler won't generate %xmm code for sources extensioned .greg.c,
# which is needed for C modules wanting to run at the executive level or
# during privileged runtime states, e.g. code morphing.
OBJECTIFY.greg.c = \
$(CC) \
$(filter-out -pg,$(OBJECTIFY.c.flags)) \
-D__MGENERAL_REGS_ONLY__ \
-mgeneral-regs-only \
-fno-stack-protector \
-fno-instrument-functions \
-fno-optimize-sibling-calls \
-fno-sanitize=all \
-c
OBJECTIFY.ansi.c = $(CC) $(OBJECTIFY.c.flags) -ansi -Wextra -Werror -pedantic-errors -c
OBJECTIFY.c99.c = $(CC) $(OBJECTIFY.c.flags) -std=c99 -Wextra -Werror -pedantic-errors -c
OBJECTIFY.c11.c = $(CC) $(OBJECTIFY.c.flags) -std=c11 -Wextra -Werror -pedantic-errors -c
OBJECTIFY.c2x.c = $(CC) $(OBJECTIFY.c.flags) -std=c2x -Wextra -Werror -pedantic-errors -c
# No-Clobber ABI (clobbers nothing, except rax and flags)
#
# This ABI is intended for core library functions that're frequently
# called by just about everything, e.g. memcpy, malloc, etc. By offering
# this guarantee, callers can optionally call these functions via asm(),
# which reduces register allocator pressure at call sites.
#
# This makes unrelated caller code faster, but the NCABI functions
# themselves a tiny bit slower. That's OK, since modern NexGen-32e CPUs
# seem to have one fifth of their execution engines devoted to pushing
# and popping, probably so legacy IA-32 code keeps going fast; so we use
# it to our advantage.
OBJECTIFY.ncabi.c = \
$(GCC) \
$(OBJECTIFY.c.flags) \
-mno-sse \
-mfpmath=387 \
-mno-fentry \
-fno-stack-protector \
-fno-instrument-functions \
-fno-optimize-sibling-calls \
-mpreferred-stack-boundary=3 \
-fno-sanitize=all \
-fcall-saved-rcx \
-fcall-saved-rdx \
-fcall-saved-rdi \
-fcall-saved-rsi \
-fcall-saved-r8 \
-fcall-saved-r9 \
-fcall-saved-r10 \
-fcall-saved-r11 \
-c \
-xc
BUILD_SRCS = \
build/definitions.mk \
build/rules.mk \
build/compile \
build/link \
build/lolsan \
build/remote

54
build/do Executable file
View file

@ -0,0 +1,54 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# Generic Command Runner
#
# DESCRIPTION
#
# This does auto mkdir and ephemeral logging.
#
# EXAMPLE
#
# build/do PROG [ARGS...]
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
# Ensure directory creation if -o PATH flag is passed.
OUT=
FIRST=1
OUTARG=0
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
elif [ $OUTARG -eq 1 ]; then
OUTARG=0
OUT="$x"
fi
case "$x" in
-o)
OUTARG=1
;;
-o*)
OUT=${x#-o}
;;
esac
set -- "$@" "$x"
done
if [ "$OUT" ]; then
OUTDIR="${OUT%/*}"
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
$MKDIR "$OUTDIR" || exit 2
fi
fi
# Log command.
if [ "$SILENT" = "0" ]; then
printf "%s\n" "$*" >&2
else
printf "$LOGFMT" "${ACTION:-BUILD}" "$TARGET" >&2
fi
exec "$@"

19
build/findtmp Executable file
View file

@ -0,0 +1,19 @@
#!/usr/bin/env bash
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# Temporary Directory Discovery
#
# DESCRIPTION
#
# We call this script once per build to ideally find a folder that's
# backed by an in-memory file system. We then export it to the TMPDIR
# environment variable. Many programs use it under the hood, e.g. gcc,
# so it grants many small performance improvements.
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
$MKDIR o/tmp
echo o/tmp

16
build/functions.mk Normal file
View file

@ -0,0 +1,16 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
#
# SYNOPSIS
#
# Cosmopolitan Functional Programming Build System
#
# OVERVIEW
#
# It's basically Blaze except a few lines of code, made possible due
# to the power and the glory of variables that're secretly lambdas.
tail = $(wordlist 2,$(words $1),$1)
reverse = $(if $1,$(call reverse,$(call tail,$1)) $(firstword $1))
uniq = $(if $1,$(firstword $1) $(call uniq,$(filter-out $(firstword $1),$1)))
uniqr = $(if $1,$(call uniqr,$(filter-out $(firstword $1),$1)) $(firstword $1))

40
build/getccname Executable file
View file

@ -0,0 +1,40 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# Compiler Name Discovery
#
# DESCRIPTION
#
# Cosmopolitan itself may be built using either GCC and Clang, and our
# build irons out many of the differences between the two. This script
# determines which one's in play, which is nontrivial, since they tend
# to call themselves so many different names.
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
fi
set -e
SPECIAL_TEXT=$(
$1 --version |
sed -n '
/Free Software/ {
i\
gcc
q
}
/clang/ {
i\
clang
q
}
')
if [ -z "$SPECIAL_TEXT" ]; then
echo gcc
else
printf '%s\n' "$SPECIAL_TEXT"
fi

38
build/getccversion Executable file
View file

@ -0,0 +1,38 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# Compiler Version Discovery
#
# DESCRIPTION
#
# Cosmopolitan itself may be built using either GCC and Clang, and our
# build irons out many of the differences between the two. This script
# is used by build/definitions.mk alongside build/getccname to support
# the different versions folks use.
#
# Our aim is to support GCC 4.2.1+ since that's the last GPLv2 version
# with any sort of industry consensus. Please note, Cosmopolitan never
# links GCC runtimes when using later versions, so some concerns might
# not apply.
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
fi
set -e
MAJOR_VERSION=$(
$1 --version |
head -n1 |
sed -n '
s!^[^(]*([^)]*) \([[:digit:]][[:digit:]]*\).*!\1!p
s!^.*clang.*version \([[:digit:]][[:digit:]]*\).*!\1!p
')
if [ -z "$MAJOR_VERSION" ]; then
echo 6
else
printf '%s\n' "$MAJOR_VERSION"
fi

32
build/getlogfmt Executable file
View file

@ -0,0 +1,32 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# Printf Logger Initializer
#
# DESCRIPTION
#
# This program is invoked once by build/definitions.mk to choose the
# most appropriate format string when logging command invocations.
if [ "$SILENT" = "0" ]; then
printf "''"
else
W1=15
if [ "$TERM" = "dumb" ]; then # e.g. emacs' dismal tty
if [ "$COLUMNS" = "" ]; then
if TPUT=$(command -v tput); then
COLUMNS=$("$TPUT" cols)
else
COLUMNS=80
fi
fi
COLUMNS=$((COLUMNS - 1))
W2=$((COLUMNS - W1))
printf '%%-%ds%%-%ds\\r' "$W1" "$W2"
else
echo ♥cosmo >&2
printf '\\033[F\\033[K%%-%ds%%s\\r\\n' "$W1"
fi
fi

57
build/htags Executable file
View file

@ -0,0 +1,57 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# Header Symbol Index Generator
#
# DESCRIPTION
#
# This is a static source analyzer that lets us configure Emacs
# keybindings to insert #include lines.
#
# EXAMPLES
#
# build/htags -o HTAGS $(find . -name \*.h)
#
# (defun jart-add-include ()
# (interactive)
# (let* ((tag-file "HTAGS")
# (case-fold-search nil)
# (search (thing-at-point 'symbol))
# (buffer (find-file-noselect (format "%s/%s"
# (locate-dominating-file
# (buffer-name) tag-file)
# tag-file)))
# (header (with-current-buffer buffer
# (save-excursion
# (goto-char 0)
# (when (re-search-forward
# (concat "\177" search "\001") nil t)
# (when (re-search-backward "\f\n\\([^,]*\\)," nil t)
# (match-string 1)))))))
# (when header
# (save-excursion
# (goto-char 0)
# (re-search-forward "#include")
# (re-search-forward "^$")
# (insert (concat "#include \"" header "\"\n"))))))
# (defun jart-c-mode-common-hook ()
# (define-key c-mode-base-map (kbd "C-c C-h") 'jart-add-include))
# (eval-after-load 'markdown-mode
# '(progn
# (add-hook 'c-mode-common-hook 'jart-c-mode-common-hook)))
# ctags doesn't understand variable prototypes, e.g.
# extern char **environ;
set -- --regex-c='/^\(\(hidden\|extern\|const\) \)*[_[:alpha:]][_[:alnum:]]*[ *][ *]*\([_[:alpha:]][_[:alnum:]]*[ *][ *]*\)*\([_[:alpha:]][_$[:alnum:]]*\)/\4/b' "$@"
# ctags doesn't understand function prototypes, e.g.
# bool isheap(void *p) nothrow nocallback;
set -- --regex-c='/^[_[:alpha:]][_[:alnum:]]*[ *][ *]*\([_[:alpha:]][_[:alnum:]]*[ *][ *]*\)*\([_[:alpha:]][_$[:alnum:]]*\)(.*/\2/b' "$@"
# ctags doesn't understand function pointers, e.g.
# extern int32_t (*const SetEvent)(int64_t hEvent) wincall;
set -- --regex-c='/^extern [^(]*(\*const \([^)]*\))(/\1/b' "$@"
exec ${TAGS:-ctags} -e --langmap=c:.c.h "$@"

6
build/includeall Executable file
View file

@ -0,0 +1,6 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
for x; do
printf '#include "%s"\n' "$x"
done

65
build/link Executable file
View file

@ -0,0 +1,65 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# GNU Linker Veneer
#
# DESCRIPTION
#
# This script wraps normal linker commands that're transparently
# passed-through. It adds ephemeral logging and directory creation.
#
# EXAMPLE
#
# build/linker ld -o program program.o
if [ ! -d o/third_party/gcc ]; then
third_party/gcc/unbundle.sh
fi
export LC_ALL=C # very important for ld
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
OUT=
FIRST=1
OUTARG=0
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
elif [ $OUTARG -eq 1 ]; then
OUTARG=0
OUT="$x"
fi
case "$x" in
-o)
OUTARG=1
;;
esac
set -- "$@" "$x"
done
if [ "$SILENT" = "0" ]; then
printf "%s\n" "$*" >&2
else
printf "$LOGFMT" "${ACTION:-LINK.elf}" "$OUT" >&2
fi
OUTDIR="${OUT%/*}"
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
$MKDIR "$OUTDIR" || exit 2
fi
REASON=failed
trap REASON=interrupted INT
"$@" && exit
if [ "$TERM" = "dumb" ]; then
f='%s %s\r\n\r\n'
else
f='\033[91m%s\033[39m \033[94m%s\033[39m\r\n\r\n'
fi
printf "$f" "link $REASON:" "$*" >&2
exit 1

21
build/mkdeps Executable file
View file

@ -0,0 +1,21 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
if [ -x "o/$MODE/tool/build/mkdeps.com" ]; then
set -- "o/$MODE/tool/build/mkdeps.com" "$@"
else
if [ ! -x o/build/bootstrap/mkdeps.com ]; then
mkdir -p o/build/bootstrap &&
cp -a build/bootstrap/mkdeps.com \
o/build/bootstrap/mkdeps.com || exit
fi
set -- o/build/bootstrap/mkdeps.com "$@"
fi
if [ "$SILENT" = "0" ]; then
printf "%s\n" "$*" >&2
else
printf "$LOGFMT" "${ACTION:-MKDEPS}" "$3" >&2
fi
exec "$@"

31
build/online.mk Normal file
View file

@ -0,0 +1,31 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
#
# SYNOPSIS
#
# Cosmopolitan Online Testing
#
# OVERVIEW
#
# make test HOSTS="rhel5 windows mac freebsd openbsd wsl"
#
# DESCRIPTION
#
# This code deploys and spawns testing infrastructure to a fleet of
# virtual machines running the various supported platforms. This is
# super trivial since αcτµαlly pδrταblε εxεcµταblε is an autonomous
# format requiring one simple file copy. Latencies are outstanding.
# Configuration is trivial using /etc/hosts and ~/.ssh/config.
#
# SEE ALSO
#
# - tool/build/runit.c
# - tool/build/runitd.c
.PRECIOUS: o/$(MODE)/%.com.ok
o/$(MODE)/%.com.ok: \
o/$(MODE)/tool/build/runit.com.dbg \
o/$(MODE)/tool/build/runitd.com \
o/$(MODE)/%.com
@ACTION=TEST TARGET=$@ build/do $^ $(HOSTS)
@touch $@

31
build/package Executable file
View file

@ -0,0 +1,31 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
if [ "$TOOL_BUILD_PACKAGE" ]; then
set -- "$TOOL_BUILD_PACKAGE" "$@"
else
if [ -x "o/tool/build/package.com" ]; then
set -- "o/tool/build/package.com" "$@"
else
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
CP=${CP:-$(command -v cp) -f} || exit
if [ ! -x o/build/bootstrap/package.com ]; then
$MKDIR o/build/bootstrap &&
$CP -a build/bootstrap/package.com \
o/build/bootstrap/package.com || exit
fi
set -- o/build/bootstrap/package.com "$@"
fi
fi
if [ "$SILENT" = "0" ]; then
COLUMNS=${COLUMNS:-80}
COLUMNS=$((COLUMNS - 4))
printf "%s\n" "$*" |
/usr/bin/fold -s -w $COLUMNS |
sed -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
else
printf "$LOGFMT" "${ACTION:-PACKAGE}" "$3" >&2
fi
exec "$@"

2186
build/rle.py Normal file

File diff suppressed because it is too large Load diff

99
build/rules.mk Normal file
View file

@ -0,0 +1,99 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
#
# SYNOPSIS
#
# Cosmopolitan Core Build Rules
#
# DESCRIPTION
#
# This file shows GNU Make how to convert between file types, based on
# their extensions. We use everyday, ordinary, boring, and ubiquitous
# system commands for everything, e.g. as, cc, ld, etc. with plain and
# simple shell-script wrappers, e.g. build/assemble and build/compile.
# Those veneers abstract away most of the boring trivialities, to keep
# our makefiles pristine and readable.
MAKEFLAGS += --no-builtin-rules
o/%.a:; @$(ARCHIVE) $@ $^
o/%.o: %.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/%.o: o/%.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/%.s: %.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/%.s: o/%.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/%.i: %.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/%.o: %.S; @ACTION=OBJECTIFY.S build/compile $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/%.o: o/%.S; @ACTION=OBJECTIFY.S build/compile $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/%.s: %.i; @ACTION=COMPILE.i build/compile $(COMPILE.i) $(OUTPUT_OPTION) $<
o/%.s: o/%.i; @ACTION=COMPILE.i build/compile $(COMPILE.i) $(OUTPUT_OPTION) $<
o/%.o: %.cc; @ACTION=OBJECTIFY.cxx build/compile $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
o/%.o: o/%.cc; @ACTION=OBJECTIFY.cxx build/compile $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
o/%.lds: %.lds; @ACTION=PREPROCESS build/compile $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
o/%.inc: %.h; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) -D__ASSEMBLER__ -P $<
o/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
o/%.h.ok: %.h; @ACTION=CHECK.h build/compile $(COMPILE.c) -x c -g0 -o $@ $<
o/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg build/compile $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
o/%.zip.o: %; @build/zipobj $(OUTPUT_OPTION) $<
o/$(MODE)/%.a:; @$(ARCHIVE) $@ $^
o/$(MODE)/%.o: %.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: o/$(MODE)/%.s; @TARGET=$@ build/assemble $(OBJECTIFY.s) $(OUTPUT_OPTION) $<
o/$(MODE)/%.s: %.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/$(MODE)/%.s: o/$(MODE)/%.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.c; @ACTION=OBJECTIFY.c build/compile $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.f; @ACTION=OBJECTIFY.f build/compile $(OBJECTIFY.f) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.F; @ACTION=OBJECTIFY.F build/compile $(OBJECTIFY.F) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: o/$(MODE)/%.c; @ACTION=OBJECTIFY.c build/compile $(OBJECTIFY.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.ss: %.c; @ACTION=COMPILE.c build/compile $(COMPILE.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.ss: o/$(MODE)/%.c; @ACTION=OBJECTIFY.s build/compile $(COMPILE.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.i: %.S; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/$(MODE)/%.i: %.c; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/$(MODE)/%.i: %.cc; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/$(MODE)/%.i: o/$(MODE)/%.c; @ACTION=PREPROCESS build/compile $(PREPROCESS) $(OUTPUT_OPTION) $<
o/$(MODE)/%.h: %.c; @ACTION=AMALGAMATE build/compile $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
o/$(MODE)/%.h: o/$(MODE)/%.c; @ACTION=AMALGAMATE build/compile $(PREPROCESS) $(OUTPUT_OPTION) -fdirectives-only -P $<
o/$(MODE)/%.o: %.S; @ACTION=OBJECTIFY.S build/compile $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: o/$(MODE)/%.S; @ACTION=OBJECTIFY.S build/compile $(OBJECTIFY.S) $(OUTPUT_OPTION) $<
o/$(MODE)/%.s: %.i; @ACTION=COMPILE.i build/compile $(COMPILE.i) $(OUTPUT_OPTION) $<
o/$(MODE)/%.s: o/$(MODE)/%.i; @ACTION=COMPILE.i build/compile $(COMPILE.i) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: %.cc; @ACTION=OBJECTIFY.cxx build/compile $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
o/$(MODE)/%.o: o/$(MODE)/%.cc; @ACTION=OBJECTIFY.cxx build/compile $(OBJECTIFY.cxx) $(OUTPUT_OPTION) $<
o/$(MODE)/%.lds: %.lds; @ACTION=PREPROCESS build/compile $(PREPROCESS.lds) $(OUTPUT_OPTION) $<
o/$(MODE)/%.h.ok: %.h; @ACTION=CHECK.h build/compile $(COMPILE.c) -x c -g0 -o $@ $<
o/$(MODE)/%.o: %.greg.c; @ACTION=OBJECTIFY.greg build/compile $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.greg.o: %.greg.c; @ACTION=OBJECTIFY.greg build/compile $(OBJECTIFY.greg.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.ansi.o: %.ansi.c; @ACTION=OBJECTIFY.ansi build/compile $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.ansi.o: %.c; @ACTION=OBJECTIFY.ansi build/compile $(OBJECTIFY.ansi.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.c99.o: %.c99.c; @ACTION=OBJECTIFY.c99 build/compile $(OBJECTIFY.c99.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.c11.o: %.c11.c; @ACTION=OBJECTIFY.c11 build/compile $(OBJECTIFY.c11.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.c2x.o: %.c2x.c; @ACTION=OBJECTIFY.c2x build/compile $(OBJECTIFY.c2x.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.initabi.o: %.initabi.c; @ACTION=OBJECTIFY.init build/compile $(OBJECTIFY.initabi.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.ncabi.o: %.ncabi.c; @ACTION=OBJECTIFY.nc build/compile $(OBJECTIFY.ncabi.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%.runs: o/$(MODE)/%; @ACTION=CHECK.runs TARGET=$< build/runcom $< $(TESTARGS) && touch $@
o/$(MODE)/%.pkg:; @build/package $(OUTPUT_OPTION) $(addprefix -d,$(filter %.pkg,$^)) $(filter %.o,$^)
o/$(MODE)/%.zip.o: %; @build/zipobj $(OUTPUT_OPTION) $<
o/$(MODE)/%-gcc.asm: %.c; @ACTION=COMPILE.c build/compile $(COMPILE.c) $(OUTPUT_OPTION) $<
o/$(MODE)/%-clang.asm: CC = $(CLANG)
o/$(MODE)/%-clang.asm: %.c; @ACTION=COMPILE.c build/compile $(COMPILE.c) $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
o/$(MODE)/%-gcc.asm: %.f; @ACTION=COMPILE.f build/compile $(COMPILE.f) $(OUTPUT_OPTION) $<
o/$(MODE)/%-clang.asm: CC = $(CLANG)
o/$(MODE)/%-clang.asm: %.f; @ACTION=COMPILE.f build/compile $(COMPILE.f) $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
o/$(MODE)/%-gcc.asm: %.F; @ACTION=COMPILE.F build/compile $(COMPILE.F) $(OUTPUT_OPTION) $<
o/$(MODE)/%-clang.asm: CC = $(CLANG)
o/$(MODE)/%-clang.asm: %.F; @ACTION=COMPILE.F build/compile $(COMPILE.F) $(OUTPUT_OPTION) $< || echo / need $(CLANG) >$@
# ragel state machine compiler
.PRECIOUS: build/bootstrap/%.c.gz
o/$(MODE)/%.c: %.rl build/bootstrap/%.c.gz
@mkdir -p $(dir $@)
@$(GZ) $(ZFLAGS) -dc $(<:%.rl=build/bootstrap/%.c.gz) >$@
-@ACTION=RAGEL build/do $(RAGEL) $(RAGELFLAGS) $(OUTPUT_OPTION) $<
build/bootstrap/%.c.gz: %.rl
@mkdir -p $(dir $@)
@$(RAGEL) -o $(@:%.gz=%) $<
@$(GZ) $(ZFLAGS) -f $(@:%.gz=%)
%.svgz: %.rl
@$(RAGEL) -V -p $< | $(DOT) -Tsvg | $(GZ) $(ZFLAGS) >$@
$(LIBC__A_SRCS:%=o/$(MODE)/%.zip.o) \

9
build/runcom Executable file
View file

@ -0,0 +1,9 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
DD=${DD:-$(command -v dd)} || exit
$DD if="$1" of="$1.bak" bs=4096 count=1 conv=notrunc 2>/dev/null
"$@"
rc=$?
$DD if="$1.bak" of="$1" bs=4096 count=1 conv=notrunc 2>/dev/null
exit $rc

13
build/ssh Executable file
View file

@ -0,0 +1,13 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
#
# OVERVIEW
#
# SSH Command Wrapper
#
# DESCRIPTION
#
# This script, like most of our wrappers, asks the tooling to whine
# less often.
exec ${SSH:-ssh} -o LogLevel=QUIET "$@"

54
build/zipobj Executable file
View file

@ -0,0 +1,54 @@
#-*-mode:sh;indent-tabs-mode:nil;tab-width:2;coding:utf-8-*-┐
#───vi: set net ft=sh ts=2 sts=2 fenc=utf-8 :vi─────────────┘
MKDIR=${MKDIR:-$(command -v mkdir) -p} || exit
CP=${CP:-$(command -v cp) -f} || exit
SED=${SED:-$(command -v sed)} || exit
MODE=
OUT=
FIRST=1
OUTARG=0
for x; do
if [ $FIRST -eq 1 ]; then
set --
FIRST=0
elif [ $OUTARG -eq 1 ]; then
OUTARG=0
OUT="$x"
fi
case "$x" in
-o)
OUTARG=1
;;
esac
set -- "$@" "$x"
done
OUTDIR="${OUT%/*}"
if [ "$OUTDIR" != "$OUT" ] && [ ! -d "$OUTDIR" ]; then
$MKDIR "$OUTDIR" || exit 2
fi
if [ -x "o/$MODE/tool/build/zipobj.com.dbg" ]; then
set -- "o/$MODE/tool/build/zipobj.com.dbg" "$@"
else
if [ ! -x o/build/bootstrap/zipobj.com ]; then
$MKDIR o/build/bootstrap &&
$CP -a build/bootstrap/zipobj.com \
o/build/bootstrap/zipobj.com || exit
fi
set -- o/build/bootstrap/zipobj.com "$@"
fi
if [ "$SILENT" = "0" ]; then
COLUMNS=${COLUMNS:-80}
COLUMNS=$((COLUMNS - 4))
printf "%s\n" "$*" |
/usr/bin/fold -s -w $COLUMNS |
$SED -e '1bb' -e 's/^/ /' -e ':b' -e '$b' -e 's/$/ \\/' >&2
else
printf "$LOGFMT" "${ACTION:-ZIPOBJ}" "$3" >&2
fi
exec "$@"