Skip to content

Commit 705481f

Browse files
committed
chore: Add a Makefile
* Idiomatic way of managing install/uninstall files * OS Agnostic (Linux, MacOS, Windows)
1 parent ac94165 commit 705481f

File tree

4 files changed

+116
-42
lines changed

4 files changed

+116
-42
lines changed

Makefile

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
#!/usr/bin/env make
2+
3+
FONT_FAMILY := Monaspace
4+
RELEASE_DIR := fonts
5+
VARIANTS := otf variable webfonts
6+
EXCLUDES := webfonts
7+
8+
ifeq ($(OS),Windows_NT)
9+
DEST_DIR := $(shell powershell (Get-Item Env:WINDIR).Value)\Fonts
10+
INSTALL := xcopy /Y /I
11+
MKDIR := mkdir
12+
RM := del /Q
13+
14+
POST_INSTALL = $(foreach font,$(notdir $(INSTALL_FONT_TARGETS)), \
15+
powershell reg add \"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\" /v \"$(font) (TrueType)\" /t REG_SZ /d $(font) /f >NUL & \
16+
)
17+
POST_UNINSTALL = $(foreach font,$(notdir $(INSTALL_FONT_TARGETS)), \
18+
powershell reg delete \"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\" /v \"$(font) (TrueType)\" /f >NUL & \
19+
)
20+
21+
sep := \\#
22+
else
23+
uname_s := $(shell uname -s)
24+
ifeq ($(uname_s),Darwin)
25+
DEST_DIR := $(HOME)/Library/Fonts
26+
else
27+
DEST_DIR := $(or $(XDG_DATA_HOME),$(HOME)/.local/share)/fonts
28+
POST_INSTALL := /usr/bin/env fc-cache -f
29+
WRAP := 1
30+
endif
31+
32+
INSTALL := /usr/bin/env install -m 644
33+
MKDIR := /usr/bin/env mkdir -p
34+
RM := /usr/bin/env rm -f
35+
36+
POST_UNINSTALL = $(ifeq $(WRAP),1,$(shell rmdir $(install_path) 2>/dev/null))
37+
38+
sep := /
39+
endif
40+
41+
install_path := $(DEST_DIR)$(if $(filter $(WRAP),1),$(sep)$(FONT_FAMILY),)
42+
43+
RELEASE_FONTS := $(wildcard $(RELEASE_DIR)/**/*)
44+
INSTALL_FONTS := $(filter-out \
45+
$(foreach exclude,$(EXCLUDES),$(wildcard $(RELEASE_DIR)/$(exclude)/*)), \
46+
$(RELEASE_FONTS) \
47+
)
48+
INSTALL_FONT_TARGETS := $(addprefix $(install_path)$(sep),$(notdir $(INSTALL_FONTS)))
49+
50+
.PHONY: install
51+
install: $(INSTALL_FONT_TARGETS)
52+
@$(POST_INSTALL)
53+
@echo Fonts successfully installed in $(install_path)
54+
55+
.PHONY: uninstall
56+
uninstall:
57+
@$(RM) $(install_path)$(sep)$(FONT_FAMILY)*
58+
@$(POST_UNINSTALL)
59+
@echo Fonts successfully uninstalled
60+
61+
$(install_path):
62+
@$(MKDIR) $@
63+
64+
define install_font_target
65+
$(install_path)$(if $(filter $(OS),Windows_NT),\,)$(sep)%: $(RELEASE_DIR)$(sep)$(1)$(sep)% | $(install_path)
66+
@$(INSTALL) $$< $(install_path)
67+
endef
68+
69+
$(foreach variant,$(filter-out $(EXCLUDES),$(VARIANTS)), \
70+
$(eval $(call install_font_target,$(variant))) \
71+
)

README.md

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,62 @@ Font caching on operating systems is an inscrutable mess dating back thirty year
7575

7676
Restarting is usually the only way to be 100% sure that the underlying machinery in the operating system picks up the new fonts.
7777

78-
### MacOS
78+
### Manual Install
79+
80+
#### MacOS
81+
7982
You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directory into Font Book.
8083

81-
There is also a script that automates the deletion of all Monaspace fonts from `~/Library/Fonts` and then copies over the latest versions. Invoke it from the root of the repo like:
84+
#### Windows
8285

83-
```bash
84-
$ bash util/install_macos.sh
86+
You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directory into `C:\Windows\Fonts`. Alternatively, right-click the fonts you want and click Install.
87+
88+
#### Linux
89+
90+
You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`.
91+
92+
### Automated with Make
93+
94+
For all OSes, use the provided [`Makefile`](Makefile) targets:
95+
96+
#### Install
97+
98+
```sh
99+
$ make install
100+
Fonts successfully installed in ~/.local/share/fonts/Monaspace
85101
```
86-
You can also use [homebrew](https://brew.sh/) as an alternative:
87102

88-
```bash
89-
brew tap homebrew/cask-fonts
90-
brew install font-monaspace
103+
#### Uninstall
104+
105+
```sh
106+
$ make uninstall
107+
Fonts successfully uninstalled
91108
```
92109

93-
### Windows
94-
You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directory into `C:\Windows\Fonts`. Alternatively, right-click the fonts you want and click Install.
110+
#### Make Optional flags
95111

96-
### Linux
97-
You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`.
112+
| name | description | default value |
113+
|-|-|-|
114+
| DEST_DIR | Base directory where the fonts should be installed. | Windows: `%WINDIR%/Fonts`<br>MacOS: `~/Library/Fonts`<br>Linux: `~/.local/share/fonts` |
115+
| WRAP | Install the fonts in a subfolder named `Monaspace` within the `DEST_DIR`<br>`1` to enable, unset or any other value to disable it.| Enable by default for Linux, not supported yet otherwise. |
116+
117+
**Examples:**
118+
```sh
119+
$ make install DEST_DIR=~/.fonts
120+
```
121+
```sh
122+
$ make install WRAP=no
123+
```
124+
125+
### Package managers
126+
127+
#### MacOS
98128

99-
There is also a script which automates the deletion of all Monaspace fonts from `~/.local/share/fonts` and then copies over the latest versions. Invoke it from the root of the repo like:
129+
A [homebrew](https://brew.sh/) cask is available for MacOS:
100130

101131
```bash
102-
$ bash util/install_linux.sh
132+
$ brew tap homebrew/cask-fonts
133+
$ brew install font-monaspace
103134
```
104135

105136
### Webfonts

util/install_linux.sh

Lines changed: 0 additions & 18 deletions
This file was deleted.

util/install_macos.sh

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)