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 Nov 19, 2023
1 parent 2bddc16 commit c4d64e0
Show file tree
Hide file tree
Showing 4 changed files with 99 additions and 40 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))) \
)
45 changes: 28 additions & 17 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,44 @@ You must enable discretionary ligatures first, often using the `dlig` setting. S

## Desktop Installation

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

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

```bash
$ cd util
$ bash ./install_macos.sh
```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
```sh
$ make uninstall
Fonts successfully uninstalled
```

#### Make Optional flags

| 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 which is the only one that supports it. |

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

### 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.
### Package managers

### Linux
You can manually drag the fonts from the `fonts/otf` and `fonts/variable` directory into `~/.local/share/fonts`.
#### 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
$ cd util
$ bash ./install_linux.sh
$ brew tap homebrew/cask-fonts
$ brew install font-monaspace
```

### Webfonts
Expand Down
13 changes: 0 additions & 13 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 c4d64e0

Please sign in to comment.