website-favicon-generator/Makefile

168 lines
9.0 KiB
Makefile
Raw Normal View History

2023-06-04 09:25:19 +03:00
# All-in-one website favicon generator
# Copyright (C) 2019 Illya Marchenko <stuzer05@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
ifeq ($(OS),Windows_NT)
CC = magick
else
CC = convert
endif
SOURCE ?= source.png
# Files & forlders
DIST = dist
override DIST := $(DIST)/
override dist_public = $(DIST)public/
override dist_icons = $(DIST)public/icons/
ICON_PATH = /icons
override ICON_PATH := $(ICON_PATH)/
override define file_manifest
@echo '{' > $(dist_public)manifest.json
@echo ' "name": "",' >> $(dist_public)manifest.json
@echo ' "short_name": "",' >> $(dist_public)manifest.json
@echo ' "icons": [' >> $(dist_public)manifest.json
@echo ' {' >> $(dist_public)manifest.json
@echo ' "src": "'$(ICON_PATH)'android-chrome-192x192.png",' >> $(dist_public)manifest.json
@echo ' "sizes": "192x192",' >> $(dist_public)manifest.json
@echo ' "type": "image/png"' >> $(dist_public)manifest.json
@echo ' },' >> $(dist_public)manifest.json
@echo ' {' >> $(dist_public)manifest.json
@echo ' "src": "'$(ICON_PATH)'android-chrome-512x512.png",' >> $(dist_public)manifest.json
@echo ' "sizes": "512x512",' >> $(dist_public)manifest.json
@echo ' "type": "image/png"' >> $(dist_public)manifest.json
@echo ' }' >> $(dist_public)manifest.json
@echo ' ],' >> $(dist_public)manifest.json
@echo ' "theme_color": "",' >> $(dist_public)manifest.json
@echo ' "background_color": "",' >> $(dist_public)manifest.json
@echo ' "display": "standalone"' >> $(dist_public)manifest.json
@echo '}' >> $(dist_public)manifest.json
endef
override define file_ieconfig
@echo '<?xml version="1.0" encoding="utf-8"?>' > $(dist_icons)ieconfig.xml
@echo '<browserconfig>' >> $(dist_icons)ieconfig.xml
@echo ' <msapplication>' >> $(dist_icons)ieconfig.xml
@echo ' <tile>' >> $(dist_icons)ieconfig.xml
@echo ' <square70x70logo src="'$(ICON_PATH)'mstile-small.png"/>' >> $(dist_icons)ieconfig.xml
@echo ' <square150x150logo src="'$(ICON_PATH)'mstile-medium.png"/>' >> $(dist_icons)ieconfig.xml
@echo ' <wide310x150logo src="'$(ICON_PATH)'mstile-wide.png"/>' >> $(dist_icons)ieconfig.xml
@echo ' <square310x310logo src="'$(ICON_PATH)'mstile-large.png"/>' >> $(dist_icons)ieconfig.xml
@echo ' <TileColor>#ffffff</TileColor>' >> $(dist_icons)ieconfig.xml
@echo ' </tile>' >> $(dist_icons)ieconfig.xml
@echo ' </msapplication>' >> $(dist_icons)ieconfig.xml
@echo '</browserconfig>' >> $(dist_icons)ieconfig.xml
endef
override define file_source
@echo '<!-- Regular icons -->' > $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-57x57.png" sizes="57x57">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-76x76.png" sizes="76x76">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-96x96.png" sizes="96x96">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-128x128.png" sizes="128x128">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-192x192.png" sizes="192x192">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-196x196.png" sizes="196x196">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-228x228.png" sizes="228x228">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-16x16.png" sizes="16x16">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-32x32.png" sizes="32x32">' >> $(DIST)index.html
@echo '<link rel="icon" type="image/png" href="'$(ICON_PATH)'favicon-48x48.png" sizes="48x48">' >> $(DIST)index.html
@echo '' >> $(DIST)index.html
@echo '<!-- Android icons -->' >> $(DIST)index.html
@echo '<link rel="shortcut icon" sizes="196x196" href="'$(ICON_PATH)'favicon-196x196.png">' >> $(DIST)index.html
@echo '<link rel="manifest" href="manifest.json">' >> $(DIST)index.html
@echo '' >> $(DIST)index.html
@echo '<!-- Apple icons -->' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="57x57" href="'$(ICON_PATH)'apple-touch-icon-57x57.png">' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="114x114" href="'$(ICON_PATH)'apple-touch-icon-114x114.png">' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="72x72" href="'$(ICON_PATH)'apple-touch-icon-72x72.png">' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="144x144" href="'$(ICON_PATH)'apple-touch-icon-144x144.png">' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="60x60" href="'$(ICON_PATH)'apple-touch-icon-60x60.png">' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="120x120" href="'$(ICON_PATH)'apple-touch-icon-120x120.png">' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="76x76" href="'$(ICON_PATH)'apple-touch-icon-76x76.png">' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="152x152" href="'$(ICON_PATH)'apple-touch-icon-152x152.png">' >> $(DIST)index.html
@echo '<link rel="apple-touch-icon" sizes="180x180" href="'$(ICON_PATH)'apple-touch-icon.png">' >> $(DIST)index.html
@echo '' >> $(DIST)index.html
@echo '<!-- IE 10 Metro tile icons -->' >> $(DIST)index.html
@echo '<meta name="msapplication-TileColor" content="#ffffff">' >> $(DIST)index.html
@echo '<meta name="msapplication-TileImage" content="'$(ICON_PATH)'mstile-144x144.png">' >> $(DIST)index.html
@echo '' >> $(DIST)index.html
@echo '<!-- IE 11 Metro tile for Windows 8.1 start screen -->' >> $(DIST)index.html
@echo '<meta name="application-name" content="Application name">' >> $(DIST)index.html
@echo '<meta name="msapplication-tooltip" content="Tooltip">' >> $(DIST)index.html
@echo '<meta name="msapplication-config" content="'$(ICON_PATH)'ieconfig.xml">' >> $(DIST)index.html
endef
all: $(SOURCE)
-mkdir $(DIST) $(dist_public) $(dist_icons)
@echo "Generating.. Regular icons"
@$(CC) $(SOURCE) -resize 16x16 $(dist_icons)favicon-16x16.png
@$(CC) $(SOURCE) -resize 32x32 $(dist_icons)favicon-32x32.png
@$(CC) $(SOURCE) -resize 48x48 $(dist_icons)favicon-48x48.png
@$(CC) $(SOURCE) -resize 57x57 $(dist_icons)favicon-57x57.png
@$(CC) $(SOURCE) -resize 76x76 $(dist_icons)favicon-76x76.png
@$(CC) $(SOURCE) -resize 96x96 $(dist_icons)favicon-96x96.png
@$(CC) $(SOURCE) -resize 128x128 $(dist_icons)favicon-128x128.png
@$(CC) $(SOURCE) -resize 192x192 $(dist_icons)favicon-192x192.png
@$(CC) $(SOURCE) -resize 192x192 $(dist_icons)favicon-196x196.png
@$(CC) $(SOURCE) -resize 228x228 $(dist_icons)favicon-228x228.png
@echo "Packing.. triple-sized favicon.ico"
@$(CC) $(dist_icons)favicon-16x16.png $(dist_icons)favicon-32x32.png $(dist_icons)favicon-48x48.png $(dist_public)favicon.ico
@echo "Generating.. Android icons"
@$(CC) $(SOURCE) -resize 196x196 $(dist_icons)favicon-196x196.png
@$(CC) $(SOURCE) -resize 192x192 $(dist_icons)android-chrome-192x192.png
@$(CC) $(SOURCE) -resize 196x196 $(dist_icons)android-chrome-512x512.png
@echo "Generating.. Apple icons"
@$(CC) $(SOURCE) -resize 57x57 $(dist_icons)apple-touch-icon-57x57.png
@$(CC) $(SOURCE) -resize 114x114 $(dist_icons)apple-touch-icon-114x114.png
@$(CC) $(SOURCE) -resize 72x72 $(dist_icons)apple-touch-icon-72x72.png
@$(CC) $(SOURCE) -resize 144x144 $(dist_icons)apple-touch-icon-144x144.png
@$(CC) $(SOURCE) -resize 60x60 $(dist_icons)apple-touch-icon-60x60.png
@$(CC) $(SOURCE) -resize 120x120 $(dist_icons)apple-touch-icon-120x120.png
@$(CC) $(SOURCE) -resize 76x76 $(dist_icons)apple-touch-icon-76x76.png
@$(CC) $(SOURCE) -resize 152x152 $(dist_icons)apple-touch-icon-152x152.png
@$(CC) $(SOURCE) -resize 180x180 $(dist_icons)apple-touch-icon.png
@$(CC) $(SOURCE) -resize 180x180 $(dist_public)apple-touch-icon.png
@$(CC) $(SOURCE) -resize 180x180 -quality 80% $(dist_public)apple-touch-icon-precomposed.png
@echo "Generating.. IE 10 Metro tile icons"
@$(CC) $(SOURCE) -resize 144x144 $(dist_icons)mstile-144x144.png
@echo "Generating.. IE 11 Metro tile for Windows 8.1 start screen"
@$(CC) $(SOURCE) -resize 70x70 $(dist_icons)mstile-small.png
@$(CC) $(SOURCE) -resize 150x150 $(dist_icons)mstile-medium.png
@$(CC) $(SOURCE) -resize 310x150 $(dist_icons)mstile-wide.png
@$(CC) $(SOURCE) -resize 310x310 $(dist_icons)mstile-large.png
@echo "Generating.. manifest.json"
$(file_manifest)
@echo "Generating.. ieconfig.xml"
$(file_ieconfig)
@echo "Generating.. index.html"
$(file_source)
@echo "Done."
.PHONY: clean
clean:
$(RM) -r $(DIST)* $(subst /,,$(DIST))