# 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 2.1 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

CFLAGS=-g -DXP_WIN -Wall -I..
CC=gcc

ifndef PY_HOME
  $(error PY_HOME is not defined. It should point to your installtion \
	  directory e.g. C:\Python25. To avoid this error, this file should \
	  be called by setup.py only, which takes care of setting that \
	  variable.)
endif

ifndef PY_DLL
  $(error PY_DLL is not defined. It should point to python dll location e.g. \
	  C:\Windows\System32\Python25.dll. To avoid this error, this \
	  makefile should be called by setup.py only, which takes care \
	  of setting that variable.)
endif

ifndef PY_VER
  $(error PY_VER is not defined. It should point to the python version \
	  e.g. 27. To avoid this error, this file should \
	  be called by setup.py only, which takes care of setting that \
	  variable.)
endif
DISTDIR=pacparser-python$(PY_VER)

CFLAGS+=-I"$(PY_HOME)\include"

.PHONY: dist clean

build: _pacparser$(PY_VER).pyd

pacparser_py$(PY_VER).o: pacparser_py.c
	$(CC) $(CFLAGS) -c pacparser_py.c -o pacparser_py$(PY_VER).o
	
python$(PY_VER).dll:
	copy $(PY_DLL) python$(PY_VER).dll

_pacparser$(PY_VER).pyd: pacparser_py$(PY_VER).o python$(PY_VER).dll ..\pacparser.dll
	$(CC) -shared -o _pacparser$(PY_VER).pyd pacparser_py$(PY_VER).o -lpython$(PY_VER) -L. -lpacparser -L.. -lws2_32

dist: build
	if exist $(DISTDIR) rmdir /s /q $(DISTDIR)
	mkdir $(DISTDIR)
	mkdir $(DISTDIR)\pacparser
	xcopy pacparser $(DISTDIR)\pacparser
	copy _pacparser$(PY_VER).pyd $(DISTDIR)\pacparser\_pacparser.pyd
	copy ..\pacparser.dll $(DISTDIR)\pacparser
	copy install_win32.py $(DISTDIR)\install.py
	copy ..\..\COPYING $(DISTDIR)\COPYING.txt
	copy ..\..\README.md $(DISTDIR)\README.txt
	copy ..\..\README.win32 $(DISTDIR)\README.win32.txt
	copy ..\..\INSTALL $(DISTDIR)\INSTALL.txt

clean:
	del /F pacparser_py*.o _pacparser*.pyd
	for /d %%a in (pacparser-python*) do rmdir /s /q "%%a"
