diff --git a/Makefile b/Makefile
index 091f426bd85ae2880fb07f3df9d8e2fa63621412..0070b703ea0af36743878d2264259bc04edb6b70 100644
--- a/Makefile
+++ b/Makefile
@@ -8,7 +8,9 @@ gmnic: $(gmnic_objects)
@printf 'CCLD\t$@\n'
@$(CC) $(LDFLAGS) $(LIBS) -o $@ $(gmnic_objects)
-.SUFFIXES: .c .o
+doc/gmnic.1: doc/gmnic.scd
+
+.SUFFIXES: .c .o .scd .1
.c.o:
@printf 'CC\t$@\n'
@@ -17,10 +19,16 @@ @grep {body}lt; $(OUTDIR)/cppcache >/dev/null || \
$(CPP) $(CFLAGS) -MM -MT $@ {body}lt; >> $(OUTDIR)/cppcache
@$(CC) -c $(CFLAGS) -o $@ {body}lt;
+.scd.1:
+ @printf 'SCDOC\t$@\n'
+ @$(SCDOC) < {body}lt; > $@
+
+docs: doc/gmnic.1
+
clean:
@rm -f gmnic
distclean: clean
@rm -rf "$(OUTDIR)"
-.PHONY: clean distclean
+.PHONY: clean distclean docs
diff --git a/config.sh b/config.sh
index ef533ec79238744458fb2e69b95e3d34333c0e5a..b93815ada4a25ec508e7a86cc79b9e9be3eba428 100644
--- a/config.sh
+++ b/config.sh
@@ -5,6 +5,7 @@ AS=${AS:-as}
CC=${CC:-cc}
CFLAGS=${CFLAGS:-}
LD=${LD:-ld}
+SCDOC=${SCDOC:-scdoc}
for arg
do
@@ -104,9 +105,19 @@
find_library OpenSSL libssl
find_library OpenSSL libcrypto
+ printf "Checking for scdoc... "
+ if scdoc -v >/dev/null 2>&1
+ then
+ echo yes
+ all="$all docs"
+ else
+ echo no
+ fi
+
printf "Creating $outdir/config.mk... "
cat <<-EOF > "$outdir"/config.mk
CC=$CC
+ SCDOC=$SCDOC
LIBS=$LIBS
PREFIX=${PREFIX:-/usr/local}
OUTDIR=${outdir}
@@ -153,6 +164,7 @@
printf "Populating build dir... "
populate "$srcdir/include"
populate "$srcdir/src"
+ populate "$srcdir/doc"
ln -sf "$srcdir"/Makefile ./
echo done
}
diff --git a/doc/gmnic.scd b/doc/gmnic.scd
new file mode 100644
index 0000000000000000000000000000000000000000..9eec29cfddf50c2678ef7ae080275fbfbe3fcaa1
--- /dev/null
+++ b/doc/gmnic.scd
@@ -0,0 +1,65 @@
+gmnic(1)
+
+# NAME
+
+gmnic - Gemini client
+
+# SYNPOSIS
+
+*gmnic* [-46lLiIN] [-E _path_] [-d _input_] [-D _path_] _gemini://..._
+
+# DESCRIPTION
+
+*gmnic* executes a gemini request and, if successful, prints the response body
+to stdout.
+
+If an error is returned, information is printed to stderr and the process exits
+with a non-zero exit status equal to the response status. If a response is
+returned which is neither successful or an error, the response status and meta
+text are printed to stderr.
+
+If the server requests user input, a prompt is shown and a second request is
+performed with the user's input supplied to the server.
+
+# OPTIONS
+
+*-4*
+ Force the connection to use IPv4.
+
+*-6*
+ Force the connection to use IPv6.
+
+*-d* _input_
+ If the server requests user input, a second request is performed with
+ the given input string as the user input.
+
+*-D* _path_
+ If the server requests user input, _path_ is opened and read, and a
+ second request is performed with the contents of _path_ as the user
+ input.
+
+*-E* _path_[:_password_]
+ Sets the path to the client certificate to use (and optionally a
+ password). If the filename contains ":" but the certificate does not
+ accept a password, append ":" to the path and it will be intepreted as
+ an empty password.
+
+*-l*
+ For *text/\** responses, gmnic normally adds a line feed if stdout is a
+ TTY and the response body does not include one. This flag suppresses
+ this behavior.
+
+*-L*
+ Follow redirects.
+
+*-i*
+ Print the response status and meta text to stdout.
+
+*-I*
+ Print the response status and meta text to stdout, and suppress the
+ printing of the response body to stdout.
+
+*-N*
+ Suppress the input prompt if the server requests an input, and instead
+ print a diagnostic message and exit with a zero (successful) status
+ code.