Browse Source

Add Atom feed generation to the makefile

Jens Pitkänen 1 year ago
8 changed files with 81 additions and 125 deletions
  1. +2
  2. +19
  3. +6
  4. +0
  5. +24
  6. +11
  7. +2
  8. +17

+ 2
- 0
.gitignore View File

@@ -1,3 +1,5 @@

+ 19
- 11
Makefile View File

@@ -1,25 +1,33 @@

POSTS = public/2019/07/06/make.html
RESOURCES = public/dark.css public/light.css
TEMPLATE = template.html
POSTS = public/2019/07/06/make.html
POSTS_XML = $(POSTS:.html=.xml)
RESOURCES = public/dark.css public/light.css public/feed.xml
TEMPLATE_POST_HTML = templates/post.html
TEMPLATE_POST_ATOM = templates/post.xml
TEMPLATE_FEED_ATOM = templates/feed.xml


public/dark.css: public/default.css
sed -e 's/(prefers-color-scheme: light)/not all/g' -e 's/(prefers-color-scheme: dark)/all/g' $? > $@
public/light.css: public/default.css
sed -e 's/(prefers-color-scheme: light)/all/g' -e 's/(prefers-color-scheme: dark)/not all/g' $? > $@

public/feed.xml: $(POSTS_XML)
cat $(POSTS_XML) > $@.tmp
awk -f templater.awk $@.tmp $(TEMPLATE_FEED_ATOM) > $@.tmp.tmp
cat $@.tmp | awk "/<updated>/ { print }" | sort | tail -n 1 | awk -f templater.awk -v REPLACE="{{updated}}" - $@.tmp.tmp > $@
rm $@.tmp $@.tmp.tmp

# Touching the .md files to trigger re-rendering if the template file is changed
touch $@

.SUFFIXES: .html .md
# TODO: RSS feed support
.SUFFIXES: .html .xml .md
awk '/<!-- insert-markdown-here -->/ { exit } { print }' $(TEMPLATE) > $@
cmark $< >> $@
awk 'BEGIN { end = 0 } end == 1 { print } /<!-- insert-markdown-here -->/ { end = 1 }' $(TEMPLATE) >> $@
cmark $< | awk -f templater.awk - $(TEMPLATE_POST_HTML) | awk -f templater.awk -v LOAD_LINES=1 $*.csv - > $@
cmark $< | awk -f templater.awk - $(TEMPLATE_POST_ATOM) | awk -f templater.awk -v LOAD_LINES=1 $*.csv - > $@

+ 6
- 0
public/2019/07/06/make.csv View File

@@ -0,0 +1,6 @@
My experience learning make,2019-07-06:/2019/07/06/make
A journal of my journey from a casual cargo fan to a make evangelist. Well, not really, but it's about make and personal development.

+ 0
- 112
public/feed.xml View File

@@ -1,112 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="">
<title>The Neon Blog</title>
<subtitle>Writing about programs and programming.</subtitle>
<link href="" rel="self" />
<link href="" />

<title>My experience learning make</title>
<link href="" />
<name>Jens Pitkänen</name>
A journal of my journey from a casual cargo fan to a make
evangelist. Well, not really, but it's about make and personal
<content type="xhtml">
<div xmlns="">
<h2>My experience learning make</h2>
<p>When I have been looking for a new language to learn, or gauging the
usefulness of a language, I tend to appreciate build systems as part
of the language. I think an important property of a tool is its
simplicity of use, and for a long time I avoided C because it did not
have a <code>mvn</code>, <code>cargo</code>, or <code>npm</code>. I thought the lack of an in-built
build tool made C unnecessarily complicated to get started with. After
reading bits and pieces of the K&amp;R, making an almost whole game in C,
and still not having touched makefiles, I have come to the conclusion
that I was wrong. I have been happily writing C and building it with
shell-scripts that build the program for each specific system. For
example, I have a batch script for Windows that builds the program
with <code>cl.exe</code>, providing the correct flags, one for Linux, and so on.</p>
<p>The reason I wrote the shell scripts instead of makefiles is because I
already knew how shell scripts work, and learning to use <code>cc</code> and
<code>cl.exe</code> was quite similar to learning to use the aforementioned build
tools. If the compilers did not do something I needed from a build
tool, I would just write that part in the script myself. In addition
to this, I have heard a lot about makefiles not being super portable,
and the existence of <code>qmake</code> and <code>cmake</code> seem to prove that idea. And
in my own experience, when I have had to call <code>make</code> manually, it has
stumbled on my system being misconfigured somehow, which makes it seem
prone to breakage.</p>
<p>That said, I definitely feel like I should learn how to write a
<code>Makefile</code>, if for no other reason than to make my negative opinion of
them more valid. Or invalid, as the case may be ;)</p>
<h3>Learning make</h3>
<p>A few days ago, I got a copy of The Unix Programming Environment by
Brian W. Kernighan and Rob Pike from the library. Why? The main reason
was because I wanted to explore the Unix philosophy a bit further than
what I had learned from hearing it repeatedly in tech articles and
social media (not much). The other reason was because I imagined it
would have a bit on <code>make</code>.</p>
<p>It does, sort-of. The eighth chapter is about writing a big program,
and has three digressions on <code>make</code>. Based on that, I got the
following impression of it: makefiles define dependencies between
generated and manually edited files, and how those dependencies
manifest (that is, how you get from the manually written files to the
generated ones). The connection to C becomes obvious once you think
about C programming in those terms: first you manually edit the C
source code, then you generate object files out of that, and then you
generate a final executable from those.</p>
<p>In this light, <code>make</code> seems like an obvious fit for C, but very
general as well. I did not realize what the specific role of <code>make</code>
was before, probably because other programming languages have built
similar functionality into their build tools, but after this
realization, it is obvious.</p>
<p>On one hand, I appreciate how <code>cc</code> and <code>make</code> split the job of making
lots of source code into an executable (something something Unix
philosophy), but on the other hand, I can not help but feel like it is
pointlessly complicated for the end-user. Almost every program follows
a similar build-pipeline, or could at least be refactored to fit, so
why not combine the functionalities to a singular build tool? Why do I
need to learn yet another syntax just to build my C? I imagine that is
what a lot of people thought, since there are at least a few trillion
different tools to build a C program. I think.</p>
<p><code>Make(1)</code> is neat. I wrote a <code>Makefile</code> for this blog to test it out,
and I enjoyed the experience after ironing out a few
misunderstandings. It is a shame that <code>make</code> is the most universal
tool to build C programs, I would much prefer a more <code>cargo</code>/<code>go build</code>-like experience, but it is not that bad either. If you are in a
similar situation to mine at the beginning of this post, just go ahead
and use <code>make</code>. It is not evil. At the very least, it can not be as
bad as picking one of the million other C build tools, because you do
not get anywhere by making <a href="" title="Yeah, it is that one xkcd everyone always posts.">yet another standard</a>. And make sure
to be <a href="">POSIX-compatible</a>, just to be a good citizen :)</p>
<p>As a final note, The Unix Programming Environment has been a pretty
fun read, if a bit obsolete. At least the C is, did you know functions
looked like this in the 1970s?</p>
<pre><code class="language-c">main(argc, argv)
char *argv[];
// ...
<h3>Unimportant meta footnote you can skip</h3>
<p>This is my first techblog, and I hope it was bearable to read. I think
my english is a bit clumsy in long-form, so if you have got any
writing tips, or just comments on this blog overall, be sure to shoot
them at <a href=""></a> (or where I might have moved to) on
the Fediverse, or via email to <a href=""></a>.</p>


+ 24
- 0
templater.awk View File

@@ -0,0 +1,24 @@
if (length(REPLACE) == 0) {
REPLACE = "{{insert-here}}";
NR == FNR {
a[n++] = $0;
LOAD_LINES && /\{\{[0-9]\}\}/ {
i = match($0, /\{\{[0-9]\}\}/);
line = substr($0, i + 2, 1);
sub(/\{\{[0-9]\}\}/, a[line]);
if ($0 ~ REPLACE) {
for (i = 0; i < n; i++) {
print a[i];
} else {

+ 11
- 0
templates/feed.xml View File

@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="">
<title>The Neon Blog</title>
<subtitle>Writing about programs and programming.</subtitle>
<link href="" rel="self" />
<link href="" />


template.html → templates/post.html View File

@@ -3,7 +3,7 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>The Neon Blog</title>
<title>The Neon Blog - {{1}}</title>
<link href="/feed.xml" rel="alternate" type="application/atom+xml" title="This blog's Atom feed" />
<link href="/default.css" rel="stylesheet" type="text/css" title="Default" />
<link href="/dark.css" rel="alternate stylesheet" type="text/css" title="Dark" />
@@ -18,7 +18,7 @@
<br />
<!-- insert-markdown-here -->
<br />

+ 17
- 0
templates/post.xml View File

@@ -0,0 +1,17 @@
<link href="{{0}}" />
<name>Jens Pitkänen</name>
<content type="xhtml">
<div xmlns="">