From 8531a023f0a3db50897ea77f38a5d59909a97825 Mon Sep 17 00:00:00 2001 From: lonkaars Date: Tue, 4 Oct 2022 17:10:08 +0200 Subject: makefile build instead of janky shell scripts --- .gitignore | 1 + common.mk | 29 +++++++++++++++++++++++++++++ opdracht-1/build | 1 - opdracht-1/makefile | 3 +++ opdracht-2/build | 3 --- opdracht-2/makefile | 9 +++++++++ opdracht-2/reset-2.sql | 2 -- opdracht-2/reset.sql | 2 ++ render-opdracht | 12 ------------ 9 files changed, 44 insertions(+), 18 deletions(-) create mode 100644 common.mk delete mode 120000 opdracht-1/build create mode 100644 opdracht-1/makefile delete mode 100755 opdracht-2/build create mode 100644 opdracht-2/makefile delete mode 100644 opdracht-2/reset-2.sql delete mode 100755 render-opdracht diff --git a/.gitignore b/.gitignore index 9b41e02..3fc3088 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ opdracht-*/*.md +opdracht-*/.tmp.sql opdracht-*/opdracht.pdf opdracht-*/opdracht-*.md diff --git a/common.mk b/common.mk new file mode 100644 index 0000000..8a0327d --- /dev/null +++ b/common.mk @@ -0,0 +1,29 @@ +RM = rm -f +MYSQL = mysql -Hu root mysql +M4 = m4 + +RESET_SQL += reset.sql +QUERY_SQL += $(wildcard q*.sql) +TESTS_SQL += $(wildcard t*.sql) + +TESTS_MD = $(patsubst %.sql,%.md, $(TESTS_SQL)) + +.PHONY: $(TARGET).m4 $(TESTS_SQL) .tmp.sql clean reset + +all: $(TARGET).md + +.tmp.sql: $(RESET_SQL) $(QUERY_SQL) + cat $(RESET_SQL) $(QUERY_SQL) > .tmp.sql + +reset: .tmp.sql + $(MYSQL) < .tmp.sql + +%.md: %.sql reset + $(MYSQL) < $< &> $@ + +$(TARGET).md: $(TESTS_MD) $(TARGET).m4 + $(M4) $(TARGET).m4 > $(TARGET).md + +clean: + $(RM) $(wildcard *.md) .tmp.sql + diff --git a/opdracht-1/build b/opdracht-1/build deleted file mode 120000 index 1fb5c6e..0000000 --- a/opdracht-1/build +++ /dev/null @@ -1 +0,0 @@ -../render-opdracht \ No newline at end of file diff --git a/opdracht-1/makefile b/opdracht-1/makefile new file mode 100644 index 0000000..b91dfe8 --- /dev/null +++ b/opdracht-1/makefile @@ -0,0 +1,3 @@ +TARGET := opdracht-1 + +include ../common.mk diff --git a/opdracht-2/build b/opdracht-2/build deleted file mode 100755 index 6f370cb..0000000 --- a/opdracht-2/build +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -cat ../opdracht-1/reset.sql ../opdracht-1/q*.sql reset-2.sql > reset.sql -source ../render-opdracht diff --git a/opdracht-2/makefile b/opdracht-2/makefile new file mode 100644 index 0000000..19a0072 --- /dev/null +++ b/opdracht-2/makefile @@ -0,0 +1,9 @@ +TARGET = opdracht-2 +RESET_SQL += ../opdracht-1/.tmp.sql + +all: $(TARGET).md + +../opdracht-1/.tmp.sql: + make -C ../opdracht-1 + +include ../common.mk diff --git a/opdracht-2/reset-2.sql b/opdracht-2/reset-2.sql deleted file mode 100644 index 08ec0f3..0000000 --- a/opdracht-2/reset-2.sql +++ /dev/null @@ -1,2 +0,0 @@ -drop table Status; - diff --git a/opdracht-2/reset.sql b/opdracht-2/reset.sql index e69de29..3e90143 100644 --- a/opdracht-2/reset.sql +++ b/opdracht-2/reset.sql @@ -0,0 +1,2 @@ +drop table if exists Status; + diff --git a/render-opdracht b/render-opdracht deleted file mode 100755 index cc4fa48..0000000 --- a/render-opdracht +++ /dev/null @@ -1,12 +0,0 @@ -#!/bin/bash -bye () { - echo "run me as root!" - exit 1 -} - -[ $(id -g) -ne 0 ] && bye -cat reset.sql q*.sql | mysql -u root mysql -for file in t*.sql; do - mysql -Hu root mysql < "$file" &> "${file/%.sql}.md" -done -m4 `basename $PWD`.m4 > `basename $PWD`.md -- cgit v1.2.3