Skip to content

Commit

Permalink
chore: Add a Makefile
Browse files Browse the repository at this point in the history
* Idiomatic way of managing install/uninstall files
* OS Agnostic (Linux, MacOS, Windows)
  • Loading branch information
sylver committed May 17, 2024
1 parent ac94165 commit 705481f
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 42 deletions.
71 changes: 71 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
#!/usr/bin/env make

FONT_FAMILY := Monaspace
RELEASE_DIR := fonts
VARIANTS := otf variable webfonts
EXCLUDES := webfonts

ifeq ($(OS),Windows_NT)
DEST_DIR := $(shell powershell (Get-Item Env:WINDIR).Value)\Fonts
INSTALL := xcopy /Y /I
MKDIR := mkdir
RM := del /Q

POST_INSTALL = $(foreach font,$(notdir $(INSTALL_FONT_TARGETS)), \
powershell reg add \"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\" /v \"$(font) (TrueType)\" /t REG_SZ /d $(font) /f >NUL & \
)
POST_UNINSTALL = $(foreach font,$(notdir $(INSTALL_FONT_TARGETS)), \
powershell reg delete \"HKLM\SOFTWARE\Microsoft\Windows NT\CurrentVersion\Fonts\" /v \"$(font) (TrueType)\" /f >NUL & \
)

sep := \\#
else
uname_s := $(shell uname -s)
ifeq ($(uname_s),Darwin)
DEST_DIR := $(HOME)/Library/Fonts
else
DEST_DIR := $(or $(XDG_DATA_HOME),$(HOME)/.local/share)/fonts
POST_INSTALL := /usr/bin/env fc-cache -f
WRAP := 1
endif

INSTALL := /usr/bin/env install -m 644
MKDIR := /usr/bin/env mkdir -p
RM := /usr/bin/env rm -f

POST_UNINSTALL = $(ifeq $(WRAP),1,$(shell rmdir $(install_path) 2>/dev/null))

sep := /
endif

install_path := $(DEST_DIR)$(if $(filter $(WRAP),1),$(sep)$(FONT_FAMILY),)

RELEASE_FONTS := $(wildcard $(RELEASE_DIR)/**/*)
INSTALL_FONTS := $(filter-out \
$(foreach exclude,$(EXCLUDES),$(wildcard $(RELEASE_DIR)/$(exclude)/*)), \
$(RELEASE_FONTS) \
)
INSTALL_FONT_TARGETS := $(addprefix $(install_path)$(sep),$(notdir $(INSTALL_FONTS)))

.PHONY: install
install: $(INSTALL_FONT_TARGETS)
@$(POST_INSTALL)
@echo Fonts successfully installed in $(install_path)

.PHONY: uninstall
uninstall:
@$(RM) $(install_path)$(sep)$(FONT_FAMILY)*
@$(POST_UNINSTALL)
@echo Fonts successfully uninstalled

$(install_path):
@$(MKDIR) $@

define install_font_target
$(install_path)$(if $(filter $(OS),Windows_NT),\,)$(sep)%: $(RELEASE_DIR)$(sep)$(1)$(sep)% | $(install_path)
@$(INSTALL) $$< $(install_path)
endef

$(foreach variant,$(filter-out $(EXCLUDES),$(VARIANTS)), \
$(eval $(call install_font_target,$(variant))) \
)
59 changes: 45 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,31 +75,62 @@ Font caching on operating systems is an inscrutable mess dating back thirty year

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

### MacOS
### Manual Install

#### MacOS

You can manually drag the fonts from the `fonts/otf` or `fonts/variable` directory into Font Book.

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:
#### Windows

```bash
$ bash util/install_macos.sh
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.

#### Linux

You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`.

### Automated with Make

For all OSes, use the provided [`Makefile`](Makefile) targets:

#### Install

```sh
$ make install
Fonts successfully installed in ~/.local/share/fonts/Monaspace
```
You can also use [homebrew](https://brew.sh/) as an alternative:

```bash
brew tap homebrew/cask-fonts
brew install font-monaspace
#### Uninstall

```sh
$ make uninstall
Fonts successfully uninstalled
```

### Windows
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.
#### Make Optional flags

### Linux
You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`.
| name | description | default value |
|-|-|-|
| DEST_DIR | Base directory where the fonts should be installed. | Windows: `%WINDIR%/Fonts`<br>MacOS: `~/Library/Fonts`<br>Linux: `~/.local/share/fonts` |
| 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. |

**Examples:**
```sh
$ make install DEST_DIR=~/.fonts
```
```sh
$ make install WRAP=no
```

### Package managers

#### MacOS

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

```bash
$ bash util/install_linux.sh
$ brew tap homebrew/cask-fonts
$ brew install font-monaspace
```

### Webfonts
Expand Down
18 changes: 0 additions & 18 deletions util/install_linux.sh

This file was deleted.

10 changes: 0 additions & 10 deletions util/install_macos.sh

This file was deleted.

0 comments on commit 705481f

Please sign in to comment.