#
# Makefile for racket
#

PACKAGE = racket

srcdir = @srcdir@
prefix = @prefix@
exec_prefix = @exec_prefix@
datarootdir = @datarootdir@
bindir = @bindir@
libdir = @libdir@
includepltdir = @includepltdir@
libpltdir = @libpltdir@
libpltdir_rel = @libpltdir_rel@
etcpltdir = @etcpltdir@
sharepltdir = @sharepltdir@
collectsdir = @collectsdir@
builddir = @builddir@

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

NOOP = :

CC = @CC@
CPP = @CPP@

# Although CFLAGS is defined via configure, the intent is that
# CFLAGS and CPPFLAGS can be adjusted at `make' time.
CFLAGS = @CFLAGS@ @COMPFLAGS@ @PROFFLAGS@ 
CPPFLAGS =  @PREFLAGS@

NICEAR = $(mainsrcdir)/utils/nicear
AR = @AR@
ARFLAGS = @ARFLAGS@
RANLIB = @RANLIB@

STRIP_DEBUG = @STRIP_DEBUG@
STRIP_LIB_DEBUG = @STRIP_LIB_DEBUG@

ARLIBFLAGS = @LDFLAGS@ @LIBS@

RACKET = racket

# See ../../Makefile about RUN_RACKET_<X>, which 
# typically redirects to RUN_THIS_RACKET_<X>:
RUN_THIS_RACKET_CGC = ./racket@CGC@
RUN_THIS_RACKET_MMM = ./racket@MMM@

SETUP_BOOT = -O "info@compiler/cm error" -l- setup @BOOT_MODE@ $(srcdir)/../setup-go.rkt ../compiled

MZSRC = $(srcdir)/src

FOREIGN_DIR = ../foreign
FOREIGN_OBJ = $(FOREIGN_DIR)/foreign.@LTO@
LIBFFI_OBJ_ON = $(FOREIGN_DIR)/libffi/src/*.@LTO@ $(FOREIGN_DIR)/libffi/src/*/*.@LTO@
LIBFFI_OBJ_OFF = 
FOREIGN_OBJS = $(FOREIGN_OBJ) $(LIBFFI_OBJ_@OWN_LIBFFI@)
LIBFFI_LIB_ON = ../foreign/libffi/libffi@FOREIGN_CONVENIENCE@.la
LIBFFI_LIB_OFF = 
FOREIGN_LIB = $(FOREIGN_OBJ) $(LIBFFI_LIB_@OWN_LIBFFI@)
FOREIGN_STUB_LIB = $(FOREIGN_OBJ)
FOREIGN_OBJSLIB = @FOREIGN_OBJSLIB@
# Dependency always uses FOREIGN_LIB, but linker uses FOREIGN_OBJSLIB. The
#  FOREIGN_OBJSLIB expansion has too many "*"s to be a valid make target,
#  while FOREIGN_LIB is not always acceptable to the linker.
# The foreign build always uses libtool, so that's why we use .la instead of @LTA@
#  in FOREIGN_LIB.

# About EXE_SUFFIX:
#  Cygwin offers the illusion that binaries have no ".exe" suffix by
#  having the file-open syscall open an ".exe" file for reading when
#  (1) the given filename has no suffix, and (2) there's not a suffixless
#  file present. However, Cygwin doesn't do that when opening a file for
#  output, even when the output mode is 'update. So we need to explcitly
#  add EXE_SUFFIX in a few places.

################################################################################

bin: 
	$(MAKE) @MZBINTARGET@

normal-bin:
	$(MAKE) @MAIN_VARIANT@

common:
	$(MAKE) g-c
	$(MAKE) @FOREIGNTARGET@
	$(MAKE) rktio

cgc:
	$(MAKE) cgc-core
	$(MAKE) sysinfer@CGC@

cgc-core:
	$(MAKE) common
	$(MAKE) dynlib
	$(MAKE) mzlibrary
	$(MAKE) racket@CGC@
	$(MAKE) cstartup
	$(MAKE) mzlibrary
	$(MAKE) racket@CGC@
	$(MAKE) mzcom@CGC@

3m:
	$(MAKE) @CGC_IF_NEEDED_FOR_MMM@
	$(MAKE) cstartup
	cd gc2; $(MAKE) all
	cd dynsrc; $(MAKE) dynlib3m
	cd gc2; $(MAKE) ../racket@MMM@
	cd gc2; $(MAKE) ../mzcom@MMM@
	$(MAKE) sysinfer@MMM@

both:
	$(MAKE) cgc-core
	$(MAKE) 3m

racketlib: 
	$(MAKE) g-c 
	$(MAKE) @FOREIGNTARGET@
	$(MAKE) mzlibrary 

dynlib:
	cd dynsrc; $(MAKE) dynlib 

dynexample:
	$(MAKE) dynlib
	cd dynsrc; $(MAKE) dynexample 

oe:
	$(MAKE) dynlib
	cd dynsrc; $(MAKE) oe

g-c:
	cd @GCDIR@; $(MAKE) ../libmzgc.@LIBSFX@ 

exports:
	cd src; $(MAKE) mzheaders

sproc-extra-lib:
	cd @GCDIR@; $(MAKE) sproc.@LTO@
	$(MAKE) sproc.@LTO@

gc.@LIBSFX@:
	$(NICEAR) $(AR) $(ARFLAGS) @GCDIR@/gc.@LIBSFX@ @GCDIR@/*.@LTO@

# Compilation of the foreign libraries (this compiles all of them)
foreign-stuff:
	cd $(FOREIGN_DIR); $(MAKE) all

foreign-stub:
	cd $(FOREIGN_DIR); $(MAKE) stub

rktio:
	cd ../rktio; $(MAKE)

mzlibrary:
	cd src; $(MAKE) all 
	$(MAKE) libracket.@LIBSFX@

# For no-cgc-needed, we don't need to build the gc or link racketcgc, 
# but gc2 depends on a few plain-src objects
no-cgc-needed:
	cd src; $(MAKE) plain-objs
	$(MAKE) @FOREIGNTARGET@
	$(MAKE) rktio
	$(MAKE) main.@LTO@
	$(MAKE) mingw-other
	cd dynsrc; $(MAKE) ../starter@EXE_SUFFIX@

ALL_CPPFLAGS = -I$(builddir) -I$(srcdir)/include -I$(srcdir)/src $(CPPFLAGS) @OPTIONS@ @GC2OPTIONS@ @MZOPTIONS@ 
MKSYSTEM_ARGS = -cqu $(srcdir)/mksystem.rkt system.rktd "$(CPP) $(ALL_CPPFLAGS) $(srcdir)/src/systype.c" "@MMM_INSTALLED@"

sysinfer@CGC@:
	@RUN_RACKET_CGC@ $(MKSYSTEM_ARGS) "@RUN_RACKET_CGC@" "$(RUN_THIS_RACKET_CGC)"

sysinfer@MMM@:
	@RUN_RACKET_MMM@ $(MKSYSTEM_ARGS) "@RUN_RACKET_MMM@" "$(RUN_THIS_RACKET_MMM)"


FOREIGN_USED_LIB = $(FOREIGN_OBJ) $(FOREIGN_LIB)
FOREIGN_USED_OBJSLIB = $(FOREIGN_OBJSLIB)
FOREIGN_NOT_USED_LIB = $(FOREIGN_OBJ)
FOREIGN_NOT_USED_OBJSLIB = $(FOREIGN_OBJ)

LIBRKTIO = ../rktio/librktio.@LTA@
LIBRKTIO_FOR_DLL_la = $(LIBRKTIO)
LIBRKTIO_FOR_DLL_a = 
LIBRKTIO_FOR_LIB_la =
LIBRKTIO_FOR_LIB_a = $(LIBRKTIO)
LIBRKTIO_FOR_DLL = $(LIBRKTIO_FOR_DLL_@LIBSFX@)
LIBRKTIO_FOR_LIB = $(LIBRKTIO_FOR_LIB_@LIBSFX@)

libracket.@LIBSFX@: src/*.@LTO@ $(@FOREIGN_IF_USED@_LIB) $(LIBRKTIO_FOR_DLL)
	$(NICEAR) $(AR) $(ARFLAGS) libracket.@LIBSFX@ src/*.@LTO@ $(@FOREIGN_IF_USED@_OBJSLIB) $(LIBRKTIO_FOR_DLL) @LIBRACKET_DEP@
	$(RANLIB) libracket.@LIBSFX@

# Irix sproc, only
sproc.@LTO@: @GCDIR@/sproc.@LTO@
	cp @GCDIR@/sproc.@LTO@ sproc.@LTO@

# Unix ----------------------------------------

racket@CGC@@NOT_OSX@@NOT_MINGW@: libracket.@LIBSFX@ libmzgc.@LIBSFX@ main.@LTO@ $(LIBRKTIO_FOR_LIB) $(SPECIALIZINGOBJECTS)
	@MZLINKER@ -o racket@CGC@ main.@LTO@ $(SPECIALIZINGOBJECTS) libracket.@LIBSFX@ libmzgc.@LIBSFX@ $(LIBRKTIO_FOR_LIB) @LDFLAGS@ @LIBS@

mzcom@CGC@@NOT_MINGW@:
	$(NOOP)

# Mac OS ----------------------------------------

MZFW = Racket.framework/Versions/$(FWVERSION)/Racket

$(MZFW): libracket.@LIBSFX@ libmzgc.@LIBSFX@ $(SPECIALIZINGOBJECTS) $(LIBRKTIO)
	mkdir -p  Racket.framework/Versions/$(FWVERSION)
	@MZLINKER@ -o $(MZFW) @LDFLAGS@ -framework CoreFoundation -dynamiclib -all_load $(SPECIALIZINGOBJECTS) libracket.@LIBSFX@ libmzgc.@LIBSFX@ $(LIBRKTIO) @LIBS@
	rm -f Racket.framework/Racket
	ln -s Versions/$(FWVERSION)/Racket Racket.framework/Racket

racket@CGC@@OSX@: $(MZFW) main.@LTO@
	@MZLINKER@ -o racket@CGC@ @PROFFLAGS@ @LDFLAGS@ main.@LTO@ -Wl,-headerpad_max_install_names -F. -framework Racket @LIBS@
	/usr/bin/install_name_tool -change "Racket.framework/Versions/$(FWVERSION)/Racket" "@executable_path/Racket.framework/Versions/$(FWVERSION)/Racket" "racket@CGC@"

# mingw ----------------------------------------

lib/libmzgcxxxxxxx.dll: libmzgc.@LIBSFX@
	mkdir -p lib
	@MZLINKER@ -shared -o lib/libmzgcxxxxxxx.dll -Wl,--output-def -Wl,libmzgc.def -Wl,--whole-archive libmzgc.@LIBSFX@ -Wl,--no-whole-archive @LDFLAGS@ -static-libgcc @LIBS@

mzsj86g.o: $(srcdir)/src/mzsj86g.S
	$(CC) -c -o mzsj86g.o $(srcdir)/src/mzsj86g.S

lib/libracketxxxxxxx.dll: lib/libmzgcxxxxxxx.dll libracket.@LIBSFX@ mzsj86g.o $(LIBRKTIO)
	mkdir -p lib
	@MZLINKER@ -shared -o lib/libracketxxxxxxx.dll mzsj86g.o -Wl,--output-def -Wl,libracket.def -Wl,--whole-archive libracket.@LIBSFX@ -Wl,--no-whole-archive $(LIBRKTIO) @LDFLAGS@ -lshell32 -luser32 -lws2_32 lib/libmzgcxxxxxxx.dll -static-libgcc @LIBS@

libracket.dll.a: lib/libracketxxxxxxx.dll
	@DLLTOOL@ --def libracket.def -D libracketxxxxxxx.dll --output-exp libracketxxxxxxx.exp --output-lib libracketxxxxxxx.lib --output-delaylib libracket.dll.a

libmzgc.dll.a: lib/libmzgcxxxxxxx.dll
	@DLLTOOL@ --def libmzgc.def -D libmzgcxxxxxxx.dll --output-lib libmzgcxxxxxxx.lib --output-exp libmzgcxxxxxxx.lib --output-delaylib libmzgc.dll.a

rres.o: $(srcdir)/../worksp/racket/racket.rc
	@WINDRES@ -i $(srcdir)/../worksp/racket/racket.rc -o rres.o

MW_RACKET_LIBS = libracket.dll.a libmzgc.dll.a @LDFLAGS@ @LIBS@ -ldelayimp -static-libgcc

racket@CGC@@MINGW@: libracket.dll.a libmzgc.dll.a main.@LTO@ MemoryModule.@LTO@ $(SPECIALIZINGOBJECTS) rres.o
	@MZLINKER@ -o racket@CGC@ main.@LTO@ MemoryModule.@LTO@ rres.o $(SPECIALIZINGOBJECTS) $(MW_RACKET_LIBS)

MemoryModule.@LTO@: $(srcdir)/../start/MemoryModule.c $(srcdir)/../start/MemoryModule.h
	$(CC) -c -I $(srcdir)/../start -o MemoryModule.@LTO@ $(srcdir)/../start/MemoryModule.c

mingw-other@MINGW@: mzsj86g.o MemoryModule.@LTO@ rres.o comres.o com_glue.@LTO@
	$(NOOP)

mingw-other@NOT_MINGW@:
	$(NOOP)

mzcom@CGC@@MINGW@: libracket.dll.a libmzgc.dll.a mzcom.@LTO@ mzobj.@LTO@ com_glue.@LTO@ $(SPECIALIZINGOBJECTS) comres.o
	@MZLINKER@ -mwindows -o mzcom@CGC@ mzcom.@LTO@ mzobj.@LTO@ com_glue.@LTO@ comres.o $(SPECIALIZINGOBJECTS) -lole32 -loleaut32 -luuid $(MW_RACKET_LIBS)

comres.o : $(srcdir)/../worksp/mzcom/mzcom.rc $(srcdir)/../mzcom/prebuilt/MzCOM.tlb
	@WINDRES@ -I $(srcdir)/../mzcom -I $(srcdir)/../mzcom/prebuilt -i $(srcdir)/../worksp/mzcom/mzcom.rc -o comres.o

# ----------------------------------------

DEF_COLLECTS_DIR = -DINITIAL_COLLECTS_DIRECTORY='"'"`cd $(srcdir)/../../collects; @PWD@`"'"'
DEF_CONFIG_DIR = -DINITIAL_CONFIG_DIRECTORY='"'"`cd $(srcdir)/../..; @PWD@`/etc"'"'
DEF_C_DIRS = $(DEF_COLLECTS_DIR) $(DEF_CONFIG_DIR)

MAIN_HEADER_DEPS = $(srcdir)/include/scheme.h $(srcdir)/include/schthread.h $(srcdir)/sconfig.h \
                   $(srcdir)/src/stypes.h $(srcdir)/cmdline.inc $(srcdir)/parse_cmdl.inc \
	           $(srcdir)/../start/config.inc $(srcdir)/../start/delayed.inc $(srcdir)/parse_cmdl.inc \
	           $(srcdir)/../start/embedded_dll.inc

main.@LTO@: $(srcdir)/main.c $(MAIN_HEADER_DEPS)
	$(CC) -I$(builddir) -I$(srcdir)/include $(CFLAGS) $(CPPFLAGS) @OPTIONS@ @MZOPTIONS@ $(DEF_C_DIRS) -c $(srcdir)/main.c -o main.@LTO@

main_ee.@LTO@: main.@LTO@
	$(CC) -I$(builddir) -I$(srcdir)/include $(CFLAGS) $(CPPFLAGS) @OPTIONS@ @MZOPTIONS@ $(DEF_C_DIRS) -DSTANDALONE_WITH_EMBEDDED_EXTENSION -c $(srcdir)/main.c -o main_ee.@LTO@

ee-main:
	$(MAKE) main_ee.@LTO@

ee-app: $(RACKET) main_ee.@LTO@
	if [ "$(EEAPP)" = '' ] ; then echo "ERROR: You must specify EEAPP" ; else $(CC) $(MAIN_CFLAGS_NODBG) -o $(EEAPP) main_ee.@LTO@ $(EEOBJECTS) $(SPECIALIZINGOBJECTS) libracket.@LIBSFX@ libmzgc.@LIBSFX@ @LIBS@ ; fi

MZCOM_DEPS = $(MAIN_HEADER_DEPS) $(srcdir)/../mzcom/com_glue.h $(srcdir)/../mzcom/resource.h

mzcom.@LTO@: $(srcdir)/../mzcom/mzcom.cxx $(MZCOM_DEPS)
	$(CC) -fno-exceptions -I$(builddir) -I$(srcdir)/include $(CFLAGS) $(CPPFLAGS) @OPTIONS@ @MZOPTIONS@ $(DEF_C_DIRS) -c $(srcdir)/../mzcom/mzcom.cxx -o mzcom.@LTO@

mzobj.@LTO@: $(srcdir)/../mzcom/mzobj.cxx $(MZCOM_DEPS)
	$(CC) -fno-exceptions -I$(builddir) -I$(srcdir)/include $(CFLAGS) $(CPPFLAGS) @OPTIONS@ @MZOPTIONS@ -c $(srcdir)/../mzcom/mzobj.cxx -o mzobj.@LTO@

com_glue.@LTO@: $(srcdir)/../mzcom/com_glue.c $(MZCOM_DEPS)
	$(CC) -I$(builddir) -I$(srcdir)/include $(CFLAGS) $(CPPFLAGS) @OPTIONS@ @MZOPTIONS@ -c $(srcdir)/../mzcom/com_glue.c -o com_glue.@LTO@

exn:
	$(RACKET) -um $(srcdir)/src/makeexn > $(srcdir)/src/schexn.h
	$(RACKET) -um $(srcdir)/src/makeexn kernstruct $(collectsdir)/racket/private/kernstruct.rkt

CSTARTUPDEST = cstartup.inc

MZCONFIGDIR@NOT_MINGW@ = .
MZCONFIGDIR@MINGW@ = "$(srcdir)/../worksp"

headers:
	@RUN_RACKET_CGC@ -cqu $(srcdir)/mkincludes.rkt @DIRCVTPRE@"$(DESTDIR)$(includepltdir)"@DIRCVTPOST@ "$(srcdir)" $(MZCONFIGDIR)
	cd ..; cp racket/system.rktd "$(DESTDIR)$(libpltdir)/system.rktd"

# The `cstartup` target may update "cstartup.inc", either replacing a
# stub "cstartup.inc" that redirects to "startup.inc" or rebuilding
# because "startup.inc" or "schvers.h" changed; so, during a CGC
# build, we try again after building this target to potentially update
# the CGC build to a compiled-startup build. A particular `cstartup`
# target variant is selected by the `configure` script based on whether
# `--{en,dis}able-cify` is specified; for example `STARTUP_AS_AUTO`
# with be the empty string is neither is specified, in which case
# of the the other targets is selected by a recursive `$(MAKE)`.

cstartup@STARTUP_AS_AUTO@:
	$(MAKE) cstartup_`@RUN_RACKET_CGC@ -cu $(srcdir)/src/startup-select.rkt`

# For compiling the startup code to bytecode
cstartup@STARTUP_AS_BYTECODE@:
	@RUN_RACKET_CGC@ -cu $(srcdir)/src/compile-startup.rkt $(CSTARTUPDEST) cstartup.zo $(srcdir)/src/startup.inc $(srcdir)/src/schvers.h

# For compiling the startup code to C
cstartup@STARTUP_AS_C@:
	@RUN_RACKET_CGC@ -cu $(srcdir)/src/cify-check.rkt $(CSTARTUPDEST)
	$(MAKE) cstartup.inc

cstartup_:
	echo "Bad startup choice, probably an error running startup-select.rkt"
	exit 1

# Running "cify-startup.rkt" through "$(SETUP_BOOT)" generates more
# dependencies in "cstartup.d" for `$(CSTARTUPDEST)`
$(CSTARTUPDEST): $(srcdir)/src/startup.inc $(srcdir)/src/schvers.h
	@RUN_RACKET_CGC@ $(SELF_RACKET_FLAGS) $(SETUP_BOOT) cstartup.inc cstartup.d $(srcdir)/src/cify-startup.rkt $(srcdir)/src/startup.inc $(srcdir)/src/schvers.h
@INCLUDEDEP@ cstartup.d

mark:
	racket -cu $(srcdir)/src/mkmark.rkt $(srcdir)/src < $(srcdir)/src/mzmarksrc.c

clean@NOT_OSX@:
	/bin/rm -rf tmp[123456789] tests/tmp[123456789] tests/sub[123]
	/bin/rm -f tests/*~
	/bin/rm -f *.@LTO@ core
	/bin/rm -f mzdyn.o libmzgc.@LIBSFX@ libracket.@LIBSFX@ libracket3m.@LIBSFX@ libdl.a racket racket.multiboot
	/bin/rm -f include/macosxpre
	/bin/rm -f include/macosxpre.p
	/bin/rm -f $(CSTARTUPDEST)
	cd gc; $(MAKE) clean
	cd gc2; $(MAKE) clean
	cd sgc; $(MAKE) clean
	cd src; $(MAKE) clean
	cd dynsrc; $(MAKE) clean
	if [ -d ../foreign ] ; then cd ../foreign ; $(MAKE) clean ; fi

clean@OSX@:
	rm -rf Racket.framework
	$(MAKE) clean@NOT_OSX@

BUILDINFO=$(DESTDIR)$(libpltdir)/buildinfo
ICP=@ICP@
ICP_LIB=@ICP_LIB@

install:
	$(MAKE) install-@MAIN_VARIANT@

install-3m:
	$(MAKE) headers
	$(MAKE) @MZINSTALLTARGET@
	$(MAKE) @MZINSTALLTARGET@-3m
	$(MAKE) @MZINSTALLTARGET@-3m-final

install-cgc:
	$(MAKE) headers
	$(MAKE) @MZINSTALLTARGET@
	$(MAKE) @MZINSTALLTARGET@-cgc
	$(MAKE) @MZINSTALLTARGET@-cgc-final

install-both:
	$(MAKE) headers
	$(MAKE) @MZINSTALLTARGET@
	$(MAKE) @MZINSTALLTARGET@-3m
	$(MAKE) @MZINSTALLTARGET@-cgc
	$(MAKE) @MZINSTALLTARGET@-@MAIN_VARIANT@-final

# Unix install ----------------------------------------

# Prefix might be relative to srcdir, or it might be absolute, so we
# have to go up and install things from there.

unix-install:
	cd ..; rm -f "$(DESTDIR)@MZINSTALLBINDIR@/racket@CGC_INSTALLED@"
	cd ..; rm -f "$(DESTDIR)@MZINSTALLBINDIR@/racket@MMM_INSTALLED@"
	cd ..; cp racket/starter@EXE_SUFFIX@ "$(DESTDIR)$(libpltdir)/starter@EXE_SUFFIX@"
	cp $(srcdir)/../start/starter-sh .
	cd ..; cp racket/starter-sh "$(DESTDIR)$(libpltdir)/starter-sh"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(libpltdir)/starter@EXE_SUFFIX@"
	@RUN_RACKET_CGC@ -cu "$(srcdir)/collects-path.rkt" "$(DESTDIR)$(libpltdir)/starter@EXE_SUFFIX@" $(DESTDIR)@COLLECTS_PATH@ $(DESTDIR)@CONFIG_PATH@
	cd ..; echo 'CC=@CC@' > "$(BUILDINFO)"
	cd ..; echo 'CFLAGS=$(CFLAGS) $(CPPFLAGS)' >> "$(BUILDINFO)"
	cd ..; echo 'OPTIONS=@OPTIONS@' >> "$(BUILDINFO)"
	cd ..; echo 'MZOPTIONS=@MZOPTIONS@' >> "$(BUILDINFO)"
	cd ..; echo "LDFLAGS=@LDFLAGS@" >> "$(BUILDINFO)"
	cd ..; echo 'LIBS=@LIBS@' >> "$(BUILDINFO)"

unix-install-cgc:
	$(MAKE) unix-@INSTALL_LIBS_ENABLE@-libs-cgc
	cd ..; $(ICP) racket/racket@CGC@ "$(DESTDIR)$(bindir)/racket@CGC_INSTALLED@"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(bindir)/racket@CGC_INSTALLED@"
	cd ..; cp racket/mzdyn.o "$(DESTDIR)$(libpltdir)/mzdyn.o"
	@RUN_RACKET_CGC@ -cu "$(srcdir)/collects-path.rkt" "$(DESTDIR)$(bindir)/racket@CGC_INSTALLED@@EXE_SUFFIX@" $(DESTDIR)@COLLECTS_PATH@ $(DESTDIR)@CONFIG_PATH@

unix-install-libs-cgc:
	cd ..; $(ICP_LIB) racket/libmzgc.@LIBSFX@ "$(DESTDIR)$(libdir)/libmzgc.@LIBSFX@"
	cd ..; $(ICP_LIB) racket/libracket.@LIBSFX@ "$(DESTDIR)$(libdir)/libracket.@LIBSFX@"
	cd ..; $(STRIP_LIB_DEBUG) "$(DESTDIR)$(libdir)/libmzgc.@LIBSFX@"
	cd ..; $(STRIP_LIB_DEBUG) "$(DESTDIR)$(libdir)/libracket.@LIBSFX@"

unix-no-install-libs-cgc:
	$(NOOP)

unix-install-cgc-final:
	$(NOOP)

unix-install-3m:
	cd ..; $(ICP) racket/racket@MMM@ "$(DESTDIR)$(bindir)/racket@MMM_INSTALLED@"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(bindir)/racket@MMM_INSTALLED@"
	$(MAKE) unix-@INSTALL_LIBS_ENABLE@-libs-3m
	cd ..; $(ICP) racket/mzdyn3m.o "$(DESTDIR)$(libpltdir)/mzdyn3m.o"
	@RUN_RACKET_MMM@ -cu "$(srcdir)/collects-path.rkt" "$(DESTDIR)$(bindir)/racket@MMM_INSTALLED@@EXE_SUFFIX@" $(DESTDIR)@COLLECTS_PATH@ $(DESTDIR)@CONFIG_PATH@

unix-install-libs-3m:
	cd ..; $(ICP_LIB) racket/libracket3m.@LIBSFX@ "$(DESTDIR)$(libdir)/libracket3m.@LIBSFX@"
	cd ..; $(STRIP_LIB_DEBUG) "$(DESTDIR)$(libdir)/libracket3m.@LIBSFX@"

unix-no-install-libs-3m:
	$(NOOP)

unix-install-3m-final:
	$(NOOP)

# mingw install ----------------------------------------

mingw-install:
	cd ..; rm -f "$(DESTDIR)@MZINSTALLBINDIR@/racket@CGC_INSTALLED@"
	cd ..; rm -f "$(DESTDIR)@MZINSTALLBINDIR@/racket@MMM_INSTALLED@"
	cd ..; cp racket/starter@EXE_SUFFIX@ "$(DESTDIR)$(libpltdir)/MzStart@EXE_SUFFIX@"
	cd ..; cp racket/mrstarter@EXE_SUFFIX@ "$(DESTDIR)$(libpltdir)/MrStart@EXE_SUFFIX@"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(libpltdir)/MzStart@EXE_SUFFIX@"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(libpltdir)/MrStart@EXE_SUFFIX@"
	cp "$(srcdir)/../mzcom/prebuilt/MzCOM.tlb" MzCOM.tlb
	cd ..; cp racket/MzCOM.tlb "$(DESTDIR)$(libpltdir)/MzCOM.tlb"

mingw-install-cgc:
	cd ..; mkdir -p "$(DESTDIR)$(libdir)/gcc"
	cd ..; $(ICP) racket/libmzgcxxxxxxx.lib "$(DESTDIR)$(libdir)/gcc/libmzgcxxxxxxx.lib"
	cd ..; $(ICP) racket/libmzgcxxxxxxx.exp "$(DESTDIR)$(libdir)/gcc/libmzgcxxxxxxx.exp"
	cd ..; $(ICP) racket/libmzgc.def "$(DESTDIR)$(libdir)/libmzgcxxxxxxx.def"
	cd ..; $(ICP) racket/libracketxxxxxxx.lib "$(DESTDIR)$(libdir)/gcc/libracketxxxxxxx.lib"
	cd ..; $(ICP) racket/libracketxxxxxxx.exp "$(DESTDIR)$(libdir)/gcc/libracketxxxxxxx.exp"
	cd ..; $(ICP) racket/libracket.def "$(DESTDIR)$(libdir)/libracketxxxxxxx.def"
	cd ..; $(ICP) racket/mzdyn3m.o "$(DESTDIR)$(libdir)/gcc/mzdyn.obj"
	cd ..; $(ICP) racket/mzdyn3m.exp "$(DESTDIR)$(libdir)/gcc/mzdyn.exp"
	cd ..; $(ICP) racket/lib/libmzgcxxxxxxx.dll "$(DESTDIR)$(libdir)/libmzgcxxxxxxx.dll"
	cd ..; $(ICP) racket/lib/libracketxxxxxxx.dll "$(DESTDIR)$(libdir)/libracketxxxxxxx.dll"
	cd ..; $(ICP) racket/racket@CGC@ "$(DESTDIR)@MZINSTALLBINDIR@/Racket@CGC_INSTALLED@@EXE_SUFFIX@"
	cd ..; $(ICP) racket/mzcom@CGC@ "$(DESTDIR)$(libdir)/MzCOM@CGC_INSTALLED@@EXE_SUFFIX@"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(libdir)/libmzgcxxxxxxx.dll"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(libdir)/libracketxxxxxxx.dll"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)@MZINSTALLBINDIR@/Racket@CGC_INSTALLED@@EXE_SUFFIX@"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(libdir)/MzCOM@CGC_INSTALLED@@EXE_SUFFIX@"
	@RUN_RACKET_CGC@ -cu "$(srcdir)/collects-path.rkt" @DIRCVTPRE@"$(DESTDIR)@MZINSTALLBINDIR@/Racket@CGC_INSTALLED@@EXE_SUFFIX@"@DIRCVTPOST@ $(DESTDIR)@COLLECTS_PATH@ $(DESTDIR)@CONFIG_PATH@

mingw-install-cgc-final:
	$(NOOP)

mingw-install-3m:
	cd ..; mkdir -p "$(DESTDIR)$(libdir)/gcc"
	cd ..; $(ICP) racket/gc2/libracket3mxxxxxxx.lib "$(DESTDIR)$(libdir)/gcc/libracket3mxxxxxxx.lib"
	cd ..; $(ICP) racket/gc2/libracket3mxxxxxxx.exp "$(DESTDIR)$(libdir)/gcc/libracket3mxxxxxxx.exp"
	cd ..; $(ICP) racket/gc2/libracket3m.def "$(DESTDIR)$(libdir)/libracket3mxxxxxxx.def"
	cd ..; $(ICP) racket/mzdyn3m.o "$(DESTDIR)$(libdir)/gcc/mzdyn3m.obj"
	cd ..; $(ICP) racket/mzdyn3m.exp "$(DESTDIR)$(libdir)/gcc/mzdyn3m.exp"
	cd ..; $(ICP) racket/racket@MMM@ "$(DESTDIR)@MZINSTALLBINDIR@/Racket@MMM_INSTALLED@@EXE_SUFFIX@"
	cd ..; $(ICP) racket/mzcom@MMM@ "$(DESTDIR)$(libdir)/MzCOM@MMM_INSTALLED@@EXE_SUFFIX@"
	cd ..; $(ICP) racket/lib/libracket3mxxxxxxx.dll "$(DESTDIR)$(libdir)/libracket3mxxxxxxx.dll"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(libdir)/libracket3mxxxxxxx.dll"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)@MZINSTALLBINDIR@/Racket@MMM_INSTALLED@@EXE_SUFFIX@"
	cd ..; $(STRIP_DEBUG) "$(DESTDIR)$(libdir)/MzCOM@MMM_INSTALLED@@EXE_SUFFIX@"
	@RUN_RACKET_MMM@ -cu "$(srcdir)/collects-path.rkt" @DIRCVTPRE@"$(DESTDIR)@MZINSTALLBINDIR@/Racket@MMM_INSTALLED@@EXE_SUFFIX@"@DIRCVTPOST@ $(DESTDIR)@COLLECTS_PATH@ $(DESTDIR)@CONFIG_PATH@

mingw-install-3m-final:
	$(NOOP)

# OS X install ----------------------------------------

MZFWDIR = @FRAMEWORK_INSTALL_DIR@/Racket.framework
MZFWMMM = Racket.framework/Versions/$(FWVERSION)_3m/Racket
FRAMEWORK_REL_PREFIX = "@executable_path/../$(libpltdir_rel)/"
FRAMEWORK_ABS_PREFIX = "$(libpltdir)/"

osx-install:
	$(MAKE) unix-install
	rm -f $(DESTDIR)$(MZFWDIR)/Racket
	rm -rf $(DESTDIR)$(MZFWDIR)/Versions/$(FWVERSION)
	rm -rf $(DESTDIR)$(MZFWDIR)/Versions/$(FWVERSION)_3m
	if [ @FRAMEWORK_REL_INSTALL@ = yes ] ; then rm -rf $(DESTDIR)$(MZFWDIR) ; fi
	mkdir -p $(DESTDIR)@FRAMEWORK_INSTALL_DIR@

osx-install-cgc:
	$(MAKE) unix-install-cgc
	mkdir -p $(DESTDIR)$(MZFWDIR)/Versions/$(FWVERSION)
	cp $(MZFW) $(DESTDIR)$(MZFWDIR)/Versions/$(FWVERSION)/
	/usr/bin/install_name_tool -change "@executable_path/Racket.framework/Versions/$(FWVERSION)/Racket" "@FRAMEWORK_PREFIX@Racket.framework/Versions/$(FWVERSION)/Racket" $(DESTDIR)"$(bindir)/racket@CGC_INSTALLED@"
	$(STRIP_DEBUG) $(DESTDIR)"$(bindir)/racket@CGC_INSTALLED@"

osx-install-cgc-final:
	$(MAKE) unix-install-cgc-final
	ln -s Versions/$(FWVERSION)/Racket $(DESTDIR)$(MZFWDIR)/

osx-install-3m:
	$(MAKE) unix-install-3m
	mkdir -p $(DESTDIR)"$(MZFWDIR)/Versions/$(FWVERSION)_3m"
	cp $(MZFWMMM) $(DESTDIR)$(MZFWDIR)/Versions/$(FWVERSION)_3m/
	/usr/bin/install_name_tool -change "@executable_path/Racket.framework/Versions/$(FWVERSION)_3m/Racket" "@FRAMEWORK_PREFIX@Racket.framework/Versions/$(FWVERSION)_3m/Racket" $(DESTDIR)"$(bindir)/racket@MMM_INSTALLED@"
	$(STRIP_DEBUG) $(DESTDIR)"$(bindir)/racket@MMM_INSTALLED@"

osx-install-3m-final:
	$(MAKE) unix-install-3m-final
	ln -s Versions/$(FWVERSION)_3m/Racket $(DESTDIR)$(MZFWDIR)/


# Cygwin install ----------------------------------------

unix-cygwin-install:
	$(MAKE) unix-install
	cd dynsrc; $(MAKE) cygwin-install-core

unix-cygwin-install-cgc:
	$(MAKE) unix-install-cgc
	cd dynsrc; $(MAKE) cygwin-install-cgc

unix-cygwin-install-cgc-final:
	$(MAKE) unix-install-cgc-final

unix-cygwin-install-3m:
	$(MAKE) unix-install-3m
	cd dynsrc; $(MAKE) cygwin-install-3m

unix-cygwin-install-3m-final:
	$(MAKE) unix-install-3m-final

# Generate plt-gdbinit ----------------------------------------

mz-gdbinit: $(srcdir)/mk-gdbinit.rkt $(srcdir)/src/stypes.h
	$(RACKET) $(srcdir)/mk-gdbinit.rkt
