diff --git a/.gitignore b/.gitignore
index edfff0d..c5e35f7 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,17 +1,17 @@
-.deps/
-.libs/
-config.mk
/cli/rtbuf
+config.mk
/doc/
+.gdb_history
+*.gcda
+*.gcno
/gtk3/rtbuf-gtk3
/gtk3/rtbuf_gtk3_resources.c
-/lib/*_type
-/lib/*_type.h
+*.la
/lib/.*.log
/lib/*/.*.log
-.gdb_history
-*.la
+/lib/*_type
+/lib/*_type.h
+.libs/
*.lo
*.o
-*.gcno
-*.gcda
\ No newline at end of file
+*.tmp
diff --git a/Makefile b/Makefile
index a5600a1..985391d 100644
--- a/Makefile
+++ b/Makefile
@@ -1,3 +1,16 @@
+## rtbuf
+## Copyright 2018-2022 kmx.io <contact@kmx.io>
+##
+## Permission is hereby granted to use this software granted
+## the above copyright notice and this permission paragraph
+## are included in all copies and substantial portions of this
+## software.
+##
+## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+## THIS SOFTWARE.
+
all: build
build:
@@ -21,4 +34,11 @@ install:
${MAKE} -C ${PWD}/cli install
${MAKE} -C ${PWD}/gtk3 install
+licence:
+ elixir bin/header.exs config.subr ${RTBUF_CONFIGURES}
+ elixir bin/header.exs Makefile ${RTBUF_MAKEFILES}
+ elixir bin/header.exs librtbuf/rtbuf.h ${RTBUF_C_SOURCES}
+
.PHONY: all build clean doc install
+
+include config.mk
diff --git a/bin/header.exs b/bin/header.exs
new file mode 100644
index 0000000..3d35f64
--- /dev/null
+++ b/bin/header.exs
@@ -0,0 +1,89 @@
+## cl89
+## Copyright 2022 kmx.io <contact@kmx.io>
+##
+## Permission is hereby granted to use this software granted
+## the above copyright notice and this permission paragraph
+## are included in all copies and substantial portions of this
+## software.
+##
+## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+## THIS SOFTWARE.
+
+defmodule Header.C do
+ def split(src) do
+ split(src, "")
+ end
+
+ def split("/*" <> rest, "") do
+ split(rest, "/*")
+ end
+ def split("/*" <> rest, acc) do
+ {"", acc <> "/*" <> rest}
+ end
+ def split("*/\n" <> rest, acc) do
+ header = acc <> "*/"
+ {header, rest}
+ end
+ def split(<<c, rest::binary>>, acc) when is_binary(acc) do
+ split(rest, acc <> <<c>>)
+ end
+ def split("", acc) do
+ {"", acc}
+ end
+
+ def main([src_path | dest_paths]) do
+ case File.read(src_path) do
+ {:ok, src} ->
+ {header, _} = split(src)
+ Enum.each dest_paths, fn dest_path ->
+ {:ok, dest} = File.read(dest_path)
+ {_, rest} = split(dest)
+ result = header <> "\n" <> rest
+ File.write(dest_path, result)
+ end
+ {:error, e} ->
+ IO.inspect "Error: #{src_path}: #{e}"
+ end
+ end
+end
+
+defmodule Header.Make do
+ def split(src) do
+ split(src, [])
+ end
+
+ def split([line = ("#" <> _) | rest], acc) do
+ split(rest, [line | acc])
+ end
+ def split(rest, acc) do
+ {Enum.reverse(acc) |> Enum.join("\n"), rest |> Enum.join("\n")}
+ end
+
+ def main([src_path | dest_paths]) do
+ {:ok, src} = File.read(src_path)
+ src_lines = String.split(src, "\n")
+ {header, _} = split(src_lines)
+ Enum.each dest_paths, fn dest_path ->
+ {:ok, dest} = File.read(dest_path)
+ dest_lines = String.split(dest, "\n")
+ {_, rest} = split(dest_lines)
+ result = header <> "\n" <> rest
+ File.write(dest_path, result)
+ end
+ end
+end
+
+src_path = hd(System.argv)
+module = case src_path do
+ "Makefile" -> Header.Make
+ "configure" -> Header.Make
+ "config.subr" -> Header.Make
+ _ ->
+ case Regex.run(~r/[.][ch]$/, src_path) do
+ [_] -> Header.C
+ _ -> raise "error"
+ end
+ end
+module.main(System.argv)
diff --git a/config.subr b/config.subr
index 1c0ccd7..ad2b9df 100644
--- a/config.subr
+++ b/config.subr
@@ -1,4 +1,17 @@
#!/bin/sh
+## rtbuf
+## Copyright 2018-2022 kmx.io <contact@kmx.io>
+##
+## Permission is hereby granted to use this software granted
+## the above copyright notice and this permission paragraph
+## are included in all copies and substantial portions of this
+## software.
+##
+## THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
+## PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
+## AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
+## THIS SOFTWARE.
+
set -e
o_rule() {
@@ -37,8 +50,17 @@ require_pkg_config() {
fi
}
+update_config_mk() {
+ if ! cmp "${CONFIG_MK}" config.mk >/dev/null 2>&1; then
+ mv "${CONFIG_MK}" config.mk
+ echo "$PWD/config.mk"
+ else
+ rm "${CONFIG_MK}"
+ fi
+}
+
CONFIG_MK=config.mk
-echo "$PWD/${CONFIG_MK}"
+CONFIG_MK=".config.mk.tmp"
echo "# config.mk generated by configure" > ${CONFIG_MK}
VER=0.4
diff --git a/configure b/configure
index 26f96bb..41e4b09 100755
--- a/configure
+++ b/configure
@@ -5,6 +5,17 @@ export SRCDIR="$PWD"
. ./config.subr
+RTBUF_DIRS="librtbuf lib cli gtk3"
+RTBUF_CONFIGURES="$(find . -name "configure" | tr '\n' ' ')"
+RTBUF_MAKEFILES="$(find . -name "Makefile" | tr '\n' ' ')"
+RTBUF_C_SOURCES="$(find $RTBUF_DIRS -name "[a-z]*.c" -or -name "[a-z]*.h" -or -name "[a-z]*.c.in" -or -name "[a-z]*.h.in" | tr '\n' ' ')"
+
+echo "RTBUF_CONFIGURES = $RTBUF_CONFIGURES" >> ${CONFIG_MK}
+echo "RTBUF_MAKEFILES = $RTBUF_MAKEFILES" >> ${CONFIG_MK}
+echo "RTBUF_C_SOURCES = $RTBUF_C_SOURCES" >> ${CONFIG_MK}
+
+update_config_mk
+
(cd librtbuf && ./configure)
(cd lib && ./configure)
(cd cli && ./configure)