#!amake
#
# Makefile to compile sswf (Script to SWF) with amake
# Written by Alexis Wilke for Made to Order Software Corp. (c) 2002-2009
#
# Copyright (c) 2002-2009 Made to Order Software Corp.
#
# 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.
#

# Get the version from the libsswf-version.h file instead (we thus avoid
# data duplication)
#VERSION=x.y.z
# The following ensures we can extract the version, it's not 100%
# correct since if a 2nd number with the same form appears in the
# version file then it will be returned too
LIBSSWF_VERSION<=include/sswf/libsswf-version.h
VERSION:=$(LIBSSWF_VERSION::[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*)


# Let's ensure that all the necessary directories
# exist from the start; this makes amake happier;
# in MS-Windows 2000 you can test if a file exists
# I'm not sure that's valid under older versions
#for p in modules bin lib VC \
		tmp\backup\src\tools tmp\object\src\tools \
		tmp\backup\src\sswf tmp\object\src\sswf \
		tmp\backup\src\misc tmp\object\src\misc \
		tmp\backup\src\lib tmp\object\src\lib \
		tmp\backup\src\libas tmp\object\src\libas \
		tmp\backup\src\libasas tmp\object\src\libasas \
		tmp\backup\src\libasc tmp\object\src\libasc
#shell if not exist $p mkdir $p
#endfor

# For cl we need to copy some header files...
#for p in include\jconfig.h include\jpeglib.h \
		include\jerror.h include\jmorecfg.h include\zconf.h \
		include\zlib.h include\iconv.h include\ft2build.h
#shell if not exist $p copy ..\..\..\..\$p include
#endfor

#shell sed -e "s/#if 1/#if 0/" include\zconf.h >tmp\zconf.h
#shell copy tmp\zconf.h include

CINCLUDEPATH:=include;src/sswf
CSUFFIXES:=.c .c++ .cpp .cxx .h .h++ .hpp .s .S .l .y

CC:=cl	#gcc
CXX:=cl	#g++
LD:=ld
# This includes folders that are specific to my computer.
CFLAGS:=/O2 /GR /I/AllDev/MinGW/3.3/include/freetype2 /I"/AllDev/Microsoft Visual Studio 8/VC/include" /I"/AllDev/Microsoft Visual Studio 8/include" /DDEBUG=1 /DYYDEBUG=1 /D_MSVC=1 /DWIN32 /DBYTE_ORDER=1 /DLITTLE_ENDIAN=1 /DBIG_ENDIAN=0 /Iinclude
CXXFLAGS:=$(CFLAGS)
COPY:=cp -f
RENAME:=rename
RM:=rm -r
RMDIR:=rmdir /s /q
MKDIR:=mkdir
AR:=ar
YFLAGS:=-t		# enable -t for debug
BISON:=bison

LIBSRC:=$(wildcard src\lib\libsswf_*.c++)
LIBASSRC:=$(wildcard src\libas\*.c++)
LIBASASSRC:=$(wildcard src\libasas\*.c++)
RAWSSWFSRC:=$(wildcard src\sswf\*.[cy]*)
SSWFSRC:=$(RAWSSWFSRC:-*~)	# no backup (some people will use ~ at the end of filenames)
TOOLSSRC:=$(wildcard src\tools\*.c) $(wildcard src\tools\*.c++)
MISCSRC:=$(wildcard src\misc\*.c)

LIBOBJ:=$(LIBSRC:*.c++=tmp\\object\\*.obj:U)
LIBASOBJ:=$(LIBASSRC:*.c++=tmp\\object\\*.obj:U)
LIBASASOBJ:=$(LIBASASSRC:*.c++=tmp\\object\\*.obj:U)
LIBASCOBJ:=$(LIBASCSRC:*.c++=tmp\\object\\*.obj:U)
SSWFOBJ:=$(SSWFSRC:*.*=tmp\\object\\*.obj:U)
TOOLSOBJ:=$(TOOLSSRC:*.*=tmp\\object\\*.obj:U)
MISCOBJ:=$(MISCSRC:*.*=tmp\\object\\*.obj:U)




OBJ:=$(LIBOBJ) $(LIBASOBJ) $(LIBASASOBJ) $(SSWFOBJ) $(TOOLSOBJ) $(MISCOBJ)
all: $(OBJ) .PHONY
	@echo "Done!"






ALLSRC:=$(LIBSRC) $(LIBASSRC) $(LIBASASSRC) $(LIBASCSRC) $(SSWFSRC) $(TOOLSSRC) $(MISCSRC)
ALLCXXOBJ:=$(ALLSRC::*.c++=tmp\\object\\*.obj)
ALLCOBJ:=$(ALLSRC::*.c=tmp\\object\\*.obj)
ALLYACCOBJ:=$(ALLSRC::*.y=tmp\\object\\*.obj)
ALLLEXOBJ:=$(ALLSRC::*.l=tmp\\object\\*.obj)



$(ALLCXXOBJ): $(.TARGET:tmp\\object\\*.obj=*.c++)
	$(CXX) /c $(CXXFLAGS) /I$(.TARGET:tmp\\object\\*\\*\\*.obj=tmp\\object\\*\\*) /Fo$(.TARGET) /Tp $(.FIRSTSRC)

$(ALLCOBJ): $(.TARGET:tmp\\object\\*.obj=*.c)
	$(CC) /c $(CFLAGS) /Fo$(.TARGET) /Tc $(.FIRSTSRC)


tmp/object/src/sswf/%.obj: tmp/object/src/sswf/%.c
	$(CC) /c $(CFLAGS) -Isrc/sswf /Fo$(.TARGET) /Tc $(.IMPSRC)

tmp/object/src/sswf/%.c tmp/object/src/sswf/%.h: src/sswf/%.y .PRECIOUS
	$(BISON) -v -d $(YFLAGS) -b $(.TARGET:R) $(.IMPSRC) /Fo$(.TARGET:*.h=*.c)









clobber: rmtarget .PHONY
	-$(RMDIR) tmp 2>ignore.tmp
	-$(RM) .amakeautodepend
	@echo "Output packages not removed with amake clobber"

clean cleaup: rmtarget .PHONY
	-$(RMDIR) tmp/object 2>ignore.tmp

rmtarget: .PHONY
	-$(RMDIR) lib bin 2>ignore.tmp
	-$(RM) core 2>ignore.tmp


