PREFIX=/usr
BINDIR=$(PREFIX)/bin
VERSION=0.2

TARGETS=autox11
AUTOX11_LIBS=$(shell pkg-config --libs x11 xtst gdk-pixbuf-2.0 gobject-2.0)
DESIGNER_LIBS=$(shell pkg-config --libs x11 gdk-pixbuf-2.0 gobject-2.0 gtk+-3.0 gtksourceview-3.0 2> /dev/null)
CFLAGS=$(shell pkg-config --cflags x11 xtst gdk-pixbuf-2.0 gobject-2.0) -g3 -Wall
ifneq ($(DESIGNER_LIBS),)
  CFLAGS+=$(shell pkg-config --cflags gtk+-3.0 gtksourceview-3.0)
  TARGETS+=autox11_designer
endif
AUTOX11_OBJ=main.o needle.o screen.o type.o guesskey.o
DESIGNER_OBJ=designer.o grab.o designer_imgcmd.o designer_typecmd.o designer_keycmd.o

all: $(TARGETS)

autox11: $(AUTOX11_OBJ) keylist.o
	$(CC) $^ $(LDFLAGS) $(AUTOX11_LIBS) -o $@

autox11_designer: $(DESIGNER_OBJ) keylist.o screen.o
	$(CC) $^ $(LDFLAGS) $(DESIGNER_LIBS) -o $@

keylist.c: genkeylist.sh
	./genkeylist.sh > keylist.c

clean:
	rm -f $(OBJ) keylist.o keylist.c autox11

tarball:
	tar -cJf autox11-$(VERSION).tar.xz --transform='s|^|autox11-$(VERSION)/|' $(subst .o,.c,$(AUTOX11_OBJ)) $(subst .o,.c,$(DESIGNER_OBJ)) autox11.h grab.h designer.h Makefile genkeylist.sh LICENSE README ChangeLog

install: all
	install -D -m 755 autox11 $(BINDIR)/autox11
ifneq ($(DESIGNER_LIBS),)
# TODO: create a .desktop file (plus icon) to install into $(PREFIX)/share/applications
	install -D -m 755 autox11_designer $(BINDIR)/autox11_designer
endif
