]> git.armaanb.net Git - stagit.git/commitdiff
Make Chroma and libcmark-gfm optional
authorArmaan Bhojwani <me@armaanb.net>
Tue, 6 Apr 2021 17:24:03 +0000 (13:24 -0400)
committerArmaan Bhojwani <me@armaanb.net>
Tue, 6 Apr 2021 17:24:44 +0000 (13:24 -0400)
Makefile
README.md
src/stagit.c

index eb9203eb0daab6633d317ac4e8405ff9f1a6475d..94ffe3002bcdce93ab9057ed2211241112174605 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -9,13 +9,24 @@ MANPREFIX = ${PREFIX}/man
 DOCPREFIX = ${PREFIX}/share/doc/${NAME}
 SHAREPREFIX = ${PREFIX}/share/${NAME}
 
+LIBCMARK = $(shell pkg-config --silence-errors --libs libcmark-gfm > /dev/null; echo $$?)
+CHROMA = $(shell which chroma; echo $$?)
 LIBGIT_INC = -I/usr/local/include
-LIBGIT_LIB = -L/usr/local/lib -lgit2 -lcmark-gfm
+LIBS = -L/usr/local/lib `pkg-config --libs libgit2`
+
+ifeq (${CHROMA}, 0)
+       STAGIT_CPPFLAGS := ${STAGIT_CPPFLAGS} -DHAS_CHROMA
+endif
+
+ifeq (${LIBCMARK}, 0)
+       LIBS := ${LIBS} -lcmark-gfm
+       STAGIT_CPPFLAGS := ${STAGIT_CPPFLAGS} -DHAS_CMARK
+endif
 
 # use system flags.
 STAGIT_CFLAGS = ${LIBGIT_INC} ${CFLAGS}
-STAGIT_LDFLAGS = ${LIBGIT_LIB} ${LDFLAGS}
-STAGIT_CPPFLAGS = -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE -D_BSD_SOURCE
+STAGIT_LDFLAGS = ${LIBS} ${LDFLAGS}
+STAGIT_CPPFLAGS := ${STAGIT_CPPFLAGS} -D_XOPEN_SOURCE=700 -D_DEFAULT_SOURCE -D_BSD_SOURCE
 
 SRC = \
        src/stagit.c\
index a06eb0a04b71906ff0f812b3e5391dcfe8bb60d3..c7cdf40baded5204c63dd82bfd320fcac2145c89 100644 (file)
--- a/README.md
+++ b/README.md
@@ -30,9 +30,10 @@ $ make
   - C compiler (C99).
   - libc (tested with OpenBSD, FreeBSD, NetBSD, Linux: glibc and musl).
   - libgit2 (v0.22+).
-  - Chroma
-  - cmark-gfm
+  - Chroma (optional - for syntax highlighting).
+  - libcmark-gfm (optional - for rendering Markdown).
   - POSIX make (optional).
+  - pkg-config (if using the makefile).
 
 ## Documentation
 See man pages: stagit(1) and stagit-index(1).
index 247fe704d42aac14c2b78348849f7c4d11974680..be6d8593c9913d3ac5f02ba7fc2381d46dcaa9ae 100644 (file)
 #include <unistd.h>
 
 #include <git2.h>
+
+#ifdef HAS_CMARK
 #include <cmark-gfm.h>
+#endif
 
 #include "cp.h"
 #include "compat.h"
@@ -414,12 +417,17 @@ void
 call_chroma(const char *filename, FILE *fp, const char *s, size_t len)
 {
        htmlized = false;
+       char *html = "";
        // Flush HTML-file
        fflush(fp);
 
-       char *html = cmark_markdown_to_html(s, len, CMARK_OPT_DEFAULT);
+#ifdef HAS_CMARK
+       html = cmark_markdown_to_html(s, len, CMARK_OPT_DEFAULT);
        if (strcmp(get_ext(filename), "md") == 0) htmlized = true;
+#endif
 
+
+#ifdef HAS_CHROMA
        if (!htmlized) {
                // Copy STDOUT
                int stdout_copy = dup(1);
@@ -450,6 +458,9 @@ call_chroma(const char *filename, FILE *fp, const char *s, size_t len)
        } else {
                fprintf(fp, "%s", html);
        }
+#else
+               fprintf(fp, "<pre>%s</pre>", s);
+#endif
 }
 
 void