DELETED arch/makefile Index: arch/makefile ================================================================== --- arch/makefile +++ arch/makefile @@ -1,44 +0,0 @@ -ifeq (${OS},lin) - p-headers-syscall ?= /usr/include/asm/unistd_${BITS}.h - p-headers-errno ?= /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h -else ifeq (${OS},fbsd) - p-headers-syscall ?= /usr/include/sys/syscall.h - p-headers-errno ?= /usr/include/errno.h -else - $(info we don’t know where to find your magic number headers.) - $(info to compile libk, please provide the following variables \ -to the make command line:) - $(info --- p-headers-syscall=(location of syscall header)) - $(info --- p-headers-errno=(location of your errno values header)) - $(info note that /usr/include/errno.h or your system’s equivalent \ -may not be sufficient. make sure the file you pass actually contains \ -individual #define statements for each possible value of errno!) - $(error table generation failed due to missing primaries) -endif - -${TMP}: - mkdir -p ${TMP} - -${TMP}/calls.lin@x86.%.tbl: $(p-headers-syscall) - mkdir -p ${TMP} - grep -h "#define __NR_" $^ | sed 's;^#define __NR_;;' > $@ -${TMP}/calls.fbsd@%.tbl: $(p-headers-syscall) - mkdir -p ${TMP} - grep -h "#define SYS_" $^ | sed 's;^#define SYS_;;' | sed 's;[\t ]\+; ;' > $@ - -${TMP}/system_calls.%: ${TMP}/calls.${OS}@${ARCH}.${BITS}.tbl ${TMP} - awk -f syscall.awk -v out=$* <$< >$@ - -${TMP}/error_names.tbl: $(p-headers-errno) - mkdir -p ${TMP} - grep -h "#[ ]*define[ ]\+E" $^ | sed 's;^#[\t ]*define[\t ]\+\(E[A-Z0-9]\+\).*$$;k_platform_error_\1 \1;' > $@ -${TMP}/error_numbers.tbl: $(p-headers-errno) ${TMP}/error_names.tbl - cat $^ | cpp -P >$@ - -${TMP}/error_table.h: ${TMP}/error_numbers.tbl ${TMP} - awk -f errtbl.awk <$< >$@ - -${TMP}/typesize: typesize.c ${TMP} - $(CC) -std=c11 $< -o $@ -${TMP}/typesize.def: ${TMP}/typesize ${TMP} - $< > $@ Index: build.sh ================================================================== --- build.sh +++ build.sh @@ -1,19 +1,26 @@ #!/usr/bin/env bash +export out=${out:-out} . global/common.sh noimpl() { say "$1 is not currently implemented on your system. an exciting chance for you to contribute, no?" exit 1 } +timestamp() { date "+%H:%M:%S %A"; } if test "$os$arch$bits" = ""; then say "set the following environment variables to the appropriate atoms describing your system. for help determining the appropriate atoms, see libk.md" say ' - $os={lin|fbsd|hai|osx…}' say ' - $arch={x86|arm|ia64|mips…}' say ' - $bits={|32|64…}' exit 1 fi + +if test "$1" = "-C"; then + say "precleaning repo" + ./clean.sh +fi # TODO: make it possible for user to change # default set with environment vars modules=(kcore kmem kstr kio kgraft kfile) @@ -33,25 +40,25 @@ win.64) bin_fmt=win64;; osx.32|dar.32) bin_fmt=macho32;; osx.64|dar.64) bin_fmt=macho64;; dos.*) bin_fmt=dosexe;; none.*) bin_fmt=bin;; - 32) bin_fmt=elf32;; - 64) bin_fmt=elf64;; + *.32) bin_fmt=elf32;; + *.64) bin_fmt=elf64;; + *) say "cannot determine correct binary format to use for target $target"; exit 1;; esac # first, we establish the # parameters of the build -has gcc && _cc=gcc -has clang && _cc=clang has cc && _cc=cc +has clang && _cc=clang +has gcc && _cc=gcc cc=${cc:-$_cc} has m4 && _m4=m4 m4=${m4:-$_m4} -has yasm && asm=yasm has nasm && asm=nasm -export out=${out:-out} +has yasm && asm=yasm export gen=${gen:-gen} library=${libkind:-static} # {static|shared|both} case $library in static) build_static_library=yes @@ -87,29 +94,24 @@ if test "$bits" != ""; then macro_compile_env="$macro_compile_env -Datom_target_bits=$bits" fi -for mod in ${modules[@]}; do - say "building libk with $mod" -done comp_mac() { $m4 $macro_compile_env -I "$gen" $3 "$1" > "$2"; } -comp_asm() { $asm "-f$bin_fmt" "-i$gen" $1 -o "$2"; } -comp_co() { comp_clib $1 $2 -c; } -comp_clib(){ +comp_asm() { $asm "-f$bin_fmt" -i "$gen" $1 -o "$2"; } +comp_co() { comp_c $1 $2 "-c -fPIC"; } +comp_c(){ src=$1 output=$2 flags=$3 - $cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -fPIC -nostdlib "-L$out" "-o$output" + $cc $src $3 -std=c11 -isystem "$out" -isystem "$gen" -isystem "arch/" -nostdlib "-L$out" "-o$output" } scan() { find "$1" -name "$2"; } -# now we make sure all the appropriate -# directories exist - +say "commencing libk build $build at $(timestamp)" set -x # get type data mkdir -p $gen $cc -D_emit_m4_include arch/typesize.c -o $gen/typesize @@ -134,45 +136,42 @@ 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 raw headers into place +# first pass: copy all headers into place, +# including ones we need to generate + for mod in ${modules[@]}; do for h in $(scan $mod '*.h'); do base=$(basename $h) cp "$h" "$out/k/$base" done -done -# second pass: run macro headers through m4 and -# copy the resulting file into place - -for mod in ${modules[@]}; do for h in $(scan $mod '*.h.m'); do base=$(basename $h) dest=${base%%.m} comp_mac "$h" "$out/k/$dest" done done -# third pass: generate manpage, html, and pdf +# 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" - # TODO html - # TODO pdf + global/build-html.sh "$doc" + global/build-pdf.sh "$doc" done done -# fourth pass: compile sources and save the +# 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 fn_objects=() @@ -181,32 +180,62 @@ for mod in ${modules[@]}; do for fn in $(scan $mod '*.fn.c'); do base="$(basename $fn)" dest="$out/$mod.${base%%.c}.o" comp_co "$fn" "$dest" - fn_objects+="$dest" + fn_objects+=("$dest") done for rt in $(scan $mod '*.rt.c'); do base="$(basename $rt)" dest="$out/$mod.${base%%.c}.o" comp_co "$rt" "$dest" - rt_objects+="$dest" + rt_objects+=("$dest") done for fn in $(scan $mod "*.fn.$target.s"); do base="$(basename $fn)" dest="$out/$mod.${base%%.s}.o" comp_asm "$fn" "$dest" - fn_objects+="$dest" + fn_objects+=("$dest") done for rt in $(scan $mod "*.rt.$target.s"); do base="$(basename $rt)" dest="$out/$mod.${base%%.s}.o" comp_asm "$rt" "$dest" - rt_objects+="$dest" + rt_objects+=("$dest") + done +done + +# fourth pass: link the libraries that are +# configured to be built + +if test $build_static_library == yes; then + for obj in ${fn_objects[@]} ${rt_objects[@]} ${data_objects[@]}; do + ar rc $out/libk.a $obj + done + ranlib $out/libk.a +fi + +if test $build_shared_library == yes; then + ld -r ${rt_objects[@]} -o $out/boot.o + ld -shared ${fn_objects[@]} -o $out/libk.so +fi + +# fifth pass: compile the executable tools +# against the libraries created in pass 5 + +for mod in ${modules[@]}; do + for exe in $(scan $mod '*.exe.c'); do + base="$(basename $exe)" + dest="$out/$mod.${base%%.exe.c}" + if test $build_shared_library == yes; then + comp_c "$out/boot.o $exe" "$dest" -lk + else + comp_c "$exe" "$dest" -lk + fi done done -echo fns: ${fn_objects[@]} -echo rts: ${rt_objects[@]} +set +x +say "all passes finished; build $build complete at $(timestamp)" Index: clean.sh ================================================================== --- clean.sh +++ clean.sh @@ -1,11 +1,10 @@ #!/usr/bin/env bash -. global/common.sh - out=${out:-out} gen=${gen:-gen} +. global/common.sh say "cleaning libk build artifacts" set -x rm -r $out rm -r $gen ADDED global/build-html.sh Index: global/build-html.sh ================================================================== --- global/build-html.sh +++ global/build-html.sh @@ -0,0 +1,11 @@ +#!/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 @@ -3,38 +3,30 @@ echo >&2 "($0) run $me from root of libk source directory" exit 1 } . global/common.sh -test "$out" = "" && { - 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!" - exit 2 -} - -if ! has cmark; then - say "to generate documentation for libk, install the cmark package and try again" - exit 3 -fi +reqpack cmark "generate documentation" file="$1" filename="$(basename "$file")" stem=${filename%%.md} mandest="$out/doc/man" section=${section:-4} out="$mandest/$stem.$section" -desc_rec="$(grep -m1 "^$name:" global/modules)" -if test $? -eq 0; then +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 ${name^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\"" +echo >"$out" ".TH ${stem^^} \"$section\" \"$date\" \"hale.su libk [r$build]\" \"modules\"" echo >>"$out" ".SH NAME" echo >>"$out" "$stem$desc" echo >>"$out" ".SH SYNOPSIS" ADDED global/build-pdf.sh Index: global/build-pdf.sh ================================================================== --- global/build-pdf.sh +++ global/build-pdf.sh @@ -0,0 +1,11 @@ +#!/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/common.sh ================================================================== --- global/common.sh +++ global/common.sh @@ -5,5 +5,17 @@ var=$1 test "${!var}" == "" || return 0 say "we were not able to detect a default value for the configuration variable \$$var. please set this variable to $2 and try again." exit 1 } + +test "$out" = "" && { + 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!" + exit 2 +} + +reqpack() { + if ! has "$1"; then + say "to $2 for libk, install the $1 package and try again" + exit 3 + fi +} DELETED kbuild/makefile Index: kbuild/makefile ================================================================== --- kbuild/makefile +++ kbuild/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kconf/makefile Index: kconf/makefile ================================================================== --- kconf/makefile +++ kconf/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kcore/makefile Index: kcore/makefile ================================================================== --- kcore/makefile +++ kcore/makefile @@ -1,45 +0,0 @@ -## kcore/makefile -# kcore has to include, among other things, a replacement -# for stddef.h, and that can't be written in portable C. -# so we're generating it at build time. - -# gen-headers = type.h - -include ../modmake - -${OUT}/k/type.h: type.h.m ${TMP}/typesize.def - $(m-comp) $(file < ${TMP}/typesize.def) $< > $@ - -## the below code predates the introduction of gpp -## to generate these headers from templates instead -## of trying to write one for everypossible arch -## tuple. it is left as a monument to a terrible -## and now blissfully forgotten past. -# -# look, imma just be straight with you. the mechanism we're -# using to generate these headers is unbelievably heinous. -# it's inelegant, it's gross, and it's horrible. in the long -# term this NEEDS to be replaced with a bespoke solution -# instead of makefile gibberish. hopefully tho this will be -# enough in the short term for libk to get going, enough that -# someone more competent than me will someday be interested -# in fixing this horrorshow. -# -# until them: i'm sorry. -# very sincerely yours, lexi hale -# ${OUT}/k/type.h: ${TMP}/type.${TARGET}.i -# cp $< $@ -# -# # generating C source in make… yaaay -# define arch = -# ${TMP}/type.$(1).%.$(2).i: type.$(1).$(2).i def.%.i ${TMP} -# echo '#ifndef KItype' > $$@ -# echo '#define KItype' >> $$@ -# cat $$< >> $$@ -# cat def.$$*.i >> $$@ -# echo '#endif' >> $$@ -# endef -# -# $(eval $(call arch,x86,32)) -# $(eval $(call arch,x86,64)) -# DELETED kdb/makefile Index: kdb/makefile ================================================================== --- kdb/makefile +++ kdb/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kdbg/makefile Index: kdbg/makefile ================================================================== --- kdbg/makefile +++ kdbg/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kfile/makefile Index: kfile/makefile ================================================================== --- kfile/makefile +++ kfile/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kgraft/makefile Index: kgraft/makefile ================================================================== --- kgraft/makefile +++ kgraft/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kio/makefile Index: kio/makefile ================================================================== --- kio/makefile +++ kio/makefile @@ -1,12 +0,0 @@ -gen-headers = kiostream.platform.h - -include ../modmake - -ifeq (${POSIX},yes) -api = posix -else -api = ${OS} -endif - -${OUT}/k/kiostream.platform.h: kiostream.$(api).i - cp $< $@ DELETED kmem/makefile Index: kmem/makefile ================================================================== --- kmem/makefile +++ kmem/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kmsg/makefile Index: kmsg/makefile ================================================================== --- kmsg/makefile +++ kmsg/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED knet/makefile Index: knet/makefile ================================================================== --- knet/makefile +++ knet/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED knum/makefile Index: knum/makefile ================================================================== --- knum/makefile +++ knum/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kproc/makefile Index: kproc/makefile ================================================================== --- kproc/makefile +++ kproc/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kstr/makefile Index: kstr/makefile ================================================================== --- kstr/makefile +++ kstr/makefile @@ -1,1 +0,0 @@ -include ../modmake DELETED kterm/makefile Index: kterm/makefile ================================================================== --- kterm/makefile +++ kterm/makefile @@ -1,1 +0,0 @@ -include ../modmake ADDED legacy/arch.makefile Index: legacy/arch.makefile ================================================================== --- legacy/arch.makefile +++ legacy/arch.makefile @@ -0,0 +1,44 @@ +ifeq (${OS},lin) + p-headers-syscall ?= /usr/include/asm/unistd_${BITS}.h + p-headers-errno ?= /usr/include/asm-generic/errno.h /usr/include/asm-generic/errno-base.h +else ifeq (${OS},fbsd) + p-headers-syscall ?= /usr/include/sys/syscall.h + p-headers-errno ?= /usr/include/errno.h +else + $(info we don’t know where to find your magic number headers.) + $(info to compile libk, please provide the following variables \ +to the make command line:) + $(info --- p-headers-syscall=(location of syscall header)) + $(info --- p-headers-errno=(location of your errno values header)) + $(info note that /usr/include/errno.h or your system’s equivalent \ +may not be sufficient. make sure the file you pass actually contains \ +individual #define statements for each possible value of errno!) + $(error table generation failed due to missing primaries) +endif + +${TMP}: + mkdir -p ${TMP} + +${TMP}/calls.lin@x86.%.tbl: $(p-headers-syscall) + mkdir -p ${TMP} + grep -h "#define __NR_" $^ | sed 's;^#define __NR_;;' > $@ +${TMP}/calls.fbsd@%.tbl: $(p-headers-syscall) + mkdir -p ${TMP} + grep -h "#define SYS_" $^ | sed 's;^#define SYS_;;' | sed 's;[\t ]\+; ;' > $@ + +${TMP}/system_calls.%: ${TMP}/calls.${OS}@${ARCH}.${BITS}.tbl ${TMP} + awk -f syscall.awk -v out=$* <$< >$@ + +${TMP}/error_names.tbl: $(p-headers-errno) + mkdir -p ${TMP} + grep -h "#[ ]*define[ ]\+E" $^ | sed 's;^#[\t ]*define[\t ]\+\(E[A-Z0-9]\+\).*$$;k_platform_error_\1 \1;' > $@ +${TMP}/error_numbers.tbl: $(p-headers-errno) ${TMP}/error_names.tbl + cat $^ | cpp -P >$@ + +${TMP}/error_table.h: ${TMP}/error_numbers.tbl ${TMP} + awk -f errtbl.awk <$< >$@ + +${TMP}/typesize: typesize.c ${TMP} + $(CC) -std=c11 $< -o $@ +${TMP}/typesize.def: ${TMP}/typesize ${TMP} + $< > $@ ADDED legacy/kbuild.makefile Index: legacy/kbuild.makefile ================================================================== --- legacy/kbuild.makefile +++ legacy/kbuild.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kconf.makefile Index: legacy/kconf.makefile ================================================================== --- legacy/kconf.makefile +++ legacy/kconf.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kcore.makefile Index: legacy/kcore.makefile ================================================================== --- legacy/kcore.makefile +++ legacy/kcore.makefile @@ -0,0 +1,45 @@ +## kcore/makefile +# kcore has to include, among other things, a replacement +# for stddef.h, and that can't be written in portable C. +# so we're generating it at build time. + +# gen-headers = type.h + +include ../modmake + +${OUT}/k/type.h: type.h.m ${TMP}/typesize.def + $(m-comp) $(file < ${TMP}/typesize.def) $< > $@ + +## the below code predates the introduction of gpp +## to generate these headers from templates instead +## of trying to write one for everypossible arch +## tuple. it is left as a monument to a terrible +## and now blissfully forgotten past. +# +# look, imma just be straight with you. the mechanism we're +# using to generate these headers is unbelievably heinous. +# it's inelegant, it's gross, and it's horrible. in the long +# term this NEEDS to be replaced with a bespoke solution +# instead of makefile gibberish. hopefully tho this will be +# enough in the short term for libk to get going, enough that +# someone more competent than me will someday be interested +# in fixing this horrorshow. +# +# until them: i'm sorry. +# very sincerely yours, lexi hale +# ${OUT}/k/type.h: ${TMP}/type.${TARGET}.i +# cp $< $@ +# +# # generating C source in make… yaaay +# define arch = +# ${TMP}/type.$(1).%.$(2).i: type.$(1).$(2).i def.%.i ${TMP} +# echo '#ifndef KItype' > $$@ +# echo '#define KItype' >> $$@ +# cat $$< >> $$@ +# cat def.$$*.i >> $$@ +# echo '#endif' >> $$@ +# endef +# +# $(eval $(call arch,x86,32)) +# $(eval $(call arch,x86,64)) +# ADDED legacy/kdb.makefile Index: legacy/kdb.makefile ================================================================== --- legacy/kdb.makefile +++ legacy/kdb.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kdbg.makefile Index: legacy/kdbg.makefile ================================================================== --- legacy/kdbg.makefile +++ legacy/kdbg.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kfile.makefile Index: legacy/kfile.makefile ================================================================== --- legacy/kfile.makefile +++ legacy/kfile.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kgraft.makefile Index: legacy/kgraft.makefile ================================================================== --- legacy/kgraft.makefile +++ legacy/kgraft.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kio.makefile Index: legacy/kio.makefile ================================================================== --- legacy/kio.makefile +++ legacy/kio.makefile @@ -0,0 +1,12 @@ +gen-headers = kiostream.platform.h + +include ../modmake + +ifeq (${POSIX},yes) +api = posix +else +api = ${OS} +endif + +${OUT}/k/kiostream.platform.h: kiostream.$(api).i + cp $< $@ ADDED legacy/kmem.makefile Index: legacy/kmem.makefile ================================================================== --- legacy/kmem.makefile +++ legacy/kmem.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kmsg.makefile Index: legacy/kmsg.makefile ================================================================== --- legacy/kmsg.makefile +++ legacy/kmsg.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/knet.makefile Index: legacy/knet.makefile ================================================================== --- legacy/knet.makefile +++ legacy/knet.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/knum.makefile Index: legacy/knum.makefile ================================================================== --- legacy/knum.makefile +++ legacy/knum.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kproc.makefile Index: legacy/kproc.makefile ================================================================== --- legacy/kproc.makefile +++ legacy/kproc.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kstr.makefile Index: legacy/kstr.makefile ================================================================== --- legacy/kstr.makefile +++ legacy/kstr.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/kterm.makefile Index: legacy/kterm.makefile ================================================================== --- legacy/kterm.makefile +++ legacy/kterm.makefile @@ -0,0 +1,1 @@ +include ../modmake ADDED legacy/legacy.makefile Index: legacy/legacy.makefile ================================================================== --- legacy/legacy.makefile +++ legacy/legacy.makefile @@ -0,0 +1,157 @@ +export OUT = $(PWD)/out + +# TODO: calculate these using $(MAKE_HOST) +export ARCH = x86 +export OS = lin +export BITS = 64 +export ROOT = $(PWD) +export TMP = $(PWD)/gen + +export BUILD = $(shell global/build-id.sh) $(build-host) + +ifneq ($(BITS),) + export TARGET = $(ARCH).$(OS).$(BITS) +else + export TARGET = $(ARCH).$(OS) +endif + +export m4 = m4 + +include makerule + +moddirs := $(wildcard k*) +binaries := $(wildcard k*/*.exe.c) +functions := $(wildcard k*/*.fn.c) +assemblies := $(wildcard k*/*.fn.$(TARGET).s) +binmods := $(sort $(dir $(binaries))) + +# i'm sorry +collect = $(strip $(foreach dir,$(moddirs),$(wildcard $(dir)/*.$1))) +transform = $(strip $(foreach dir,$(moddirs),$(patsubst $(dir)/%.$1,$(subst @,$(dir),$2),$(wildcard $(dir)/*.$1)))) + +m-hdr-macs := $(call collect,h.m) +m-c-src-macs := $(call collect,c.m) +m-s-src-macs := $(call collect,$(TARGET).s.m) + +m-c-sources := $(call transform,c.m,$(TMP)/@.%.c) +m-s-sources := $(call transform,$(TARGET).s.m,$(TMP)/@.%.$(TARGET).s) + +m-headers := $(call transform,h.m,$(OUT)/k/%.h) +m-c-objects := $(call transform,c.m,$(OUT)/@.%.o) +m-s-objects := $(call transform,$(TARGET).s.m,$(OUT)/@.%.$(TARGET).o) + +fnobjects := $(call transform,fn.c,$(OUT)/@.%.fn.o) \ + $(call transform,fn.c.m,$(OUT)/@.%.fn.o) \ + $(call transform,fn.$(TARGET).s,$(OUT)/@.%.fn.$(TARGET).o) \ + $(call transform,fn.$(TARGET).s.m,$(OUT)/@.%.fn.$(TARGET).o) + +rtobjects := $(call transform,rt.c,$(OUT)/@.%.rt.o) \ + $(call transform,rt.c.m,$(OUT)/@.%.rt.o) \ + $(call transform,rt.$(TARGET).s,$(OUT)/@.%.rt.$(TARGET).o) \ + $(call transform,rt.$(TARGET).s.m,$(OUT)/@.%.rt.$(TARGET).o) + +docs := $(wildcard k*/*.md) +docs-out := $(patsubst %.md,$(OUT)/doc/man/%.4.gz,$(notdir $(docs))) +objects := $(fnobjects) $(rtobjects) + +prefix ?= /usr +d-header = $(prefix)/include +d-lib = $(prefix)/lib +d-share = $(prefix)/share + +unix-oses = lin fbsd dar and +posix-oses = lin fbsd dar and hai mgw cyg + +ifeq ($(findstring $(OS),$(unix-oses)),$(OS)) + export UNIX = yes + export POSIX = yes +else + export UNIX = no + ifeq ($(findstring $(OS),$(posix-oses)),$(OS)) + export POSIX = yes + else + export POSIX = no + endif +endif + +# include libgcc.a in gcc builds, just in case +ifeq ($(CC),gcc) + export COMPLIB = -lgcc +endif + +all: $(OUT) defs obj tool lib.static $(OUT)/boot.o lib.shared +lib.static: defs obj $(OUT)/libk.a +lib.shared: defs obj $(OUT)/libk.so +obj: $(moddirs:%=%.obj) +defs: $(moddirs:%=%.def) +tool: $(OUT)/boot.o $(OUT)/libk.a $(binmods:%=%.tool) +doc: $(docs-out) +clean: + rm -rf $(TMP) $(OUT) + +install: all + install -d $(header-dir)/k $(share-dir)/k -o root -g wheel -m 0755 + install $(OUT)/k/* $(header-dir)/k/ -o root -g wheel -m 0644 + install $(OUT)/libk.a $(OUT)/libk.so \ + $(lib-dir) -o root -g wheel -m 0644 + install $(OUT)/boot.o $(share-dir)/k/boot.o -o root -g wheel -m 0644 + +uninstall: $(header-dir)/k $(lib-dir)/k + rm -rf $^ + +lists = BUILD moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX docs docs-out +dbg: + @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))") + +%.obj: %/makefile $(OUT)/internal.ident.o $(OUT) + cd $* && $(MAKE) obj + +%.tool: %/makefile $(OUT) + cd $* && $(MAKE) tool + +%.dbg: %/makefile $(OUT) + cd $* && $(MAKE) dbg + +%.def: %/makefile $(TMP)/typesize.def \ + $(OUT)/k/internal.egroup.h \ + $(TMP)/system_calls.h \ + $(TMP)/system_calls.s \ + $(TMP)/error_table.h \ + $(OUT) $(OUT)/k + cd $* && $(MAKE) def + +.PRECIOUS: $(TMP)/system_calls.% +$(TMP)/system_calls.%: arch/makefile + $(MAKE) -C arch $@ + +$(TMP)/error_table.h: arch/makefile + $(MAKE) -C arch $@ + +$(TMP)/typesize.def: arch/makefile $(TMP) + $(MAKE) -C arch $@ + +$(OUT)/libk.so: $(fnobjects) + ld -shared $(COMPLIB) -o $@ $^ + @# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o + +$(OUT)/boot.o: $(rtobjects) + ld -r $^ -o $(OUT)/boot.o + +$(OUT)/libk.a: $(fnobjects) $(rtobjects) + @# using `ar rc` and ranlib here instead of + @# `ar rcs` in case `ar` isn't the GNU version + ar rc $@ $^ + ranlib $@ + +$(OUT)/man/doc: + mkdir -p $@ + +$(OUT)/k/internal.egroup.h: global/modules global/gen-conds.awk $(OUT)/k + awk -f global/gen-conds.awk <$< >$@ +$(TMP)/internal.ident.c: global/modules global/gen-ident.awk $(OUT)/k/internal.egroup.h $(TMP) + awk -f global/gen-ident.awk <$< >$@ +$(OUT)/%.o: $(TMP)/%.c $(OUT) + $(CC) $(cflags) -c $< -o $@ + +$(OUT) $(OUT)/k $(TMP): + mkdir -p $@ DELETED legacy/makefile Index: legacy/makefile ================================================================== --- legacy/makefile +++ legacy/makefile @@ -1,157 +0,0 @@ -export OUT = $(PWD)/out - -# TODO: calculate these using $(MAKE_HOST) -export ARCH = x86 -export OS = lin -export BITS = 64 -export ROOT = $(PWD) -export TMP = $(PWD)/gen - -export BUILD = $(shell global/build-id.sh) $(build-host) - -ifneq ($(BITS),) - export TARGET = $(ARCH).$(OS).$(BITS) -else - export TARGET = $(ARCH).$(OS) -endif - -export m4 = m4 - -include makerule - -moddirs := $(wildcard k*) -binaries := $(wildcard k*/*.exe.c) -functions := $(wildcard k*/*.fn.c) -assemblies := $(wildcard k*/*.fn.$(TARGET).s) -binmods := $(sort $(dir $(binaries))) - -# i'm sorry -collect = $(strip $(foreach dir,$(moddirs),$(wildcard $(dir)/*.$1))) -transform = $(strip $(foreach dir,$(moddirs),$(patsubst $(dir)/%.$1,$(subst @,$(dir),$2),$(wildcard $(dir)/*.$1)))) - -m-hdr-macs := $(call collect,h.m) -m-c-src-macs := $(call collect,c.m) -m-s-src-macs := $(call collect,$(TARGET).s.m) - -m-c-sources := $(call transform,c.m,$(TMP)/@.%.c) -m-s-sources := $(call transform,$(TARGET).s.m,$(TMP)/@.%.$(TARGET).s) - -m-headers := $(call transform,h.m,$(OUT)/k/%.h) -m-c-objects := $(call transform,c.m,$(OUT)/@.%.o) -m-s-objects := $(call transform,$(TARGET).s.m,$(OUT)/@.%.$(TARGET).o) - -fnobjects := $(call transform,fn.c,$(OUT)/@.%.fn.o) \ - $(call transform,fn.c.m,$(OUT)/@.%.fn.o) \ - $(call transform,fn.$(TARGET).s,$(OUT)/@.%.fn.$(TARGET).o) \ - $(call transform,fn.$(TARGET).s.m,$(OUT)/@.%.fn.$(TARGET).o) - -rtobjects := $(call transform,rt.c,$(OUT)/@.%.rt.o) \ - $(call transform,rt.c.m,$(OUT)/@.%.rt.o) \ - $(call transform,rt.$(TARGET).s,$(OUT)/@.%.rt.$(TARGET).o) \ - $(call transform,rt.$(TARGET).s.m,$(OUT)/@.%.rt.$(TARGET).o) - -docs := $(wildcard k*/*.md) -docs-out := $(patsubst %.md,$(OUT)/doc/man/%.4.gz,$(notdir $(docs))) -objects := $(fnobjects) $(rtobjects) - -prefix ?= /usr -d-header = $(prefix)/include -d-lib = $(prefix)/lib -d-share = $(prefix)/share - -unix-oses = lin fbsd dar and -posix-oses = lin fbsd dar and hai mgw cyg - -ifeq ($(findstring $(OS),$(unix-oses)),$(OS)) - export UNIX = yes - export POSIX = yes -else - export UNIX = no - ifeq ($(findstring $(OS),$(posix-oses)),$(OS)) - export POSIX = yes - else - export POSIX = no - endif -endif - -# include libgcc.a in gcc builds, just in case -ifeq ($(CC),gcc) - export COMPLIB = -lgcc -endif - -all: $(OUT) defs obj tool lib.static $(OUT)/boot.o lib.shared -lib.static: defs obj $(OUT)/libk.a -lib.shared: defs obj $(OUT)/libk.so -obj: $(moddirs:%=%.obj) -defs: $(moddirs:%=%.def) -tool: $(OUT)/boot.o $(OUT)/libk.a $(binmods:%=%.tool) -doc: $(docs-out) -clean: - rm -rf $(TMP) $(OUT) - -install: all - install -d $(header-dir)/k $(share-dir)/k -o root -g wheel -m 0755 - install $(OUT)/k/* $(header-dir)/k/ -o root -g wheel -m 0644 - install $(OUT)/libk.a $(OUT)/libk.so \ - $(lib-dir) -o root -g wheel -m 0644 - install $(OUT)/boot.o $(share-dir)/k/boot.o -o root -g wheel -m 0644 - -uninstall: $(header-dir)/k $(lib-dir)/k - rm -rf $^ - -lists = BUILD moddirs functions assemblies fnobjects rtobjects binaries binmods POSIX docs docs-out -dbg: - @echo -e lists: $(foreach var, $(lists), "\\n - \\e[1m$(var)\\e[m = $($(var))") - -%.obj: %/makefile $(OUT)/internal.ident.o $(OUT) - cd $* && $(MAKE) obj - -%.tool: %/makefile $(OUT) - cd $* && $(MAKE) tool - -%.dbg: %/makefile $(OUT) - cd $* && $(MAKE) dbg - -%.def: %/makefile $(TMP)/typesize.def \ - $(OUT)/k/internal.egroup.h \ - $(TMP)/system_calls.h \ - $(TMP)/system_calls.s \ - $(TMP)/error_table.h \ - $(OUT) $(OUT)/k - cd $* && $(MAKE) def - -.PRECIOUS: $(TMP)/system_calls.% -$(TMP)/system_calls.%: arch/makefile - $(MAKE) -C arch $@ - -$(TMP)/error_table.h: arch/makefile - $(MAKE) -C arch $@ - -$(TMP)/typesize.def: arch/makefile $(TMP) - $(MAKE) -C arch $@ - -$(OUT)/libk.so: $(fnobjects) - ld -shared $(COMPLIB) -o $@ $^ - @# $(CC) -shared -fPIC -nostdlib $(COMPLIB) -o $@ $(OUT)/*.o - -$(OUT)/boot.o: $(rtobjects) - ld -r $^ -o $(OUT)/boot.o - -$(OUT)/libk.a: $(fnobjects) $(rtobjects) - @# using `ar rc` and ranlib here instead of - @# `ar rcs` in case `ar` isn't the GNU version - ar rc $@ $^ - ranlib $@ - -$(OUT)/man/doc: - mkdir -p $@ - -$(OUT)/k/internal.egroup.h: global/modules global/gen-conds.awk $(OUT)/k - awk -f global/gen-conds.awk <$< >$@ -$(TMP)/internal.ident.c: global/modules global/gen-ident.awk $(OUT)/k/internal.egroup.h $(TMP) - awk -f global/gen-ident.awk <$< >$@ -$(OUT)/%.o: $(TMP)/%.c $(OUT) - $(CC) $(cflags) -c $< -o $@ - -$(OUT) $(OUT)/k $(TMP): - mkdir -p $@