
# for build glut4gcj
srcdir = .
top_srcdir = ..

JAR= jar
AR= ar -cr
RANLIB=ranlib

CC = gcc
CXX = g++

DEFS = -DPACKAGE_NAME=\"\" -DPACKAGE_TARNAME=\"\" -DPACKAGE_VERSION=\"\" -DPACKAGE_STRING=\"\" -DPACKAGE_BUGREPORT=\"\" -DSTDC_HEADERS=1  
OPT_FLAGS = -O2
CFLAGS = $(OPT_FLAGS) -I$(srcdir)  -Wall -DNDEBUG  

GCJ = gcj
GCJH = gcjh
JAVAC = $(GCJ) -C
JFLAGS = $(OPT_FLAGS) 
GCJFLAGS = $(OPT_FLAGS)  

NATIVE_CLASS_JAVA_SOURCES= \
	glut4gcj/GLUT.java \


NATIVE_CLASS_CLASSES= $(NATIVE_CLASS_JAVA_SOURCES:.java=.class)
NATIVE_CLASS_HEADERS= $(NATIVE_CLASS_JAVA_SOURCES:.java=.h)
NATIVE_CLASS_CPP_SOURCES=  $(NATIVE_CLASS_JAVA_SOURCES:.java=_native.cpp)
NATIVE_CLASS_OBJECTS=  \
	$(NATIVE_CLASS_JAVA_SOURCES:.java=.o) \
	$(NATIVE_CLASS_CPP_SOURCES:.cpp=.o) \

SOURCES= \
	glut4gcj/GLUTConstants.java \
	glut4gcj/DisplayFunc.java \
	glut4gcj/EntryFunc.java \
	glut4gcj/IdleFunc.java \
	glut4gcj/KeyboardFunc.java \
	glut4gcj/MenuStateFunc.java \
	glut4gcj/MenuFunc.java \
	glut4gcj/MotionFunc.java \
	glut4gcj/MouseFunc.java \
	glut4gcj/PassiveMotionFunc.java \
	glut4gcj/SpecialFunc.java \
	glut4gcj/ReshapeFunc.java \
	glut4gcj/TimerFunc.java \
	glut4gcj/VisibilityFunc.java \
	glut4gcj/SpaceballButtonFunc.java \
	glut4gcj/SpaceballMotionFunc.java \
	glut4gcj/SpaceballRotateFunc.java \

HEADERS= $(SOURCES:.java=.h)

CLASSES= $(SOURCES:.java=.class)

OBJECTS= $(CLASSES:.class=.o)


# for install
prefix = /usr/local
exec_prefix = ${prefix}
bindir = ${exec_prefix}/bin
includedir = ${prefix}/include
libdir = ${exec_prefix}/lib
datadir = ${prefix}/share
sysconfdir = ${prefix}/etc

pkgdatadir = ${prefix}/share/gl4gcj
pkgsysconfdir = ${prefix}/etc/gl4gcj

extdir = ${prefix}/share/java/ext

INSTALL = /usr/bin/install -c
INSTALL_PROGRAM = ${INSTALL}
INSTALL_DATA = ${INSTALL} -m 644

LIBRARY = libglut4gcj.a
JAR_FILE = glut4gcj.jar

############################################################
# rules
############################################################
all : lib jar

lib : $(LIBRARY)

jar : $(JAR_FILE)


$(LIBRARY): classes headers objects 
	$(AR) $@ $(OBJECTS) $(NATIVE_CLASS_OBJECTS) 
	$(RANLIB) $@


$(JAR_FILE): $(NATIVE_CLASS_CLASSES) $(CLASSES)
	$(JAR) cvf $@  $(NATIVE_CLASS_CLASSES) $(CLASSES)

classes : $(CLASSES) $(NATIVE_CLASS_CLASSES)

headers : $(HEADERS) $(NATIVE_CLASS_HEADERS) 

objects : $(OBJECTS) $(NATIVE_CLASS_OBJECTS) $(HEADERS) $(NATIVE_CLASS_HEADERS) 


.SUFFIXES : .java .class .h .cpp .o

.java.class:
	$(JAVAC) $(JFLAGS) $<

.class.h: 
	$(GCJH) $(<:.class=)

.cpp.o: 
	$(CXX) $(CFLAGS) -o $@ -c $<

.java.o: 
	$(GCJ) -c $(GCJFLAGS) -o $@ $<



## install rules
install: $(LIBRARY) $(JAR_FILE) headers install-target-dirs
	$(INSTALL) $(LIBRARY) $(libdir)
	$(INSTALL_DATA) $(JAR_FILE) $(extdir)
	for i in $(HEADERS) $(NATIVE_CLASS_HEADERS) ; do \
		echo $$i; \
		$(INSTALL) -d $(includedir)/`dirname $$i`; \
		$(INSTALL_DATA) $$i $(includedir)/`dirname $$i`; \
	done

install-target-dirs:
	$(INSTALL) -d $(libdir)
	$(INSTALL) -d $(extdir)
	$(INSTALL) -d $(includedir)


clean :
	-rm \
	$(NATIVE_CLASS_HEADERS) \
	$(NATIVE_CLASS_CLASSES) \
	$(NATIVE_CLASS_OBJECTS) \
	$(OBJECTS) \
	$(CLASSES) \
	$(HEADERS) \
	$(LIBRARY) \
	$(JAR_FILE) \


