GIMP_VER = 2.4

#USE_LCMS2 = yes

PREFIX      = $(PROGRAMFILES)/gimp-$(GIMP_VER)
INSTALLDIR  = $(PREFIX)/lib/gimp/2.0/plug-ins
#INSTALLDIR = $(USERPROFILE)/.gimp-$(GIMP_VER)/plug-ins

ifdef USE_LCMS2
  LCMS_PKG  = lcms2
  CFLAGS   += -DUSE_LCMS2
else
  LCMS_PKG  = lcms
endif

GTK_INCLUDE  = `pkg-config gtk+-2.0 --cflags`
GTK_LIB      = `pkg-config gtk+-2.0 --libs`
GIMP_INCLUDE = `pkg-config gimp-2.0 --cflags` `pkg-config gimpui-2.0 --cflags`
GIMP_LIB     = `pkg-config gimp-2.0 --libs` `pkg-config gimpui-2.0 --libs`
LCMS_INCLUDE = `pkg-config $(LCMS_PKG) --cflags`
LCMS_LIB     = `pkg-config $(LCMS_PKG) --libs`
TIFF_LIB     = -ltiff
JPEG_LIB     = -ljpeg
SYS_LIBS     = -lmscms

GETTEXT_PACKAGE = gimp20-separate

VERSION = 0.5.8
CC      = gcc -g
DEPEND  = gccmakedep
RM      = rm -f
MAKE    = make PREFIX="$(PREFIX)"

# If you will use with the GIMP 2.2.x, remove "-DENABLE_COLOR_MANAGEMENT".
CM       = -DENABLE_COLOR_MANAGEMENT
NLS      = -DENABLE_NLS -DGETTEXT_PACKAGE="\"$(GETTEXT_PACKAGE)\""
CFLAGS  += $(GIMP_INCLUDE) $(GTK_INCLUDE) $(LCMS_INCLUDE) $(CM) $(NLS) \
           -DUSE_ICC_BUTTON \
           -mms-bitfields -march=pentium3 -msse -mfpmath=sse
LDFLAGS += -mwindows
LIBS     = $(GIMP_LIB) $(GTK_LIB) $(LCMS_LIB) $(TIFF_LIB) $(JPEG_LIB) $(SYS_LIBS)

SOURCES = $(SEPARATE_SOURCES) $(IMPORT_SOURCES) \
          $(ICC_COLORSPACE_SOURCES) $(EXTRA_SOURCES)

OBJECTS = $(SOURCES:.c=.o)

EXTRA_SOURCES = iccbutton.c lcms_wrapper.c

SEPARATE_SOURCES = separate-core.c separate-gui.c separate-export.c util.c tiff.c psd.c jpeg.c

SEPARATE_OBJECTS = $(SEPARATE_SOURCES:.c=.o) $(EXTRA_SOURCES:.c=.o)

IMPORT_SOURCES = import.c

IMPORT_OBJECTS = $(IMPORT_SOURCES:.c=.o)

ICC_COLORSPACE_SOURCES = icc_colorspace.c

ICC_COLORSPACE_OBJECTS = $(ICC_COLORSPACE_SOURCES:.c=.o) $(EXTRA_SOURCES:.c=.o)

TARGETS = separate.exe separate_import.exe icc_colorspace.exe


.PHONY: all
all: plugins catalogs

depend:
	$(DEPEND) -- $(CFLAGS) -- $(SOURCES)

clean-plugins:
	$(RM) $(OBJECTS) $(TARGETS) core *~

clean-catalogs:
	$(MAKE) -C po clean

clean: clean-plugins clean-catalogs

catalogs:
	$(MAKE) -C po

plugins: $(TARGETS)

separate.exe: $(SEPARATE_OBJECTS)
	$(CC) $(LDFLAGS) $(SEPARATE_OBJECTS) -o $@ $(LIBS)

separate_import.exe: $(IMPORT_OBJECTS)
	$(CC) $(LDFLAGS) $(IMPORT_OBJECTS) -o $@ $(LIBS)

icc_colorspace.exe: $(ICC_COLORSPACE_OBJECTS)
	$(CC) $(LDFLAGS) $(ICC_COLORSPACE_OBJECTS) -o $@ $(LIBS)

install-catalogs:
	$(MAKE) -C po install

install-plugins: $(TARGETS)
	install -d "$(INSTALLDIR)"
	install -c -s $^ "$(INSTALLDIR)"

install: install-plugins install-catalogs

uninstall-plugins:
	targets="$(TARGETS)"; \
	for target in $$targets; do \
		$(RM) "$(INSTALLDIR)/$$target"; \
	done

uninstall-catalogs:
	$(MAKE) -C po uninstall

uninstall: uninstall-plugins uninstall-catalogs


# Inference rules
.c.o:
	$(CC) $(CFLAGS) -c $<


#
iccbutton.o: iccbutton.h iccclassicons.h lcms_wrapper.h
lcms_wrapper.o: lcms_wrapper.h
separate-core.o: separate.h separate-core.h lcms_wrapper.h
separate-export.o: separate.h separate-export.h tiff.h psd.h jpeg.h
separate-gui.o: separate.h separate-core.h separate-export.h iccbutton.h icon.h
import.o: separate.h
icc_colorspace.o: icc_colorspace.h iccbutton.h lcms_wrapper.h
tiff.o: separate.h util.h tiff.h
psd.o: separate.h util.h psd.h
jpeg.o: separate.h util.h jpeg.h
util.o: separate.h util.h
