Last active
March 8, 2021 17:49
-
-
Save ddrscott/bf786c589d8feeaf5dfc9546008de1ad to your computer and use it in GitHub Desktop.
Convert cbr files to PDF files
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
src_dir = sources | |
dist_dir = dist | |
cbr_files = $(wildcard $(src_dir)/*.cbr) | |
pdf_files = $(cbr_files:$(src_dir)/%.cbr=$(dist_dir)/%.pdf) | |
image_dir = .images-$< | |
all: ${pdf_files} | $(dist_dir) | |
@echo Done | |
clean: | |
rm -rf $(dist_dir) | |
$(dist_dir): | |
mkdir -p $@ | |
$(dist_dir)/%.pdf : $(src_dir)/%.cbr | $(dist_dir) | |
@# use @ to prevent `make` from printing the command it is executing | |
@echo Building $< into $@ | |
@# ^ ^ | |
@# | | | |
@# | | | |
@# | +- foo.pdf | |
@# | | |
@# +- foo.cbr | |
@# | |
rar x $< ${image_dir}/ | |
@# ^ ^ ^ | |
@# | | | | |
@# | | +- unpack to destination directory | |
@# | | | |
@# | +- foo.cbr | |
@# | | |
@# +- extract | |
@# | |
find ${image_dir}/ -size 0 -ls -delete | |
@# ^ ^ ^ ^ | |
@# | | | | | |
@# | | | +- delete the file | |
@# | | | | |
@# | | +- print `ls -l` of the file | |
@# | | | |
@# | +- only files with zero size | |
@# +- find in image directory | |
@# | |
magick convert ${image_dir}/* $@ | |
@# ^ ^ | |
@# | | | |
@# | +- foo.pdf | |
@# | | |
@# +- all files in image directory | |
@# | |
rm -rf ${image_dir} | |
@# ^ | |
@# | | |
@# +- delete entire image director. We don't need it anymore. | |
@# | |
@echo $@ is ready |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uses
rar
,make
andconvert
from imagemagick to unpack cbr files into.images/
andconvert
them to a pdf.The
Makefile
is only a few lines longer than a bash script would be and has the following benefits because ofmake
:wildcard
-e
make
will only create new and changed cbr filesmake -j 4
provides parallel processing! Change4
to the number of cores minus 1.