playing a bit with Makefile
This commit is contained in:
parent
c06d1afecb
commit
8e2cb330f9
37
Makefile
37
Makefile
|
@ -1,8 +1,5 @@
|
||||||
# Generate my website out of org-mode/gemini files
|
# Generate my website out of org-mode/gemini files
|
||||||
#
|
|
||||||
# maybe check https://themattchan.com/blog/2017-02-28-make-site-generator.html
|
|
||||||
# From https://github.com/fcanas/bake/blob/master/Makefile
|
|
||||||
# Finally https://www.arsouyes.org/blog/2017/10_Static_website/
|
|
||||||
|
|
||||||
all: site
|
all: site
|
||||||
SRC_DIR ?= src
|
SRC_DIR ?= src
|
||||||
|
@ -17,20 +14,21 @@ NO_SRC_FILE := ! -name '*.org'
|
||||||
# ASSETS
|
# ASSETS
|
||||||
SRC_RAW_FILES := $(shell find $(SRC_DIR) -type f $(NO_DRAFT) $(NO_SRC_FILE))
|
SRC_RAW_FILES := $(shell find $(SRC_DIR) -type f $(NO_DRAFT) $(NO_SRC_FILE))
|
||||||
DST_RAW_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES))
|
DST_RAW_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES))
|
||||||
ALL += $(DST_RAW_FILES)
|
$(DST_DIR)/%: $(SRC_DIR)/%
|
||||||
$(DST_DIR)/% : $(SRC_DIR)/%
|
|
||||||
@mkdir -p "$(dir $@)"
|
@mkdir -p "$(dir $@)"
|
||||||
cp "$<" "$@"
|
cp "$<" "$@"
|
||||||
|
.PHONY: assets
|
||||||
assets: $(DST_RAW_FILES)
|
assets: $(DST_RAW_FILES)
|
||||||
|
ALL += assets
|
||||||
|
|
||||||
# CSS
|
# CSS
|
||||||
SRC_CSS_FILES := $(shell find $(SRC_DIR) -type f -name '*.css')
|
SRC_CSS_FILES := $(shell find $(SRC_DIR) -type f -name '*.css')
|
||||||
DST_CSS_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES))
|
DST_CSS_FILES := $(patsubst $(SRC_DIR)/%,$(DST_DIR)/%,$(SRC_RAW_FILES))
|
||||||
ALL += $(DST_CSS_FILES)
|
$(DST_DIR)/%.css: $(SRC_DIR)/%.css
|
||||||
$(DST_DIR)/%.css : $(SRC_DIR)/%.css
|
|
||||||
@mkdir -p "$(dir $@)"
|
@mkdir -p "$(dir $@)"
|
||||||
minify "$<" > "$@"
|
minify "$<" > "$@"
|
||||||
css: $(DST_CSS_FILES)
|
css: $(DST_CSS_FILES)
|
||||||
|
ALL += css
|
||||||
|
|
||||||
# ORG -> HTML
|
# ORG -> HTML
|
||||||
EXT ?= .org
|
EXT ?= .org
|
||||||
|
@ -46,8 +44,9 @@ $(DST_DIR)/%.html: $(SRC_DIR)/%.org $(PANDOC_TEMPLATE) $(MK_HTML)
|
||||||
$(PANDOC) "$<" "$@.tmp"
|
$(PANDOC) "$<" "$@.tmp"
|
||||||
minify --mime text/html "$@.tmp" > "$@"
|
minify --mime text/html "$@.tmp" > "$@"
|
||||||
@rm "$@.tmp"
|
@rm "$@.tmp"
|
||||||
ALL += $(DST_PANDOC_FILES)
|
.PHONY: html
|
||||||
html: $(DST_PANDOC_FILES)
|
html: $(DST_PANDOC_FILES)
|
||||||
|
ALL += html
|
||||||
|
|
||||||
# INDEXES
|
# INDEXES
|
||||||
SRC_POSTS_DIR ?= $(SRC_DIR)/posts
|
SRC_POSTS_DIR ?= $(SRC_DIR)/posts
|
||||||
|
@ -57,11 +56,12 @@ RSS_CACHE_DIR ?= $(CACHE_DIR)/rss
|
||||||
DST_XML_FILES ?= $(patsubst %.org,%.xml, \
|
DST_XML_FILES ?= $(patsubst %.org,%.xml, \
|
||||||
$(patsubst $(SRC_POSTS_DIR)/%,$(RSS_CACHE_DIR)/%, \
|
$(patsubst $(SRC_POSTS_DIR)/%,$(RSS_CACHE_DIR)/%, \
|
||||||
$(SRC_POSTS_FILES)))
|
$(SRC_POSTS_FILES)))
|
||||||
ALL += $(DST_XML_FILES)
|
|
||||||
$(RSS_CACHE_DIR)/%.xml: $(DST_POSTS_DIR)/%.html
|
$(RSS_CACHE_DIR)/%.xml: $(DST_POSTS_DIR)/%.html
|
||||||
@mkdir -p "$(dir $@)"
|
@mkdir -p "$(dir $@)"
|
||||||
hxclean "$<" > "$@"
|
hxclean "$<" > "$@"
|
||||||
|
.PHONY: indexcache
|
||||||
indexcache: $(DST_XML_FILES)
|
indexcache: $(DST_XML_FILES)
|
||||||
|
ALL += indexcache
|
||||||
|
|
||||||
# HTML INDEX
|
# HTML INDEX
|
||||||
HTML_INDEX := $(DST_DIR)/index.html
|
HTML_INDEX := $(DST_DIR)/index.html
|
||||||
|
@ -69,13 +69,12 @@ MKINDEX := engine/mk-index.sh
|
||||||
$(HTML_INDEX): $(DST_XML_FILES) $(MKINDEX) $(TEMPLATE)
|
$(HTML_INDEX): $(DST_XML_FILES) $(MKINDEX) $(TEMPLATE)
|
||||||
@mkdir -p $(DST_DIR)
|
@mkdir -p $(DST_DIR)
|
||||||
$(MKINDEX)
|
$(MKINDEX)
|
||||||
ALL += $(HTML_INDEX)
|
.PHONY: index
|
||||||
index: $(HTML_INDEX)
|
index: $(HTML_INDEX)
|
||||||
|
ALL += index
|
||||||
|
|
||||||
# RSS
|
# RSS
|
||||||
DST_RSS_FILES ?= $(patsubst %.xml,%.rss, $(DST_XML_FILES))
|
DST_RSS_FILES ?= $(patsubst %.xml,%.rss, $(DST_XML_FILES))
|
||||||
ALL += $(DST_RSS_FILES)
|
|
||||||
|
|
||||||
MK_RSS_ENTRY := ./engine/mk-rss-entry.sh
|
MK_RSS_ENTRY := ./engine/mk-rss-entry.sh
|
||||||
$(RSS_CACHE_DIR)/%.rss: $(RSS_CACHE_DIR)/%.xml $(MK_RSS_ENTRY)
|
$(RSS_CACHE_DIR)/%.rss: $(RSS_CACHE_DIR)/%.xml $(MK_RSS_ENTRY)
|
||||||
@mkdir -p $(RSS_CACHE_DIR)
|
@mkdir -p $(RSS_CACHE_DIR)
|
||||||
|
@ -86,7 +85,9 @@ MKRSS := engine/mkrss.sh
|
||||||
$(RSS): $(DST_RSS_FILES) $(MKRSS)
|
$(RSS): $(DST_RSS_FILES) $(MKRSS)
|
||||||
$(MKRSS)
|
$(MKRSS)
|
||||||
ALL += $(RSS)
|
ALL += $(RSS)
|
||||||
|
.PHONY: rss
|
||||||
rss: $(DST_RSS_FILES) $(RSS)
|
rss: $(DST_RSS_FILES) $(RSS)
|
||||||
|
ALL += rss
|
||||||
|
|
||||||
|
|
||||||
# ORG -> GEMINI
|
# ORG -> GEMINI
|
||||||
|
@ -100,6 +101,7 @@ $(DST_DIR)/%.gmi: $(SRC_DIR)/%.org $(GMI) engine/org2gemini_step1.sh
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
$(GMI) "$<" "$@"
|
$(GMI) "$<" "$@"
|
||||||
ALL += $(DST_GMI_FILES)
|
ALL += $(DST_GMI_FILES)
|
||||||
|
.PHONY: gmi
|
||||||
gmi: $(DST_GMI_FILES)
|
gmi: $(DST_GMI_FILES)
|
||||||
|
|
||||||
# GEMINI INDEX
|
# GEMINI INDEX
|
||||||
|
@ -109,6 +111,7 @@ $(GMI_INDEX): $(DST_GMI_FILES) $(MK_GMI_INDEX)
|
||||||
@mkdir -p $(DST_DIR)
|
@mkdir -p $(DST_DIR)
|
||||||
$(MK_GMI_INDEX)
|
$(MK_GMI_INDEX)
|
||||||
ALL += $(GMI_INDEX)
|
ALL += $(GMI_INDEX)
|
||||||
|
.PHONY: gmi-index
|
||||||
gmi-index: $(GMI_INDEX)
|
gmi-index: $(GMI_INDEX)
|
||||||
|
|
||||||
# RSS
|
# RSS
|
||||||
|
@ -117,8 +120,10 @@ MK_GEMINI_ATOM := engine/mk-gemini-atom.sh
|
||||||
$(GEM_ATOM): $(DST_GMI_FILES) $(MK_GEMINI_ATOM)
|
$(GEM_ATOM): $(DST_GMI_FILES) $(MK_GEMINI_ATOM)
|
||||||
$(MK_GEMINI_ATOM)
|
$(MK_GEMINI_ATOM)
|
||||||
ALL += $(GEM_ATOM)
|
ALL += $(GEM_ATOM)
|
||||||
|
.PHONY: gmi-atom
|
||||||
gmi-atom: $(GMI_ATOM)
|
gmi-atom: $(GMI_ATOM)
|
||||||
|
|
||||||
|
.PHONY: gemini
|
||||||
gemini: $(DST_GMI_FILES) $(GMI_INDEX) $(GEM_ATOM)
|
gemini: $(DST_GMI_FILES) $(GMI_INDEX) $(GEM_ATOM)
|
||||||
|
|
||||||
# Images
|
# Images
|
||||||
|
@ -141,18 +146,20 @@ $(DST_DIR)/%.png: $(SRC_DIR)/%.png
|
||||||
@mkdir -p $(dir $@)
|
@mkdir -p $(dir $@)
|
||||||
convert "$<" -quality 50 -resize 800x800\> "$@"
|
convert "$<" -quality 50 -resize 800x800\> "$@"
|
||||||
|
|
||||||
ALL += $(DST_IMG_FILES)
|
.PHONY: img
|
||||||
img: $(DST_IMG_FILES)
|
img: $(DST_IMG_FILES)
|
||||||
|
ALL += $(DST_IMG_FILES)
|
||||||
|
|
||||||
# DEPLOY
|
# DEPLOY
|
||||||
|
.PHONY: site
|
||||||
site: $(ALL)
|
site: $(ALL)
|
||||||
|
|
||||||
|
.PHONY: deploy
|
||||||
deploy: $(ALL)
|
deploy: $(ALL)
|
||||||
engine/sync.sh # deploy to her.esy.fun
|
engine/sync.sh # deploy to her.esy.fun
|
||||||
engine/ye-com-fastpublish.hs # deploy to yannesposito.com (via github pages)
|
engine/ye-com-fastpublish.hs # deploy to yannesposito.com (via github pages)
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-[ ! -z "$(DST_DIR)" ] && rm -rf $(DST_DIR)/*
|
-[ ! -z "$(DST_DIR)" ] && rm -rf $(DST_DIR)/*
|
||||||
-[ ! -z "$(CACHE_DIR)" ] && rm -rf $(CACHE_DIR)/*
|
-[ ! -z "$(CACHE_DIR)" ] && rm -rf $(CACHE_DIR)/*
|
||||||
|
|
|
@ -62,5 +62,9 @@ mkdir -p $(dirname $dst)
|
||||||
printf "%s" "$categories"
|
printf "%s" "$categories"
|
||||||
printf "\\n<description><![CDATA[\\n%s\\n]]></description>" "$(getcontent "$xfic" "$absoluteurl")"
|
printf "\\n<description><![CDATA[\\n%s\\n]]></description>" "$(getcontent "$xfic" "$absoluteurl")"
|
||||||
printf "\\n</item>\\n\\n"
|
printf "\\n</item>\\n\\n"
|
||||||
} > "$dst"
|
} > "${dst}.tmp"
|
||||||
|
# overwrite only if the value in the index are different
|
||||||
|
if ! cmp -s ${dst} ${dst}.tmp; then
|
||||||
|
mv -f ${dst}.tmp ${dst}
|
||||||
|
fi
|
||||||
echo " [${fg[green]}OK${reset_color}]"
|
echo " [${fg[green]}OK${reset_color}]"
|
||||||
|
|
|
@ -10,27 +10,26 @@
|
||||||
|
|
||||||
After many different tools, I recently switched to a simple Makefile to
|
After many different tools, I recently switched to a simple Makefile to
|
||||||
generate my static website.
|
generate my static website.
|
||||||
In [[https://her.esy.fun/posts/0017-static-blog-builder/index.html][Static Blog Builder]] I give a starter pack.
|
In previous article [[https://her.esy.fun/posts/0017-static-blog-builder/index.html][Static Blog Builder]] I give a starter pack.
|
||||||
Along the way I had to learn about Makefiles.
|
In this post I provide more detail about my specific Makefile.
|
||||||
So here are a few pointers and helpers.
|
|
||||||
|
|
||||||
So an important one.
|
A Makefile is constitued of rules.
|
||||||
The first rule of your Makefile will be the default rule.
|
The first rule of your Makefile will be the default rule.
|
||||||
I called mine =all= which will depends on another rule call =site=.
|
The first rule of my Makefile is called =all=.
|
||||||
Why?
|
|
||||||
Because, the rule format is generally something like:
|
A rule as the following format:
|
||||||
|
|
||||||
#+begin_src makefile
|
#+begin_src makefile
|
||||||
file_to_generate: file_to_use another_file_to_use
|
target: file1 file2
|
||||||
build --input file_to_use another_file_to_user \
|
cmd --input file1 file2 \
|
||||||
--output file_to_generate
|
--output target
|
||||||
#+end_src
|
#+end_src
|
||||||
|
|
||||||
if =file_to_generate= does not exists, then =make= will look at its
|
if =target= does not exists, then =make= will look at its
|
||||||
dependencies.
|
dependencies.
|
||||||
If any of its dependency need to be updated, it will run all the rules in
|
If any of its dependency need to be updated, it will run all the rules in
|
||||||
the correct order to rebuild them, and finally run the script to build
|
the correct order to rebuild them, and finally run the script to build
|
||||||
=file_to_generate=.
|
=target=.
|
||||||
A file need to be updated if one of its dependency need to be updated or is
|
A file need to be updated if one of its dependency need to be updated or is
|
||||||
newer.
|
newer.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue