#
# Makefile for Cygwin.
#
CC = gcc
CXX = c++

DEBUG = -g #-O2
CXXFLAGS = $(DEBUG)
CFLAGS = $(DEBUG)
CPPFLAGS = -x c++ -I. -I../../../Lib/Smalltalk # -mno-cygwin
SWIG = swig

.SUFFIXES: .cxx

#
# Various targets to build.
#

DLL_NAME = ExampleClass.a

all: $(DLL_NAME)

#
# sources, objects, etc.
#
SRCS  = $(wildcard *.cxx *.c)
OBJS  = $(SRCS:.cxx=.o)
OBJS := $(OBJS:.c=.o)
OBJS := $(OBJS:.i=.c)

#
# DLL related variables. These are used when building the DLL. See later.
#

# Must define BUILDING_DLL when building the DLL. Otherwise import/exports
# will not work correctly. See dllclass.h for more info.
DLL_CFLAGS = -fno-common -dynamic
# The default entry point defined by dllwrap; the default user callback
# is DllMain, and there is stub in dllinit.c.
DLL_LDFLAGS = -dynamic -bundle -flat_namespace -bind_at_load \
	-bundle_loader /Users/stp/Code/Smalltalk/visual_Mac86.app/Contents/MacOS/visual \
	-undefined suppress -lgcc  -L/usr/local/lib
# any extra libraries that your DLL may depend on.
DLL_LDLIBS =

DLL_SRCS  = example_class.cxx example_wrap.cxx
DLL_OBJS  = $(DLL_SRCS:.cxx=.o)
DLL_OBJS := $(DLL_OBJS:.c=.o)
DLL_OBJS := $(DLL_OBJS:.i=.c)

###
#
# Making DLL
#
###

example_wrap.cxx: example_class.i
	$(SWIG) -smalltalk -c++ -o $@ $<

#$(DLL_NAME): $(DLL_OBJS) example_wrap.cxx
#	c++ -shared -Wl,--export-dynamic -mno-cygwin \
#	-Wl,--enable-auto-image-base \
#	-o $(DLL_NAME) $(DLL_OBJS) $(DLL_LDFLAGS) $(DLL_LDLIBS)

$(DLL_NAME): $(DLL_OBJS) example_wrap.cxx
	gcc -bind_at_load -o $(DLL_NAME) $(DLL_OBJS) $(DLL_LDFLAGS) $(DLL_LDLIBS)

#
# dependencies.
#

$(OBJS):
example.o: example_class.cxx
example_wrap.o: example_wrap.cxx

#
# default rules for building DLL objects. Note that client programs (ie.,
# the ones that *use* the DLL) have to be compiled without the DLL_CFLAGS
# flags.
#

.cxx.o:
	$(CXX) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CXXFLAGS) -o $@ $<
.c.o:
	$(CC) -c $(DLL_CFLAGS) $(CPPFLAGS) $(CFLAGS) -o $@ $<

clean:
	-rm -f $(OBJS) $(DLL_NAME) $(DLL_EXP_DEF) SWIGTYPE*.ssi example_wrap.cxx ExampleClass.ssi ExampleClassNI.ssi ExternalCircle.ssi ExternalShape.ssi ExternalSquare.ssi BigObject.ssi
