summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkdx <kikoodx@paranoici.org>2023-07-12 22:03:48 +0200
committerkdx <kikoodx@paranoici.org>2023-07-12 22:07:19 +0200
commit55c668cc5642a03e4867073dd732c6808c7cef27 (patch)
tree03bdb9d0e66de4be7d5656bb50dc6751b21d5393
parent01cc3bda91c2609e474b634797d32e8db0bd796e (diff)
downloadfld-55c668cc5642a03e4867073dd732c6808c7cef27.tar.gz
generate module
-rw-r--r--.gitignore6
-rw-r--r--Makefile26
-rw-r--r--_head.cpp4
-rw-r--r--_tail.cpp21
-rwxr-xr-xbuild.sh9
-rw-r--r--compile_flags.txt2
-rwxr-xr-xcreate_FLD.cpp.sh23
-rw-r--r--demo.cpp2
8 files changed, 81 insertions, 12 deletions
diff --git a/.gitignore b/.gitignore
index cba7efc..6caf53f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1 +1,5 @@
-a.out
+/FLD.*
+/build*
+/a.out
+/demo
+/demo.o
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..8a3a8e9
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,26 @@
+CFLAGS = -O3 -std=c++20 -Wall -Wextra
+LIBS = -lSDL2
+SRC = FLD.pcm demo.cpp
+
+all: demo
+
+FLD.cpp:
+ ./create_FLD.cpp.sh
+
+FLD.pcm: FLD.cpp
+ clang++ $(CFLAGS) -c -o $@ -Xclang -emit-module-interface $<
+
+demo: demo.o FLD.pcm
+ clang++ $(CFLAGS) -o $@ demo.o FLD.pcm $(LIBS)
+
+demo.o: demo.cpp FLD.pcm
+ clang++ $(CFLAGS) -fprebuilt-module-path=. -c -o $@ demo.cpp
+
+clean:
+ rm -rf FLD.cpp FLD.pcm TZR.h demo demo.o build_FLD.cpp
+
+re:
+ @$(MAKE) --no-print-directory clean
+ @$(MAKE) --no-print-directory all
+
+.PHONY: all FLD.cpp clean re
diff --git a/_head.cpp b/_head.cpp
new file mode 100644
index 0000000..94fa132
--- /dev/null
+++ b/_head.cpp
@@ -0,0 +1,4 @@
+/* Licensing information can be found at the end of the file. */
+
+module;
+
diff --git a/_tail.cpp b/_tail.cpp
new file mode 100644
index 0000000..fd8ac30
--- /dev/null
+++ b/_tail.cpp
@@ -0,0 +1,21 @@
+/*
+** Copyright (c) 2023 kdx
+**
+** Permission is hereby granted, free of charge, to any person obtaining a copy
+** of this software and associated documentation files (the "Software"), to
+** deal in the Software without restriction, including without limitation the
+** rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
+** sell copies of the Software, and to permit persons to whom the Software is
+** furnished to do so, subject to the following conditions:
+**
+** The above copyright notice and this permission notice shall be included in
+** all copies or substantial portions of the Software.
+**
+** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+** IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+** FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+** AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+** LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+** FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+** IN THE SOFTWARE.
+*/
diff --git a/build.sh b/build.sh
deleted file mode 100755
index 8802526..0000000
--- a/build.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/sh
-CFLAGS="-std=c++20 -Wall -Wextra -iquotesrc"
-LIBS="-lSDL2"
-SRC="src/*.cpp demo.cpp"
-
-g++ $CFLAGS $SRC $LIBS
-echo g++
-clang++ $CFLAGS $SRC $LIBS
-echo clang++
diff --git a/compile_flags.txt b/compile_flags.txt
index a2f670f..85c506c 100644
--- a/compile_flags.txt
+++ b/compile_flags.txt
@@ -1,4 +1,4 @@
-Wall
-Wextra
-std=c++20
--iquotesrc
+-fprebuilt-module-path=.
diff --git a/create_FLD.cpp.sh b/create_FLD.cpp.sh
new file mode 100755
index 0000000..69b9d63
--- /dev/null
+++ b/create_FLD.cpp.sh
@@ -0,0 +1,23 @@
+#!/bin/sh
+BUILDDIR=build_FLD.cpp
+rm -Rf "$BUILDDIR"
+mkdir -p "$BUILDDIR"
+
+for FILE in src/FLD.hpp src/*.cpp; do
+ grep "^#include <" "$FILE" >>"$BUILDDIR/includes"
+ printf '/* %s */\n' "$FILE" >>"$BUILDDIR/sources"
+ grep -v '^#include' "$FILE" \
+ | grep -v "^#pragma" \
+ | sed 's/^class FLD/export class FLD/' \
+ >>"$BUILDDIR/sources"
+done
+
+cp _head.cpp "$BUILDDIR/out"
+sort -u "$BUILDDIR/includes" >>"$BUILDDIR/out"
+printf '\nexport module FLD;\n' >>"$BUILDDIR/out"
+cat "$BUILDDIR/sources" >>"$BUILDDIR/out"
+printf '\n' >>"$BUILDDIR/out"
+cat _tail.cpp >>"$BUILDDIR/out"
+git log -n1 --format="/* commit hash: %H */" >>"$BUILDDIR/out"
+
+cp "$BUILDDIR/out" FLD.cpp
diff --git a/demo.cpp b/demo.cpp
index 46a6788..5ed0da6 100644
--- a/demo.cpp
+++ b/demo.cpp
@@ -1,4 +1,4 @@
-#include "FLD.hpp"
+import FLD;
static int
main_loop(FLD& fld, [[maybe_unused]] void *udata)