💾 Archived View for jay.scot › rants › 007.gmi captured on 2021-12-05 at 23:47:19. Gemini links have been rewritten to link to archived content

View Raw

More Information

⬅️ Previous capture (2021-11-30)

-=-=-=-=-=-=-

Build, patch and maintain suckless tools

I am a long time supporter of the Unix philosophy and have been using tools such as dwm as my daily driver since 2011, as such I mainly use the terminal for everything. Lots of these tools are best built via the latest source code release or development copy instead of a package build, so you can apply your custom configuration. The most common methods I have come across on managing to do this is a mixture of using separate git branches for each patch or even just manually applying the patches and then fixing anything that didn't succeed.

I am a big fan of Makefiles, I even use Makefiles to manage my dotfiles instead of a tool like GNU Stow. So it will be no surprise I use these to build, patch and install all my suckless based tools such as dwm, st, dmenu and herbe. My Makefile makes patching easy and means I don't need to worry about maintaining multiple branches, it's super easy to get the latest versions etc. It also helps that I don't have any extra patches apart from dmenu and st, any additions I have for dwm and herbe are added to config.h as functions.

MAKEFILE

Below is the generic Makefile I use, this one is for dmenu as it's a good example to use since I use a few minimal external patches. The options at the top of the Makefile should be pretty obvious, the defaults should be fine for most people.

	REPOSITORY = http://git.suckless.org/dmenu
	SRC_DIR = dmenu-src
	PINNED_REVISION = HEAD
	PATCH_DIR = patches

	all: $(SRC_DIR)

	clean: reset
		@if test -d $(SRC_DIR); then \
			$(MAKE) -C "${SRC_DIR}" -s clean; \
			git -C "${SRC_DIR}" clean -f; \
		fi

	$(SRC_DIR): clone reset patch
		@cp config.h $@
		$(MAKE) -C "${SRC_DIR}" -s

	patch: $(PATCH_DIR)/*
		@for file in $^ ; do \
			patch -d "${SRC_DIR}" < ${file}; \
		done
	reset:
		@if [ -n "$(strip $(PINNED_REVISION))" ]; then \
			git -C "${SRC_DIR}" reset --hard $(PINNED_REVISION); \
		fi

	clone:
		@if ! test -d $(SRC_DIR); then \
			git clone $(REPOSITORY) $(SRC_DIR); \
		fi

	update: clean
		@git -C "${SRC_DIR}" pull

	install:
		$(MAKE) -C "${SRC_DIR}" -s install


	.PHONY: all clean update install reset clone patch

And this is the file structure I have:

	|- dwm
	|-- dwm-src         # git clone of dwm, handled by Makefile
	|-- config.h        # my custom config for dmenu
	|-- Makefile        # the Makefile from above
	|-- patches         # directory containing patches
	|---- 01-dmenu-centre.patch
	|---- 02-dmenu-border.patch

If you have no patches to apply, then remove the 'patch' from line 14 then run 'make', this will git clone or reset if already cloned, apply patches, copy your custom config.h and the build, A 'make install' after that will install as normal.

To see a working copy of these you can clone my dotfiles and have a look in the dwm, dmenu, st or herbe folders.

git clone git://jay.scot/dotfiles