#===============================================================
# V Makefile - Version 1.20 - 6/30/98
#
# Copyright (C) 1995,1996,1997,1998  Bruce E. Wampler
#
# This file is part of the V C++ GUI Framework, and is covered
# under the terms of the GNU Library General Public License,
# Version 2. This library has NO WARRANTY. See the source file
# vapp.cxx for more complete information about license terms.
#
# Many thanks to Jan Broeckhove for contributing this
# set of makefiles, which are the standard method of building
# V beginning with Version 1.16.
#===============================================================
#
# IMPORTANT NOTE:
# This Makefile is the top level makefile used to build V on
# various Unix-like platforms. First and foremost, this Makefile
# requires a version of make compatible with Gnu make. One
# specific requirement is VPATH support, for example. There
# are other incompatibilities with gmake and the old standard
# Unix make.
#
# Also, all the Makefiles in this version are controlled by
# the file Config.mk. It defines various directory locations
# and things needed to make V work correctly. You should only
# have to edit Config.mk to get V compiled correctly.
#
# There are TWO versions of Config.mk - one for the standard
# Athena widget version of V, and one for the Motif version.
# To build the Athena version, copy ConfigX.mk to Config.mk
# and edit for your system. To build the Motif version,
# copy ConfigM.mk to Config.mk and edit for your system.
#

CONFIG = ./Config.mk
include $(CONFIG)

#===============================================================
# Available targets:
#
# 	all (default):	vlib, vtest, utils, examp ...
#	vlib:		build V library
#       vtest:		build exhaustive test program v1
#	utils:		vgen, viconed, vdraw, vtexted, bmp2vbm
#	examples:	demos proto, drawex, tutor, icondemo
#	clean:		general cleanup
#	cleanmotif:	cleanup motif .o's, etc.
#	cleanobj:	cleanup .o's
#	cleanbin:	cleanup bins's
#	cleanall:	cleanup all non-source stuff
#	tar:		X and Windows Distribution
#	tarwin:		Windows only Distribution"
#	tarx:		X only distribution
#	tarfull:	everthing, including .o's, etc.
#	getwin:		copy MS-Windows source from /dosc
#	permissions:	make sources readable to world
#	installv:	run as root to install to /usr/local/v
#	installvlinux:	run as root to install to /usr/local
#	installunm:	install to ../pubv (UNM specific)
#
#===============================================================


#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#
# composite targets and targets for builds in subdirs
# (with some in-between targets to map target to directory)
#
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

SRCEXTS	=  *.cpp *.cxx *.c *.h Make* make* Config* *.tex *.txt

.PHONY: default all vlib vtest utils examples testlib
.PHONY: srcx test appgen iconed draw texted vide bmp2vbm tutor examp drawex icons

default: all

all:	vlib vtest utils examples
	@echo "Library, test, utils, examples and tutorial made"

vlib: srcx

vtest: test

testlib:
	-rm bin/linux/v1
	cd srcx ; $(MAKE)
	cd test ; $(MAKE)

utils: appgen iconed draw texted bmp2vbm vide

examples: examp drawex icons tutor

srcx test appgen iconed draw texted vide bmp2vbm tutor examp drawex icons:
	cd $@ ; $(MAKE) 


#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#
# Platform specific MAKES
#
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

.PHONY:	linux linuxelf sun4 sgi hpux aix solaris bsd
linux linuxelf sun4 sgi hpux aix solaris bsd:
	$(MAKE) ARCH=$@ vlib
	$(MAKE) ARCH=$@ vtest
	(cd appgen ; $(MAKE) ARCH=$@)
	(cd iconed ; $(MAKE) ARCH=$@)


#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#
# targets for cleaning up
#
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

.PHONY:	clean
clean:
	-rm -f $(CLEANEXTS) *.bkh v.tgz
	for i in srcx appgen doc draw drawex examp iconed icons \
		srcx test texted vide tutor; do \
		(cd $$i; $(MAKE) clean); \
	done
	for i in contrib vopengl includex/v includew/v srcwin; do \
		(cd $$i; rm -f $(CLEANEXTS)); \
	done
	-rm -f bccide/*.bak bccide/*.tmp bccide/*.csm
	-rm -f bccide/*.dsw bccide/*.obr bccide/*.tr
	-rm -f watcom/*.bak watcom/*.tmp watcom/*/*.exe watcom/*/*.obj
	-rm -f watcom/*/*.map watcom/*/*.lib watcom/*/*.err watcom/*/*.sym
	-rm -f bccide/*.bak bccide/*.tmp bccide/*.\~* bccide/*.csm

.PHONY: cleanmotif
cleanmotif:
	-rm -f objm/*/* lib/*/libVm.a bin/*/v1m
	for i in linuxelf linux mips sgi hpux solaris aix sun4 bsd; do \
		date > objm/$$i/ThisIs;\
	done

.PHONY:	cleantestlib
cleantestlib:
	for i in linuxelf linux mips sgi hpux solaris aix sun4 winbsd ; do \
		-rm bin/$$i/v1 ; \
	done

.PHONY:	cleanbin
cleanbin:
	-rm -f bin/*/*
	for i in linuxelf linux mips sgi hpux solaris aix bsd sun4 win mingw32; do \
		date > lib/$$i/ThisIs; date > bin/$$i/ThisIs ; \
	done

.PHONY:	cleanobj
cleanobj:
	-rm -f obj/*/* objm/*/*
	-rm -f watcom/*/*.obj
	for i in linuxelf linux mips sgi hpux solaris aix bsd sun4 win16 win32 win32db mingw32; do \
		date > obj/$$i/ThisIs; \
	done
	for i in linuxelf linux mips sgi hpux solaris bsd aix sun4; do \
		date > objm/$$i/ThisIs; \
	done

.PHONY:	cleanall
cleanall: clean cleanobj
	-rm -f lib/*/* bin/*/*
	for i in linuxelf linux mips sgi hpux solaris aix bsd sun4 win mingw32; do \
		date > lib/$$i/ThisIs; date > bin/$$i/ThisIs ; \
	done

.PHONY: cleanlf
cleanlf:
	for i in srcx appgen doc draw drawex examp iconed icons \
		test texted vide tutor; do \
		(cd $$i; rm -f $(CLEANEXTS); dos2unix $(SRCEXTS) ); \
	done
	for i in contrib vopengl includex/v includew/v srcwin; do \
		(cd $$i; rm -f $(CLEANEXTS); dos2unix $(SRCEXTS) ); \
	done

#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#
# targets for making tar files
#
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

.PHONY:	tar
tar: clean
	@echo "Making v.tgz - X and Windows Distribution"
	@echo "    Cleaning up old tar file"
	-rm ../v-$(VV).tar$(TARZ)
	cd .. ; tar cvf$(TARZ) v-$(VV).tar$(TARZ) v/Make* v/README v/C* v/P* \
	 v/doc/* v/examp/* v/bmp2vbm/* v/tutor/* v/include v/includex/* \
	 v/includew/* v/lib/*/ThisIs v/obj/*/ThisIs v/objm/*/ThisIs v/srcx/* \
	 v/srcwin/* v/test/* v/draw/* v/iconed/* v/drawex/* v/bin/*/ThisIs \
	 v/instwin.txt v/bccide v/icons/* v/watcom/* v/contrib/* v/appgen/* \
	 v/texted/* v/vide/* v/vopengl/* v/msvc/* v/mingw32/* v/rdmewin.txt; cd v

.PHONY:	tarwin
tarwin: clean
	@echo "Making vwin.tar - Windows Distribution"
	@echo "    Cleaning up old tar file"
	-rm ../vwin$(VVW).tar$(TARZ)
	cd .. ; tar cvf$(TARZ) vwin$(VVW).tar$(TARZ) v/Make* v/README v/C* v/P* \
	 v/doc/* v/examp/* v/bmp2vbm/* v/tutor/* v/include \
	 v/includew/* v/lib/*/ThisIs v/lib/win/* v/obj/*/ThisIs v/objm/*/ThisIs \
	 v/srcwin/* v/test/* v/draw/* v/drawex/* v/bin/*/ThisIs  \
	 v/instwin.txt v/bccide  v/icons/* v/iconed/* v/contrib/* \
	 v/appgen/* v/texted/* v/vide/* v/vopengl/* v/msvc/* v/mingw32/* v/rdmewin.txt ; cd v

.PHONY:	tarx
tarx: clean
	@echo "Making vx-$(VV).tar - X only distribution"
	@echo "    Cleaning up old tar file"
	-rm ../vx-$(VV).tar$(TARZ)
	cd .. ; tar cvf$(TARZ) vx-$(VV).tar$(TARZ) v/Make* v/README v/C* v/P* \
	 v/doc/* v/examp/* v/bmp2vbm/* v/tutor/* v/include v/includex/* \
	 v/lib/*/ThisIs v/obj/*/ThisIs v/objm/*/ThisIs v/srcx/* v/icons/* \
	 v/test/* v/draw/* v/iconed/* v/drawex/* v/bin/*/ThisIs \
	 v/contrib/* v/appgen/* v/texted/* v/vide/* v/vopengl/* ; cd v

.PHONY:	tarxsrc
tarxsrc: clean
	@echo "Making vxsrc-$(VV).tar - X only distribution"
	@echo "    Cleaning up old tar file"
	-rm ../vxsrc-$(VV).tar$(TARZ)
	cd .. ; tar cvf$(TARZ) vxsrc-$(VV).tar$(TARZ) v/Make* v/README v/C* v/P* \
	 v/examp/* v/bmp2vbm/* v/tutor/* v/include v/includex/* \
	 v/lib/*/ThisIs v/obj/*/ThisIs v/objm/*/ThisIs v/srcx/* v/icons/* \
	 v/test/* v/draw/* v/iconed/* v/drawex/* v/bin/*/ThisIs \
	 v/contrib/* v/appgen/* v/texted/* v/vide/* v/vopengl/* ; cd v

.PHONY:	tarfull
tarfull: clean
	@echo "Making vfull.tgz - FULL VERSION"
	@echo "    Cleaning up old tar file"
	-rm ../vfull.tar$(TARZ)
	cd .. ; tar cvf$(TARZ) vfull.tar$(TARZ) v/* ; cd v


.PHONY:	tarxdemo
tarxdemo:
	-rm ../vdemox-$(VV).tar$(TARZ)
	-cp bin/linux/vdraw vdraw.linux.bin
	tar cvf$(TARZ) vdemox-$(VV).tar$(TARZ) vdraw.linux.bin
	mv vdemox-$(VV).tar$(TARZ) ..
	-rm vdraw.linux.bin

.PHONY:	tardemo
tardemo:
	-rm ../vdemos-$(VV).tar$(TARZ)
	-cp bin/linux/vdraw vdraw.linux.bin
	-cp bin/win/vdraw.exe vdraw.exe
	tar cvf$(TARZ) vdemos-$(VV).tar$(TARZ) vdraw.exe vdraw.linux.bin
	mv vdemos-$(VV).tar$(TARZ) ..
	-rm vdraw.linux.bin
	-rm vdraw.exe


#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#
# target for fixing permissions
#
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

PERMDIRS =	. doc  examp tutor includex includex/v includew/v lib \
		lib/* obj obj/* objm objm/* srcx srcwin test draw drawex iconed bin \
		bin/* bmp2vbm icons vopengl texted vide appgen contrib bccide watcom msvc mingw32

WINDIRS =	watcom/win16 watcom/win16db watcom/win32 watcom/win32db \
		msvc/vgen32 msvc/viconed msvc/vmsvc32 msvc/vtstms32 \
		msvc/vgen32/release msvc/viconed/release msvc/vmsvc32/release \
		msvc/vtstms32/release

PERMFILES =	Make* README P* C* instwin.txt rdmewin.txt doc/* includex/v/* \
		includew/v/* lib/*/* obj/*/* objm/*/* srcx/* srcwin/* test/* \
		draw/* iconed/* drawex/* examp/* bin/*/* tutor/* bmp2vbm/* bccide/* \
		icons/* watcom/*/* watcom/* contrib/*  \
		appgen/* texted/* vide/* vopengl/* mingw32/* msvc/*/* msvc/*

EXEFILES =	bin/*/* 

.PHONY:	permissions
permissions:
	-chmod 755 $(PERMDIRS)
	-chmod 755 $(WINDIRS)
	-chmod 644 $(PERMFILES)
	-chmod 755 $(PERMDIRS)
	-chmod 755 $(WINDIRS)
	-chmod 755 $(EXEFILES)


#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
#
# installation targets
# These work best for dedicated systems where you can run as
# root. 
# IMPORTANT! It will be easier if you make a symbolic link
# in the home directory of root to whereever V is before
# doing the install. E.g.,
#
#    [root]# cd
#    [root]# ln -s /home/bruce/v v
#    [root]# cd v
#    [root]# make installLinux
#
# This makefile uses $(LibDir), which is
# set to HOME by default, so adding a link from the root
# directory of root to the real v directory makes this work right.
#
# The Linux version assumes that X11 binaries are at /usr/X11/bin.
# Some versions have /usr/X11R6/bin instead. If that is your case,
# you should also create a symbolic link in /usr: ln -s X11R6 X11
#
#xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx

.PHONY:	installLinux
installLinux:
	$(MAKE) ARCH=linux installVLinux

.PHONY:	uninstallLinux
uninstallLinux:
	$(MAKE) ARCH=linux uninstallVLinux

.PHONY:	uninstallLinuxElf
uninstallLinuxElf:
	$(MAKE) ARCH=linuxelf uninstallVLinux

.PHONY:	installLinuxElf
installLinuxElf:
	$(MAKE) ARCH=linuxelf installVLinux

.PHONY:	installv
installv:
	-mkdir /usr/local/v
	-mkdir /usr/local/v/lib
	-mkdir /usr/local/v/bin
	-mkdir /usr/local/v/include
	-mkdir /usr/local/v/include/v
	-chmod 755 /usr/local/v 
	-chmod 755 /usr/local/v/lib
	-chmod 755 /usr/local/v/bin
	-chmod 755 /usr/local/v/include
	-chmod 755 /usr/local/v/include/v
	cp includex/v/* /usr/local/v/include/v
	cp $(LibDir)/*.a /usr/local/v/lib
	cp $(Bin)/* /usr/local/v/bin
	-chmod 644 /usr/local/v/include/v/*
	-chmod 644 /usr/local/v/lib/*
	-chmod 755 /usr/local/v/bin/*

.PHONY:	installmingw32
installmingw32:
	cp includew/v/* $(HOMEMW)/include/v
	cp $(LibDir)/*.a $(HOMEMW)/lib
	cp $(Bin)/* $(HOMEMW)/bin

.PHONY:	instalVlLinux
installVLinux:
	@echo "You must run this as root"
	-mkdir /usr/include/v
	-chmod 644 includex/v/*
	cp includex/v/* /usr/include/v
ifeq ($(Arch),linuxelf)
	chmod 644 $(LibDir)/*.so.$(VV)
	cp $(LibDir)/*.so.$(VV) /usr/lib
	rm -f /usr/lib/$(LIBNAME).so.1
	ln -s /usr/lib/$(LIBNAME).so.$(VV) /usr/lib/$(LIBNAME).so.1
	rm -f /usr/lib/$(LIBNAME).so
	ln -s /usr/lib/$(LIBNAME).so.$(VV) /usr/lib/$(LIBNAME).so
else
	-chmod 644 $(LibDir)/*.a
	cp $(LibDir)/*.a /usr/lib
endif
	-chmod 755 $(Bin)/*
	cp $(Bin)/* /usr/X11/bin

.PHONY:	uninstalVlLinux
uninstallVLinux:
	@echo "You must run this as root"
	-rm  /usr/include/v/*
ifeq ($(Arch),linuxelf)
	rm -f /usr/lib/$(LIBNAME).so.1
	rm -f /usr/lib/$(LIBNAME).so
	rm -f /usr/lib/$(LIBNAME).so.$(VV)
else
	rm -f /usr/lib/libV.a
endif
	-rm /usr/X11/bin/viconed
	-rm /usr/X11/bin/b2v
	-rm /usr/X11/bin/icondemo
	-rm /usr/X11/bin/proto
	-rm /usr/X11/bin/tutapp
	-rm /usr/X11/bin/v1
	-rm /usr/X11/bin/vdraw
	-rm /usr/X11/bin/vdrawex
	-rm /usr/X11/bin/ved
	-rm /usr/X11/bin/vgen

# To install V to /usr/local hierarchy at UNM
# The strategy I used at UNM, where I don't have access to
# the system as root was to get symbolic links on all the local
# architectures to ~wampler/pubv/xxx for each architecture.
# I then make the files on my private directory, and them
# copy them to the /pubv directory for public consumption.
# This scheme allows you to add whatever you need, such
# as /usr/local/v/doc, or whatever.
.PHONY: installunm
installunm:
	cp includex/v/* ../pubv/irix/include/v
	-chmod 644 ../pubv/irix/include/v/*
	cp includex/v/* ../pubv/sunos/include/v
	-chmod 644 ../pubv/sunos/include/v/*

	cp lib/sgi/* ../pubv/irix/lib
	-chmod 644 ../pubv/irix/lib/*
	cp lib/sun4/* ../pubv/sunos/lib
	ranlib ../pubv/sunos/lib/libV.a
	-chmod 644 ../pubv/sunos/lib/*

	cp bin/sgi/* ../pubv/irix/bin
	-chmod 755 ../pubv/irix/bin/*
	cp bin/sun4/* ../pubv/sunos/bin
	-chmod 755 ../pubv/sunos/bin/*
