
PACKAGE = racket

srcdir = @srcdir@
builddir = @builddir@
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
bindir = @bindir@
libdir = @libdir@
libpltdir = @libpltdir@
sharepltdir = @sharepltdir@
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 = @COMPFLAGS@ @PROFFLAGS@ @CFLAGS@
CPPFLAGS = @PREFLAGS@
ALL_CFLAGS = $(INC) $(OPTIONS) -D$(WXVARIANT) @COMPFLAGS@ @PROFFLAGS@ $(CFLAGS) $(CPPFLAGS)
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) $(SELF_RACKET_FLAGS) -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@`"'"'
DEF_CONFIG_DIR = +D INITIAL_CONFIG_DIRECTORY='"'"`cd $(srcdir)/../../..; @PWD@`/etc"'"'
DEF_C_DIRS = $(DEF_COLLECTS_DIR) $(DEF_CONFIG_DIR)

XFORMWP = $(XFORM)

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

GCPREINC = -include $(srcdir)/../../racket/gc2/gc2.h
POSTFLAGS = $(OPTIONS)

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

grmain.@LTO@: xsrc/grmain.c
	$(CC) $(ALL_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@

LIBRKTIO = ../../rktio/librktio.@LTA@
LIBRKTIO_a = $(LIBRKTO)
LIBRKTIO_la =

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

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

../gracket@MMM@@MINGW@: grmain.@LTO@ ../../racket/gc2/libracket3m.dll.a ../gres.o
	$(GRACKETLINKER) -mwindows $(GRACKETLDFLAGS) -o ../gracket@MMM@ grmain.@LTO@ ../gres.o ../../racket/gc2/libracket3m.dll.a $(GRACKETMZOBJS_@LIBSFX@) $(GRACKETLIBS_@LIBSFX@) -l delayimp -static-libgcc

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

../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  $(srcdir)/../../racket/src/schvers.h $(srcdir)/../../mac/icon/GRacket.icns
	env BUILDBASE=../.. BUILDING_3M=yes @RUN_RACKET_MMM@ $(SELF_RACKET_FLAGS) -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)
