# Overall control of Slate builds across platforms. Simply define new targets
# with $(PLATFORM)-(action).

# PLATFORM should be 'unix' for now on most Unix-like platforms.
# Use 'unix' as well if you wish to compile with Cygwin (Unix emulation) over Windows.
# Use 'mingw' if you wish to compile natively for Windows using MinGW.
# Otherwise, VC on Windows is only supported through a .vcproj file.
PLATFORM=unix
#PLATFORM=mingw
#PLATFORM=beos

VM=vm
PLATFORM_DIR=src/mobius/vm/platform
BOOTSTRAP_FILES=vm.c vm.h big.image little.image AutoLoad

UNIXMAKE=$(MAKE) -C $(PLATFORM_DIR)/unix/
WINDOWSMAKE=$(MAKE) -C $(PLATFORM_DIR)/windows/
BEOSMAKE=$(MAKE) -C $(PLATFORM_DIR)/beos/

PLUGINS_DIR=src/plugins
NCURSES_PLUGIN=$(PLUGINS_DIR)/smart-console/ncurses

default: build
all: build plugins

#Generic platform independant targets
clean: $(PLATFORM)-clean
build: $(BOOTSTRAP_FILES) $(PLATFORM)-build
plugins: $(PLATFORM)-plugins
install: $(PLATFORM)-install
uninstall: $(PLATFORM)-uninstall

install: $(PLATFORM)-install

#Unix(-like) targets:
unix-clean:
	$(UNIXMAKE) clean
	$(MAKE) -C $(NCURSES_PLUGIN) clean
	$(MAKE) -C $(PLUGINS_DIR)/socket clean

unix-build:
	$(UNIXMAKE)

unix-install:
	$(UNIXMAKE) install

unix-plugins:
	$(MAKE) -C $(NCURSES_PLUGIN)
	$(MAKE) -C $(PLUGINS_DIR)/socket

# Windows targets:
mingw-clean:
	$(WINDOWSMAKE) clean

mingw-build:
	$(WINDOWSMAKE)

mingw-install:
	$(WINDOWSMAKE) install

mingw-plugins:

#BeOS (mix of POSIX-ish and Be API's):
beos-clean:
	$(BEOSMAKE) clean
	$(MAKE) -C $(NCURSES_PLUGIN) clean

beos-build:
	$(BEOSMAKE)

beos-install:
	$(BEOSMAKE) install

beos-plugins:
	$(MAKE) -C $(NCURSES_PLUGIN)

#Obtain the latest Slate alpha bootstrapped release
#NOTE: This overwrites existing files with the same names:
ALPHA_URL=http://slate.tunes.org/repos/alpha
GET=wget -N

$(BOOTSTRAP_FILES) :
	-$(GET) $(ALPHA_URL)/$@

full-clean: clean
	rm -f $(BOOTSTRAP_FILES)

update-source: full-clean $(BOOTSTRAP_FILES)

update-vm: full-clean build
