#! gmake
# The contents of this file are subject to the Netscape Public License
# Version 1.0 (the "NPL"); you may not use this file except in
# compliance with the NPL.  You may obtain a copy of the NPL at
# http://www.mozilla.org/NPL/
#
# Software distributed under the NPL is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
# for the specific language governing rights and limitations under the
# NPL.
#
# The Initial Developer of this code under the NPL is Netscape
# Communications Corporation.  Portions created by Netscape are
# Copyright (C) 1998 Netscape Communications Corporation.  All Rights
# Reserved.

DEPTH		= ../..

include $(DEPTH)/config/config.mk

ifdef MOZ_OJI
DIRS = liveconnect
endif

LIBRARY_NAME	= js

ifeq ($(subst /,_,$(shell uname -s)),OS2)
ifndef XCFLAGS
OS2_IMPLIB=1
LIBRARY	= js$(MOZ_BITS)$(VERSION_NUMBER).$(LIB_SUFFIX)
DEF_FILE	= jsos2$(VERSION_NUMBER).def
EXTRA_LIBS	= $(LIBNSPR) $(LIBNSJAVA)
else
EXTRA_LIBS	= $(LIBNSPR) $(LIBNSJAVA) $(OBJDIR)/libjs.lib
endif
endif

MODULE		= js

CSRCS		= 	jsapi.c		\
			jsarena.c	\
			jsarray.c	\
			jsatom.c	\
			jsbool.c	\
			jscntxt.c	\
			jsdate.c	\
			jsdbgapi.c	\
			jsdtoa.c	\
			jsemit.c	\
			jsexn.c		\
			jsfun.c		\
			jsgc.c		\
			jshash.c	\
			jsinterp.c	\
			jslock.c	\
			jslog2.c	\
			jslong.c	\
			jsmath.c	\
			jsnum.c		\
			jsobj.c		\
			jsopcode.c      \
			jsparse.c	\
			jsprf.c		\
			jsregexp.c	\
			jsscan.c	\
			jsscope.c	\
			jsscript.c	\
			jsstr.c		\
			jsutil.c        \
			jsxdrapi.c	\
			prmjtime.c	\
			$(NULL)

EXPORTS		= js.msg \
		  jsapi.h \
		  jsarray.h \
		  jsarena.h \
		  jsatom.h \
		  jsbit.h \
		  jsbool.h \
		  jsclist.h \
		  jscntxt.h \
		  jscompat.h \
		  jsconfig.h \
		  jsdate.h \
		  jsdbgapi.h \
		  jsemit.h \
		  jsfun.h \
		  jsgc.h \
	          jshash.h \
		  jsinterp.h \
		  jslock.h \
		  jslong.h \
		  jsmath.h \
		  jsnum.h \
		  jsobj.h \
		  jsopcode.tbl \
		  jsopcode.h \
		  jsosdep.h \
		  jsotypes.h \
		  jsparse.h \
		  jsprf.h \
		  jsprvtd.h \
		  jspubtd.h \
		  jsregexp.h \
		  jsscan.h \
		  jsscope.h \
		  jsscript.h \
		  jsstr.h \
		  jstypes.h \
		  jsutil.h \
		  jsxdrapi.h \
		  $(NULL)

# when using gcc the assembly is inlined in the C-file (see jslock.c)
ifdef NS_USE_NATIVE
ASFILES = $(wildcard *_$(OS_ARCH).s)
endif

JS_SAFE_ARENA = 1

ifdef JS_SAFE_ARENA
DEFINES += -DJS_USE_SAFE_ARENA
endif

include $(DEPTH)/config/rules.mk

ifndef BUILD_OPT
MOCHAFILE	= 1
endif

ifdef JSFILE
DEFINES		+= -DJSFILE
endif

ifdef JS_THREADSAFE
DEFINES += -DJS_THREADSAFE
endif

ifdef JS_NO_THIN_LOCKS
DEFINES += -DJS_USE_ONLY_NSPR_LOCKS
endif

ifdef JS_VERSION
DEFINES += -DJS_VERSION=$(JS_VERSION)
endif

ifeq ($(CPU_ARCH),sparc)

ifndef JS_NO_ULTRA
ULTRA_OPTIONS := -xarch=v8plus,-DULTRA_SPARC
ULTRA_OPTIONSCC := -DULTRA_SPARC
else
ULTRA_OPTIONS := -xarch=v8
ULTRA_OPTIONSCC :=
endif

ifeq ($(shell uname -m),sun4u)
ASFLAGS	+= -Wa,$(ULTRA_OPTIONS),-P,-L,-D_ASM,-D__STDC__=0 $(ULTRA_OPTIONSCC)
else
ASFLAGS	+= -Wa,-xarch=v8,-P,-L,-D_ASM,-D__STDC__=0
endif

endif # sparc

INCLUDES	+= -I. 

ifndef NSBUILDROOT
JSJAVA_STUBHEADERS = -I$(DEPTH)/sun-java/include/_gen \
		     -I$(DEPTH)/sun-java/netscape/javascript/_jri \
		     -I$(DEPTH)/sun-java/netscape/security/_jri
else
JSJAVA_STUBHEADERS = -I$(JRI_GEN_DIR) -I$(JDK_GEN_DIR)
endif

JSJAVA_CFLAGS	= -I$(DEPTH)/sun-java/md-include \
		  -I$(DEPTH)/sun-java/include \
		  $(JSJAVA_STUBHEADERS)

# LIBNSPR abstracts nspr version, etc. nicely.
LDFLAGS 	= $(LIBNSPR) -lm

ifeq ($(OS_ARCH), OSF1)
LDFLAGS += -lc_r
endif
ifeq ($(OS_ARCH), SunOS)
LDFLAGS += -lposix4 -ldl -lnsl -lsocket
endif
ifeq ($(OS_ARCH), Linux)
LDFLAGS += -ldl
endif

# this requires clobbering and recompiling with XCFLAGS=-DJSFILE
js:
	$(MAKE) clobber
	$(MAKE) XCFLAGS=-DJSFILE $(OBJDIR)/js$(BIN_SUFFIX)

.PHONY: js$(BIN_SUFFIX)

ifneq ($(OS_ARCH),OS2)
$(OBJDIR)/js$(BIN_SUFFIX): $(OBJDIR)/js.o $(LIBRARY)
	    @$(MAKE_OBJDIR)
	    $(CC) -o $@ $(OBJDIR)/js.o $(LIBRARY) $(LDFLAGS)
else
OS_CFLAGS += -tm-
$(OBJDIR)/js$(BIN_SUFFIX): $(OBJDIR)/js.o $(LIBRARY)
	    @$(MAKE_OBJDIR)
	    $(LINK_EXE) -OUT:$@ $(OBJDIR)/js.o  $(LIBRARIES) $(EXTRA_LIBS)
endif

# hardwire dependencies on jsopcode.tbl
jsopcode.h jsopcode.c: jsopcode.tbl

# Generate jsautocfg.h header
$(OBJDIR)/jsautocfg.h: $(OBJDIR)/jscpucfg
	rm -f $@
	$(OBJDIR)/jscpucfg > $@

$(OBJDIR)/jscpucfg: $(OBJDIR)/jscpucfg.o
	$(CC) -o $@ $(OBJDIR)/jscpucfg.o

export:: $(OBJDIR)/jsautocfg.h
	$(INSTALL) -m 444 $(OBJDIR)/jsautocfg.h $(DIST)/include

# Add to TARGETS so clobber rule works
TARGETS += $(OBJDIR)/jsautocfg.h $(OBJDIR)/jscpucfg $(OBJDIR)/jscpucfg.o

# this section was put in the merged by danda into the
# JAVA_*_MERGE section and normally would have
# been removed.  However it looks like it shouldn't have
# been put there in the first place, so we're leaving it
# here until danda can confirm (we don't have OS/2 machines
# to build on) - hshaw/sudu
#
ifeq ($(OS_ARCH),OS2)
$(OBJDIR)/js.o: js.c
	@$(MAKE_OBJDIR)
	$(CC) -Fo$@ -c $(CFLAGS) $(JSJAVA_CFLAGS) js.c
endif

clobber::
	rm -f $(OBJDIR)/jscpucfg $(OBJDIR)/jscpucfg.h

