VERSION=5.3

# C Compiler to use
CC=gcc

# Program used to install binaries and data.
INSTALL=install
INSTALL_PROGRAM=$(INSTALL)
INSTALL_STRIP=$(INSTALL_PROGRAM) -s
INSTALL_DATA=$(INSTALL) -m 644

# Optimization and debug flags
CFLAGS=-O3 -Wall # -g

# Set PREFIX to the root of where you want to install gtklife
prefix=/usr/local

# Installation points for the gtklife program, data, and documentation,
# respectively.
bindir=$(prefix)/games
pkgdatadir=$(prefix)/share/gtklife
docdir=$(prefix)/doc/gtklife

# Set to "gtk2=yes" to compile for gtk+ 2 instead of 1.2
gtk2=no

##### You shouldn't need to edit anything below this line #####

# Preprocessor and linking flags

CPPFLAGS:=$(CPPFLAGS) -DVERSION=\"$(VERSION)\" -DDATADIR=\"$(pkgdatadir)\" -DDOCDIR=\"$(docdir)\"

ifeq ($(gtk2),yes)
  CPPFLAGS:=$(CPPFLAGS) `pkg-config --cflags gtk+-2.0` -DGTK2 -DGTK_ENABLE_BROKEN
  LDFLAGS:=$(LDFLAGS) `pkg-config --libs gtk+-2.0` -lX11
else
  CPPFLAGS:=$(CPPFLAGS) `gtk-config --cflags`
  LDFLAGS:=$(LDFLAGS) `gtk-config --libs`
endif

# Object files

OBJS=gtklife.o life.o loadsave.o ewmh.o util.o icons.o ul_lookup.o ur_lookup.o ll_lookup.o lr_lookup.o
CL_OBJS=create_lookup.o util.o

# Targets

all: gtklife

install: all install-data
	$(INSTALL) -d $(bindir)
	$(INSTALL_STRIP) gtklife $(bindir)

install-data:
	$(INSTALL) -d $(pkgdatadir)
	$(INSTALL) -d $(pkgdatadir)/graphics
	$(INSTALL_DATA) graphics/* $(pkgdatadir)/graphics
	rm -rf $(pkgdatadir)/patterns
	umask 022; cp -r patterns $(pkgdatadir)
	$(INSTALL) -d $(docdir)
	$(INSTALL_DATA) doc/* $(docdir)

gtklife: $(OBJS)
	$(CC) -o gtklife $(OBJS) $(LDFLAGS)

create_lookup: $(CL_OBJS)
	$(CC) -o create_lookup $(CL_OBJS)

mostlyclean:
	rm -f gtklife create_lookup *.o

clean: mostlyclean
	rm -f [ul][lr]_lookup.c

distclean: clean

# Generated source files

ul_lookup.c: create_lookup
	./create_lookup ul
ur_lookup.c: create_lookup
	./create_lookup ur
ll_lookup.c: create_lookup
	./create_lookup ll
lr_lookup.c: create_lookup
	./create_lookup lr

# Dependencies

gtklife.o: gtklife.h life.h ewmh.h util.h icons.h
life.o: life.h loadsave.h lookup.h util.h
loadsave.o: loadsave.h life.h util.h
create_lookup.o: create_lookup.h util.h
ewmh.o: ewmh.h util.h
util.o: util.h
