#
# Harissa, copyright (C) Irisa/Inria 1996
#
# $Id: makefile_jdk,v 1.7 1997/12/04 15:20:48 ups Exp $
#
# $Log: makefile_jdk,v $
# Revision 1.7  1997/12/04 15:20:48  ups
# Ensured proper propagation of PIC flag
#
# Revision 1.6  1997/12/02 11:14:42  ups
# The makefile variables CC and CFLAGS are now taken from the main Makefile
#
# Revision 1.5  1997/11/27 10:01:09  muller
# *** empty log message ***
#
# Revision 1.4  1997/11/26 11:25:04  ups
# - Support for renaming of libraries
# - 'install' is included as target in 'all'
# - libraries are linked into the default library directory
#
# Revision 1.3  1997/11/17 17:27:48  muller
# - bug corrected in install
#
# Revision 1.2  1997/10/27 12:38:39  ups
# Support for generating threaded and non-threaded versions of libjdk
#
# Revision 1.1  1997/10/27 12:32:50  ups
# Initial revision
#
# Revision 1.2  1997/05/07 14:34:02  muller
# - version publique alpha2.2
#
# Revision 1.1  1997/02/24 08:00:17  muller
# Initial revision
#
# 
# Initial revision
#
#
#

# Destination directory for installed library
INSTDIR=$(HARISSAHOME)

# GEN   : where hac generate *.c files
GEN=gen

# DEST  : the name of the destination lib
LIBDEST= jdk_nonth
THREADEDLIBDEST= jdk

OSNAME=$(shell uname)
OSVERSION=$(shell uname -r)
OS=$(OSNAME)$(basename $(OSVERSION))

UNZIP=unzip

# The following lines are patched by the Makefile during installation
CC=gcc
CFLAGS=-O2 -Wall -I../include -m486 -malign-double -D_REENTRANT -DHARISSALIBS -DLINUX -DHARISSA -fPIC

ifeq ($(OS),sunos)
	# SunOS 4.10
	LIBSHARED =
	LIBEXT = so.1.0
else
ifeq ($(OS),SunOS5)
	LIBSHARED = -G
	LIBEXT = so
else
ifeq ($(OS),Linux2.0)
	#Linux 1,x. For Linux 2.x, you can throw away '-ldl' in 'LIBS'.
	LIBSHARED = -shared
	LIBEXT = so
else
ifeq ($(OS),alpha)
	#DEC Alpha OSF/1
	LIBSHARED = -shared
	LIBEXT = so
else
	OS = unknown
endif #alpha
endif #linux
endif #solaris
endif #sunos

#########################################################################
#                         Do not modify after this
#########################################################################  

# we will build libjava.$(LIBEXT) with this file
ZIPFILE = $(JDKLIB)/classes.zip

# ONLY is a pattern to select files from the ZIPFILE
ONLY = class

# WITHOUT is a pattern that exclude files from ZIPFILE
WITHOUT1 = "sun|zip|awt|applet"


FLAGS= $(CFLAGS) -DHARISSA -I$(HARISSAHOME)/include
PROG = libjava.$(LIBEXT)

all:   lib-dyn lib-dyn-th install

lib-dyn:  gen_done
	cd $(GEN); \
	ld  $(LIBSHARED) *.o -o ../lib$(LIBDEST).$(LIBEXT)

lib-dyn-th:  gen_done_th
	cd $(GEN); \
	ld  $(LIBSHARED) *.o -o ../lib$(THREADEDLIBDEST).$(LIBEXT)

lib-sta: gen_done
#	@ar cr libjava.a $(LIBOBJ)
#	@ranlib libjava.a
#	mv libjava.a lib

class_done: 
	@rm -f class_done
	@echo "Cleaning gen"
	@if test ! -d gen; then mkdir gen; fi
	@rm -f gen/*
	@echo "compiling .class into C"
	@CLASSES=`$(UNZIP) -l $(ZIPFILE) | grep $(ONLY) | egrep -v $(WITHOUT1) |cut -c28-90`; \
	for file in $$CLASSES ; \
	 do \
	   (file2=`echo $$file | sed -e 's/.[^.]*$$//'`; \
	    echo "Compiling class" $$file2; \
	    hac -S -d$(GEN) code $$file2) \
	 done
	@touch class_done

class_done_th: 
	@rm -f class_done_th
	@echo "Cleaning gen"
	@if test ! -d gen; then mkdir gen; fi
	@rm -f gen/*
	@echo "compiling .class into C"
	@CLASSES=`$(UNZIP) -l $(ZIPFILE) | grep $(ONLY) | egrep -v $(WITHOUT1) |cut -c28-90`; \
	for file in $$CLASSES ; \
	 do \
	   (file2=`echo $$file | sed -e 's/.[^.]*$$//'`; \
	    echo "Compiling class" $$file2; \
	    hac -d$(GEN) code $$file2) \
	 done
	@touch class_done_th

gen_done: class_done
	@rm -f gen_done
	@echo "compiling C into object code"
	@cd $(GEN); \
	for file in *.c ; \
	 do \
	  echo "Compiling" $$file; \
	  $(CC) $(FLAGS) -DSINGLE_TH $(PIC) -c  $$file; \
	 done
	cd ..
	touch gen_done

gen_done_th: class_done_th
	@rm -f gen_done_th
	@echo "compiling C into object code"
	@cd $(GEN); \
	for file in *.c ; \
	 do \
	  echo "Compiling" $$file; \
	  $(CC) $(FLAGS) $(PIC) -c  $$file; \
	 done
	cd ..
	touch gen_done_th

install: 
	rm -f $(INSTDIR)/lib/lib$(LIBDEST).$(LIBEXT)
	rm -f $(INSTDIR)/lib/lib$(THREADEDLIBDEST).$(LIBEXT)
	ln -s $(PWD)/lib$(LIBDEST).$(LIBEXT) $(INSTDIR)/lib
	ln -s $(PWD)/lib$(THREADEDLIBDEST).$(LIBEXT) $(INSTDIR)/lib

clean: clean-gen
	@rm -f gen_done class_done gen_done_th class_done_th

clean-gen:
	@\rm -rf $(GEN)/*
