# Host Identity Protocol
# Copyright (C) 2002-04 the Boeing Company
# 
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program 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 General Public License for more details.
#
#  Windows Service Makefile
#
#  Author:	Jeff Ahrenholz, <jeffrey.m.ahrenholz@boeing.com>
#


CC		= gcc
CFLAGS		= -g -Wall -O2 -DCONFIG_HIP
#  is this macosx?
ifeq ($(shell uname -s), Darwin)
CFLAGS          += -D__MACOSX__
endif
# -g for debug
XMLL = $(shell xml2-config --libs)
XMLI = $(shell xml2-config --cflags)

ifeq ($(shell uname -s), Darwin)
OBJS = hip_dns.o hip_esp.o hip_pfkey.o hip_sadb.o hip_status2.o
else
OBJS = hip_dns.o hip_esp.o hip_pfkey.o hip_sadb.o hip_status2.o
endif
all:	linux

win:	hipservice finish
linux:	umh finish
status:	

# source rules
# HIP for Windows service
hipservice:	${OBJS} hip_nl.o hip_service.o hip_service.h
	@echo \>\> Building HIP Windows Service...
	rm -f ../src/hitgen.o ../src/i3_send.o ../src/i3_recv.o
	${CC} ${OBJS} hip_nl.o hip_service.o ../src/*.o -o hip -lcrypto -lpthread ${XMLL} -liphlpapi ${CFLAGS}

# User-mode HIP
umh:	${OBJS} hip_umh.o hip_service.h
	@echo \>\> Building user-mode HIP...
	rm -f ../src/i3_send.o ../src/i3_recv.o
	${CC} ${OBJS} hip_umh.o ../src/*.o -o hip -lcrypto -lpthread ${XMLL} ${CFLAGS}
	
# Status helper app	
status:		status.c ../src/hip_status.h
	@echo \>\> Building status app...
	${CC} ${CFLAGS} status.c -o status
hip_dns.o:	hip_service.h
hip_esp.o:	hip_sadb.h hip_service.h ${CRYPTOLIB}
hip_nl.o:	hip_service.h
hip_pfkey.o:	hip_sadb.h hip_service.h
hip_sadb.o:	hip_sadb.h
hip_status2.o:	hip_sadb.h

# utility rules
finish:
	@echo done.

clean:
	@echo Removing binary files...
	rm -f hip hip.exe status.exe
	rm -f ${OBJS} hip_nl.o hip_service.o hip_umh.o
	@echo done.


