# Makefile to build the GIMP plug-ins with Microsoft nmake and compiler

# I don't want to use many hand-written makefiles, so this is quite complex.
# This same makefile is also included by sub-makes called as subroutines.
# Various parts of this file are used when makeing from the plug-ins directory,
# and when building individual plug-ins and the three plug-in libraries.

INSTALL = copy

GIMP = C:\gimp

BIN = $(GIMP)\plug-ins

!IFNDEF LIBRARY
!IFNDEF PLUGIN
!IFNDEF MODULE

# This part is used when making from the plug-ins directory

FROMPLUGINSDIR=YES		# Used to bypass other parts below

# List plug-ins. We must use several lists to work around nmake's limits

# The COMMON* ones are in the common subdirectory
COMMON1 = CEL CML_explorer align_layers animationplay animoptimize apply_lens autocrop autostretch_hsv blinds blur bumpmap c_astretch checkerboard colorify compose convmatrix csource cubism curve_bend
COMMON2 = decompose deinterlace depthmerge despeckle destripe diffraction displace edge emboss engrave exchange film flarefx fractaltrace
COMMON3 = gauss_iir gauss_rle gbr gee gicon gif gifload glasstile gpb gqbist gradmap grid gtm guillotine gz header hot hrz illusion iwarp jigsaw jpeg laplace lic
COMMON4 = mapcolor max_rgb mblur newsprint nlfilt noisify normalize nova oilify papertile pat pcx pix pixelize plasma plugindetails png pnm polar ps psd randomize ripple rotate
COMMON5 = sample_colorize scatter_hsv semiflatten sharpen shift smooth_palette snoise sobel sparkle spheredesigner spread sunras tga threshold_alpha tiff tile tileit tiler video vinvert vpropagate waves whirlpinch winclipboard wind winprint wmf xbm xwd zealouscrop

# These have own subdirectories each
SEPARATE = AlienMap AlienMap2 FractalExplorer Lighting MapObject bmp borderaverage dbbrowser faxg3 fits flame fp gdyntext gfig gflare gfli gimpressionist ifscompose imagemap maze mosaic pagecurl rcm sel2path sgi sinus struc twain unsharp winsnap

# These are unofficial, ie not in the CVS. To build these, you should
# get tml's source snapshot and copy this makefile to the
# ..\unofficial-plug-ins directory, go there, and do "nmake -f
# makefile.msc unofficial".

UNOFFICIAL = Anamorphose RGB_Displace ccanalyze gimp_ace guash pmosaic sel_gauss user_filter

# The main target

all : ..\config.h libs-all common-plugins-all separate-plugins-all

..\config.h : ..\config.h.win32
	copy ..\config.h.win32 ..\config.h

install : libs-install common-plugins-install separate-plugins-install data-install

unofficial:
	for %d in ($(UNOFFICIAL)) do nmake -nologo -f makefile.msc sub-one-separate DIR=%d TARGET=install

clean : libs-clean common-plugins-clean separate-plugins-clean

libs-all :
	@nmake -nologo -f makefile.msc sub-libs TARGET=all

libs-install :
	@nmake -nologo -f makefile.msc sub-libs TARGET=install

libs-clean :
	@nmake -nologo -f makefile.msc sub-libs TARGET=clean

sub-libs:
	cd libgck\gck
	nmake -nologo -f ..\..\makefile.msc TOP=..\..\.. LIBRARY=gck OBJECTS="gckcolor.obj gckui.obj" $(TARGET)
	cd ..\..



common-plugins-all :
	@nmake -nologo -f makefile.msc sub-common-plugins TARGET=all

common-plugins-install :
	@nmake -nologo -f makefile.msc sub-common-plugins TARGET=install

common-plugins-clean :
	@nmake -nologo -f makefile.msc sub-common-plugins TARGET=clean



sub-common-plugins :
	for %d in ($(COMMON1)) do nmake -nologo -f makefile.msc sub-one-common DIR=%d TARGET=$(TARGET)
	for %d in ($(COMMON2)) do nmake -nologo -f makefile.msc sub-one-common DIR=%d TARGET=$(TARGET)
	for %d in ($(COMMON3)) do nmake -nologo -f makefile.msc sub-one-common DIR=%d TARGET=$(TARGET)
	for %d in ($(COMMON4)) do nmake -nologo -f makefile.msc sub-one-common DIR=%d TARGET=$(TARGET)
	for %d in ($(COMMON5)) do nmake -nologo -f makefile.msc sub-one-common DIR=%d TARGET=$(TARGET)

sub-one-common :
	@cd common
	@nmake -nologo -f ..\makefile.msc TOP=..\.. PLUGIN=$(DIR) EXTRA_$(DIR)=1 $(TARGET)



separate-plugins-all :
	@nmake -nologo -f makefile.msc sub-separate-plugins TARGET=all

separate-plugins-install :
	@nmake -nologo -f makefile.msc sub-separate-plugins TARGET=install

separate-plugins-clean :
	@nmake -nologo -f makefile.msc sub-separate-plugins TARGET=clean



sub-separate-plugins :
	for %d in ($(SEPARATE)) do nmake -nologo -f makefile.msc sub-one-separate DIR=%d TARGET=$(TARGET)
# We must handle script-fu separately because of the dash, sigh
	@cd script-fu
	@nmake -nologo -f ..\makefile.msc TOP=..\.. PLUGIN=script-fu EXTRA_script_fu=1 $(TARGET)
	@cd ..
# Also GAP is special
	@cd gap
	@nmake -nologo -f ..\makefile.msc TOP=..\.. PLUGIN=gap_filter EXTRA_gap_filter=1 $(TARGET)
	@cd ..
	@cd gap
	@nmake -nologo -f ..\makefile.msc TOP=..\.. PLUGIN=gap_plugins EXTRA_gap_plugins=1 $(TARGET)
	@cd ..


sub-one-separate :
	cd $(DIR)
	nmake -nologo -f ..\makefile.msc TOP=..\.. PLUGIN=$(DIR) EXTRA_$(DIR)=1 $(TARGET)


data-install : gimpressionist-data-install guash-data-install
	-md $(GIMP)\scripts
	$(INSTALL) script-fu\scripts\*.scm $(GIMP)\scripts
	$(INSTALL) script-fu\scripts\*.jpg $(GIMP)\scripts
	$(INSTALL) FractalExplorer\fractalexplorer-examples\* $(GIMP)\fractalexplorer
	del $(GIMP)\fractalexplorer\Makefile.am

gimpressionist-data-install :
	-md $(GIMP)\gimpressionist
	-md $(GIMP)\gimpressionist\Brushes
	-md $(GIMP)\gimpressionist\Paper
	-md $(GIMP)\gimpressionist\Presets
	$(INSTALL) gimpressionist\Brushes\*.pgm $(GIMP)\gimpressionist\Brushes
	$(INSTALL) gimpressionist\Brushes\*.ppm $(GIMP)\gimpressionist\Brushes
	$(INSTALL) gimpressionist\Paper\*.pgm $(GIMP)\gimpressionist\Paper
	$(INSTALL) gimpressionist\Presets\* $(GIMP)\gimpressionist\Presets
	del $(GIMP)\gimpressionist\Presets\Makefile.am

guash-data-install :


!ENDIF
!ENDIF
!ENDIF

!IFNDEF FROMPLUGINSDIR

# This part is used when building individual plug-ins or one of
# the libraries. 

# If a plug-in has several object files, or needs extra libraries or
# compiler flags, these are in an EXTRA_xxx part.

!IFDEF EXTRA_FractalExplorer
OBJECTS = \
	Callbacks.obj \
	Dialogs.obj \
	Events.obj \
	FractalExplorer.obj \
	Globals.obj \
	Languages.obj
!ENDIF

!IFDEF EXTRA_Lighting
OBJECTS = \
	lighting_apply.obj \
	lighting_image.obj \
	lighting_main.obj \
	lighting_preview.obj \
	lighting_shade.obj \
	lighting_ui.obj
!ENDIF

!IFDEF EXTRA_MapObject
OBJECTS = \
	arcball.obj \
	mapobject_apply.obj \
	mapobject_image.obj \
	mapobject_main.obj \
	mapobject_preview.obj \
	mapobject_shade.obj \
	mapobject_ui.obj
OPTIMIZE =
!ENDIF

!IFDEF EXTRA_bmp
OBJECTS = \
	bmp.obj \
	bmpread.obj \
	bmpwrite.obj
!ENDIF

!IFDEF EXTRA_dbbrowser
OBJECTS = \
	dbbrowser.obj \
	dbbrowser_utils.obj
!ENDIF

!IFDEF EXTRA_faxg3
OBJECTS = \
	faxg3.obj \
	g3.obj	\
	run_tbl.obj
!ENDIF

!IFDEF EXTRA_fits
OBJECTS = \
	fits.obj \
	fitsrw.obj
!ENDIF

!IFDEF EXTRA_flame
OBJECTS = \
	cmap.obj \
	flame.obj \
	libifs.obj \
	megawidget.obj \
	rect.obj
!ENDIF

!IFDEF EXTRA_fp
OBJECTS = \
	fp.obj \
	fp_gdk.obj \
	fp_gtk.obj \
	fp_hsv.obj \
	fp_misc.obj
!ENDIF

!IFDEF EXTRA_gap_filter
OBJECTS = \
	gap_filter_main.obj \
	gap_dbbrowser_utils.obj \
	gap_filter_foreach.obj \
	gap_filter_iterators.obj \
	gap_filter_pdb.obj \
	gap_filter_codegen.obj \
	gap_arr_dialog.obj \
	gap_pdb_calls.obj
!ENDIF
	
!IFDEF EXTRA_gap_plugins
OBJECTS = \
	gap_main.obj \
	gap_mov_exec.obj \
	gap_range_ops.obj \
	gap_arr_dialog.obj \
	gap_mov_dialog.obj \
	gap_layer_copy.obj \
	gap_split.obj \
	gap_resi_dialog.obj \
	gap_mpege.obj \
	gap_mod_layer.obj \
	gap_filter_pdb.obj \
	gap_filter_codegen.obj \
	gap_dbbrowser_utils.obj \
	gap_match.obj \
	gap_lib.obj \
	gap_exchange_image.obj \
	gap_pdb_calls.obj \
	resize.obj
!ENDIF

!IFDEF EXTRA_gdyntext
OBJECTS = \
	charmap.obj \
	charmap_window.obj \
	font_selection.obj \
	gdyntext.obj \
	gdyntext_ui.obj \
	message_window.obj
!ENDIF

ifdef EXTRA_gflare
OBJECTS = \
	asupsample.obj \
	gflare.obj \
	gtkmultioptionmenu.obj
endif

!IFDEF EXTRA_gfli
OBJECTS = \
	fli.obj \
	gfli.obj
!ENDIF

!IFDEF EXTRA_ifscompose
OBJECTS = \
	ifscompose.obj \
	ifscompose_storage.obj \
	ifscompose_utils.obj
!ENDIF

!IFDEF EXTRA_imagemap
OBJECTS = \
	imap_cmd_copy_object.obj \
	imap_about.obj \
	imap_browse.obj \
	imap_cern_lex.obj \
	imap_cern_parse.obj \
	imap_circle.obj \
	imap_cmd_clear.obj \
	imap_cmd_copy.obj \
	imap_cmd_create.obj \
	imap_cmd_cut.obj \
	imap_cmd_cut_object.obj \
	imap_cmd_delete.obj \
	imap_cmd_delete_point.obj \
	imap_cmd_edit_object.obj \
	imap_cmd_guides.obj \
	imap_cmd_insert_point.obj \
	imap_cmd_move.obj \
	imap_cmd_move_down.obj \
	imap_cmd_move_sash.obj \
	imap_cmd_move_selected.obj \
	imap_cmd_move_to_front.obj \
	imap_cmd_move_up.obj \
	imap_cmd_object_down.obj \
	imap_cmd_object_move.obj \
	imap_cmd_object_up.obj \
	imap_cmd_paste.obj \
	imap_cmd_select.obj \
	imap_cmd_select_all.obj \
	imap_cmd_select_next.obj \
	imap_cmd_select_prev.obj \
	imap_cmd_select_region.obj \
	imap_cmd_send_to_back.obj \
	imap_cmd_unselect.obj \
	imap_cmd_unselect_all.obj \
	imap_command.obj \
	imap_csim_lex.obj \
	imap_csim_parse.obj \
	imap_default_dialog.obj \
	imap_edit_area_info.obj \
	imap_file.obj \
	imap_grid.obj \
	imap_main.obj \
	imap_menu.obj \
	imap_menu_funcs.obj \
	imap_misc.obj \
	imap_mru.obj \
	imap_ncsa_lex.obj \
	imap_ncsa_parse.obj \
	imap_object.obj \
	imap_object_popup.obj \
	imap_polygon.obj \
	imap_popup.obj \
	imap_preferences.obj \
	imap_preview.obj \
	imap_rectangle.obj \
	imap_selection.obj \
	imap_settings.obj \
	imap_source.obj \
	imap_statusbar.obj \
	imap_string.obj \
	imap_table.obj \
	imap_toolbar.obj \
	imap_tools.obj
!ENDIF

!IFDEF EXTRA_iwarp
OPTIMIZE =
!ENDIF

!IFDEF EXTRA_jpeg
EXTRACFLAGS = -I$(JPEG)
EXTRALIBS = $(JPEG)\libjpeg.lib
!ENDIF

!IFDEF EXTRA_maze
OBJECTS = \
	algorithms.obj \
	handy.obj \
	maze.obj \
	maze_face.obj
!ENDIF

!IFDEF EXTRA_mpeg
EXTRACFLAGS = -I$(MPEG)
EXTRALIBS = $(MPEG)\release\libmpeg.lib
!ENDIF

!IFDEF EXTRA_png
EXTRACFLAGS = -I$(PNG) -I$(ZLIB)
EXTRALIBS = $(PNG)\libpng.lib $(ZLIB)\zlib.lib
!ENDIF

!IFDEF EXTRA_print
OBJECTS = \
	print.obj \
	print-escp2.obj \
	print-pcl.obj \
	print-ps.obj \
	print-util.obj
!ENDIF

!IFDEF EXTRA_psp
EXTRACFLAGS = -I$(ZLIB)
EXTRALIBS = $(ZLIB)\zlib.lib user32.lib
!ENDIF

!IFDEF EXTRA_rcm
OBJECTS = \
	rcm.obj \
	rcm_callback.obj \
	rcm_dialog.obj \
	rcm_gdk.obj \
	rcm_misc.obj
OPTIMIZE = 
!ENDIF

!IFDEF EXTRA_script_fu
OBJECTS = \
	interp_md5.obj \
	interp_regex.obj \
	interp_slib.obj \
	interp_sliba.obj \
	interp_trace.obj \
	script-fu.obj \
	script-fu-console.obj \
	script-fu-constants.obj \
	script-fu-scripts.obj \
	regex.obj \
	..\dbbrowser\dbbrowser_utils.obj
EXTRACFLAGS = -DREGEX_MALLOC
HAVE_RESOURCE = YES
!ENDIF

!IFDEF EXTRA_sel2path
OBJECTS = \
	curve.obj \
	edge.obj \
	fit.obj \
	math.obj \
	pxl-outline.obj \
	sel2path.obj \
	sel2path_adv_dialog.obj \
	spline.obj \
	vector.obj
!ENDIF

!IFDEF EXTRA_sgi
OBJECTS = \
	sgi.obj \
	sgilib.obj
!ENDIF

!IFDEF EXTRA_tiff
EXTRACFLAGS = -I$(TIFF)
EXTRALIBS = $(TIFF)\libtiff.lib $(JPEG)\libjpeg.lib $(ZLIB)\zlib.lib user32.lib
!ENDIF

!IFDEF EXTRA_unsharp
OBJECTS = \
	dialog_f.obj \
	dialog_i.obj \
	unsharp.obj
!ENDIF

!IFDEF EXTRA_gimp_ace
EXTRACFLAGS = -DGLACE_GIMP
OBJECTS = \
	gimp_ace.obj \
	glace.obj \
	glaceG.obj
!ENDIF

!IFDEF EXTRA_gimpressionist

OBJECTS = \
	about.obj \
	brush.obj \
	color.obj \
	general.obj \
	gimp.obj \
	gimpressionist.obj \
	orientation.obj \
	orientmap.obj \
	paper.obj \
	placement.obj \
	plasma.obj \
	ppmtool.obj \
	presets.obj \
	preview.obj \
	repaint.obj \
	size.obj \
	sizemap.obj
!ENDIF

!IFDEF EXTRA_guash
HAVE_RESOURCE = YES
!ENDIF

!IFDEF EXTRA_user_filter

uf_lexer.c : uf_lexer.l
	flex -Cem -ouf_lexer.c uf_lexer.l
uf_parser.tab.c: uf_parser.y
	bison --defines --verbose uf_parser.y

OBJECTS = \
	libyywrap.obj \
	uf_eval.obj \
	uf_file.obj \
	uf_gui.obj \
	uf_lexer.obj \
	uf_main.obj \
	uf_parser.tab.obj
!ENDIF

!IFDEF EXTRA_pmosaic
EXTRACFLAGS = -I$(JPEG)
EXTRALIBS = $(JPEG)\libjpeg.lib
OBJECTS = \
	pmosaic.obj \
	pmsc.obj
!ENDIF

!IFDEF EXTRA_twain
OBJECTS = \
	tw_func.obj \
	tw_util.obj \
	twain.obj
EXTRALIBS = user32.lib
!ENDIF

!IFDEF EXTRA_winprint
EXTRALIBS = user32.lib gdi32.lib comdlg32.lib
!endif

!IFDEF EXTRA_winclipboard
EXTRALIBS = user32.lib
!endif

!IFDEF EXTRA_winsnap
HAVE_RESOURCE = YES
EXTRALIBS = user32.lib gdi32.lib
!endif

GIMP_VER = 1.1
GTK_VER = 1.3
GLIB_VER = 1.3

GTK = $(TOP)\..\gtk+
GLIB = $(TOP)\..\glib
INTL = $(TOP)\..\intl

# Location of libpng sources
PNG = $(TOP)\..\libpng-1.0.3
# Location of tiff-3.4 sources
TIFF = $(TOP)\..\tiff-v3.4\libtiff
# Location of jpeg-6b sources
JPEG = $(TOP)\..\jpeg-6b
# and zlib
ZLIB = $(TOP)\..\zlib-1.1.3
# and libmpeg
MPEG = $(TOP)\..\mpeg_lib-1.3.0

PLUGINDIR = $(TOP)\plug-ins

!IFNDEF OPTIMIZE
!IFNDEF DEBUG
OPTIMIZE = -Ox
!ELSE
OPTIMIZE = -Zi
!ENDIF
!ENDIF

!IFNDEF DEBUG
LINKDEBUG =
RTL = -MD
!ELSE
LINKDEBUG = /debug
RTL = -MDd
!ENDIF

CC = cl -nologo -G5 -GF $(OPTIMIZE) $(RTL) -W2 -Zm200

CFLAGS = -DHAVE_CONFIG_H $(EXTRACFLAGS) -I. -I$(TOP) -I$(PLUGINDIR) -I$(PLUGINDIR)\libgck -I$(GLIB) -I$(GTK)\gdk -I$(GTK)\gdk -I$(GTK) -I$(INTL)

LDFLAGS = /link /subsystem:windows /machine:ix86 $(LINKDEBUG)

!IFDEF PLUGIN

# This part is used when building individual plug-ins

all : $(PLUGIN).exe

install : all
	$(INSTALL) $(PLUGIN).exe $(BIN)

!IFNDEF OBJECTS
OBJECTS = $(PLUGIN).obj
!ENDIF

!IFDEF HAVE_RESOURCE
# We have our own resource file (just an icon, usually)
RESOURCE = $(PLUGIN).res
!ELSE
# Use the Wilber icon otherwise. If gimp.exe eventually gets more resources,
# this will have to be changed.
RESOURCE = ..\..\app\gimp.res
!ENDIF

$(PLUGIN).exe : $(OBJECTS) $(RESOURCE)
	$(CC) $(CFLAGS) -MD -Fe$(PLUGIN).exe $(OBJECTS) $(RESOURCE) $(PLUGINDIR)\libgck\gck\gck.lib ..\..\libgimp\gimp-$(GIMP_VER).lib ..\..\libgimp\gimpui-$(GIMP_VER).lib $(GTK)\gtk\gtk-$(GTK_VER).lib $(GTK)\gdk\gdk-$(GTK_VER).lib $(INTL)\gnu-intl.lib $(GLIB)\glib-$(GLIB_VER).lib $(EXTRALIBS) $(LDFLAGS)

$(PLUGIN).res : $(PLUGIN).rc
	rc -r -fo $(PLUGIN).res $(PLUGIN).rc

!ENDIF

!IFDEF LIBRARY

# This part is used when building a library

all : $(LIBRARY).lib

install : all

!IFNDEF OBJECTS
OBJECTS = $(LIBRARY).obj
!ENDIF

$(LIBRARY).lib : $(OBJECTS)
	lib /out:$(LIBRARY).lib $(OBJECTS)

!ENDIF

!IFDEF MODULE

# This part is used when building a module

# Allow building libraries with specific extensions
!IFNDEF MODULE_EXT
MODULE_EXT = dll
!ENDIF

all : $(MODULE).$(MODULE_EXT)

install : all

!IFNDEF OBJECTS
OBJECTS = $(MODULE).obj
!ENDIF

$(MODULE).$(MODULE_EXT) : $(OBJECTS) $(MODULE).def
	$(CC) $(CFLAGS) -LD -Fe$@ $(OBJECTS) $(LDFLAGS) $(EXTRALIBS) ..\..\libgimp\gimp-$(GIMP_VER).lib ..\..\libgimp\gimpui-$(GIMP_VER).lib $(GTK)\gtk\gtk-$(GTK_VER).lib $(GLIB)\gmodule-$(GLIB_VER).lib $(GLIB)\glib-$(GLIB_VER).lib /def:$(MODULE).def
!ENDIF

.c.obj :
	$(CC) $(CFLAGS) -c $<

clean :
	erase *.obj
	erase *.lib
	erase *.exp
	erase *.exe
	erase *.pdb
	erase *.ilk

!ENDIF
