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

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

#
# Various targets to build.
#

DLL_NAME = ExampleConstants.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 = -DBUILDING_DLL=1
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 /usr/lib/bundle1.o -lgcc  -L/usr/local/lib

# any extra libraries that your DLL may depend on.
DLL_LDLIBS =

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

###
#
# Making DLL
#
###

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

#$(DLL_NAME): $(DLL_OBJS) example_wrap.c
#	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.c
	gcc -bind_at_load -undefined dynamic_lookup \
	-o $(DLL_NAME) $(DLL_OBJS) $(DLL_LDFLAGS) $(DLL_LDLIBS)

#
# dependencies.
#

$(OBJS):
example_wrap.o: example_wrap.c

#
# 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) *.c ExampleConstants.ssi ExampleConstantsConstants.ssi ExampleConstantsEmbeddedConstants.ssi ExampleConstantsNI.ssi
