# Makefile for pandora panorama gimp plugin

GIMP_1_3_DIR=${HOME}/.gimp-1.3/plug-ins

# gimp 2.0 will write to ~/.gimp-1.3 if it's there, otherwise it will
# create ~/.gimp-2.0.  So we can't count on finding either one.
# This is an egregious hack to try to pick one.
GIMP_2_0_DIR=$(shell if test -d ${HOME}/.gimp-2.0/plug-ins ; then echo ${HOME}/.gimp-2.0/plug-ins ; elif test -d ${HOME}/.gimp-1.3/plug-ins ; then echo ${HOME}/.gimp-1.3/plug-ins ; else echo ${HOME}/.gimp-2.0/plug-ins ; fi )

GIMP_1_2_DIR=${HOME}/.gimp-1.2/plug-ins

GIMPTOOL_1_2=$(shell which gimptool-1.2)
GIMPTOOL_1_3=$(shell which gimptool-1.3)
GIMPTOOL_2_0=$(shell which gimptool-2.0)
GIMPTOOL_2=$(shell if test -x ${GIMPTOOL_2_0} ; then echo ${GIMPTOOL_2_0} ; else echo ${GIMPTOOL_1_3} ; fi )

# We don't need C99, but gcc 3.3 forces it by default, so we don't
# see errors that might kill other people's builds.  Force C89:
export CFLAGS=-std=c89

# Most people will want make install, but this dummy target is for
# people who don't want a makefile to install anything unless asked.
build:
	@echo Type make install to build and install the plugin.
	@echo I will try to install it for both gimp 1.2 and 2.0,
	@echo if you have both.

install:
	if test -x "${GIMPTOOL_1_2}"; then make install-1.2; fi
	if test -x "${GIMPTOOL_2}"; then make install-2.0; fi

# pandora-match is experimental and not very useful yet.
# Most people probably shouldn't bother.
debug-all:
	if test -x "${GIMPTOOL_1_2}"; then make debug-1.2; fi
	if test -x "${GIMPTOOL_2}"; then make debug-2.0; fi

install-2.0: ${GIMP_2_0_DIR}/pandora_gen

install-1.2: ${GIMP_1_2_DIR}/pandora_gen

debug-2.0: ${GIMP_2_0_DIR}/pandora_gen ${GIMP_2_0_DIR}/pandora_match

debug-1.2: ${GIMP_1_2_DIR}/pandora_gen ${GIMP_1_2_DIR}/pandora_match

${GIMP_1_2_DIR}/pandora_gen: pandora_gen.c
	mkdir -p ${GIMP_1_2_DIR}
	gimptool-1.2 --install-strip pandora_gen.c

${GIMP_1_2_DIR}/pandora_match: pandora_match.c
	mkdir -p ${GIMP_1_2_DIR}
	gimptool-1.2 --install-strip pandora_match.c

${GIMP_2_0_DIR}/pandora_gen: pandora_gen.c
	mkdir -p ${GIMP_2_0_DIR}
	gimptool-2.0 --install-strip pandora_gen.c

${GIMP_2_0_DIR}/pandora_match: pandora_match.c
	mkdir -p ${GIMP_2_0_DIR}
	gimptool-2.0 --install-strip pandora_match.c

clean:
	rm -f pandora_match pandora_gen *.o

