# Makefile.in for Unix Squeak using VMMaker		-*- makefile -*-
# 
#   Copyright (C) 1996-2005 by Ian Piumarta and other authors/contributors
#                              listed elsewhere in this file.
#   All rights reserved.
#   
#   This file is part of Unix Squeak.
# 
#   Permission is hereby granted, free of charge, to any person obtaining a copy
#   of this software and associated documentation files (the "Software"), to deal
#   in the Software without restriction, including without limitation the rights
#   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
#   copies of the Software, and to permit persons to whom the Software is
#   furnished to do so, subject to the following conditions:
# 
#   The above copyright notice and this permission notice shall be included in
#   all copies or substantial portions of the Software.
# 
#   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
#   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
#   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
#   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
#   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
#   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
#   SOFTWARE.
# 
# Author: ian.piumarta@inria.fr
# 
# Last edited: 2006-10-18 10:13:50 by piumarta on emilia.local

@make_cfg@
@make_prg@

la		= .la

SQLIBS		= [targets]
PLUGINS_LA	= [plugins]

squeak		= squeak

all : $(squeak) plugins squeak.1 $(npsqueak)

# VM

$(squeak) : config.sh $(SQLIBS) version.o
	$(LINK) $(squeak) $(SQLIBS) version.o $(LIBS) [plibs] vm/vm.a
	@echo
	@size $(squeak)
	@echo
	@./$(squeak) -version
	@echo

version.o : version.c
	$(COMPILE) version.o version.c

version.c : $(SQLIBS)
	${cfgdir}/verstamp version.c $(CC)

plugins : config.sh $(PLUGINS_LA)

# npsqueak

npsqueak : nps/npsqueak.so

nps :
	mkdir nps
	$(SHELL) -ec 'cd nps; ln -s $(topdir)/platforms/unix/npsqueak/* .'

nps/npsqueak.so : nps
	$(SHELL) -ec 'cd nps; $(MAKE) plgdir=$(plgdir) bindir=$(bindir) imgdir=$(imgdir)'

# OSX app bundle

osxdir=$(topdir)/platforms/unix/vm-display-Quartz
app=Squeak-$(VM_MAJOR).$(VM_MINOR)-$(VM_RELEASE).app
appdir=$(app)/Contents

Squeak.app : squeak plugins Info.plist
	/bin/rm -rf $(app)
	mkdir -p			$(appdir)/MacOS
	cp -p  squeak			$(appdir)/MacOS/.
	cp -p  */.libs/*		$(appdir)/MacOS/.
	rm -f				$(appdir)/MacOS/*.la
	rm -f				$(appdir)/MacOS/*.lai
	cp -p  Info.plist		$(appdir)/.
	cp -p  $(osxdir)/PkgInfo	$(appdir)/.
	cp -pr $(osxdir)/Resources	$(appdir)/.
	-find $(app) -name '*~' | xargs rm -f

bndl_version=${VM_VERSION} (${SQ_VERSION})

Info.plist : $(osxdir)/Info.plist.in $(osxdir)/mkinfo
	$(osxdir)/mkinfo $(osxdir)/Info.plist.in Info.plist.tmp "${bndl_version}"
	mv Info.plist.tmp Info.plist

# OSX plugin bundle

nposxdir=$(topdir)/platforms/unix/vm-display-Quartz
npapp=NPSqueak.bundle
npappdir=$(npapp)/Contents

NPSqueak.bundle : NPSqueak plugins
	/bin/rm -rf $(npapp)
	mkdir -p			$(npappdir)/MacOS
	cp -p  squeak			$(npappdir)/MacOS/.
	cp -p  */.libs/*.so		$(npappdir)/MacOS/.
	cp -p  Info.plist		$(npappdir)/.
	cp -p  $(nposxdir)/PkgInfo	$(npappdir)/.
	cp -pr $(nposxdir)/Resources	$(npappdir)/.
	-find $(npapp) -name '*~' | xargs rm -f

NPOBJS		= vm-display-Quartz/sqUnixSafari.o vm-sound-MacOSX/sqUnixSoundMacOSX.o vm-display-Quartz/sqUnixQuartz.o
NPLIBS		= $(NPOBJS) -framework CoreAudio -framework AudioToolbox

NPSqueak : config.sh $(SQLIBS) version.o $(NPOBJS)
	gcc -bundle -flat_namespace -undefined suppress -o NPSqueak \
	  $(NPLIBS) $(SQLIBS) version.o $(LIBS)  vm/vm.a

# manual page

squeak.1 : $(topdir)/platforms/unix/doc/squeak.1
	$(cfgdir)/mkman $(VM_MAJOR) $(VM_VERSION) \
	  $(bindir) $(imgdir) $(plgdir) $(mandir) $(docdir) \
	  < $(topdir)/platforms/unix/doc/squeak.1 > $@

# install/distrib (these just get in the way -- suck 'em in from elsewhere)

@Makefile_install@
@Makefile_dist@
@Makefile_rpm@
@Makefile_deb@

# VMM configuration changes

config.sh : $(srcdir)/plugins.int $(srcdir)/plugins.ext $(srcdir)/vm/sqNamedPrims.h
	./config.status
	@echo
	@echo "configuration changed: please run make again"
	@echo
	@exit 1

[make_targets]

.force :
