
#############################################################################
#
# Makefile for TWIN Library
#
# The Willows TWIN Software consists of the Willows TWIN Libraries, and
# the tools necessary to build the Libraries and Applications.
# The components are:
#
# TOOLS		Tools to build the libraries and applications
# PARTS		Subsystems of the library, DOS, multimedia
# DRIVER	The platform dependent graphical interface 
# TWIN		The actual core TWIN library
# LIBS		Support DLL's for TWIN, Keyboard, WinSock, commdlg...
#
# DEMO		Source samples for the TWIN library
#
#############################################################################
#
# These are defaults, and can/will be overwritten by lower level Makefiles
#
#############################################################################

TWINDIR=.
default = all
project = world
localclean = clean-twin
localclobber = clobber-twin

include ./Makefile.config

#####################################################################
#
# Tools necessary to build the library
#
#####################################################################

TOOLS = bin/rc

#####################################################################
#
# Components built separately
#
# Debugger vs. Interpreter	binary emulator code
# xdos				dos emulation library 
# multimedia			mmedia.dll code
# dll				support for .dll's
# memory			support for win32 memory functions
#
#####################################################################

PARTS_ALL  = xdos dll memory 

#####################################################################
#
# Optional components
#
# PARTS_CPU  only used on linux, with direct execution ie. CPUTYPE=CPU
# PARTS_INT  only used on risc, with interpreter ie. CPUTYPE=INT
#
# set in ./makeinclude/Makefile.config
#
######################################################################

PARTS_CPU = 
PARTS_INT = intp32

PARTS =  $(PARTS_$(CPUTYPE)) $(PARTS_ALL) 

#####################################################################
#
# Platform Abstraction Layer
#
# x11 graphics interface 	for support for x11 based systems
#
#####################################################################

DRIVER  = pal/x11

#####################################################################
#
# The twin library itself
#
# libtwin.so			the basic library, built-in user, kernel, gdi
#
#####################################################################

TWIN     = win

# build the library in parallel...
#JOBS     = -j2

#####################################################################
#
# Standard Well-Known Windows DLL's
#
#####################################################################
BIN32_0 = 
BIN32_1 = bin32

PACKAGES  = readline
PACKAGES  = 

DEBUGGER_0  = 
DEBUGGER_1  = readline debugger
DEBUGGER    = $(DEBUGGER_$(TWIN_DEBUGGER))

BASE	  = commdlg shell
COMM      = winsock ddeml ole
SOUND     = sound mmsystem win87em
DLLS      = keyboard lzexpand toolhelp comm version system $(SOUND) $(COMM)
DLLS32    = $(DLLS) commctrl $(BIN32_$(TWIN_BIN32))

LIBS      = $(BASE) $(DLLS$(TWIN_APISIZE)) $(DEBUGGER)

#####################################################################
#
# Sample code using the library
# 
DEMO    = samples

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

#####################################################################
#
#	default target will build rc and the library
#	world wil build rc, library and samples
#

world:	makedepend-twin
	@echo "Build: Willows Library"
	@echo "Build: $(TWIN)"
	@date
	@echo "========== Tools =========="
	@for i in $(TOOLS); do cd $(TWINDIR)/$$i && $(MAKE) TWINDIR=$(TWINDIR); done
	@echo "========== Library ========"
	@for i in $(PARTS); do cd $(TWINDIR)/$$i && $(MAKE)  TWINDIR=$(TWINDIR); done 
	@for i in $(DRIVER); do cd $(TWINDIR)/$$i && $(MAKE) TWINDIR=$(TWINDIR); done 
	@for i in $(TWIN); do cd $(TWINDIR)/$$i && $(MAKE) $(JOBS) TWINDIR=$(TWINDIR); done 
	@for i in $(LIBS); do ( cd $(TWINDIR)/$$i 2>/dev/null && $(MAKE)  TWINDIR=$(TWINDIR) ) || true ; done 
	@for i in win; do cd $(TWINDIR)/$$i && $(MAKE) xwin$(TWIN_APISIZE) TWINDIR=$(TWINDIR); done
	@date
	@echo "Build: Willows Library complete."

###########################################################################
#
# Support targets
#
# target	make sure all dependent directories are built
# clean		how to clean up the mess we made
# clobber	how to really clean up the mess	
# depend 	how to make sure we can build things
# install	how to install the mess we made
#

target: 
	@echo "Building/verifying installation directories"
	@if [ ! -d $(INSTALLDIR) ]; then mkdir $(INSTALLDIR); fi
	@if [ ! -d $(INSTALLDIR)/bin ]; then mkdir $(INSTALLDIR)/bin; fi
	@if [ ! -d $(INSTALLDIR)/lib ]; then mkdir $(INSTALLDIR)/lib; fi 
	@if [ ! -d $(INSTALLDIR)/include ]; then mkdir $(INSTALLDIR)/include; fi 

makedepend-twin: 
	@-for i in $(TOOLS); do [ -d $(TWINDIR)/$$i ] && touch $(TWINDIR)/$$i/Makedepend.$(TARGET) ; done
	@-for i in $(PARTS); do [ -d $(TWINDIR)/$$i ] && touch $(TWINDIR)/$$i/Makedepend.$(TARGET) ; done
	@-for i in $(DRIVER); do [ -d $(TWINDIR)/$$i ] && touch $(TWINDIR)/$$i/Makedepend.$(TARGET) ; done
	@-for i in $(TWIN); do [ -d $(TWINDIR)/$$i ] && touch $(TWINDIR)/$$i/Makedepend.$(TARGET) ; done
	@-for i in $(LIBS); do touch $(TWINDIR)/$$i/Makedepend.$(TARGET) 2>/dev/null || true ; done

#
#
#

clean-twin:	makedepend-twin
	@-for i in $(TOOLS); do cd $(TWINDIR)/$$i && $(MAKE) clean TWINDIR=$(TWINDIR) ; done
	@-for i in $(PARTS); do [ -d $(TWINDIR)/$$i ] && cd $(TWINDIR)/$$i && $(MAKE) clean TWINDIR=$(TWINDIR) ; done
	@-for i in $(DRIVER); do cd $(TWINDIR)/$$i && $(MAKE) clean TWINDIR=$(TWINDIR) ; done
	@-for i in $(TWIN); do cd $(TWINDIR)/$$i && $(MAKE) clean TWINDIR=$(TWINDIR) ; done
	@-for i in $(LIBS); do ( cd $(TWINDIR)/$$i 2>/dev/null && $(MAKE) clean TWINDIR=$(TWINDIR) ) || true ; done
	@-for i in $(DEMO); do ( cd $(TWINDIR)/$$i 2>/dev/null && $(MAKE) clean TWINDIR=$(TWINDIR) ) || true; done
	@-rm -f ./*/lib/*.o
	@-rm -f config.cache config.log config.status 
	@-rm -f Makedepend.$(TARGET)
	@-rm -f $(TWINDIR)/*/Makedepend.$(TARGET)
	@-rm -f $(TWINDIR)/*/Makedepend.$(TARGET).bak
	@-rm -f $(TWINDIR)/*/*/Makedepend.$(TARGET)
	@-rm -f $(TWINDIR)/*/*/Makedepend.$(TARGET).bak

#
#
#

clobber-twin: clean-twin
	@-for i in $(TOOLS); do ( cd $(TWINDIR)/$$i && $(MAKE) TWINDIR=$(TWINDIR) clobber ) ; done
	@-for i in $(LIBS); do ( cd $(TWINDIR)/$$i 2>/dev/null && $(MAKE) TWINDIR=$(TWINDIR) clobber ) || true  ; done
	@-rm -rf core ctags tags err make.log make.err Makefile.config
#
#
#
depend-twin: makedepend-twin
	@-for i in $(TOOLS); do [ -d $(TWINDIR)/$$i ] && cd $(TWINDIR)/$$i && $(MAKE) depend TWINDIR=$(TWINDIR) ; done
	@-for i in $(PARTS); do [ -d $(TWINDIR)/$$i ] && cd $(TWINDIR)/$$i && $(MAKE) depend TWINDIR=$(TWINDIR) ; done
	@-for i in $(DRIVER); do [ -d $(TWINDIR)/$$i ] && cd $(TWINDIR)/$$i && $(MAKE) depend TWINDIR=$(TWINDIR) ; done
	@-for i in $(TWIN); do [ -d $(TWINDIR)/$$i ] && cd $(TWINDIR)/$$i && $(MAKE) depend TWINDIR=$(TWINDIR) ; done
	@-for i in $(LIBS); do [ -d $(TWINDIR)/$$i ] && cd $(TWINDIR)/$$i && $(MAKE) depend TWINDIR=$(TWINDIR) ; done

#
#
#

install: all target
	@echo Copy components in...
	@cp -rv $(TWINDIR)/win/xwin$(TWIN_APISIZE) $(INSTALLDIR)/bin
	@cp -rv $(TWINDIR)/win/lib*.so*  $(INSTALLDIR)/lib
	@cp -rv $(TWINDIR)/include/*.h $(INSTALLDIR)/include
	@cp -rv $(TWINDIR)/bin/rc/rc $(INSTALLDIR)/bin
	@find $(INSTALLDIR) -print
