#/************************************************************************
# * Copyright (c) 2007, 2010 OC Systems Inc. and others
# * All rights reserved. This program and the accompanying materials
# * are made available under the terms of the Eclipse Public License v1.0
# * which accompanies this distribution, and is available at
# * http://www.eclipse.org/legal/epl-v10.html
# *
# * Contributors:
# *    Vsevolod Sandomirskiy, OC Systems - Probekit support
# *
# * $Id$ 
# ************************************************************************/
 
ROOTDIR = ../..

include $(ROOTDIR)/src/makefile.inc

INCLUDES = -I../../include/JPIAgent \
	-I../../include/Martini \
	-I../../src/BaseProf \
	-I../../src/Martini/Include \
	-I../../src/Martini/Infrastructure/Include \
	-I../../../../org.eclipse.hyades.probekit/src-native \
	-I$(TPTP_ACSDK_HOME)/include \
	-I$(JAVA_HOME)/include

ifdef SOLARIS
	INCLUDES += -I$(JAVA_HOME)/include/solaris
endif

ifdef SOLARISX86
	INCLUDES += -I$(JAVA_HOME)/include/solaris
endif


ifdef AIX
	INCLUDES += -I $(JAVA_HOME)/include/aix
endif

ifdef LINUX
	INCLUDES += -I $(JAVA_HOME)/include/linux
endif

OBJS = 	\
	$(OBJDIR)/ProbekitAgent.o \
	$(OBJDIR)/InstrumenterFactory.o \
	$(OBJDIR)/Instrumenter.o \
	$(OBJDIR)/ClassFileLoadHookEvent.o \
	$(OBJDIR)/VMInitEvent.o \
	$(OBJDIR)/Globals.o \
	$(OBJDIR)/ECAttachEvent.o \
	$(OBJDIR)/ECDetachEvent.o \
	$(OBJDIR)/ECStartEvent.o \
	$(OBJDIR)/ECStopEvent.o \
	$(OBJDIR)/ECCustomEvent.o \
	$(OBJDIR)/Util.o

EXTRA_CXX_FLAGS = -D_LINUX_X86 

ifdef MVS
ifndef SIXTYFOURBIT
	EXTRA_CXX_FLAGS += -D_OE_SOCKETS
endif 
endif

LIB = libProbekitAgent.so

VER_FILE = ProbekitAgent.ver

all: release

release: $(OBJDIR) $(OUTDIR)/$(LIB)

$(OBJDIR): 
	mkdir -p $(OBJDIR) ; mkdir -p $(OUTDIR)

clean: 
	rm -rf $(OBJS) $(OUTDIR)/$(LIB)
	rm -f libProbekitAgent.x

include ./Makefile.dep

$(OUTDIR)/$(LIB): $(OBJS)
ifdef MVS
    # if unable to find the .x files in the usual build directories, assume the user is building from a pre-packaged ac sdk and look in the lib directory for the .x files instead
	$(CPP_LINK) $(OBJS) -o $@ -L$(OUTDIR) ../Martini/Infrastructure/OSA/zOS/libMartiniOSA.x \
	$(OUTDIR)/LibraryLoader.a \
	-L $(TPTP_ACSDK_HOME)/lib \
	`if [ -s "$(TPTP_ACSDK_HOME)"/src/shared/TPTPUtil/libtptpUtils.*.x ]; then echo -n "$(TPTP_ACSDK_HOME)/src/shared/TPTPUtil/libtptpUtils.*.x"; else echo -n "$(TPTP_ACSDK_HOME)/lib/libtptpUtils.*.x"; fi` \
 	$(STD_LIBS) $(VER_SCR)
else
	$(CPP_LINK) $(OBJS) -o $@ -L$(OUTDIR) -lMartiniOSA \
	$(OUTDIR)/LibraryLoader.a \
	-L $(TPTP_ACSDK_HOME)/lib \
 	-lpthread -ldl $(STD_LIBS) $(VER_SCR)
endif
