### Instructions: type "make" and hope for the best.
###
### If that doesn't work, DON'T PANIC!  Read the file "BUILD" instead.
###
### Top-level targets are:
###
###	target		- determine the target and create the build dir if needed
###	config		- as above, then configure the target if needed
###	squeak		- make config if needed, then build the Squeak virtual machine
###	plugins		- make config if needed, then build the plugin modules
###	all		- make config if needed, then build squeak and plugins
###	Foo.so		- make config if needed, then build the plugin "Foo"
###	reconfig	- force a reconfiguration (e.g. after adding a new plugin)
###
### The default target is "all".
###
### Note: this Makefile should work everywhere (it does not require GNU make).

SRCDIR=		src
UTILDIR=	util
CONFDIR=	conf

MAKEFILE_IN=	$(SRCDIR)/Makefile.in
CONFIG_H_IN=	$(SRCDIR)/sqUnixConfig.h.in

CONFIGURE=	$(CONFDIR)/configure
CONFIG_IN=	$(CONFDIR)/configure.in
CONFGUESS=	$(CONFDIR)/config.guess

CONFARGS=

MAKEFLAGS=	--no-print-directory

default:	all
		@true

# targets that end in "@" are internal: they depend on TARGET being set

# external targets: set TARGET and make the corresponding internal target

.DEFAULT:
		@$(MAKE) TARGET=`$(CONFGUESS)` $@@

# internal targets

TARGETMF=	$(TARGET)/Makefile

%.so@:		config@
		@$(MAKE) -C $(TARGET) $(@:@=)

%@:
		@echo "don't know how to make $(@:@=)"
		@exit

all@:		squeak@ plugins@
		@true

squeak@:	config@
		@$(MAKE) -C $(TARGET)

plugins@:	config@
		@$(MAKE) -C $(TARGET) plugins

config@:	target@ $(TARGETMF)
		@echo $(TARGET) is configured

target@:	$(TARGET)
		@echo target is $(TARGET)

reconfig@:
		@/bin/rm -f $(TARGET)/Makefile $(TARGET)/config.cache
		@$(MAKE) config@

test@:		all
		/bin/rm *.so
		ln -s $(TARGET)/*.so .
		$(TARGET)/squeak

$(TARGET):
		mkdir -p $(TARGET)

$(TARGETMF):	$(CONFIGURE) $(MAKEFILE_IN) $(CONFIG_H_IN)
		$(SHELL) -ec 'cd $(TARGET); ../$(SRCDIR)/configure $(CONFARGS)'

$(CONFIGURE):	$(CONFIG_IN)
		$(MAKE) -C $(CONFDIR)


release@:	$(TARGETMF)
		/bin/rm -f $(CONFDIR)/*~
		/bin/rm -f $(SRCDIR)/*~
		/bin/rm -f $(UTILDIR)/*~
		$(MAKE) -C $(TARGET) release

clean@:
		/bin/rm -rf $(TARGET)

distclean@:	clean@
		/bin/rm -f $(CONFDIR)/*~
		/bin/rm -f $(SRCDIR)/*~
		/bin/rm -f $(UTILDIR)/*~
