
srcdir = @srcdir@
builddir = @builddir@
prefix = @prefix@
exec_prefix = @exec_prefix@
bindir = @bindir@
libdir = @libdir@
libpltdir = @libpltdir@
collectsdir = @collectsdir@

# for version.mak:
mainsrcdir = @srcdir@/../..
@INCLUDEDEP@ @srcdir@/../../racket/version.mak

PLTSRCDIR = $(srcdir)/../..
PLTBUILDDIR = $(builddir)/../..

###########################
#      Common Macros      #
###########################
CC = @CC@
LINKER = $(CC)
RANLIB = @RANLIB@
AR = @AR@
ARFLAGS = @ARFLAGS@
OPTIONS = @OPTIONS@ @GC2OPTIONS@ @MROPTIONS@
XINCLUDE = @X_CFLAGS@
LDLIBS = @LIBS@
GCDIRECTORY = @GCDIR@
WBUILD = @WBUILD@
WXVARIANT =  @WXVARIANT@

NOGCINC = -I$(PLTBUILDDIR)/racket/ -I$(PLTSRCDIR)/racket/include/
INC = -I$(PLTSRCDIR)/racket/$(GCDIRECTORY) $(NOGCINC)
CFLAGS = $(INC) $(OPTIONS) -D$(WXVARIANT) @COMPFLAGS@ @PROFFLAGS@ @CFLAGS@ @PREFLAGS@
LDFLAGS = @LDFLAGS@
ARLIBFLAGS = $(LDFLAGS) $(LDLIBS)
###########################

CPP = @CPP@

XFORM_INC_wx_xt = -Dwx_xt @WX_MMD_FLAG@
XFORM_INC_wx_mac = -Dwx_mac -DOS_X -MMD -DWX_CARBON

# See ../../Makefile about RUN_RACKET_MMM, which 
# typically redirects to RUN_THIS_RACKET_MMM:
RUN_THIS_RACKET_MMM = ../../racket/racket@MMM@

MZMMM_wx_xt = @RUN_RACKET_MMM@
MZMMM_wx_mac = @RUN_RACKET_MMM@
MZMMM = $(MZMMM_@WXVARIANT@)

XFORM_CMD = $(MZMMM) -cqu $(srcdir)/../../racket/gc2/xform.rkt --setup ../../racket/gc2
XFORM_CPP_ARGS = -I$(srcdir)/../../racket/gc2 $(NOGCINC) $(OPTIONS) @PREFLAGS@ $(XFORM_INC_@WXVARIANT@)

XFORM = $(XFORM_CMD) --cpp "$(CPP) $(XFORM_CPP_ARGS)" @XFORMFLAGS@ -o
XFORMDEP = $(srcdir)/../../racket/gc2/xform.rkt $(srcdir)/../../racket/gc2/xform-mod.rkt $(srcdir)/../../racket/gc2/gc2.h

GRACKETLDFLAGS = $(LDFLAGS) -L../../racket

DEF_COLLECTS_DIR = +D INITIAL_COLLECTS_DIRECTORY='"'"`cd $(srcdir)/../../../collects; pwd`"'"'

XFORMWP = $(XFORM)

xsrc/grmain.c: $(srcdir)/../grmain.c $(XFORMDEP)
	$(XFORMWP) xsrc/grmain.c $(DEF_COLLECTS_DIR) $(srcdir)/../grmain.c

GCPREINC = -include $(srcdir)/../../racket/gc2/gc2.h
POSTFLAGS = $(OPTIONS) @COMPFLAGS@ @PROFFLAGS@ @CFLAGS@

wx_xt_EXTRAFLAGS =
wx_mac_EXTRAFLAGS =
EXTRAFLAGS = $(@WXVARIANT@_EXTRAFLAGS)

grmain.@LTO@: xsrc/grmain.c
	$(CC) $(CFLAGS) $(EXTRAFLAGS) -DGC2_JUST_MACROS $(GCPREINC) -c $(POSTFLAGS) -o grmain.@LTO@ xsrc/grmain.c

XSRCS = xsrc/grmain.c

wx_xt_LIBS =
wx_mac_LIBS = -framework CoreFoundation

GRACKETLINKER = @MZLINKER@

GRACKETLIBS_a = $(LDLIBS)
GRACKETLIBS_la =
GRACKETMZOBJS_a = $(MZOBJS)
GRACKETMZOBJS_la =

../gracket@MMM@@NOT_OSX@: grmain.@LTO@ ../../racket/libracket3m.@LIBSFX@
	$(GRACKETLINKER) $(GRACKETLDFLAGS) -o ../gracket@MMM@ grmain.@LTO@ ../../racket/libracket3m.@LIBSFX@ $(GRACKETMZOBJS_@LIBSFX@) $(GRACKETLIBS_@LIBSFX@)

MZFW = ../../racket/Racket.framework/Versions/$(FWVERSION)_3m/Racket
MRAPPSKEL = ../GRacket@MMM@.app/Contents/MacOS

../GRacket@MMM@.app/Contents/MacOS/GRacket@MMM@: $(MRAPPSKEL) $(MZFW) grmain.@LTO@
	$(GRACKETLINKER) $(LDFLAGS) -o ../GRacket@MMM@.app/Contents/MacOS/GRacket@MMM@ grmain.@LTO@ -Wl,-headerpad_max_install_names -F../../racket/gc2 -framework Racket -framework CoreFoundation
	/usr/bin/install_name_tool -change "Racket.framework/Versions/$(FWVERSION)_3m/Racket" "@executable_path/../../../../racket/Racket.framework/Versions/$(FWVERSION)_3m/Racket" "../GRacket@MMM@.app/Contents/MacOS/GRacket@MMM@"

$(MRFW) : $(XOBJS) $(@WXVARIANT@_PLAIN_OBJS) ../../racket/libracket3m.@LIBSFX@ wx_font.o wx_file_dialog.o $(MRFWRES)
	$(GRACKETLINKER) $(LDFLAGS) -dynamiclib -o $(MRFW) -Wl,-headerpad_max_install_names $(XOBJS) $(@WXVARIANT@_PLAIN_OBJS) ../../racket/libracket3m.@LIBSFX@ $(@WXVARIANT@_LIBS) @X_EXTRA_LIBS@ wx_font.o wx_file_dialog.o

$(MRAPPSKEL): $(srcdir)/../../mac/osx_appl.rkt
	env BUILDBASE=../.. BUILDING_3M=yes @RUN_RACKET_MMM@ -cqu $(srcdir)/../../mac/osx_appl.rkt $(srcdir)/../.. "@MMM@"

../gracket@MMM@@OSX@ :
	$(MAKE) ../GRacket@MMM@.app/Contents/MacOS/GRacket@MMM@

xsrc:
	mkdir xsrc

3m: xsrc
	$(MAKE) ../gracket@MMM@

########################################
#             Make Depends             #
########################################

GRMAIN_DEPS = $(srcdir)/../grmain.c \
  $(srcdir)/../../racket/main.c \
  $(srcdir)/../../racket/include/scheme.h \
  $(srcdir)/../../racket/include/../sconfig.h \
  ../../racket/mzconfig.h \
  $(srcdir)/../../racket/include/../uconfig.h \
  $(srcdir)/../../racket/include/../src/stypes.h \
  $(srcdir)/../../racket/include/../gc2/gc2_obj.h \
  $(srcdir)/../../racket/include/schthread.h \
  $(srcdir)/../../racket/include/../src/schexn.h \
  $(srcdir)/../../racket/include/../gc2/gc2.h \
  $(srcdir)/../../racket/include/../gc2/../include/schthread.h \
  $(srcdir)/../../racket/include/../src/schemef.h \
  $(srcdir)/../../racket/cmdline.inc

xsrc/grmain.c: $(GRMAIN_DEPS)

grmain.@LTO@: $(GRMAIN_DEPS)
