include makerules

# pass debug=yes for debugging symbols, and to disable
# stripping and optimization of all binaries

# to build project contained in their own directory, run 
# $ make (dir).proj

all: ctl conv xutil gen
clean:
	rm xpriv safekill mkpw kpw.bin rosshil ord nkvd.so bgrd
install:
	mkdir -p $(prefix)/bin $(prefix)/lib
	cp xpriv safekill mkpw rosshil ord bgrd ${out}/bin/
	cp kpw.bin ${out}/bin/kpw
	cp nkvd.so $(prefix)/lib

xutil: xpriv safekill
  # X11 tools
gen: mkpw kpw.bin rosshil
  # procedural generators
conv: ord
  # converters
ctl: nkvd.so bgrd
  # manipulating disobedient software

nkvd.so: nkvd.c
	$(CC) -fPIC -pie -shared $< -o$@ -Wl,-E -ldl $(nkvd-flags)

bgrd: bgrd.c
	$(cc) $< -lutil -o$@ $(cc-post)

safekill: safekill.c
	$(cc) $< -lX11 -o$@ $(cc-post)

xpriv: xpriv.c
	$(cc) $< -lrt -lutil -lX11 -o $@ $(cc-post)

kpw.bin: kpw/makefile
	$(MAKE) root=$(realpath .) flags=$(kpw-flags) -C kpw $(realpath .)/$@

.PHONY: kpw
