# Generated automatically from Makefile.in by configure.
#! 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		= ../..
topsrcdir	= ../..
srcdir		= .

include $(DEPTH)/config/autoconf.mk

include $(topsrcdir)/config/config.mk

ifdef MOZ_OJI
DIRS = liveconnect
endif

DIRS	+=	fdlibm

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	= $(NSPR_LIBS) $(LIBNSJAVA)
else
EXTRA_LIBS	= $(NSPR_LIBS) $(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)

EXPORTS := $(addprefix $(srcdir)/, $(EXPORTS))

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

JS_SAFE_ARENA = 1

ifdef JS_SAFE_ARENA
DEFINES += -DJS_USE_SAFE_ARENA
endif

include $(topsrcdir)/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$(srcdir)

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

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

# NSPR_LIBS abstracts nspr version, etc. nicely.
LDFLAGS 	= $(NSPR_LIBS) -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

FDLIBM_LIBRARY	= fdlibm/libfdm.a
JSMATH_PRELINK	= jsmathtemp.o

# special rule for jsmath.o since we want to incrementally link
# against fdlibm to pull in only what is needed
jsmath.o: $(FDLIBM_LIBRARY) $(JSMATH_PRELINK)
	@$(MAKE_OBJDIR)
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
	ld -r -o $@ $(JSMATH_PRELINK) $(FDLIBM_LIBRARY)
else
	ld -r -o $@ $(JSMATH_PRELINK) $(FDLIBM_LIBRARY)
endif

$(JSMATH_PRELINK): jsmath.c
	@$(MAKE_OBJDIR)
ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
	$(CC) -Fo$@ -c $(CFLAGS) $<
else
	$(CC) -o $@ -c $(CFLAGS) $<
endif

# ripped from $(topsrcdir)/config/rules.mk
$(FDLIBM_LIBRARY):
			set -e;					\
			set $(EXIT_ON_ERROR);			\
			echo "cd $(@D); $(MAKE) $(@F)";		\
			oldDir=`pwd`;				\
			cd $(@D); $(MAKE) $(@F); cd $$oldDir;	\
			set +e;

# 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
