Skip to content

Commit 2bed230

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

File tree

4 files changed

+117
-42
lines changed

4 files changed

+117
-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: 46 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -75,31 +75,63 @@ 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+
82+
>>>>>>> d3b56f4 (chore: Add a Makefile)
7983
You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directory into Font Book.
8084

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:
85+
#### Windows
8286

83-
```bash
84-
$ bash util/install_macos.sh
87+
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.
88+
89+
#### Linux
90+
91+
You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`.
92+
93+
### Automated with Make
94+
95+
For all OSes, use the provided [`Makefile`](Makefile) targets:
96+
97+
#### Install
98+
99+
```sh
100+
$ make install
101+
Fonts successfully installed in ~/.local/share/fonts/Monaspace
85102
```
86-
You can also use [homebrew](https://brew.sh/) as an alternative:
87103

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

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.
111+
#### Make Optional flags
95112

96-
### Linux
97-
You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`.
113+
| name | description | default value |
114+
|-|-|-|
115+
| DEST_DIR | Base directory where the fonts should be installed. | Windows: `%WINDIR%/Fonts`<br>MacOS: `~/Library/Fonts`<br>Linux: `~/.local/share/fonts` |
116+
| 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. |
117+
118+
**Examples:**
119+
```sh
120+
$ make install DEST_DIR=~/.fonts
121+
```
122+
```sh
123+
$ make install WRAP=no
124+
```
125+
126+
### Package managers
127+
128+
#### MacOS
98129

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:
130+
A [homebrew](https://brew.sh/) cask is available for MacOS:
100131

101132
```bash
102-
$ bash util/install_linux.sh
133+
$ brew tap homebrew/cask-fonts
134+
$ brew install font-monaspace
103135
```
104136

105137
### 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)