summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRafael G. Martins <rafael@rafaelmartins.eng.br>2024-06-02 00:01:35 +0200
committerRafael G. Martins <rafael@rafaelmartins.eng.br>2024-06-02 00:01:35 +0200
commit3f82948f4f9fb9d3e1332f306e36c317c67f5575 (patch)
treec912501433a7a369ca7cf09cc060c0c4a98c28a7
parent202bf3c23141f8efb4b154d72400c822b4726007 (diff)
downloadblogc-3f82948f4f9fb9d3e1332f306e36c317c67f5575.tar.gz
blogc-3f82948f4f9fb9d3e1332f306e36c317c67f5575.tar.bz2
blogc-3f82948f4f9fb9d3e1332f306e36c317c67f5575.zip
make: added setting to allow enforcing to run from make
-rw-r--r--man/blogcfile.5.ronn8
-rw-r--r--src/blogc-make/main.c8
-rw-r--r--src/blogc-make/settings.c1
-rwxr-xr-xtests/blogc-make/check_blogc_make.sh.in25
4 files changed, 41 insertions, 1 deletions
diff --git a/man/blogcfile.5.ronn b/man/blogcfile.5.ronn
index 7feb964..669086b 100644
--- a/man/blogcfile.5.ronn
+++ b/man/blogcfile.5.ronn
@@ -125,6 +125,12 @@ however these rules can be customized with the following settings, from the
in the `[posts]` section, in descending order. This setting is compatible with
`html_order` and `atom_order` settings, to control the order of the posts.
+ * `run_from_make` (default: `false`):
+ If true, enforces blogc-make(1) to check if it is running as a make(1) subprocess,
+ and exit with an error otherwise. This is useful when blogc-make(1) is called by
+ make(1) as part of a larger build infrastructure, and calling blogc-make(1) directly
+ could cause errors due to some generated dependencies missing.
+
* `source_ext` (default: `.txt`):
The extension of the source files.
@@ -209,4 +215,4 @@ Rafael G. Martins &lt;<rafael@rafaelmartins.eng.br>&gt;
## SEE ALSO
-blogc(1), blogc-make(1), blogc-template(7) strftime(3)
+blogc(1), blogc-make(1), make(1), blogc-template(7), strftime(3)
diff --git a/src/blogc-make/main.c b/src/blogc-make/main.c
index 7007c1a..5643a45 100644
--- a/src/blogc-make/main.c
+++ b/src/blogc-make/main.c
@@ -120,6 +120,14 @@ main(int argc, char **argv)
ctx->dev = dev;
ctx->verbose = verbose;
+ if (bc_str_to_bool(bm_ctx_settings_lookup_str(ctx, "run_from_make"))) {
+ if (getenv("MAKEFLAGS") == NULL) {
+ fprintf(stderr, "blogc-make: error: must run from `make`, try:\n\n $ make\n");
+ rv = 1;
+ goto cleanup;
+ }
+ }
+
rv = bm_rule_executor(ctx, rules);
cleanup:
diff --git a/src/blogc-make/settings.c b/src/blogc-make/settings.c
index 2b78177..20bf3f8 100644
--- a/src/blogc-make/settings.c
+++ b/src/blogc-make/settings.c
@@ -47,6 +47,7 @@ static const struct default_settings_map {
// generic
{"date_format", "%b %d, %Y, %I:%M %p GMT"},
{"locale", NULL},
+ {"run_from_make", NULL},
{NULL, NULL},
};
diff --git a/tests/blogc-make/check_blogc_make.sh.in b/tests/blogc-make/check_blogc_make.sh.in
index 179529a..50af17c 100755
--- a/tests/blogc-make/check_blogc_make.sh.in
+++ b/tests/blogc-make/check_blogc_make.sh.in
@@ -20,6 +20,31 @@ trap_func() {
trap trap_func EXIT
+mkdir -p "${TEMP}/proj/"
+
+
+### minimal settings, failure when not running from make
+
+cat > "${TEMP}/proj/blogcfile" <<EOF
+[global]
+AUTHOR_NAME = Lol
+AUTHOR_EMAIL = author@example.com
+SITE_TITLE = Lol's Website
+SITE_TAGLINE = WAT?!
+BASE_DOMAIN = http://example.org
+
+[settings]
+run_from_make = true
+EOF
+
+set +e
+${TESTS_ENVIRONMENT} ${BLOGC_MAKE} -f "${TEMP}/proj/blogcfile" 2>&1 | tee "${TEMP}/output.txt"
+set -e
+
+grep "error: must run from " "${TEMP}/output.txt"
+
+rm -rf "${TEMP}/proj/"
+
mkdir -p "${TEMP}"/proj{,/templates,/content/post}