aboutsummaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorAyush Agarwal <ayushnix@fastmail.com>2022-02-19 16:59:59 +0530
committerAyush Agarwal <ayushnix@fastmail.com>2022-02-19 22:48:32 +0530
commitc628b73022a3bc75cfeb3b565f84904577e6e167 (patch)
tree497f6df6a827796f4118a7907a2c3167d41cd269 /Makefile
parentd635587c4982986318c97cff977bc6104a365c4f (diff)
build: allow minimal installation with Makefile
the `minimal` target allows a minimal installation without the man pages or the shell completion files
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile90
1 files changed, 67 insertions, 23 deletions
diff --git a/Makefile b/Makefile
index eab77b2..1b205d0 100644
--- a/Makefile
+++ b/Makefile
@@ -1,40 +1,84 @@
-PROG ?= tessen
-PREFIX ?= /usr
+# `?=` assigns value to a variable only if it has not been set before
+# this can be useful when you want to override variables during execution of
+# the make command
+# for example, sudo make PREFIX=/custom/dir install
DESTDIR ?=
-BINDIR ?= $(PREFIX)/bin
-MANDIR ?= $(PREFIX)/share/man
-BASHCOMPDIR ?= $(PREFIX)/share/bash-completion/completions
-FISHCOMPDIR ?= $(PREFIX)/share/fish/vendor_completions.d
+PREFIX ?= /usr
+BINDIR ?= ${PREFIX}/bin
+DATAROOTDIR ?= ${PREFIX}/share
+MANDIR ?= ${DATAROOTDIR}/man
+BASHCOMPDIR ?= ${DATAROOTDIR}/bash-completion/completions
+FISHCOMPDIR ?= ${DATAROOTDIR}/fish/vendor_completions.d
+PROG ?= tessen
+# `:=` is simple variable assignment and variables which are part of the values
+# being assigned are expanded only if they are already set
RM := rm
+# `@echo` prevents the command itself from being printed
ECHO := @echo
SCDOC := scdoc
INSTALL := install
-.PHONY: all man install clean uninstall
+# this is where the basic structure of Makefiles start and it looks like
+# file_a : file_b
+# command
+# command
+# ...
+#
+# file_b: file_c
+# command
+# command
+# ...
+#
+# file_a needs file_b and file_b needs file_c - this is how Makefiles operate
+
+# file_a can be a `.PHONY`, a special target, which says that the files `all`,
+# `man` etc aren't really files but other targets
+# think of them as pseudo files or fake files which don't exist but serve to
+# execute commands in a certain logical sequence
+# by default, if nothing is specified, the `all` target is executed
+.PHONY: all install minimal bashcomp fishcomp clean uninstall
all:
- $(ECHO) "$(PROG) is a shell script and doesn't need to be compiled"
- $(ECHO) "To install it, enter \"make install\""
+ ${ECHO} "${PROG} is a shell script and doesn't need to be compiled"
+ ${ECHO} "To install it, enter \"make install\""
+
+install: man bashcomp fishcomp
+ ${INSTALL} -Dm 0755 ${PROG} -t ${DESTDIR}${BINDIR}
+ ${ECHO} ""
+ ${ECHO} "${PROG} has been installed succesfully"
-man: man/tessen.1
+# a minimal alternative for people who don't want completion files or man pages
+# `make man`, `make install_man`, `make bashcomp`, `man fishcomp`, and `make
+# minimal` can be used selectively to install what's needed
+minimal:
+ ${INSTALL} -Dm 0755 ${PROG} -t ${DESTDIR}${BINDIR}
+ ${ECHO} ""
+ ${ECHO} "${PROG} has been installed succesfully"
+man: man/${PROG}.1 man/${PROG}.5
+ ${INSTALL} -Dm 0644 man/${PROG}.1 -t ${DESTDIR}${MANDIR}/man1
+ ${INSTALL} -Dm 0644 man/${PROG}.5 -t ${DESTDIR}${MANDIR}/man5
+
+# we want *.scd files from the files that are inside man/
+# the `$^` is an automatic variable which means the list of `file_b`'s
+# the `$@` is an automatic variable which means the list of `file_a`'s
man/%: man/%.scd
- $(SCDOC) < $^ > $@
+ ${SCDOC} < $^ > $@
+
+bashcomp:
+ ${INSTALL} -Dm 0644 completion/${PROG}.bash-completion ${DESTDIR}${BASHCOMPDIR}/${PROG}
-install: man
- $(INSTALL) -Dm 0755 $(PROG) -t $(DESTDIR)$(BINDIR)
- $(INSTALL) -Dm 0644 man/*.1 -t $(DESTDIR)$(MANDIR)/man1
- $(INSTALL) -Dm 0644 completion/$(PROG).bash-completion $(DESTDIR)$(BASHCOMPDIR)/$(PROG)
- $(INSTALL) -Dm 0644 completion/$(PROG).fish-completion $(DESTDIR)$(FISHCOMPDIR)/$(PROG).fish
- $(ECHO) ""
- $(ECHO) "$(PROG) has been installed succesfully"
+fishcomp:
+ ${INSTALL} -Dm 0644 completion/${PROG}.fish-completion ${DESTDIR}${FISHCOMPDIR}/${PROG}.fish
clean:
- $(RM) -f man/*.1
+ ${RM} -f man/${PROG}.1
+ ${RM} -f man/${PROG}.5
uninstall:
- $(RM) -f "$(DESTDIR)$(BINDIR)/$(PROG)"
- $(RM) -f "$(DESTDIR)$(MANDIR)/man1/$(PROG).1"
- $(RM) -f "$(DESTDIR)$(BASHCOMPDIR)/$(PROG)"
- $(RM) -f "$(DESTDIR)$(FISHCOMPDIR)/$(PROG).fish"
+ ${RM} -f "${DESTDIR}${BINDIR}/${PROG}"
+ ${RM} -f "${DESTDIR}${MANDIR}/man1/${PROG}.1"
+ ${RM} -f "${DESTDIR}${MANDIR}/man5/${PROG}.5"
+ ${RM} -f "${DESTDIR}${BASHCOMPDIR}/${PROG}"
+ ${RM} -f "${DESTDIR}${FISHCOMPDIR}/${PROG}.fish"