######!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.
srcdir = `pwd`
DEPTH	= /c/mozilla_SDK/mozilla
include $(DEPTH)/config/config.mk

CCC = c++
INCLUDE = -I./_xpidlgen -I. -I$(DEPTH)/dist/include -I$(DEPTH)/dist/include/nspr -I$(DEPTH)/dist/include/plugin -I$(DEPTH)/dist/include/java -I$(DEPTH)/dist/include/xpcom
SYSTEM_LIBS = -lstdc++ -lversion -lgdi32

.SUFFIXES: .o .c .res. .rc .cpp .h .idl .xpt

MODULE = np4xscr
DLLNAME = np4xscr
RESFILE = np4xscr.res
DEFFILE = np4xscr.def
DLL=$(DLLNAME).dll

XPIDL_GEN_DIR           = _xpidlgen
XPIDL_MODULE            = $(MODULE)
REPORT_BUILD = @echo $(notdir $<)
EXPORS =
SDK_HEADERS =
SDK_XPIDLSRCS =

XPIDLSRCS =                                   \
        nsI4xScriptablePlugin.idl

XPIDL_HEADERS = 	\
	$(XPIDL_GEN_DIR)/nsI4xScriptablePlugin.h    \
	$(XPIDL_GEN_DIR)/acmeIScriptObject.h       

OBJS =                     \
	./np_entry.o \
	./npn_gate.o \
	./npp_gate.o \
	./plugin.o   \
	./nsScriptablePeer.o 

# followings are define in config.mk
#XPIDL_GENDIR = $(srcdir)/_xpidlgen
#XPIDL_COMPILE   = $(DIST)/bin/xpidl$(BIN_SUFFIX)
#XPIDL_LINK      = $(DIST)/bin/xpt_link$(BIN_SUFFIX
#IDL_DIR


all: $(XPIDL_HEADERS) $(XPIDL_GEN_DIR)/$(XPIDL_MODULE).xpt $(DLL)

clean:
	rm *.o
	rm -rf _xpidlgen
	rm *.dll

$(XPIDL_GEN_DIR)/.done:
	@if test ! -d $(XPIDL_GEN_DIR); then echo Creating $(XPIDL_GEN_DIR)/.done; rm -rf $(XPIDL_GEN_DIR); mkdir $(XPIDL_GEN_DIR); fi
	@touch $@

$(XPIDL_GEN_DIR)/%.xpt: %.idl $(XPIDL_COMPILE) $(XPIDL_GEN_DIR)/.done
	$(REPORT_BUILD)
	$(ELOG) $(XPIDL_COMPILE) -m typelib -w -I $(IDL_DIR) -I$(srcdir) -o $(XPIDL_GEN_DIR)/$* $<

$(XPIDL_GEN_DIR)/%.h: %.idl $(XPIDL_COMPILE) $(XPIDL_GEN_DIR)/.done
	$(REPORT_BUILD)
	$(ELOG) $(XPIDL_COMPILE) -m header -w -I $(IDL_DIR) -I$(srcdir) -o $(XPIDL_GEN_DIR)/$* $<
	@if test -n "$(findstring $*.h, $(EXPORTS) $(SDK_HEADERS))"; \
	 then echo "*** WARNING: file $*.h generated from $*.idl overrides $(srcdir)/$*.h"; else true; fi

$(XPIDL_GEN_DIR)/$(XPIDL_MODULE).xpt: $(patsubst %.idl,$(XPIDL_GEN_DIR)/%.xpt,$(XPIDLSRCS) $(SDK_XPIDLSRCS))  Makefile
	$(XPIDL_LINK) $(XPIDL_GEN_DIR)/$(XPIDL_MODULE).xpt $(patsubst %.idl,$(XPIDL_GEN_DIR)/%.xpt,$(XPIDLSRCS) $(SDK_XPIDLSRCS))


$(DLL):$(OBJS) $(DEFFILE) $(RESFILE)
	dllwrap --dllname $@ --def $(DEFFILE)   $(OBJS) $(RESFILE) $(SYSTEM_LIBS)

%.o: %.cpp
	c++ -c $(ACDEFINES) $(INCLUDE) -o $@ $<

%.res:%.rc
	windres -o $@ -i $< -O coff
