Explorar o código

Add first version of ninja based build system

Caveats:
- Only shown to work on OpenBSD
- Does not build documentation yet
Wictor Lund %!s(int64=4) %!d(string=hai) anos
pai
achega
c3c1abf4ca

+ 14 - 0
symon/build.ninja

@@ -0,0 +1,14 @@
+
+include parameters.ninja
+include config.ninja
+
+rdir = .
+cdir = $rdir
+pdir = $cdir/platform/$platform
+stubpdir = $cdir/platform/stub
+
+include $pdir/build.ninja
+subninja $cdir/lib/build.ninja
+subninja $cdir/symon/build.ninja
+subninja $cdir/symux/build.ninja
+subninja $cdir/client/build.ninja

+ 0 - 0
symon/client/build.ninja


+ 70 - 0
symon/genbld.sh

@@ -0,0 +1,70 @@
+#!/bin/sh
+
+#---help---
+# Usage: genbld.sh [options] [--]
+#
+# Arguments:
+#
+# Options:
+#   -t					Generate template for a new shell script
+#   -x				  Activate shell tracing (set -x)
+#   -h				  Print this message
+#---help---
+
+set -eu
+
+# Prints help and exists with the specified status.
+help() {
+	sed -Enf /dev/fd/3 "$0" 3<<-EOF
+	/^#---help---/,/^#---help---/ {
+		/^#---help---/d;
+		s/^#(NT)? ?//;
+		p
+	}
+	EOF
+	exit ${1:-0}
+}
+
+template() {
+	local new_name="$1"
+	local dz_basename="$(basename "$0")"
+	sed -Enf /dev/fd/3 "$0" 3<<-EOF |
+	1,/^#---template-end---/ {
+		s/^(#[[:space:]]*Usage:[[:space:]]*)${dz_basename}.*$/\1${new_name} [options] [--]/
+		/^#NT/d;
+		s/ {8}/	/g;
+		#/^#---template-end---/d;
+		p
+	}
+	EOF
+	cat
+	exit 0
+}
+
+O=$(getopt "t:xh" "$@") || exit 1
+eval set -- "$O"
+
+while true; do
+	case "$1" in 
+	-t)	gent="YES"; new_script_name="$2"; shift 2; ;;
+	-x)     shift 1; set -x;;
+	-h)     help 1;;
+	--)     shift; break;;
+	*)      echo "Error: Unknown command-line parameter \"$1\"" >&2 && exit 1;;
+	esac
+done
+
+if [ "${gent:-NO}" = "YES" ]; then
+	template "$new_script_name"
+	exit "$?"
+fi
+
+#---template-end---
+
+srcdir="$(dirname "$0")"
+
+[ -f "$srcdir"/config.ninja ] && rm "$srcdir"/config.ninja
+
+echo "platform = $(uname -s)" > "$srcdir"/config.ninja
+
+exec ninja

+ 20 - 0
symon/lib/build.ninja

@@ -0,0 +1,20 @@
+cdir = $cdir/lib
+
+cflags = $cflags -I$pdir -I$cdir
+
+build $cdir/error.o: cc $cdir/error.c || $cdir/conf.h
+build $cdir/lex.o: cc $cdir/lex.c || $cdir/conf.h
+build $cdir/xmalloc.o: cc $cdir/xmalloc.c || $cdir/conf.h
+build $cdir/net.o: cc $cdir/net.c || $cdir/conf.h
+build $cdir/data.o: cc $cdir/data.c || $cdir/conf.h
+
+build $cdir/libsym.a: static_lib $cdir/error.o $cdir/lex.o $cdir/xmalloc.o $cdir/net.o $cdir/data.o
+
+build $cdir/diskname.o: cc $cdir/diskname.c
+build $cdir/percentages.o: cc $cdir/percentages.c
+build $cdir/smart.o: cc $cdir/smart.c
+
+build $cdir/libprobe.a: static_lib $cdir/diskname.o $cdir/percentages.o $cdir/smart.o
+
+build $cdir/conf.h: run_script $cdir/gen_conf.sh
+  env = SYSCONFDIR=$sysconfdir V=$v OS=$platform PDIR=$pdir

+ 24 - 0
symon/lib/gen_conf.sh

@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -euC
+
+if [ "$#" -ne 1 ]; then
+	echo "Wrong number of arguments" >&2
+	exit 1
+fi
+
+output="$1"
+
+[ -f "$1" ] && rm "$output"
+
+cat > "$output" <<EOF
+/* This file was automagically generated by $0 */
+#define SYMON_CONFIG_FILE "${SYSCONFDIR}/symon.conf"
+#define SYMON_VERSION "${V}"
+#define SYMON_PLATFORM "${OS}"
+#include "platform.h"
+EOF
+
+if [ -f $PDIR/conf.sh ]; then 
+	/bin/sh $PDIR/conf.sh >> "$output"
+fi

+ 50 - 0
symon/parameters.ninja

@@ -0,0 +1,50 @@
+v = 2.88
+
+ar = ar
+cc = cc
+cflags = -Wall -g
+install = install
+lorder = lorder
+tsort = tsort
+nroff = nroff
+ranlib = ranlib
+strip = strip
+pod2man = pod2man
+
+rrddir = /usr/local
+bindir = libexec
+mandir = man
+shrdir = share/symon
+exadir = share/examples/symon
+clientdir = $shrdir/client
+
+prefix = /usr/local
+sysconfdir = /etc
+
+installuser = root
+installgroupdir = bin
+installgroupfile = wheel
+
+rule cc
+  depfile = $out.d
+  command = $cc -MD -MF $out.d $cflags -o $out -c $in
+
+rule link
+  command = $cc -o $out $ldflags $in
+
+rule nroff
+  command = $nroff -mandoc $in > $out || rm $out
+# || (rm -f $out; false) <- add this??
+
+rule pod2man
+  command = $pod2man $in > $out || rm $out
+# || (rm -f $out; false) <- add this??
+
+rule static_lib
+  command = $ar cq $out `$lorder $in | $tsort` && ranlib $out
+
+rule symlink
+  command = ln -fs `readlink -f $in` $out
+
+rule run_script
+  command = env $env ./$in ./$out

+ 7 - 0
symon/platform/OpenBSD/build.ninja

@@ -0,0 +1,7 @@
+symux_libs = -L/usr/X11R6/lib -lfontconfig
+nroff = mandoc
+
+build $pdir/sm_cpuiow.c: symlink $stubpdir/sm_cpuiow.c
+build $pdir/sm_flukso.c: symlink $stubpdir/sm_flukso.c
+build $pdir/sm_load.c: symlink $stubpdir/sm_load.c
+build $pdir/sm_pfq.c: symlink $stubpdir/sm_pfq.c

+ 33 - 0
symon/symon/build.ninja

@@ -0,0 +1,33 @@
+cdir = $cdir/symon
+
+libs = $libs -L$rdir/lib -lsym -lprobe
+cflags = $cflags -I$rdir/lib -I$pdir -I$cdir
+
+build $pdir/sm_cpu.o: cc $pdir/sm_cpu.c || $cdir/conf.h
+build $pdir/sm_cpuiow.o: cc $pdir/sm_cpuiow.c || $cdir/conf.h
+build $pdir/sm_debug.o: cc $pdir/sm_debug.c || $cdir/conf.h
+build $pdir/sm_df.o: cc $pdir/sm_df.c || $cdir/conf.h
+build $pdir/sm_flukso.o: cc $pdir/sm_flukso.c || $cdir/conf.h
+build $pdir/sm_if.o: cc $pdir/sm_if.c || $cdir/conf.h
+build $pdir/sm_io.o: cc $pdir/sm_io.c || $cdir/conf.h
+build $pdir/sm_load.o: cc $pdir/sm_load.c || $cdir/conf.h
+build $pdir/sm_mbuf.o: cc $pdir/sm_mbuf.c || $cdir/conf.h
+build $pdir/sm_mem.o: cc $pdir/sm_mem.c || $cdir/conf.h
+build $pdir/sm_pf.o: cc $pdir/sm_pf.c || $cdir/conf.h
+build $pdir/sm_pfq.o: cc $pdir/sm_pfq.c || $cdir/conf.h
+build $pdir/sm_proc.o: cc $pdir/sm_proc.c || $cdir/conf.h
+build $pdir/sm_sensor.o: cc $pdir/sm_sensor.c || $cdir/conf.h
+build $pdir/sm_smart.o: cc $pdir/sm_smart.c || $cdir/conf.h
+
+build $cdir/symon.o: cc $cdir/symon.c || $cdir/conf.h
+build $cdir/readconf.o: cc $cdir/readconf.c || $cdir/conf.h
+build $cdir/symonnet.o: cc $cdir/symonnet.c || $cdir/conf.h
+
+build $cdir/conf.h: run_script $cdir/gen_conf.sh
+  env = SYSCONFDIR=$sysconfdir V=$v OS=$platform PDIR=$pdir
+
+build $cdir/symon: link $cdir/symon.o $cdir/readconf.o $cdir/symonnet.o $pdir/sm_cpu.o $pdir/sm_cpuiow.o $pdir/sm_debug.o $pdir/sm_df.o $pdir/sm_flukso.o $pdir/sm_if.o $pdir/sm_io.o $pdir/sm_load.o $pdir/sm_mbuf.o $pdir/sm_mem.o $pdir/sm_pf.o $pdir/sm_pfq.o $pdir/sm_proc.o $pdir/sm_sensor.o $pdir/sm_smart.o $rdir/lib/libsym.a $rdir/lib/libprobe.a
+
+# TODO: do install
+
+# TODO: do conf.h

+ 24 - 0
symon/symon/gen_conf.sh

@@ -0,0 +1,24 @@
+#!/bin/sh
+
+set -euC
+
+if [ "$#" -ne 1 ]; then
+	echo "Wrong number of arguments" >&2
+	exit 1
+fi
+
+output="$1"
+
+[ -f "$1" ] && rm "$output"
+
+cat > "$output" <<EOF
+/* This file was automagically generated by $0 */
+#define SYMON_CONFIG_FILE "${SYSCONFDIR}/symon.conf"
+#define SYMON_VERSION "${V}"
+#define SYMON_PLATFORM "${OS}"
+#include "platform.h"
+EOF
+
+if [ -f $PDIR/conf.sh ]; then 
+	/bin/sh $PDIR/conf.sh >> "$output"
+fi