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 d3b56f4
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 39 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))) \
)
57 changes: 41 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,33 +42,58 @@ You must enable discretionary ligatures first, often using the `dlig` setting. S

## Desktop Installation

### MacOS
### Manually

#### 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
$ cd util
$ bash ./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`.

### Make

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

```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
```

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

**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
$ 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 d3b56f4

Please sign in to comment.