#copyright (c) 2006-2007 Kazuki IWAMOTO http://www.maid.org/ iwm@maid.org
#
#Permission is hereby granted, free of charge, to any person obtaining
#a copy of this software and associated documentation files (the
#"Software"), to deal in the Software without restriction, including
#without limitation the rights to use, copy, modify, merge, publish,
#distribute, sublicense, and/or sell copies of the Software, and to
#permit persons to whom the Software is furnished to do so, subject to
#the following conditions:
#
#The above copyright notice and this permission notice shall be included
#in all copies or substantial portions of the Software.
#
#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
#EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
#MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
#IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
#CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
#TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
#SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

VERSION=0.0.1

!ifndef LINK
LINK=link
!endif
!ifndef MT
MT=mt
!endif

CLFLAGS=/c /D_MBCS /DNDEBUG /DWIN32 /D_WINDOWS /D_WIN32_WINNT=0x0500 /DWINVER=0x0500 /D_CRT_SECURE_NO_DEPRECATE /Fo$@ /MD /nologo /O2
LNFLAGS=/INCREMENTAL:NO /MACHINE:IX86 /NOLOGO /OUT:$@ /RELEASE

all: iconv.dll intl.dll msgfmt.exe

iconv.dll: $*.obj
	$(LINK) $(LNFLAGS) /DLL /EXPORT:_libiconv_version,@1 /EXPORT:iconv_canonicalize,@2 /EXPORT:libiconv,@3 /EXPORT:libiconv_close,@4 /EXPORT:libiconv_open,@5 /EXPORT:libiconv_set_relocation_prefix,@6 /EXPORT:libiconvctl,@7 /EXPORT:libiconvlist,@8 ole32.lib oleaut32.lib user32.lib $**
	if exist $@.manifest $(MT) -manifest $@.manifest -outputresource:$@;#2

iconv.obj: $*.c
	$(CC) $(CLFLAGS) $**

intl.dll: iconv.dll $*.obj
	$(LINK) $(LNFLAGS) /DLL \
		/EXPORT:bind_textdomain_codeset=libintl_bind_textdomain_codeset,@3 \
		/EXPORT:bindtextdomain=libintl_bindtextdomain,@4 \
		/EXPORT:dcgettext=libintl_dcgettext,@5 \
		/EXPORT:dcngettext=libintl_dcngettext,@6 \
		/EXPORT:dgettext=libintl_dgettext,@7 \
		/EXPORT:dngettext=libintl_dngettext,@8 \
		/EXPORT:gettext=libintl_gettext,@9 \
		/EXPORT:libintl_bind_textdomain_codeset,@10 \
		/EXPORT:libintl_bindtextdomain,@11 \
		/EXPORT:libintl_dcgettext,@12 \
		/EXPORT:libintl_dcngettext,@13 \
		/EXPORT:libintl_dgettext,@14 \
		/EXPORT:libintl_dngettext,@15 \
		/EXPORT:libintl_fprintf,@16 \
		/EXPORT:libintl_gettext,@17 \
		/EXPORT:libintl_ngettext,@18 \
		/EXPORT:libintl_printf,@19 \
		/EXPORT:libintl_set_relocation_prefix,@20 \
		/EXPORT:libintl_sprintf,@21 \
		/EXPORT:libintl_textdomain,@22 \
		/EXPORT:libintl_version,@23 \
		/EXPORT:libintl_vfprintf,@24 \
		/EXPORT:libintl_vprintf,@25 \
		/EXPORT:libintl_vsprintf,@26 \
		/EXPORT:ngettext=libintl_ngettext,@27 \
		/EXPORT:textdomain=libintl_textdomain,@28 iconv.lib $*.obj
	if exist $@.manifest $(MT) -manifest $@.manifest -outputresource:$@;#2

intl.obj: $*.c
	$(CC) $(CLFLAGS) $**

msgfmt.exe: $*.obj
	$(LINK) $(LNFLAGS) $**
	if exist $@.manifest $(MT) -manifest $@.manifest -outputresource:$@;#1

msgfmt.obj: $*.c
	$(CC) $(CLFLAGS) $**

clean:
	if exist iconv.dll del /q iconv.dll
	if exist iconv.dll.manifest del /q iconv.dll.manifest
	if exist iconv.exp del /q iconv.exp
	if exist iconv.lib del /q iconv.lib
	if exist iconv.obj del /q iconv.obj
	if exist intl.dll del /q intl.dll
	if exist intl.dll.manifest del /q intl.dll.manifest
	if exist intl.exp del /q intl.exp
	if exist intl.lib del /q intl.lib
	if exist intl.obj del /q intl.obj
	if exist msgfmt.exe del /q msgfmt.exe
	if exist msgfmt.exe.manifest del /q msgfmt.exe.manifest
	if exist msgfmt.obj del /q msgfmt.obj

dist:
	mkdir iconvmlang-$(VERSION)
	copy /y AUTHORS iconvmlang-$(VERSION)
	copy /y COPYING iconvmlang-$(VERSION)
	copy /y Makefile iconvmlang-$(VERSION)
	copy /y iconv.dll iconvmlang-$(VERSION)
	copy /y iconv.lib iconvmlang-$(VERSION)
	copy /y iconv.c iconvmlang-$(VERSION)
	copy /y iconv.h iconvmlang-$(VERSION)
	copy /y intl.dll iconvmlang-$(VERSION)
	copy /y intl.lib iconvmlang-$(VERSION)
	copy /y intl.c iconvmlang-$(VERSION)
	copy /y libintl.h iconvmlang-$(VERSION)
	copy /y msgfmt.exe iconvmlang-$(VERSION)
	copy /y msgfmt.c iconvmlang-$(VERSION)
	tar zcf iconvmlang-$(VERSION).tar.gz iconvmlang-$(VERSION)
	zip -9 -r iconvmlang-$(VERSION).zip iconvmlang-$(VERSION)
	rmdir /q /s iconvmlang-$(VERSION)
