2023-11-28 00:37:38 +01:00
# ABOUT In this Makefile, 'building a file' means: - if the file has a '.html' extension: run the html preprocessor on the file and place the output in the output directory
2023-11-19 17:10:16 +01:00
# - elif the file has a '.sass' or '.scss' extension: run the sass compiler on the file and place the output in the output directory
2022-12-16 05:11:16 +01:00
# - else: copy the file to the output directory
# - Folder structure from source directories will be preserved in the output directory
# - Abbreviations:
# - FLS: files
# - DIR: directory
# - SRC: source
# - LANG: language
# - PP: preprocessor
# - DEP: dependency
#
# NORMAL SETTINGS
# change these to fir your project
#
2023-11-23 15:44:47 +01:00
# root dir for the project, most other paths are relative to PROJECT_DIR
# [absolute or relative to current working directory]
2023-09-29 16:05:51 +02:00
PROJECT_DIR = src
2022-12-16 05:11:16 +01:00
2023-11-23 15:44:47 +01:00
# path where final website will be in
# [absolute or relative to current working directory]
2023-09-29 16:05:51 +02:00
OUT_DIR = build
2022-12-16 05:11:16 +01:00
# SOURCE FILES:
2023-09-29 16:05:51 +02:00
# all SRC_FLS and all files (recursively) in the SRC_DIRS will be built
# all files in PROJECT_DIR (not recursively) are source files
2023-11-23 15:44:47 +01:00
# [relative to PROJECT_DIR]
2023-11-19 17:05:54 +01:00
SRC_DIRS = de en script
2023-09-29 16:05:51 +02:00
SRC_FLS =
2022-12-16 05:11:16 +01:00
2023-11-19 17:05:54 +01:00
# CSS FILES:
# directories which may contain sass and scss to compile sass to a correspondig css in OUT_DIR/CSS_DIR (also css, it will simply be copied)
2023-11-23 15:44:47 +01:00
# [relative to PROJECT_DIR]
2023-11-19 17:05:54 +01:00
CSS_DIRS = style
CSS_FILES =
2023-11-22 12:50:35 +01:00
# RESOURCE FILES:
2022-12-16 05:11:16 +01:00
# all RESOURCE_FLS and all files in the RESOURCE_DIRS will be copied to OUT_DIR
2023-11-23 15:44:47 +01:00
# [relative to PROJECT_DIR]
2022-12-16 05:11:16 +01:00
RESOURCE_DIRS = resources
RESOURCE_FLS =
# MULTI-LANG SOURCE FILES:
# the files in COMMON_DIR will be built for all LANGS:
2023-11-23 15:44:47 +01:00
# for example:
# LANGS = de en
# PROJECT_DIR/COMMON_DIR/home.html
# -> OUT_DIR/de/home.html
# -> OUT_DIR/en/home.html
2022-12-16 05:11:16 +01:00
# foreach html-file in COMMON_DIR:
# foreach lang in LANGS:
# run HTML_PP_CMD with --var lang=lang on file and output to OUT_DIR without the COMMON_DIR prefix, so COMMON_DIR/subdir/file.html -> OUT_DIR/lang/subdir/file.html
2023-11-23 15:44:47 +01:00
# For all .html files, the proprocessor will make the variable `lang` available, for example lang=de
# All non-html files will handled the same way, but without the preprocessor being run on them. They are simply copied.
2023-11-23 19:59:43 +01:00
# leave COMMON_DIR blank to disable multi-lang feature
2023-11-23 15:44:47 +01:00
# [relative to PROJECT_DIR]
COMMON_DIR = common
2022-12-16 05:11:16 +01:00
LANGS = de en
2023-11-23 19:59:43 +01:00
# FAVICON
# image from which the favicons will be generated
2023-11-28 00:37:38 +01:00
# leave FAVICON blank to not generate favicons
2023-11-23 19:59:43 +01:00
# [relative to PROJECT_DIR]
2023-11-28 00:37:38 +01:00
FAVICON = resources/favicon.png
2023-11-23 19:59:43 +01:00
# directory where all genreated favicons will be placed
# [relative to OUT_DIR]
2023-11-28 00:37:38 +01:00
FAVICON_OUT_DIR = favicon
2023-11-23 19:59:43 +01:00
# in addition to the ones below, a favicon.ico containing the 16x16, 32x32 and 48x48will be generated
# all apple-touch-icon-XXxXX.png sizes
APPLE_ICON_SIZES = 180x180
# all mstile-XXxXX.png sizes
WINDOWS_ICON_SIZES = 150x150
# all android-chrome-XXxXX.png sizes
ANDROID_ICON_SIZES = 192x192 512x512
# all favicon-XXxXX.png sizes
2023-11-24 04:16:16 +01:00
FAVICON_ICON_SIZES = 16x16 32x32 48x48
2023-11-23 19:59:43 +01:00
2023-11-28 00:37:38 +01:00
# THUMBNAILS and OPTIMIZED IMAGES:
# In the source paths _FLS and _DIRS, the redundant '/./' will be replaced by /_OUT_DIR/
# This way leaves more control over where the thumbanils/optimized images will be placed.
# THUMBNAILS
# Thumbnails for THUMB_FLS and all files in THUMB_DIRS (recursively) having an extension in THUMB_FOR_TYPES
# will be generated.
# example:
# THUMB_DIRS = resources/./video ././resources/music
# THUMB_OUT_DIR = thumbnails
# resources/video/cool-video.mp4 -> resources/thumbnails/video/cool-video.webp
# resources/music/song.mp3 -> thumbnails/resources/music/song.webp
THUMB_FLS =
THUMB_DIRS = resources/./
# Substitution for /./ in THUMB_FLS and THUMB_DIRS
THUMB_OUT_DIR = thumbnails
2023-11-23 19:59:43 +01:00
# build thumbnails for these types: supported: mp3, flac, wav, pdf and all image formats that magick can handle
2023-11-28 00:37:38 +01:00
THUMB_FOR_TYPES = pdf mp4 mp3 flac wav
# filetype for the thumbnails
THUMB_TYPE = webp
# size for the thumbnails, the larger dimension will have this size
THUMB_SIZE = 400
# OPTIMIZED IMAGES
# A optimized image version will be generated for all images in OPTIMIZED_IMG_FLS and in OPTIMIZED_IMG_DIRS (recursively)
# having an extension in OPTIMIZED_IMG_FOR_TYPES
OPTIMIZED_IMG_FLS =
OPTIMIZED_IMG_DIRS = resources/./
# Substitution for /./ in OPTIMIZED_IMG_FLS and OPTIMIZED_IMG_DIRS
OPTIMIZED_IMG_OUT_DIR = optim
OPTIMIZED_IMG_FOR_TYPES = png gif jpg jpeg
OPTIMIZED_IMG_TYPE = webp
OPTIMIZED_IMG_QUALITY = 80
2023-11-23 19:59:43 +01:00
2023-11-23 15:44:47 +01:00
# SITEMAP
2023-11-23 19:59:43 +01:00
# leave SITEMAP blank to not generate a sitemap
# [relative to OUT_DIR]
2023-11-23 15:44:47 +01:00
SITEMAP = sitemap.xml
# base url of the website, without trailing /
WEBSITE_URL = https://quintern.xyz
# file required during build process for sitemap generation [absolute or relative to current working directory]
SITEMAP_TEMP_FILE = .sitemap.pkl
# comment to keep the file extension on sitemap entries
SITEMAP_REMOVE_EXT = 1
2022-12-16 05:11:16 +01:00
# PREPROCESSOR
# path to of the files that should be included
2023-11-23 15:44:47 +01:00
# [relative to PROJECT_DIR]
2022-12-16 05:11:16 +01:00
INCLUDE_DIR = include
2023-11-19 17:05:54 +01:00
# additional search paths passed to sass compiler
2023-11-23 15:44:47 +01:00
# [relative to PROJECT_DIR]
2023-11-19 17:05:54 +01:00
SASS_INCLUDE_DIRS = include/style
2022-12-16 05:11:16 +01:00
# ADVANCED
# the command to run the html preprocessor
2023-11-23 22:07:36 +01:00
HTML_PP_CMD = python3 html-preprocessor --exit-on light
2023-11-19 17:05:54 +01:00
# command to compile sass and scss files with
# --indented is added for sass and --no-indented for scss
# --source-maps-urls=absolute is appended for generating dependency files
SASS_CMD = sass --color
2022-12-16 05:11:16 +01:00
2023-11-28 00:37:38 +01:00
OPTIMIZED_IMG_CMD = convert -quality $( OPTIMIZED_IMG_QUALITY)
2023-11-23 15:44:47 +01:00
# [absolute or relative to current working directory]
2022-12-16 05:11:16 +01:00
DEP_DIR = .dependencies
2023-11-28 00:37:38 +01:00
# required for thumbnail creation
TMP_DIR = /tmp
2022-12-16 05:11:16 +01:00
#
# NOT SETTINGS ANYMORE
# DO NOT CHANGE ANYTHING HERE UNLESS YOU KNOW WHAT YOU ARE DOING!
#
# all variables starting with _ are relative to PROJECT_DIR
# make everything relative to PROJECT_DIR
_SRC_DIRS = $( addprefix $( PROJECT_DIR) /, $( SRC_DIRS) )
_SRC_FLS = $( addprefix $( PROJECT_DIR) /, $( SRC_FLS) )
2023-11-19 17:05:54 +01:00
_CSS_FLS = $( addprefix $( PROJECT_DIR) /, $( CSS_FLS) )
_CSS_DIRS = $( addprefix $( PROJECT_DIR) /, $( CSS_DIRS) )
_SASS_INCLUDE_DIRS = $( addprefix $( PROJECT_DIR) /, $( SASS_INCLUDE_DIRS) )
2022-12-16 05:11:16 +01:00
_RES_DIRS = $( addprefix $( PROJECT_DIR) /, $( RESOURCE_DIRS) )
_RES_FLS = $( addprefix $( PROJECT_DIR) /, $( RESOURCE_FLS) )
2023-11-28 00:37:38 +01:00
_OPTIMIZED_IMG_DIRS = $( addprefix $( PROJECT_DIR) /, $( OPTIMIZED_IMG_DIRS) )
_OPTIMIZED_IMG_FLS = $( addprefix $( PROJECT_DIR) /, $( OPTIMIZED_IMG_FLS) )
_THUMB_DIRS = $( addprefix $( PROJECT_DIR) /, $( THUMB_DIRS) )
_THUMB_FLS = $( addprefix $( PROJECT_DIR) /, $( THUMB_FLS) )
2022-12-16 05:11:16 +01:00
_COMMON_DIR = $( addprefix $( PROJECT_DIR) /, $( COMMON_DIR) )
_INCLUDE_DIR = $( addprefix $( PROJECT_DIR) /, $( INCLUDE_DIR) )
# NORMAL SRC
2023-11-19 17:05:54 +01:00
# all SRC_DIRS + CSS_DIRS + all subdirs of each srcdir
_SRC_SUB_DIRS = $( foreach srcdir, $( _SRC_DIRS) $( _CSS_DIRS) , $( shell find $( srcdir) / -type d 2>/dev/null) )
2023-09-29 16:05:51 +02:00
# add files in project dir
_SRC_FLS += $( shell find $( PROJECT_DIR) / -maxdepth 1 -type f)
# add files src dirs, recursively
_SRC_FLS += $( foreach srcdir, $( _SRC_DIRS) , $( shell find $( srcdir) / -type f 2>/dev/null) )
2023-11-19 17:05:54 +01:00
_CSS_FLS += $( foreach srcdir, $( _CSS_DIRS) , $( shell find $( srcdir) / -type f 2>/dev/null) )
OUT_DIRS = $( OUT_DIR) / $( patsubst $( PROJECT_DIR) /%, $( OUT_DIR) /%, $( _SRC_SUB_DIRS) )
# path of the (css/sass) source files after being processed
OUT_FLS = $( patsubst $( PROJECT_DIR) /%, $( OUT_DIR) /%, $( _SRC_FLS) )
OUT_FLS += $( patsubst $( PROJECT_DIR) /%, $( OUT_DIR) /%, $( foreach cssfile, $( _CSS_FLS) , $( shell echo $( cssfile) | sed 's/\.s[ac]ss$$/.css/' ) ) )
2022-12-16 05:11:16 +01:00
# RESOURCES
2023-09-29 16:05:51 +02:00
_RES_SUB_DIRS = $( foreach srcdir, $( _RES_DIRS) , $( shell find $( srcdir) / -type d 2>/dev/null) )
_RES_FLS += $( foreach srcdir, $( _RES_DIRS) , $( shell find $( srcdir) / -type f 2>/dev/null) )
2022-12-16 05:11:16 +01:00
RES_OUT_DIRS = $( OUT_DIR) / $( patsubst $( PROJECT_DIR) /%, $( OUT_DIR) /%, $( _RES_SUB_DIRS) )
RES_OUT_FLS = $( patsubst $( PROJECT_DIR) /%, $( OUT_DIR) /%, $( _RES_FLS) )
# MULTILANG
2023-09-29 16:05:51 +02:00
i f d e f C O M M O N _ D I R
2022-12-16 05:11:16 +01:00
_ML_SRC_FLS = $( shell find $( _COMMON_DIR) / -type f)
_ML_SRC_SUB_DIRS = $( shell find $( _COMMON_DIR) / -type d)
# will contain one subdir for each lang, each of which contains every file from ML_SRC_FLS
ML_OUT_DIR = $( OUT_DIR)
ML_OUT_LANG_DIRS = $( foreach lang, $( LANGS) , $( addprefix $( ML_OUT_DIR) /, $( lang) ) )
ML_OUT_DIRS = $( foreach lang, $( LANGS) , $( patsubst $( _COMMON_DIR) /%, $( ML_OUT_DIR) /$( lang) /%, $( _ML_SRC_SUB_DIRS) ) )
ML_OUT_FLS = $( foreach lang, $( LANGS) , $( patsubst $( _COMMON_DIR) /%, $( ML_OUT_DIR) /$( lang) /%, $( _ML_SRC_FLS) ) )
2023-09-29 16:05:51 +02:00
e n d i f
2022-12-16 05:11:16 +01:00
2023-11-28 00:37:38 +01:00
i f d e f F A V I C O N _ O U T _ D I R
__FAVICON_OUT_DIR = $( addprefix $( OUT_DIR) /,$( FAVICON_OUT_DIR) )
2023-11-23 19:59:43 +01:00
e l s e
2023-11-28 00:37:38 +01:00
__FAVICON_OUT_DIR = $( OUT_DIR)
2023-11-23 19:59:43 +01:00
e n d i f
2023-11-28 00:37:38 +01:00
i f d e f F A V I C O N
_FAVICON = $( addprefix $( PROJECT_DIR) /,$( FAVICON) )
FAVICON_ICO = $( __FAVICON_OUT_DIR) /favicon.ico
2023-11-23 19:59:43 +01:00
APPLE_ICONS = $( addsuffix .png,$( addprefix apple-touch-icon-,$( APPLE_ICON_SIZES) ) )
WINDOWS_ICONS = $( addsuffix .png,$( addprefix mstile-,$( WINDOWS_ICON_SIZES) ) )
ANDROID_ICONS = $( addsuffix .png,$( addprefix android-chrome-,$( ANDROID_ICON_SIZES) ) )
FAVICON_ICONS = $( addsuffix .png,$( addprefix favicon-,$( FAVICON_ICON_SIZES) ) )
2023-11-28 00:37:38 +01:00
FAVICONS_PNG = $( addprefix $( __FAVICON_OUT_DIR) /,$( APPLE_ICONS) $( WINDOWS_ICONS) $( ANDROID_ICONS) $( FAVICON_ICONS) )
2023-11-23 19:59:43 +01:00
FAVICONS = $( FAVICONS_PNG) $( FAVICON_ICO)
e n d i f
2023-11-28 00:37:38 +01:00
_THUMB_FLS += $( foreach srcdir, $( _THUMB_DIRS) , $( shell find $( subst //,/,$( srcdir) /) -type f 2>/dev/null) )
2023-11-22 12:50:35 +01:00
# files for which to generate thumbnails
2023-11-28 00:37:38 +01:00
_THUMB_FLS_FILTERED = $( filter $( foreach type, $( THUMB_FOR_TYPES) , %.$( type ) ) , $( _THUMB_FLS) )
THUMB_OUT_FLS = $( addsuffix .$( THUMB_TYPE) , $( basename $( subst /./,/$( THUMB_OUT_DIR) /,$( patsubst $( PROJECT_DIR) /%, $( OUT_DIR) /%, $( _THUMB_FLS_FILTERED) ) ) ) )
THUMB_OUT_DIRS = $( sort $( dir $( THUMB_OUT_FLS) ) ) # sort for removing duplicates
_OPTIMIZED_IMG_FLS += $( foreach srcdir, $( _OPTIMIZED_IMG_DIRS) , $( shell find $( subst //,/,$( srcdir) ) -type f 2>/dev/null) )
_OPTIMIZED_IMG_FLS_FILTERED += $( filter $( foreach type, $( OPTIMIZED_IMG_FOR_TYPES) , %.$( type ) ) , $( _OPTIMIZED_IMG_FLS) )
OPTIMIZED_IMG_OUT_FLS = $( addsuffix .$( OPTIMIZED_IMG_TYPE) , $( basename $( subst /./,/$( OPTIMIZED_IMG_OUT_DIR) /,$( patsubst $( PROJECT_DIR) /%, $( OUT_DIR) /%, $( _OPTIMIZED_IMG_FLS_FILTERED) ) ) ) )
OPTIMIZED_IMG_OUT_DIRS = $( sort $( dir $( OPTIMIZED_IMG_OUT_FLS) ) ) # sort for removing duplicates
2023-11-22 12:50:35 +01:00
2022-12-16 05:11:16 +01:00
# needed for creating them
2023-09-29 16:05:51 +02:00
_DEP_DIRS = $( sort $( patsubst $( OUT_DIR) /%, $( DEP_DIR) /%, $( OUT_DIRS) $( ML_OUT_DIRS) ) )
2022-12-16 05:11:16 +01:00
# needed for reading
2023-09-29 16:05:51 +02:00
_DEP_FLS = $( shell find $( DEP_DIR) -type f -name '*.d' 2>/dev/null)
2022-12-16 05:11:16 +01:00
2023-11-23 15:44:47 +01:00
i f d e f S I T E M A P
2023-11-23 19:59:43 +01:00
SITEMAP_OUT = $( addprefix $( OUT_DIR) /, $( SITEMAP) )
2023-11-23 15:44:47 +01:00
HTML_PP_CMD += --sitemap-temp-file " $( SITEMAP_TEMP_FILE) " --sitemap-base-url $( WEBSITE_URL) --sitemap-webroot-dir " $( OUT_DIR) "
e n d i f
i f d e f S I T E M A P _ R E M O V E _ E X T
HTML_PP_CMD += --sitemap-remove-ext
e n d i f
2023-11-19 17:05:54 +01:00
# SASS, add load-paths
_SASS_CMD = $( SASS_CMD) $( foreach includedir, $( _SASS_INCLUDE_DIRS) , --load-path= $( includedir) ) --source-map-urls= absolute
2022-12-16 05:11:16 +01:00
# PRINTING
FMT_VAR_SRC = "Variable '\e[1;34m%s\e[0m': \e[0;33m%s\e[0m\n"
FMT_VAR_OUT = "Variable '\e[1;34m%s\e[0m': \e[0;35m%s\e[0m\n"
FMT_DIR = "\e[1;34mMaking directory\e[0m: \e[0;35m%s\e[0m\n"
2023-11-22 12:50:35 +01:00
FMT_OUT_HTML = "\e[1;34mBuilding html\e[0m: \e[1;33m%s\e[0m at \e[1;35m%s\e[0m\n"
2023-11-23 00:12:54 +01:00
FMT_OUT_CSS = "\e[1;34mBuilding css\e[0m: \e[1;33m%s\e[0m at \e[1;35m%s\e[0m\n"
2023-11-23 19:59:43 +01:00
FMT_OUT_THUMB = "\e[1;34mGenerating thumbnail\e[0m: \e[1;33m%s\e[0m at \e[1;35m%s\e[0m\n"
2023-11-28 00:37:38 +01:00
FMT_OUT_OPTIMIZED_IMG = "\e[1;34mGenerating optimized image\e[0m: \e[1;33m%s\e[0m at \e[1;35m%s\e[0m\n"
2023-11-23 19:59:43 +01:00
FMT_OUT_SITEMAP = "\e[1;34mGenerating sitemap\e[0m: \e[1;35m%s\e[0m\n"
FMT_OUT_FAVICON = "\e[1;34mGenerating favicon\e[0m: \e[1;33m%s\e[0m at \e[1;35m%s\e[0m\n"
2022-12-16 05:11:16 +01:00
FMT_OUT_OTHER = "\e[1;34mBuilding\e[0m: \e[1;33m%s\e[0m at \e[1;35m%s\e[0m\n"
2023-11-23 22:07:36 +01:00
FMT_OUT_ML_HTML = "\e[1;34mBuilding html\e[0m in lang \e[1;34m%s\e[0m: \e[1;33m%s\e[0m at \e[1;35m%s\e[0m\n"
FMT_OUT_ML_OTHER = "\e[1;34mBuilding\e[0m in lang \e[1;34m%s\e[0m: \e[1;33m%s\e[0m at \e[1;35m%s\e[0m\n"
# .SUFFIXES:
# .SUFFIXES: .html .md
2022-12-16 05:11:16 +01:00
2023-11-28 00:37:38 +01:00
.PHONY : default normal multilang resources sitemap favicons thumbnails images print start stop clean cleaner
2022-12-16 05:11:16 +01:00
.DEFAULT_GOAL = all
# include all the dependency makefiles
i n c l u d e $( _DEP_FLS )
2023-11-28 00:37:38 +01:00
all : normal multilang resources thumbnails sitemap favicons images
2023-11-23 19:59:43 +01:00
normal : $( OUT_FLS )
sitemap : $( SITEMAP_OUT )
favicons : $( FAVICONS ) $( FAVICON_ICO )
2022-12-16 05:11:16 +01:00
multilang : $( ML_OUT_FLS )
resources : $( RES_OUT_FLS )
2023-11-22 12:50:35 +01:00
thumbnails : $( THUMB_OUT_FLS )
2023-11-28 00:37:38 +01:00
images : $( OPTIMIZED_IMG_OUT_FLS )
2022-12-16 05:11:16 +01:00
print :
@printf $( FMT_VAR_SRC) "PROJECT_DIR" " $( PROJECT_DIR) "
@printf $( FMT_VAR_OUT) "OUT_DIRS" " $( OUT_DIRS) "
@printf $( FMT_VAR_SRC) "_INCLUDE_DIR" " $( _INCLUDE_DIR) "
@printf $( FMT_VAR_SRC) "_SRC_FLS" " $( _SRC_FLS) "
@printf $( FMT_VAR_OUT) "OUT_FLS" " $( OUT_FLS) "
@printf $( FMT_VAR_SRC) "_RES_FLS" " $( _RES_FLS) "
@printf $( FMT_VAR_OUT) "RES_OUT_FLS" " $( RES_OUT_FLS) "
2023-11-19 17:05:54 +01:00
@printf $( FMT_VAR_OUT) "_CSS_FLS" " $( _CSS_FLS) "
2023-09-29 16:05:51 +02:00
i f d e f C O M M O N _ D I R
2022-12-16 05:11:16 +01:00
@printf $( FMT_VAR_SRC) "_ML_SRC_FLS" " $( _ML_SRC_FLS) "
@printf $( FMT_VAR_OUT) "ML_OUT_FLS" " $( ML_OUT_FLS) "
2023-09-29 16:05:51 +02:00
e n d i f
2022-12-16 05:11:16 +01:00
@printf $( FMT_VAR_SRC) "_DEP_FLS" " $( _DEP_FLS) "
2023-11-22 12:50:35 +01:00
i f d e f T H U M B _ O U T _ D I R
@printf $( FMT_VAR_SRC) "THUMB_OUT_DIR" " $( THUMB_OUT_DIR) "
2023-11-28 00:37:38 +01:00
@printf $( FMT_VAR_OUT) "_THUMB_FLS_FILTERED" " $( _THUMB_FLS_FILTERED) "
2023-11-22 12:50:35 +01:00
@printf $( FMT_VAR_OUT) "THUMB_OUT_FLS" " $( THUMB_OUT_FLS) "
@printf $( FMT_VAR_OUT) "THUMB_OUT_DIRS" " $( THUMB_OUT_DIRS) "
2023-11-28 00:37:38 +01:00
e n d i f
i f d e f O P T I M I Z E D _ I M G _ O U T _ D I R
@printf $( FMT_VAR_SRC) "OPTIMIZED_IMG_OUT_DIR" " $( OPTIMIZED_IMG_OUT_DIR) "
@printf $( FMT_VAR_OUT) "_OPTIMIZED_IMG_FLS_FILTERED" " $( _OPTIMIZED_IMG_FLS_FILTERED) "
@printf $( FMT_VAR_OUT) "OPTIMIZED_IMG_OUT_FLS" " $( OPTIMIZED_IMG_OUT_FLS) "
@printf $( FMT_VAR_OUT) "OPTIMIZED_IMG_OUT_DIRS" " $( OPTIMIZED_IMG_OUT_DIRS) "
2023-11-22 12:50:35 +01:00
e n d i f
2022-12-16 05:11:16 +01:00
@# @printf $( FMT_VAR_SRC) "y" " $( y) "
2023-09-29 16:05:51 +02:00
# DIRECTORIES
2023-11-28 00:37:38 +01:00
$(sort $(ML_OUT_DIRS) $(_DEP_DIRS) $(RES_OUT_DIRS) $(OUT_DIRS) $(THUMB_OUT_DIRS) $(OPTIMIZED_IMG_OUT_DIRS) $(__FAVICON_OUT_DIR)) :
2022-12-16 05:11:16 +01:00
@printf $( FMT_DIR) " $@ "
@mkdir -p $@
2023-09-29 16:05:51 +02:00
# MULTILANG RULES
i f d e f C O M M O N _ D I R
# $@ is the target to trigger the rule, but all languages have to be built now
2022-12-16 05:11:16 +01:00
$(foreach out_dir, $(ML_OUT_LANG_DIRS), $(out_dir)/%.html) : $( _COMMON_DIR ) /%.html | $( ML_OUT_DIRS ) $( _DEP_DIRS )
2023-09-29 16:05:51 +02:00
@RAW_TARGET= ` echo $@ $( foreach lang, $( LANGS) , | sed 's|$(ML_OUT_DIR)/$(lang)/||' ) ` ; \
for lang in $( LANGS) ; do \
target = $( ML_OUT_DIR) /$$ lang/$$ RAW_TARGET; \
printf $( FMT_OUT_ML_HTML) " $$ lang " " $< " " $$ target " ; \
$( HTML_PP_CMD) --input " $< " --output " $$ target " --var include_dir = $( _INCLUDE_DIR) --var lang = $$ lang --output-deps " `echo $$ {target}.d | sed 's| $( OUT_DIR) /| $( DEP_DIR) /|'` " ; \
done
2022-12-16 05:11:16 +01:00
# rule for all not html files
$(foreach out_dir, $(ML_OUT_LANG_DIRS), $(out_dir)/%) : $( _COMMON_DIR ) /% | $( ML_OUT_DIRS )
@lang= ` echo $( patsubst $( ML_OUT_DIR) /%, %, $@ ) | awk -F "/" '{print $$1}' ` ; \
printf $( FMT_OUT_ML_OTHER) " $$ lang " " $< " " $@ " ; \
cp $< $@
2023-09-29 16:05:51 +02:00
e n d i f
2022-12-16 05:11:16 +01:00
2023-11-23 19:59:43 +01:00
i f d e f F A V I C O N S
# must be first
2023-11-28 00:37:38 +01:00
$(FAVICON_ICO) : $( _FAVICON ) | $( __FAVICON_OUT_DIR )
2023-11-23 19:59:43 +01:00
@printf $( FMT_OUT_FAVICON) " $< " " $@ "
@convert " $< " -define icon:auto-resize= 16,32,48 " $@ "
2023-11-28 00:37:38 +01:00
$(FAVICONS_PNG) : $( _FAVICON ) | $( __FAVICON_OUT_DIR )
2023-11-23 19:59:43 +01:00
@printf $( FMT_OUT_FAVICON) " $< " " $@ "
@# resize to 512x512 and pad with transparency in case resize did not resize to correct size
@size= $$ ( echo " $@ " | grep -o -P '\d{2,4}x\d{2,4}' ) ; \
convert " $< " -resize " $$ {size} " -background none -gravity center -extent " $$ {size} " " $@ "
e n d i f
2023-11-22 12:50:35 +01:00
# THUMBNAILS
2023-11-28 00:37:38 +01:00
$(THUMB_OUT_FLS) : | $( THUMB_OUT_DIRS ) $( TMP_DIR )
@sources= ( $( foreach f,$( _THUMB_FLS_FILTERED) , " $( f) " ) ) ; \
targets = ( $( foreach f,$( THUMB_OUT_FLS) , " $( f) " ) ) ; \
index = $$ ( printf "%s\n" " $$ {targets[@]} " | awk '$$0 == "$@" {print NR-1}' ) ; \
source = " $$ {sources[ $$ index]} " ; \
printf $( FMT_OUT_THUMB) " $$ source " " $@ " ; \
2023-11-23 15:44:47 +01:00
case " $$ {source##*.} " in \
2023-11-28 00:37:38 +01:00
"mp4-use-magick-as-well" ) ffmpegthumbnailer -i " $$ source " -o " $@ " -s 300 -q 5; ; \
"pdf" ) \
pdftoppm -f 1 -singlefile -jpeg -r 50 " $$ source " " $( TMP_DIR) /buwuma-pdf " ; \
magick " $( TMP_DIR) /buwuma-pdf.jpg " -thumbnail '$(THUMB_SIZE)x$(THUMB_SIZE)>' " $@ " ; \
rm " $( TMP_DIR) /buwuma-pdf.jpg " ; \
; ; \
"mp3" | "flac" | "wav" ) ffmpeg -hide_banner -i " $$ source " " $@ " -y >/dev/null; ; \
2023-11-23 15:52:47 +01:00
*) magick " $$ {source}[0] " -thumbnail '$(THUMB_SIZE)x$(THUMB_SIZE)>' " $@ " ; ; \
2023-11-23 15:44:47 +01:00
esac
2023-11-28 00:37:38 +01:00
# OPTIMIZED IMAGES
$(OPTIMIZED_IMG_OUT_FLS) : | $( OPTIMIZED_IMG_OUT_DIRS )
@sources= ( $( foreach f,$( _OPTIMIZED_IMG_FLS_FILTERED) , " $( f) " ) ) ; \
targets = ( $( foreach f,$( OPTIMIZED_IMG_OUT_FLS) , " $( f) " ) ) ; \
index = $$ ( printf "%s\n" " $$ {targets[@]} " | awk '$$0 == "$@" {print NR-1}' ) ; \
source = " $$ {sources[ $$ index]} " ; \
printf $( FMT_OUT_OPTIMIZED_IMG) " $$ source " " $@ " ; \
$( OPTIMIZED_IMG_CMD) " $$ {source}[0] " " $@ "
2023-11-23 15:44:47 +01:00
# SITEMAP
2023-11-23 19:59:43 +01:00
i f d e f S I T E M A P _ O U T
$(SITEMAP_OUT) : $( OUT_FLS ) $( ML_OUT_FLS ) # build sitemap after all other files
2023-11-23 15:44:47 +01:00
@printf $( FMT_OUT_SITEMAP) " $@ "
@$( HTML_PP_CMD) --sitemap-generate " $@ "
e n d i f
2023-11-22 12:50:35 +01:00
2022-12-16 05:11:16 +01:00
#
# (NORMAL/RE-)SOURCE RULES
#
2023-09-29 16:05:51 +02:00
$(OUT_DIR)/%.html : $( PROJECT_DIR ) /%.html | $( OUT_DIRS ) $( _DEP_DIRS )
2022-12-16 05:11:16 +01:00
@printf $( FMT_OUT_HTML) " $< " " $@ " ;
2023-09-29 16:05:51 +02:00
@$( HTML_PP_CMD) --input " $< " --output " $@ " --var include_dir = $( _INCLUDE_DIR) --output-deps " $( subst $( DEP_DIR) /$( PROJECT_DIR) , $( DEP_DIR) , $( DEP_DIR) /$<.d) " ;
2022-12-16 05:11:16 +01:00
@# remove comments and empty lines. two separate lines bc the substitution might create new empty lines
@#awk -i inplace '{FS="" sub(/<!--.*-->/,"")}1' $@
@#awk -i inplace '{if (NF != 0) print}' $@
2023-11-24 18:31:15 +01:00
# SASS
2023-11-19 17:05:54 +01:00
$(OUT_DIR)/%.css : $( PROJECT_DIR ) /%.sass | $( OUT_DIRS ) $( _DEP_DIRS )
@printf $( FMT_OUT_CSS) " $< " " $@ " ;
2023-11-24 18:31:15 +01:00
@$( _SASS_CMD) --indented " $< " " $@ " || { rm " $@ " ; exit 1; }
2023-11-19 17:05:54 +01:00
@depfile= $( patsubst $( OUT_DIR) /%,$( DEP_DIR) /%,$@ ) .d; echo -n " $@ : " > " $$ depfile " ; \
jq -r '.sources | @sh' $@ .map | tr -d \' | sed 's|file://||g' >> " $$ depfile " ; \
rm $@ .map
2023-11-24 18:31:15 +01:00
@# generate a dependecy file from the source map and delete the map
2023-11-28 00:37:38 +01:00
2023-11-24 18:31:15 +01:00
# SCSS
2023-11-19 17:05:54 +01:00
$(OUT_DIR)/%.css : $( PROJECT_DIR ) /%.scss | $( OUT_DIRS ) $( _DEP_DIRS )
@printf $( FMT_OUT_CSS) " $< " " $@ " ;
2023-11-24 18:31:15 +01:00
@$( _SASS_CMD) --no-indented " $< " " $@ " || { rm " $@ " ; exit 1; }
2023-11-19 17:05:54 +01:00
@# generate a dependecy file from the source map and delete the map
@depfile= $( patsubst $( OUT_DIR) /%,$( DEP_DIR) /%,$@ ) .d; echo -n " $@ : " > " $$ depfile " ; \
jq -r '.sources | @sh' $@ .map | tr -d \' | sed 's|file://||g' >> " $$ depfile " ; \
rm $@ .map
2023-11-23 15:44:47 +01:00
# this rule must be last!
2023-09-29 16:05:51 +02:00
$(OUT_DIR)/% : $( PROJECT_DIR ) /% | $( OUT_DIRS ) $( RES_OUT_DIRS )
2022-12-16 05:11:16 +01:00
@printf $( FMT_OUT_OTHER) " $< " " $@ "
@cp -r $< $@
# .DEFAULT:
# @echo "MISSING RULE: $@"
start :
/usr/sbin/nginx -c nginx.conf -p $( shell pwd ) &
firefox http://localhost:8080/
stop :
killall nginx
clean :
2023-11-23 22:07:36 +01:00
-@rm $( OUT_FLS) $( ML_OUT_FLS) $( SITEMAP_TEMP_FILE) $( SITEMAP) 2>/dev/null
2023-11-19 17:05:54 +01:00
-@rm -r $( DEP_DIR) 2>/dev/null
2022-12-16 05:11:16 +01:00
cleaner :
2023-11-19 17:05:54 +01:00
-@rm -r $( OUT_DIR)
-@rm -r $( DEP_DIR) 2>/dev/null