#
# @(#)GNUmakefile	1.6 98/08/18
#
# Copyright 1997, 1998 by Sun Microsystems, Inc.,
# 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
# All rights reserved.
#
# This software is the confidential and proprietary information
# of Sun Microsystems, Inc. ("Confidential Information").  You
# shall not disclose such Confidential Information and shall use
# it only in accordance with the terms of the license agreement
# you entered into with Sun.
#

PLATFORM     = solaris
JDK          = ../../../../build/solaris
VERSION      = 1.2
THREADS_FLAG = green
VARIANT      =
ARCH	     = $(shell /usr/bin/uname -p)

OINCLUDES    = $(THRINCL) -I$(JDK)/include/$(PLATFORM) -I$(JDK)/include
ifeq ($(VERSION), 1.2)
JVMDLL	     = jvm
INCLUDES     = $(OINCLUDES) \
	       -I$(JDK)/include-old/$(PLATFORM) -I$(JDK)/include-old
endif
ifeq ($(VERSION), 1.1)
JVMDLL	     = java
INCLUDES      = $(OINCLUDES)
endif

ifeq ($(VARIANT), DBG)
G          = _g
CFLAGS     = -DDEBUG -g
TRACE      = -trace
endif

ifeq ($(THREADS_FLAG), green)
THRINCL =
else
THRINCL = -I$(JDK)/include-old/$(PLATFORM)/native_threads
endif

CLASSES  = OldNMI.class Helper.class
HEADERS  = $(patsubst %.class,%.h,$(CLASSES))
OBJECTS  = OldNMI.o OldNMI-impl.o
CFLAGS   += $(INCLUDES)
LDFLAGS  = -lc -z defs -L$(JDK)/lib/$(ARCH)/$(THREADS_FLAG)_threads -L$(JDK)/lib/$(ARCH) -l$(JVMDLL)

libOldNMI$G.so: $(CLASSES) $(HEADERS) $(OBJECTS)
	ld -G $(LDFLAGS) -o $@ $(OBJECTS)

%.class: %.java
	$(JDK)/bin/javac $<

%.c: %.class
	$(JDK)/bin/javah -old -stubs $(TRACE) $(patsubst %.class,%,$<)
	@echo $@ >> .generated.files

%.h: %.class
	$(JDK)/bin/javah -old $(patsubst %.class,%,$<)
	@echo $@ >> .generated.files
	@touch $@

clean:
	rm -f *.class *.o *.so
	if [ -s .generated.files ]; then \
	   rm -f $(shell if [ -s .generated.files ]; then cat .generated.files; fi); \
	   rm -f .generated.files; \
	fi

.PHONY: default run clean debug debug-run
.PRECIOUS: OldNMI.c

run: libOldNMI$G.so
	LD_LIBRARY_PATH=.:$$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; \
	    $(JDK)/bin/java$G OldNMI

debug:
	$(MAKE) VARIANT=DBG
debug-run:
	$(MAKE) VARIANT=DBG run
