Skip to content

Commit c4d64e0

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

File tree

4 files changed

+99
-40
lines changed

4 files changed

+99
-40
lines changed

Makefile

+71
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

+28-17
Original file line numberDiff line numberDiff line change
@@ -42,33 +42,44 @@ You must enable discretionary ligatures first, often using the `dlig` setting. S
4242

4343
## Desktop Installation
4444

45-
### MacOS
46-
You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directory into Font Book.
45+
### Manually
4746

48-
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:
47+
Use the provided [`Makefile`](Makefile) targets:
4948

50-
```bash
51-
$ cd util
52-
$ bash ./install_macos.sh
49+
```sh
50+
$ make install
51+
Fonts successfully installed in ~/.local/share/fonts/Monaspace
5352
```
54-
You can also use [homebrew](https://brew.sh/) as an alternative:
5553

56-
```bash
57-
brew tap homebrew/cask-fonts
58-
brew install font-monaspace
54+
```sh
55+
$ make uninstall
56+
Fonts successfully uninstalled
57+
```
58+
59+
#### Make Optional flags
60+
61+
| name | description | default value |
62+
|-|-|-|
63+
| DEST_DIR | Base directory where the fonts should be installed. | Windows: `%WINDIR%/Fonts`<br>MacOS: `~/Library/Fonts`<br>Linux: `~/.local/share/fonts` |
64+
| 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 which is the only one that supports it. |
65+
66+
**Examples:**
67+
```sh
68+
$ make install DEST_DIR=~/.fonts
69+
```
70+
```sh
71+
$ make install WRAP=no
5972
```
6073

61-
### Windows
62-
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.
74+
### Package managers
6375

64-
### Linux
65-
You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`.
76+
#### MacOS
6677

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

6980
```bash
70-
$ cd util
71-
$ bash ./install_linux.sh
81+
$ brew tap homebrew/cask-fonts
82+
$ brew install font-monaspace
7283
```
7384

7485
### Webfonts

util/install_linux.sh

-13
This file was deleted.

util/install_macos.sh

-10
This file was deleted.

0 commit comments

Comments
 (0)