#*******************************************************************************
#*                              uBee512 Makefile                               *
#*        An emulator for the Microbee Z80 ROM, FDD and HDD based models       *
#*                                                                             *
#*                    Copyright (C) 2007-2009 Stewart Kay                      *
#*******************************************************************************
#
#===============================================================================
# REVISION HISTORY (Most recent at top)
#===============================================================================
# v4.3.0 - S.J.Kay 7/8/2009
# -------------------------
# - Added AUTHORS file.
#
# v4.2.0 - S.J.Kay 15/7/2009
# -------------------------
# - Added hdd.o and mouse.o modules.
#
# v4.1.0 - S.J.Kay 7/7/2009
# -------------------------
# - Added roms.o, log.o and ide.o, removed paknet.o modules.
# - Added make-cf-roms.sh script.
# - Added work arounds for some make's 'else ifeq' problems.
#
# v4.0.0 - S.J.Kay 9/6/2009
# -------------------------
# - Improvements made by removing repeated code and making builds more
#   consistent from one to another.
# - Changes made to allow other Z80 CPU emulators to be used. z80ex is now
#   used for Z80 emulation.
#
# v3.1.0 - S.J.Kay 9/3/2009
# -------------------------
# - Host builds now use 'uname' to establish the host OS.  Linux, FreeBSD
#   and Mac OSX (experimental) builds are currently supported.  Only 'make'
#   or 'gmake' is required now. 'make install' and 'make uninstall' are now
#   the standard install/unistall targets. Host target files are now placed
#   in the new 'build' directory.
# - Use 'sdl-config --libs' and 'sdl-config --cflags' where possible.
# - Added basic dependency checking for headers and Makefiles.
# - Changes to allow either the ASM or 'C' build to be compiled. The 'C'
#   build using mz80 v3.4 has problems and is NOT used for production
#   builds.
# - Added compile time options that can be passed as parameters to make.
# - Shifted creation of all distribution packages out of this Makefile into
#   a top level directory Makefile (not part of the distribution).
# - Removed the Xaw3D libraries, mbox.c, fallback.c, info.xbm and excl.xbm
#   as Unix (and Windows) now uses an OSD for dialogues.
# - Added osd.o, md5.o and console.o modules.
# - Added a local customised getopt.o module.
# - Changed the debdist target to unixdist and changed the call target name.
# - Added upload target.
# - Removed mkinstalldirs and replaced with 'mkdir -p'
# - make cleanall now also removes all build directories.
#
# v3.0.0 - S.J.Kay 30/9/2008
# --------------------------
# - Added OpenGL libraries to all builds and Mesa licensing information.
# - Added video.o module.
# - Added $DESTDIR variable: PREFIX=$(DESTDIR)/usr/local
# - Added Debian ditribution creation entry.
# - Linux build now links 'LibDsk' statically. This makes creating a package
#   easier for Debian as I am unaware of any standard LibDsk Debian packages.
# - Changes made to install targets.
#
# v2.8.0 - S.J.Kay 1/9/2008
# -------------------------
# - Removed -Duse_audio from all builds, audio support is always compiled in.
# - Added INSTALL file to distribution packages.
# - Added CP/M tools documentation files to the source distribution.
# - Clean no longer removes makez80, this is rarely a requirement. A new
#   cleanall entry has been added that acts like the previous clean command.
# - Removed include paths where not necessesary. <SDL/SDL.h> now used in
#   source files.
# - Changes to icon creation method.
#
# v2.7.1 - S.J.Kay 16/7/2008
# --------------------------
# - Fixed icon creation problem when attempting to build from source.  Icon
#   creation is now handled by a seperate build rule.
# - Added ubee512-logo.png and ubee512-logo.ico files where these were missing
#   in the distributions.
#
# v2.7.0 - S.J.Kay 9/7/2008
# --------------------------
# - Changes to icon and creation methods.
# - Added games.ini.sample configuration file.
# - Added UBSCRIPT.PAS and VSCREST.AZM source files.
# - Added roms.alias.sample and disks.alias.sample files.
# - Added files directory.
# - Added configs directory for win32.
# - Change libdskrc to libdskrc.sample
#
# v2.6.0 - S.J.Kay 5/5/2008
# --------------------------
# - Added joystick.o module.
#
# v2.5.0 - S.J.Kay 29/2/2008
# --------------------------
# - Added options.o module.
# - Added ubee512rc.sample configuration file.
# - Changed libdsk directories to now be config directories.
# - Added -ldsk to FreeBSD build.
#
# v2.4.0 - S.J.Kay 29/1/2008
# --------------------------
# - Added libdsk library (-ldsk) and -DUSE_LIBDSK
# - Added libdskrc file to distribution
#
# v2.3.0 - S.J.Kay 5/1/2008
# ---------------------------
# - Added z80debug.c and scc.c module.
# - Removed -DINFOFILE=$(INFOFILE) from Linux build
#
# v2.2.0 - S.J.Kay 13/12/2007
# ---------------------------
# - Added emulator CP/M tools.
# - Added documention: microbee_disk_to_image.txt
# - Changed APPIDSTR to =\"$(APP)\"
# - Install target added for FreeBSD.
#
# v2.1.0 - S.J.Kay 19/10/2007
# ---------------------------
# - Added clock.o module.
#
# v2.0.0 - S.J.Kay 17/10/2007
# ---------------------------
# - Added changes for Unices builds for a message box.
# - Added keystd.o, keytc.o, rtc.o, mbox.o and fallback.o modules.
# - Added rtc directory.
#
# v1.4.0 - S.J.Kay 25/9/2007
# -------------------------
# - Added a Windows InnoSetup installer "winexedist".  ZIP distribution file is
#   now built with "winzipdist",  to build both added "winalldist", to build
#   all distribution files added "alldist"
# - Added .ico file creation and insertion into win32 exe file and creation of
#   .bmp graphic for SDL from .png
# - Added strip command for all builds resulting in much smaller executables.
# - Added -mwindows to windows build to make a "windows" application.  This
#   stops the cmd prompt in the background appearing.
# - Added -O2 code optimization to all builds.
# - Changes to distribution destinations and contents.
# - Change TITLESTRING to be shorter and more generic.
#
# v1.3.0 - S.J.Kay 31/8/2007
# --------------------------
# - Added async, serial, and printer C modules.
# - Added printer sub directory to Windows ZIP file.
#
# v1.2.0 - S.J.Kay 22/8/2007
# --------------------------
# - Added tapes sub directory to Windows ZIP file
# - Added tape and function C modules.
# - Fixed -DAPPVER=$(APPVER) for Windows, and FreeBSD.  Caused the --version
#   option to crash program.
#
# v1.1.0 - S.J.Kay 17/8/2007
# --------------------------
# Added and changed some variable names,  added -DAPPVER, modified FreeBSD
# build section for v6.2.
#
# v1.0.0 - S.J.Kay 28/6/2007
# --------------------------
# Created initial multi-platform make file to produce Linux, Win32 and FreeBSD
# targets.  The Win32 target is cross compiled on a Linux host.  The FreeBSD
# target currently requires building on a FreeBSD machine. 
#
#===============================================================================
# How to use this GNU make file.
#===============================================================================
# make help or gmake help on a FreeBSD machine will show the options available.
#
#===============================================================================
# Requirements
#===============================================================================
# Requirements for all targets:
# - z80ex library
# - Application sources !
#
# Requirements for native target:
# - GCC tool chain
# - The SDL development package
#
# Requirements for cross compile target (win32):
# - For the Win32 build the i386-mingw32 cross compile tool chain is required.
# - The SDL development package for mingw32 must be installed using the cross
#   compile option.
# - z80ex library (cross compiled)

#===============================================================================
# Notes
#===============================================================================
# Default OPT_* values are specified for each build and may also be
# specified on the command line.
#
# A 'make clean' MUST be run first if any options have been changed between
# builds.
#
# Determines if libdsk is built in and if static or a shared library is linked.
# 0=not used, 1=use static, 2=use shared
#OPT_LIBDSK?=1
#
# Determine if OpenGL is to be built in.
# 0=not used, 1=use shared
#OPT_OPENGL?=1
#
# Determines which Z80 emulator is to be used.
# 1=z80ex, 2=other
#OPT_Z80EMU?=1
#
# Determines if a static or shared library use of the Z80 emulator on. Win32
# builds are always static.
#OPT_Z80_STATIC=1

#===============================================================================
# Overrides
#===============================================================================
.SUFFIXES:

TOPDIR=..

#===============================================================================
# Application specific definitions
#===============================================================================
APP=ubee512
# Append 'dev' if this is a development version, don't use any '-' or '_'
# characters as the debian packaging scripts won't work correctly.
VERSION=4.4.0
TITLE=uBee512

# Set the debugging level
OPT_DEBUG?=0

# Set other system until a known one is detected
OTHER_SYSTEM=1

# Values passed as defines when compiling
APPVER=\"$(VERSION)\"
APPIDSTR=\"$(APP)\"
TITLESTRING=\"$(TITLE)\ v$(VERSION)\ -\ Microbee\ emulator\"
ICONSTRING=\"$(TITLE)\"

# Various compile options
#Z80EX_OPTIONS=-DZ80EX_NO_VERSION_CODE

# Object modules
OBJC=./$(APP).o ./crtc.o ./fdc.o ./gui.o ./keystd.o ./keytc.o
OBJC+=./keyb.o ./memmap.o ./vdu.o ./z80.o ./disk.o ./pio.o
OBJC+=./sound.o ./roms.o ./tape.o ./function.o ./async.o
OBJC+=./serial.o ./printer.o ./rtc.o ./clock.o ./scc.o
OBJC+=./z80debug.o ./options.o ./joystick.o ./console.o
OBJC+=./video.o ./getopt.o ./osd.o ./md5.o ./log.o ./ide.o
OBJC+=./hdd.o ./mouse.o

DEL_XOBJC=$(OBJC:./%=build/%) ./build/z80ex_api.o
DEL_WOBJC=$(OBJC:./%=win32/%) ./win32/z80ex_api.o

#===============================================================================
# Platform specific definitions
#===============================================================================
# Get the host OS name
SYSTEM?=$(shell uname -s)

# Mingw cross-compiling prefix
MINGW_PREFIX=i386-mingw32

# Icon for windows use
WICON=win32/$(APP)-logo.o

ifneq ($(TOS),win)
#===============================================================================
# Host target.  Linux, FreeBSD and MAC OSX Darwin builds are supported.
# Other systems will require a conditional section to be added or the 'other
# native systems' definitions will be used.
#
# This is the default build when 'make' is used by itself.
#===============================================================================

#================================ Linux build ==================================
ifeq ($(SYSTEM),Linux)
   OPT_LIBDSK?=1
   OPT_OPENGL?=1
   OPT_Z80EMU?=1
   OPT_Z80_STATIC?=1

   OTHER_SYSTEM=0
   
   SDL_LIBS=$(shell sdl-config --libs)
   SDL_CFLAGS=$(shell sdl-config --cflags)

   ifeq ($(OPT_LIBDSK),1)
      LIBS+=/usr/lib/libdsk.a /usr/lib/libbz2.a /usr/lib/libz.a
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_LIBDSK),2)
      LIBS+=-ldsk
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_OPENGL),1)
      LIBS+=-lGL
      CINC+=-I/usr/include/GL -I/usr/local/include/GL
      COMOPTS+=-DUSE_OPENGL
   endif

   ifeq ($(OPT_Z80EMU),1)
      COMOPTS+=-DUSE_Z80EX $(Z80EX_OPTIONS)
      z80_targets=
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      XOBJC=$(OBJC:./%=build/%) ./build/z80ex_api.o
      ifeq ($(OPT_Z80_STATIC),1)
         LIBS+=/usr/local/lib/libz80ex.a
      else    
         LIBS+=-lz80ex
      endif   
   else
      COMOPTS+=-DUSE_OTHER
      z80_targets=
      OBJC+=./other.o
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      XOBJC=$(OBJC:./%=build/%) ./build/other_api.o
   endif
endif

#============================== FreeBSD build ==================================
ifeq ($(SYSTEM),FreeBSD)
   OPT_LIBDSK?=1
   OPT_OPENGL?=1
   OPT_Z80EMU?=1
   OPT_Z80_STATIC?=1
   
   OTHER_SYSTEM=0

   SDL_LIBS=$(shell sdl-config --libs)
   SDL_CFLAGS=$(shell sdl-config --cflags)

   ifeq ($(OPT_LIBDSK),1)
      LIBS+=/usr/lib/libdsk.a /usr/lib/libbz2.a /usr/lib/libz.a
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_LIBDSK),2)
      LIBS+=-ldsk
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_OPENGL),1)
      LIBS+=-lGL
      CINC+=-I/usr/include/GL -I/usr/local/include/GL
      COMOPTS+=-DUSE_OPENGL
   endif

   ifeq ($(OPT_Z80EMU),1)
      COMOPTS+=-DUSE_Z80EX $(Z80EX_OPTIONS)
      z80_targets=
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      XOBJC=$(OBJC:./%=build/%) ./build/z80ex_api.o
      ifeq ($(OPT_Z80_STATIC),1)
         LIBS+=/usr/local/lib/libz80ex.a
      else    
         LIBS+=-lz80ex
      endif   
   else
      COMOPTS+=-DUSE_OTHER
      z80_targets=
      OBJC+=./other.o
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      XOBJC=$(OBJC:./%=build/%) ./build/other_api.o
   endif
endif

#========================== Darwin build i386 OSX ==============================
ifeq ($(SYSTEM),Darwin)
   OPT_LIBDSK?=0
   OPT_OPENGL?=1
   OPT_Z80EMU?=1
   OPT_Z80_STATIC?=1
   
   OTHER_SYSTEM=0
   
   SDL_LIBS=$(shell sdl-config --libs)
   SDL_CFLAGS=$(shell sdl-config --cflags)

   ifeq ($(OPT_LIBDSK),1)
      LIBS+=/usr/lib/libdsk.a /usr/lib/libbz2.a /usr/lib/libz.a
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_LIBDSK),2)
      LIBS+=-ldsk
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_OPENGL),1)
      LIBS+=-L/System/Library/Frameworks/OpenGL.framework/Versions/A/Libraries
      LIBS+=-lGL
      CINC+=-I/System/Library/Frameworks/OpenGL.framework/Versions/A/Headers
      COMOPTS+=-DUSE_OPENGL
   endif

   ifeq ($(OPT_Z80EMU),1)
      COMOPTS+=-DUSE_Z80EX $(Z80EX_OPTIONS)
      z80_targets=
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      XOBJC=$(OBJC:./%=build/%) ./build/z80ex_api.o
      ifeq ($(OPT_Z80_STATIC),1)
         LIBS+=/usr/local/lib/libz80ex.a
      else    
         LIBS+=-lz80ex
      endif   
   else
      COMOPTS+=-DUSE_OTHER
      z80_targets=
      OBJC+=./other.o
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      XOBJC=$(OBJC:./%=build/%) ./build/other_api.o
   endif
   
   COMOPTS+=-DDARWIN
endif

#=========================== other native systems ==============================
ifeq ($(OTHER_SYSTEM),1)
   OPT_LIBDSK?=1
   OPT_OPENGL?=1
   OPT_Z80EMU?=1
   OPT_Z80_STATIC?=1

   SDL_LIBS=$(shell sdl-config --libs)
   SDL_CFLAGS=$(shell sdl-config --cflags)

   ifeq ($(OPT_LIBDSK),1)
      LIBS+=/usr/lib/libdsk.a /usr/lib/libbz2.a /usr/lib/libz.a
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_LIBDSK),2)
      LIBS+=-ldsk
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_OPENGL),1)
      LIBS+=-lGL
      CINC+=-I/usr/include/GL -I/usr/local/include/GL
      COMOPTS+=-DUSE_OPENGL
   endif

   ifeq ($(OPT_Z80EMU),1)
      COMOPTS+=-DUSE_Z80EX $(Z80EX_OPTIONS)
      z80_targets=
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      XOBJC=$(OBJC:./%=build/%) ./build/z80ex_api.o
      ifeq ($(OPT_Z80_STATIC),1)
         LIBS+=/usr/local/lib/libz80ex.a
      else    
         LIBS+=-lz80ex
      endif   
   else
      COMOPTS+=-DUSE_OTHER
      z80_targets=
      OBJC+=./other.o
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      XOBJC=$(OBJC:./%=build/%) ./build/other_api.o
   endif
endif   

#=========================== Unix host target build ============================
   ifeq ($(OPT_DEBUG),1)
      STRIP=
      DEBUG=-g
      OPT=
   else
      STRIP=strip build/$(APP)
      DEBUG=-g
      OPT=-O2
   endif

   CC = gcc
   CFLAGS=$(DEBUG) $(OPT) $(SDL_CFLAGS) -Wall
   CLIB=-L/usr/local/lib $(LIBS) $(SDL_LIBS)
   CINC+=-I/usr/local/include
   CDEF+=-DAPPVER=$(APPVER) -DTITLESTRING=$(TITLESTRING) -DICONSTRING=$(ICONSTRING)
   CDEF+=-DAPPIDSTR=$(APPIDSTR) $(COMOPTS)

build: build/$(APP)

build/$(APP): $(z80_targets) $(XOBJC)
	$(CC) $(XOBJC) $(CLIB) -o build/$(APP)
	$(STRIP)

build/%.o: %.c $(DEPENDENCIES)
	@[ -d build ] || mkdir build
	$(CC) -c $(CFLAGS) $(CINC) $(CDEF) $(*).c -o build/$(*).o

endif  # ifneq $(TOS),win)

#===============================================================================
# Windows target
#===============================================================================
ifeq ($(TOS),win)
   OPT_LIBDSK?=1
   OPT_OPENGL?=1
   OPT_Z80EMU?=1

   ifeq ($(OPT_LIBDSK),1)
      LIBS+=-ldsk
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_LIBDSK),2)
      LIBS+=-ldsk
      COMOPTS+=-DUSE_LIBDSK
   endif

   ifeq ($(OPT_OPENGL),1)
      LIBS+=-lopengl32
      CINC+=-I/usr/local/cross-tools/i386-mingw32/include/GL
      COMOPTS+=-DUSE_OPENGL
   endif

   ifeq ($(OPT_Z80EMU),1)
      COMOPTS+=-DUSE_Z80EX $(Z80EX_OPTIONS)
      z80_targets=
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      WOBJC=$(OBJC:./%=win32/%) ./win32/z80ex_api.o
      LIBS+=/usr/local/cross-tools/i386-mingw32/lib/libz80ex.a
   else
      COMOPTS+=-DUSE_OTHER
      z80_targets=
      OBJC+=./other.o
      DEPENDENCIES=$(OBJC:.o=.h) ./z80api.h Makefile
      WOBJC=$(OBJC:./%=build/%) ./build/other_api.o
   endif

   ifeq ($(OPT_DEBUG),1)
      STRIP=
      DEBUG=-g
      OPT=
   else
      STRIP=$(MINGW_PREFIX)-strip win32/$(APP).exe
      DEBUG=-g
      OPT=-O2
   endif

   COMOPTS+=-DMINGW

   CC=$(MINGW_PREFIX)-gcc
   CFLAGS=$(DEBUG) $(OPT) -Wall
   WINDRES=$(MINGW_PREFIX)-windres
   CLIB=$(LIBS) -lmingw32 -lSDLmain -lSDL -mwindows
   CINC+=-I/usr/local/cross-tools/i386-mingw32/include
   CINC+=-I/usr/local/cross-tools/i386-mingw32/include/SDL
   CDEF=-D_GNU_SOURCE=1 -D_REENTRANT -DNOTWINDLL
   CDEF+=-DAPPVER=$(APPVER) -DTITLESTRING=$(TITLESTRING) -DICONSTRING=$(ICONSTRING)
   CDEF+=-DAPPIDSTR=$(APPIDSTR) $(COMOPTS)

winx: win32/$(APP).exe

win32/$(APP).exe: $(z80_targets) winicons $(WOBJC)
	$(CC) $(WOBJC) $(WICON) $(CLIB) -o win32/$(APP).exe
	$(STRIP)

win32/%.o: %.c $(DEPENDENCIES)
	@[ -d win32 ] || mkdir win32
	$(CC) -c $(CFLAGS) $(CINC) $(CDEF) $(*).c -o win32/$(*).o

winicons:
	cd $(TOPDIR)/images && $(WINDRES) $(APP)-logo.rc $(APP)-logo.o
	@[ -d win32 ] || mkdir win32
	mv $(TOPDIR)/images/$(APP)-logo.o $(WICON)

endif #ifeq ($(TOS),win)

#===============================================================================
# Build the host system and Windows targets
#===============================================================================
win:
	make winx TOS=win

all:
	make
	make winx TOS=win

#===============================================================================
# General maintenance
#===============================================================================
clean:
	rm -f $(DEL_XOBJC) build/$(APP) \
	      $(DEL_WOBJC) win32/$(APP).exe \
              $(TOPDIR)/distributions/$(APP)-$(VERSION).tar.gz \
              $(TOPDIR)/distributions/$(APP)-$(VERSION)-win32.zip \
              $(TOPDIR)/distributions/$(APP)-$(VERSION)-win32.exe \
              $(TOPDIR)/distributions/$(APP)_$(VERSION)_i386.deb \
              $(TOPDIR)/distributions/$(APP)-$(VERSION)-2.i386.rpm \
              $(TOPDIR)/distributions/$(APP)-$(VERSION).tgz \
              $(TOPDIR)/distributions/$(APP)-$(VERSION)-portable.zip \
              $(WICON)
	rm -Rf win32/$(APP)

cleanall: clean
	rm -Rf win32/ build/

#===============================================================================
# Install and remove installed binaries, and shared application directory
#
# The install process must only copy the files actually required or the
# Debian build will contain unwanted files from the original source
# directories.
#===============================================================================
PREFIX=$(DESTDIR)/usr/local
BINDIR=$(PREFIX)/bin
APPDIR=$(PREFIX)/share/$(APP)
DOCDIR=$(APPDIR)/doc
DISKDIR=$(APPDIR)/disks
TOOLSDIR=$(APPDIR)/tools
IMAGEDIR=$(APPDIR)/images
CONFIGDIR=$(APPDIR)/config

makedirs:
	mkdir -p $(BINDIR)
	mkdir -p $(DOCDIR)/GPL
	mkdir -p $(DOCDIR)/LGPL
	mkdir -p $(DOCDIR)/MIT
	mkdir -p $(IMAGEDIR)
	mkdir -p $(DISKDIR)
	mkdir -p $(TOOLSDIR)/cpm/src/	
	mkdir -p $(CONFIGDIR)	

install: makedirs
	install -m 755 build/$(APP) $(BINDIR)
	cp $(TOPDIR)/images/$(APP)-logo.bmp $(IMAGEDIR)/
	cp $(TOPDIR)/images/$(APP)-logo.png $(IMAGEDIR)/
	cp $(TOPDIR)/images/$(APP)-logo.ico $(IMAGEDIR)/

	cp $(TOPDIR)/doc/GPL/COPYING $(DOCDIR)/GPL
	cp $(TOPDIR)/doc/LGPL/lgpl-3.0.txt $(DOCDIR)/LGPL
	cp $(TOPDIR)/doc/MIT/mesa-license.txt $(DOCDIR)/MIT
	cp $(TOPDIR)/doc/ChangeLog $(DOCDIR)/
	cp $(TOPDIR)/doc/INSTALL $(DOCDIR)/
	cp $(TOPDIR)/doc/README $(DOCDIR)/
	cp $(TOPDIR)/doc/AUTHORS $(DOCDIR)/
	cp $(TOPDIR)/doc/quickstart.txt $(DOCDIR)/
	cp $(TOPDIR)/doc/license.txt $(DOCDIR)/

	cp $(TOPDIR)/tools/cpm/src/fixturbo.pas $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/cpm2host.pas $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/c2h.sub $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/host2cpm.pas $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/h2c.sub $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/hostdir.pas $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/hd.sub $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/startver.inc $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/ubeefunc.inc $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/parmfunc.inc $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/reset.azm $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/reset.sub $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/exitemu.azm $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/exitemu.sub $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/ubscript.pas $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/src/vscrest.azm $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/doc/tools.txt $(TOOLSDIR)/cpm/src/
	cp $(TOPDIR)/tools/cpm/doc/chngelog.txt $(TOOLSDIR)/cpm/src/
	
	cp $(TOPDIR)/disks/ubee512_cpm_tools.????_ $(DISKDIR)/

	cp $(TOPDIR)/config/libdskrc.sample $(CONFIGDIR)/
	cp $(TOPDIR)/config/$(APP)rc.sample $(CONFIGDIR)/
	cp $(TOPDIR)/config/games.ini.sample $(CONFIGDIR)/	
	cp $(TOPDIR)/config/roms.alias.sample $(CONFIGDIR)/
	cp $(TOPDIR)/config/disks.alias.sample $(CONFIGDIR)/
	cp $(TOPDIR)/config/roms.md5 $(CONFIGDIR)/
	cp $(TOPDIR)/config/make-cf-roms.sh $(CONFIGDIR)/

uninstall:
	rm $(BINDIR)/$(APP)
	rm -Rf $(APPDIR)

#===============================================================================
# Help
#===============================================================================
help:
	@echo "This is the $(APP) v$(VERSION) Microbee emulator GNU makefile"
	@echo ""
	@echo "Host system (uname -s): $(SYSTEM)"
	@echo ""
	@echo "Specify one of the following:"
	@echo "make                  native host build"
	@echo "gmake                 native FreeBSD build"
	@echo "make win              cross compiled Windows build"
	@echo "make all              make native host and Windows builds"
	@echo "make clean            removes build/win32 and distribution files"
	@echo "make cleanall         cleans and removes all generated files"
	@echo "make install          install files on the host system"
	@echo "make uninstall        uninstall files on the host system"
	@echo "make help             this help information"
	@echo ""
	@echo "Packaging system only:"	
	@echo "make srcdist          make source distribution"
	@echo "make alldist          make all Unix and win32 binary distributions"
	@echo "make winzipdist       make win32 ZIP binary distribution"
	@echo "make winexedist       make win32 executable installer distribution"
	@echo "make winalldist       make win32 EXE and ZIP binary distributions"
	@echo "make unixdist         make Unix binary distributions"
	@echo "make upload           upload distribution packages"

#===============================================================================
# Create source distribution.
#===============================================================================
srcdist:
	cd $(TOPDIR) && make srcdist V=$(VERSION)
	
#===============================================================================
# Create all distributions.
#===============================================================================
alldist:
	cd $(TOPDIR) && make alldist V=$(VERSION)

#===============================================================================
# Create a win32 binary ZIP file distribution.
#===============================================================================
winzipdist:
	cd $(TOPDIR) && make winzipdist V=$(VERSION)

#===============================================================================
# Create a win32 binary installer distribution.
#===============================================================================
winexedist: 
	cd $(TOPDIR) && make winexedist V=$(VERSION)

#===============================================================================
# Create the ZIP and win32 binary installer distributions.
#===============================================================================
winalldist:
	cd $(TOPDIR) && make winalldist V=$(VERSION)

#===============================================================================
# Create Unix binary distributions.
#===============================================================================
unixdist:
	cd $(TOPDIR) && make make_unix_packages V=$(VERSION)

#===============================================================================
# Upload all the distribution files.
#===============================================================================
upload:
	cd $(TOPDIR) && make upload_to_sf V=$(VERSION)
