# ******************************************************************************
# *					           NCSA ImageTool 1.1 beta
# *						   19 September 1990	
# * 
# * NCSA ImageTool 1.1 beta source code and documentation are in the public
# * domain.
# * Specifically, we give to the public domain all rights for future licensing
# * of the source code, all resale rights, and all publishing rights.
# * 
# * We ask, but do not require, that the following message be included in all
# * derived works:
# * 
# * Portions developed at the National Center for Supercomputing Applications at
# * the University of Illinois at Urbana-Champaign.
# * 
# * THE UNIVERSITY OF ILLINOIS GIVES NO WARRANTY, EXPRESSED OR IMPLIED, FOR THE
# * SOFTWARE AND/OR DOCUMENTATION PROVIDED, INCLUDING, WITHOUT LIMITATION,
# * WARRANTY OF MERCHANTABILITY AND WARRANTY OF FITNESS FOR A PARTICULAR PURPOSE
# * 
# ******************************************************************************
#
# abstract:	Make file for creating and installing NCSA ImageTool 1.1
#		beta. There are two make targets: personal and system.
#		Repeated executions of this file are possible.
# by:		NCSA Software Development Group
# date:		Sep 90
#
# notes: 	Typing 
#
#			make personal
#
#		will attempt to:
#
#		1. Create a working version of ImageTool, called
#		   imagetool, in this directory.
#		2. Update (create) entries for SunView user defaults
#		   database in file $HOME/.defaults. See the macro list
#		   in the "Personal Installation" section below to change
#		   the value of default options. One should be able to
#		   produce a working version without changing anything
#		   provided you don't move any files around AND you have
#		   enough space AND you execute imagetool from this
#		   directory.
#
#		Typing
#
#			make system
#
#		will attempt to:
#
#		1. Create a working version of ImageTool, called
#		   imagetool, and move it and associated files to a
#		   system wide directory. See the macro list in the "System
#		   Installation" section below to set the appropriate
#		   directory.
#		2. Add ImageTool.d to the master database files in
#		   directory /usr/lib/defaults. Check the macro list in
#		   "System Installation" section below to change the value
#		   of default options.
#
#		IMPORTANT:
#		1. You must be root to "make system".
#		2. After running "make system" each user of the system wide
#		   version MUST execute defaultsedit in SunView and save
#		   the ImageTool entries or set them to the system
#		   defaults. Otherwise, executing imagetool will fail with
#		   an error message.
#		3. Run "make system" only on a standalone or server system.
#
#-------------------------------------------------------------------------------
#
# Installation independent macros:
#
# HDFDIR	-	HDF directory with header files relative to this
#			makefile directory. DO NOT CHANGE!!!
#
HDFDIR = HDF
HEADERS = headers
SRCOBJ = src+obj
#
CC = cc
CFLAGS = -O -I$(HEADERS) -I$(HDFDIR)
CFLAGSX = -O -I../$(HEADERS) -I../$(HDFDIR)
#
#------------------------------------------------------------------------------
#
# Personal Intallation
#
# PCTMPDIR		- C compiler temporary directory. WATCH OUT!
#			  This may have to be changed to have enough space to
#			  compile successfully! Especially on a Sun-4.
#			  NEED
#				~1.2 MB (?)	- SunOS 4.x - Sun-3
#				~1.4 MB (?)	- SunOS 4.x - Sun386i
#				~8.0 MB (?)	- SunOS 4.x - Sun-4
#
PCTMPDIR = /tmp
#
# Values of defaults option macros for "make personal". These need not be
# changed to check out a "personal" version. Go to the "System Installation"
# section for the "system" version.
#
# PHelp_dir		- Directory containing the help files.
# PPalette_file		- Initial palette file. Part of distribution.
# PImage_dir		- Initial image directory. If it doesn't exit the
#			  current directory is used.
# PFont_panel		- Sun provided screen font. DO NOT CHANGE!!!!
# PFont_panel_button	- Sun provided screen font. DO NOT CHANGE!!!!
# PFont_menu		- Sun provided screen font. DO NOT CHANGE!!!!
# PMessage_limit        - Maximum number of messages saved in the "rolladex".
# PBug_email_address    - Address to send bug messages to.
#			  
PHelp_dir =		imagetool.help
PPalette_file =		imagetool.pal
PImage_dir =		samples
PFont_panel =		/usr/lib/fonts/fixedwidthfonts/cour.b.14
PFont_panel_button =	/usr/lib/fonts/fixedwidthfonts/cour.b.14
PFont_menu =		/usr/lib/fonts/fixedwidthfonts/cour.b.18
PMessage_limit =	20
PBug_email_address =	martink@ncsa.uiuc.edu
#
personal:
	@ echo ". . . build personal copy of software - this takes a few minutes"
	@ echo ". . . . . . build HDF library"
	@ (cd $(HDFDIR); make)
	@ echo ". . . . . . build imagetool executable"
	@ if [ -f $(SRCOBJ)/main.c ];  then mv $(SRCOBJ)/main.c .; fi
	@ (cd $(SRCOBJ); for i in *.c; \
	   do \
		$(CC) -c $(CFLAGSX) -temp=$(PCTMPDIR) $$i; \
	   done)
	@ $(CC) -o imagetool $(CFLAGS) -temp=$(PCTMPDIR) main.c $(SRCOBJ)/*.o $(HDFDIR)/libdf.a -lsuntool -lsunwindow -lpixrect -lm
	@ if [ -f main.c ]; then mv main.* $(SRCOBJ); fi
	@ echo ". . . update $$HOME/.defaults"
	@ if [ -f $$HOME/.defaults ]; then exit; \
		else echo "SunDefaults_Version 2" > $$HOME/.defaults; exit; fi
	@ awk '/^\/ImageTool/ { next } {print} \
	     END { \
	print "/ImageTool/Help_dir\t\"$(PHelp_dir)\""; \
	print "/ImageTool/Palette_file\t\"$(PPalette_file)\""; \
	print "/ImageTool/Image_dir\t\"$(PImage_dir)\""; \
	print "/ImageTool/Font_panel\t\"$(PFont_panel)\""; \
	print "/ImageTool/Font_panel_button\t\"$(PFont_panel_button)\""; \
	print "/ImageTool/Font_menu\t\"$(PFont_menu)\""; \
	print "/ImageTool/Message_limit\t\"$(PMessage_limit)\""; \
	print "/ImageTool/Bug_email_address\t\"$(PBug_email_address)\""; }' $$HOME/.defaults > .defaults
	@ cp .defaults $$HOME/.defaults
	@ echo ". . . cleanup files"
	@ rm .defaults
	@ echo ". . . done"
#
#------------------------------------------------------------------------------
# System Installation
#
# SCTMPDIR		- C compiler temporary directory. WATCH OUT!
#			  This may have to be changed to have enough space to
#			  compile successfully! Especially on a Sun-4.
#			  NEED
#				~1.2 MB (?)	- SunOS 4.x - Sun-3
#				~1.4 MB (?)	- SunOS 4.x - Sun386i
#				~8.0 MB (?)	- SunOS 4.x - Sun-4
#			  Must be physically on the system you will be
#			  installing on. It must already exist!
# TMPDIR		- System temporary directory. WATCH OUT! This may
#			  have to be changed to have enough space to create
#			  the distribution. It must already exist!
#			  NEED
#			  	~1.0 MB (?) - SunOS 4.x
#			  Must be physically on the system you will be
#			  installing on.
# SYSTEMDIR		- System wide directory where ImageTool and 
#			  associated files will be put. WATCH OUT! You
#			  MUST provide this value!
#			  NEED
#				~.3 MB (?) - SunOS 4.x
#			  Must be physically on the system you will be
#			  installing on. It must already exist!
#			  
SCTMPDIR = /tmp
TMPDIR = /tmp
SYSTEMDIR = ?
#
# Values of defaults option macros for "make system".
#
# Help_dir		- Directory containing the help files. Put in system
#			  wide directory.
# Palette_file		- Initial palette file. Part of distribution. Put in
#			  system wide directory.
# Image_dir		- Initial image directory. If it doesn't exit the
#			  current directory is used.
# Font_panel		- Sun provided screen font. DO NOT CHANGE!!!!
# Font_panel_button	- Sun provided screen font. DO NOT CHANGE!!!!
# Font_menu		- Sun provided screen font. DO NOT CHANGE!!!!
# Message_limit		- Maximum number of messages saved in the "rolladex".
# Bug_email_address	- Address to send bug messages to.
#			  
Help_dir =		$(SYSTEMDIR)/imagetool.help
Palette_file =		$(SYSTEMDIR)/imagetool.pal
Image_dir =		/usr/local/samples
Font_panel =		/usr/lib/fonts/fixedwidthfonts/cour.b.14
Font_panel_button =	/usr/lib/fonts/fixedwidthfonts/cour.b.14
Font_menu =		/usr/lib/fonts/fixedwidthfonts/cour.b.18
Message_limit =		20
Bug_email_address =	bugs@ncsa.uiuc.edu
#
system:
	@ id | awk 'BEGIN {FS = "("} { if ( $$1 != "uid=0") \
		{ print "Must be root to install system. Make terminated!"; exit -1} }'
	@ echo ". . . build system copy of software - this takes a few minutes"
	@ echo ". . . . . . build HDF library"
	@ rm -rf $(TMPDIR)/imagetool 1>/dev/null 2>&1
	@ mkdir $(TMPDIR)/imagetool
	@ cp -r $(HDFDIR) $(TMPDIR)/imagetool
	@ (cd $(TMPDIR)/imagetool/$(HDFDIR); rm -f *.o *.a) 1>/dev/null 2>&1
	@ (cd $(TMPDIR)/imagetool/$(HDFDIR); make)
	@ echo ". . . . . . build imagetool executable"
	@ cp -r $(SRCOBJ) $(TMPDIR)/imagetool
	@ cp -r $(HEADERS) $(TMPDIR)/imagetool
	@ (cd $(TMPDIR)/imagetool; mv $(SRCOBJ)/main.c .)
	@ (cd $(TMPDIR)/imagetool/$(SRCOBJ); for i in *.c; \
	   do \
		$(CC) -c $(CFLAGSX) -temp=$(SCTMPDIR) $$i; \
	   done)
	@ (cd $(TMPDIR)/imagetool; $(CC) -o imagetool $(CFLAGS) -temp=$(SCTMPDIR) main.c $(SRCOBJ)/*.o $(HDFDIR)/libdf.a -lsuntool -lsunwindow -lpixrect -lm)
	@ (cd $(TMPDIR)/imagetool; mv main.* $(SRCOBJ))
	@ echo ". . . install files"
	@ if [ -d $(SYSTEMDIR) ]; then exit; \
		else echo "No such system wide directory (SYSTEMDIR=$(SYSTEMDIR)). Make terminated!"; exit 1 ; fi
	@ install -d -g bin -m 0775 -o root $(SYSTEMDIR)/imagetool.help
	@ install -g bin -m 0664 -o root imagetool.help/imagetool* $(SYSTEMDIR)/imagetool.help
	@ install -g bin -m 0644 -o root imagetool.pal $(SYSTEMDIR)
	@ install -g bin -m 0755 -o root $(TMPDIR)/imagetool/imagetool $(SYSTEMDIR)
	@ echo ". . . update Master Database defaults file"
	@ awk ' { m = 0 }\
	   /^\/\/Help_dir[ \t]/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Help_dir)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Help_dir)\""; n = 0 }; m = 1} \
	   /^\/\/Palette_file[ \t]/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Palette_file)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Palette_file)\""; n = 0 }; m = 1} \
	   /^\/\/Image_dir[ \t]/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Image_dir)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Image_dir)\""; n = 0 }; m = 1} \
	   /^\/\/Font_panel[ \t]/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Font_panel)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Font_panel) - DO NOT CHANGE!\""; n = 0 }; m = 1} \
	   /^\/\/Font_panel_button[ \t]/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\"$(Font_panel_button)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Font_panel_button) - DO NOT CHANGE!\""; n = 0 }; m = 1} \
	   /^\/\/Font_menu[ \t]/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Font_menu)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Font_menu)\""; n = 0 }; m = 1} \
	   /^\/\/Message_limit[ \t]/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Message_limit)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Message_limit). Valid range is in the interval [3, 100].\""; n = 0 }; m = 1} \
	   /^\/\/Bug_email_address/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Bug_email_address)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Bug_email_address) - use local equivalent\""; n = 0 }; m = 1} \
	      { if ( m == 0) print }' ImageTool.d > $(TMPDIR)/imagetool/ImageTool.d
	@ cp $(TMPDIR)/imagetool/ImageTool.d /usr/lib/defaults/ImageTool.d
	@ echo ". . . cleanup files"
	@ rm -r $(TMPDIR)/imagetool
	@ echo ". . . done"
