# Copyright (C) 2007 Manu Garg.
# Author: Manu Garg <manugarg@gmail.com>
#
# Makefile for pacparser. Please read README file included with this package
# for more information about pacparser.
#
# pacparser is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3 of the License, or (at your option) any later version.

# pacparser 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
# Lesser General Public License for more details.

# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA

# This file is not part of the source code repository. It's generated by the
# packaging script.
-include version.mk

LIB_VER=1
CFLAGS=-g -DXP_WIN -DVERSION=$(VERSION) -Ispidermonkey/js/src -Wall
CC=gcc

.PHONY: clean pymod install-pymod

all: pacparser.dll pacparser.lib pactester

pacparser.o: pacparser.c pac_utils.h js.lib
	$(CC) $(CFLAGS) -c pacparser.c -o pacparser.o
	
fdlibm.lib js.lib:
	$(MAKE) -C spidermonkey -f Makefile.win32
	copy spidermonkey\fdlibm.lib .
	copy spidermonkey\js.lib .

pacparser.dll: pacparser.o fdlibm.lib js.lib
	$(CC) -shared -o pacparser.dll \
	-Wl,--output-def,pacparser.def \
	-Wl,--out-implib,libpacparser.a \
	-Wl,--export-all-symbols \
	pacparser.o -ljs -L. -lws2_32

pacparser.lib: pacparser.dll pacparser.def
	lib /machine:i386 /def:pacparser.def

pactester: pactester.c pacparser.h pacparser.dll
	$(CC) pactester.c -o pactester -lpacparser -L. -I.

dist: pacparser.dll pactester
	if exist dist rmdir /s /q dist
	mkdir dist
	copy pacparser.dll dist
	copy pacparser.h dist
	copy pactester.exe dist
	if exist pacparser.lib copy pacparser.lib dist
	copy ..\README dist\README.txt
	copy ..\COPYING dist\COPYING.txt
	copy ..\INSTALL dist\INSTALL.txt
	mkdir dist\docs
	copy ..\README.win32 dist\docs
	if exist ..\docs\html xcopy ..\docs\html dist\docs

# Targets to build python module
pymod: pacparser.h pacparser.dll
	cd pymod && setup.py dist
	cd .. && tests\runtests.py

clean:
	del /F pacparser.dll *.lib pacparser.def pacparser.exp pacparser.o pactester.exe libpacparser.a
	$(MAKE) -C spidermonkey -f Makefile.win32 clean
	cd pymod && setup.py clean
	if exist dist rmdir /s /q dist
