##
 # OCaml-Win32
 # Makefile
 # By Harry Chomsky and Nicolas Cannasse
 # Copyright (c) 2002-2004 by Harry Chomsky
 #
 # This library is free software; you can redistribute it and/or
 # modify it under the terms of the GNU Library General Public
 # License as published by the Free Software Foundation; either
 # version 2 of the License, or (at your option) any later version.
 #
 # This library is distributed in the hope that it will be useful,
 # but WITHOUT ANY WARRANTY; without even the implied warranty of
 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 # Library General Public License for more details.
 #
 # You should have received a copy of the GNU Library General Public
 # License along with this library; if not, write to the Free
 # Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 ##

######################################################################
# DIRECTIVES :

.SUFFIXES : .ml .mli .cmo .cmx

######################################################################
# EXTENSIONS :

EXTFLAGS=
EXTCFLAGS=
EXTWINLIBS=
EXTCCWINLIBS=
EXTMODULES=

######################################################################
# MACROS :

FLAGS=$(EXTFLAGS)
CFLAGS=-ccopt /W3 -ccopt /YX -ccopt /Fpwin32.pch $(EXTCFLAGS)
WINLIBS=user32.lib gdi32.lib shell32.lib advapi32.lib comdlg32.lib comctl32.lib $(EXTWINLIBS)
CCWINLIBS= \
    -cclib user32.lib -cclib gdi32.lib -cclib shell32.lib -cclib advapi32.lib -cclib comdlg32.lib -cclib comctl32.lib \
    $(EXTCCWINLIBS)
MODULES= \
    win32_bitmap.+ win32_brush.+ win32_clipping.+ win32_color.+ win32_coord.+ win32_dc.+ win32_filledshape.+ win32_fonttext.+ win32_line.+ win32_paint.+ win32_path.+ win32_pen.+ win32_rectangle.+ win32_region.+ \
    win32_error.+ win32_errorcode.+ \
    win32_console.+ win32_process.+ win32_synch.+ \
    win32_disk.+ win32_volume.+ win32_directory.+ win32_file.+ \
    win32_pipe.+ \
    win32_handle.+ win32_time.+ \
    win32_control.+ win32_animation.+ win32_button.+ win32_combobox.+ win32_comboboxex.+ win32_datetimepicker.+ win32_editcontrol.+ win32_flatscrollbar.+ win32_header.+ win32_hotkey.+ win32_imagelist.+ win32_ipaddress.+ win32_listbox.+ win32_listview.+ win32_monthcalendar.+ win32_pager.+ win32_progressbar.+ win32_rebar.+ win32_scrollbar.+ win32_staticcontrol.+ win32_statusbar.+ win32_tabcontrol.+ win32_toolbar.+ win32_tooltip.+ win32_trackbar.+ win32_treeview.+ win32_updown.+ \
    win32_atom.+ win32_datacopy.+ \
    win32_resource.+ win32_caret.+ win32_cursor.+ win32_icon.+ win32_menu.+ win32_string.+ \
    win32_commondialog.+ win32_accelerator.+ win32_keyboard.+ win32_mouse.+ \
    win32_dialog.+ win32_message.+ win32_windowclass.+ win32_windowproc.+ win32_windowprop.+ win32_window.+ \
    $(EXTMODULES)

######################################################################
# TARGETS :

all : static dynamic opt mkwinapp

static : libwin32.lib win32.cma lkwinapp.obj test_static.exe

dynamic : dllwin32.dll win32.cma test_dynamic.exe

opt : libwin32.lib win32.cmxa lkwinapp.obj test_opt.exe

mkwinapp : mkwinapp.exe

#---------------------------------------------------------------------

clean :
    -@del win32.pch 2>NUL
    -@del win32_core.sobj 2>NUL
    -@del win32_core.dobj 2>NUL
    -@del win32_core.cmo 2>NUL
    -@del win32_core.cmi 2>NUL
    -@del win32_core.cmx 2>NUL
    -@del win32_core.obj 2>NUL
    -@del $(MODULES:+=sobj) 2>NUL
    -@del $(MODULES:+=dobj) 2>NUL
    -@del $(MODULES:+=cmo) 2>NUL
    -@del $(MODULES:+=cmi) 2>NUL
    -@del $(MODULES:+=cmx) 2>NUL
    -@del $(MODULES:+=obj) 2>NUL
    -@del win32.cmi 2>NUL
    -@del win32.cmo 2>NUL
    -@del win32.cmx 2>NUL
    -@del win32.obj 2>NUL
    -@del win32.cma 2>NUL
    -@del win32.cmxa 2>NUL
    -@del win32.lib 2>NUL
    -@del libwin32.lib 2>NUL
    -@del dllwin32.lib 2>NUL
    -@del dllwin32.exp 2>NUL
    -@del dllwin32.dll 2>NUL
    -@del mkwinapp.cmi 2>NUL
    -@del mkwinapp.cmo 2>NUL
    -@del mkwinapp.exe 2>NUL
    -@del lkwinapp.obj 2>NUL
    -@del test_res.obj 2>NUL
    -@del test.cmi 2>NUL
    -@del test.cmo 2>NUL
    -@del test.cmx 2>NUL
    -@del test.obj 2>NUL
    -@del testnores.cmi 2>NUL
    -@del testnores.cmo 2>NUL
    -@del test_static.exe 2>NUL
    -@del test_dynamic.exe 2>NUL
    -@del test_opt.exe 2>NUL

######################################################################
# BUILDS :

libwin32.lib : win32_core.sobj $(MODULES:+=sobj)
    -@del $@ 2>NUL
    lib /out:$@ $**

dllwin32.dll : win32_core.dobj $(MODULES:+=dobj)
    -@del $@ 2>NUL
    link $(WINLIBS) ocamlrun.lib /dll /out:$@ $**

win32.cma : win32_core.cmo $(MODULES:+=cmo) win32.cmo
    ocamlc -a -o $@ -cclib -lwin32 $(CCWINLIBS) -dllib -lwin32 $**

win32.cmxa : win32_core.cmx $(MODULES:+=cmx) win32.cmx
    ocamlopt -a -o $@ -cclib -lwin32 $(CCWINLIBS) $**

win32_core.cmi : win32_core.mli
    ocamlc $(FLAGS) -c $**

win32_core.cmo : win32_core.cmi win32_core.ml

win32_core.cmx : win32_core.cmi win32_core.ml

win32.cmo : win32_core.cmo $(MODULES:+=cmo) win32.ml

win32.cmx : win32_core.cmx $(MODULES:+=cmx) win32.ml

mkwinapp.exe : mkwinapp.ml
    ocamlc $(FLAGS) -o $@ unix.cma $**

test_static.exe : win32.cma test.ml test_res.obj libwin32.lib lkwinapp.obj
    ocamlc $(FLAGS) -o $@ -custom win32.cma test.ml test_res.obj lkwinapp.obj

test_dynamic.exe : win32.cma testnores.ml
    ocamlc $(FLAGS) -o $@ win32.cma testnores.ml

test_opt.exe : win32.cmxa test.ml test_res.obj libwin32.lib lkwinapp.obj
    ocamlopt $(FLAGS) -o $@ win32.cmxa test.ml test_res.obj lkwinapp.obj

######################################################################
# SUFFIXES :

.c.obj :
    ocamlc $(CFLAGS) $*.c

.c.sobj :
    ocamlc $(CFLAGS) -ccopt /Fo$@ $*.c

.c.dobj :
    ocamlc $(CFLAGS) -ccopt /Fo$@ -ccopt /MD -ccopt /DCAML_DLL $*.c

.rc.obj :
    rc $*.rc
    cvtres /machine:ix86 $*.res
    @del $*.res

.ml.cmo :
    ocamlc $(FLAGS) -c $*.ml

.ml.cmx :
    ocamlopt $(FLAGS) -c $*.ml

######################################################################
# END
