#
#******************************************************************************
#*					           NCSA CompositeTool 1.1
#*						   18 April 1990
#* 
#* NCSA CompositeTool 1.1 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 CompositeTool 1.1
#		There are two make targets: personal and system.
#		Repeated executions of this file are possible.
#
# by:		NCSA Software Tools Group
#
# date:		May 90
#
# notes: 	Typing 
#
#			make personal
#
#		will attempt to:
#
#		1. Create a working version of CompositeTool, called
#		   compositetool, 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 compositetool from this
#		   directory.
#
#		Typing
#
#			make system
#
#		will attempt to:
#
#		1. Create a working version of CompositeTool, called
#		   compositetool, 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 CompositeTool.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" it is NO LONGER NECESSARY
#		   for a user to execute defaultsedit in SunView to add
#		   CompositeTool entries to her private defaults database,
#		   normally, $HOME/.defaults. On startup the master database 
#		   is searched as required to create a temporary private
#		   defaults database.
#		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
#
CC = cc
CFLAGS = -O -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	- SunOS 4.x - Sun-3
#				~1.4	- SunOS 4.x - Sun386i
#				~8.0	- 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.
#
# PInitial_palette_file	- Initial palette file. Part of distribution.
# PLogo_palette_file 	- File containing logo image. Part of distribution.
# PLogo_image_file	- File containing logo palette. Part of distribution.
# PFont_panel		- Sun provided screen font. DO NOT CHANGE!!!!
# PFont_panel_button	- Sun provided screen font. DO NOT CHANGE!!!!
# PText_font_dir	- Sun provided default font directory for text font.
#			  The value below should be available on all Suns.
#			  If the versatec fonts are available then use
#				/usr/lib/vfont
#			  CompositeTool will still work if this value is
#			  bad, but you will have to replace the value
#		          by the correct one each time you invoke a text
#			  frame in CompositeTool.
# PText_font		- Sun provided default font for text font.
#			  The value below should be available on all Suns.
#			  If the versatec fonts are available then use a
#			  font from
#				/usr/lib/vfont
#			  CompositeTool will still work if this value is
#			  bad, but you will have to replace the value
#		          by the correct one each time you invoke a text
#			  frame in CompositeTool.
#
PInitial_palette_file =	pal_initial.raw
PLogo_palette_file =	logo.hdf
PLogo_image_file =	logo.hdf
PFont_panel =		/usr/lib/fonts/fixedwidthfonts/screen.b.12
PFont_panel_button =	/usr/lib/fonts/fixedwidthfonts/screen.r.11
PText_font_dir =	/usr/lib/fonts/fixedwidthfonts
PText_font =		screen.b.12
#
personal:
	@ echo ". . . build personal copy of software - this takes a few minutes"
	@ echo ". . . . . . build HDF library"
	@ (cd $(HDFDIR); make)
	@ echo ". . . . . . build compositetool executable"
	@ $(CC) -o compositetool $(CFLAGS) -temp=$(PCTMPDIR) compositetool.c $(HDFDIR)/libdf.a -lsuntool -lsunwindow -lpixrect -lm
	@ echo ". . . update $$HOME/.defaults"
	@ if [ -f $$HOME/.defaults ]; then exit; \
		else echo "SunDefaults_Version 2" > $$HOME/.defaults; exit; fi
	@ awk '/^\/CompositeTool/ { next } {print} \
	     END { \
	print "/CompositeTool/Initial_palette_file\t\"$(PInitial_palette_file)\""; \
	print "/CompositeTool/Logo_palette_file\t\"$(PLogo_palette_file)\""; \
	print "/CompositeTool/Logo_image_file\t\"$(PLogo_image_file)\""; \
	print "/CompositeTool/Font_panel\t\"$(PFont_panel)\""; \
	print "/CompositeTool/Font_panel_button\t\"$(PFont_panel_button)\""; \
	print "/CompositeTool/Text_font_dir\t\"$(PText_font_dir)\""; \
	print "/CompositeTool/Text_font\t\"$(PText_font)\""; }' $$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	- SunOS 4.x - Sun-3
#				~1.4	- SunOS 4.x - Sun386i
#				~8.0	- SunOS 4.x - Sun-4
#			  Must be physically on the system you will be
#			  installing on.
# TMPDIR		- System temporary directory. WATCH OUT! This may
#			  have to be changed to have enough space to create
#			  the distribution.
#			  NEED
#			  	~1.0 MB - SunOS 4.x
#			  Must be physically on the system you will be
#			  installing on.
# SYSTEMDIR		- System wide directory where CompositeTool 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.
#			  
SCTMPDIR = /tmp
TMPDIR = /tmp
SYSTEMDIR = ?
#
# Values of defaults option macros for "make system".
#
# Initial_palette_file	- Initial palette file. Part of distribution. Put
#			  in system wide directory.
# Logo_palette_file 	- File containing logo image. Part of distribution.
#			  Put in system wide directory.
# Logo_image_file	- File containing logo palette. Part of distribution.
#			  Put in system wide directory.
# Font_panel		- Sun provided screen font. DO NOT CHANGE!!!!
# Font_panel_button	- Sun provided screen font. DO NOT CHANGE!!!!
# Text_font_dir		- Sun provided default font directory for text font.
#			  The value below should be available on all Suns.
#			  If the versatec fonts are available then use
#				/usr/lib/vfont
#			  CompositeTool will still work if this value is
#			  bad, but you will have to replace the value
#		          by the correct one each time you invoke a text
#			  frame in CompositeTool.
# Text_font		- Sun provided default font for text font.
#			  The value below should be available on all Suns.
#			  If the versatec fonts are available then use a
#			  font from
#				/usr/lib/vfont
#			  CompositeTool will still work if this value is
#			  bad, but you will have to replace the value
#		          by the correct one each time you invoke a text
#			  frame in CompositeTool.
#
Initial_palette_file =	$(SYSTEMDIR)/pal_initial.raw
Logo_palette_file =	$(SYSTEMDIR)/logo.hdf
Logo_image_file =	$(SYSTEMDIR)/logo.hdf
Font_panel =		/usr/lib/fonts/fixedwidthfonts/screen.b.12
Font_panel_button =	/usr/lib/fonts/fixedwidthfonts/screen.r.11
Text_font_dir =		/usr/lib/fonts/fixedwidthfonts
Text_font =		screen.b.12
#
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)/$(HDFDIR) 1>/dev/null 2>&1
	@ cp -r $(HDFDIR) $(TMPDIR)
	@ (cd $(TMPDIR)/$(HDFDIR); rm -f *.o *.a) 1>/dev/null 2>&1
	@ (cd $(TMPDIR)/$(HDFDIR); make)
	@ echo ". . . . . . build compositetool executable"
	@ cp compositetool.c $(TMPDIR)
	@ (cd $(TMPDIR); $(CC) -o compositetool $(CFLAGS) -temp=$(SCTMPDIR) compositetool.c $(HDFDIR)/libdf.a -lsuntool -lsunwindow -lpixrect -lm)
	@ echo ". . . install files"
	@ if [ -d $(SYSTEMDIR) ]; then exit; \
		else echo "No such system wide directory (SYSTEMDIR=$(SYSTEMDIR)). Make terminated!"; exit 1 ; fi
	@ install -g bin -m 0644 -o root pal_initial.raw logo.hdf $(SYSTEMDIR)
	@ install -g bin -m 0755 -o root $(TMPDIR)/compositetool $(SYSTEMDIR)
	@ echo ". . . update Master Database defaults file"
	@ awk ' { m = 0 }\
	   /^\/\/Initial_palette_file/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Initial_palette_file)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Initial_palette_file)\""; n = 0 }; m = 1} \
	   /^\/\/Logo_palette_file/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Logo_palette_file)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Logo_palette_file)\""; n = 0 }; m = 1} \
	   /^\/\/Logo_image_file/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Logo_image_file)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Logo_image_file)\""; 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/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\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} \
	   /^\/\/Text_font_dir/, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Text_font_dir)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Text_font_dir) - use /usr/lib/fonts/fixedwidthfonts if not available\""; n = 0 }; m = 1} \
	   /^\/\/Text_font[ \t] /, /^	\$$Help/ { \
		if ( n == 0 ) { print $$1 "\t\t\"$(Text_font)\""; n++; } \
		else if ( n == 1 ) { print; n++ } \
		else if ( n == 2 ) { print "\t" $$1 "\t\t\"DEFAULT = $(Text_font) - use a screen font if not available\""; n = 0 }; m = 1} \
	      { if ( m == 0) print }' CompositeTool.d > $(TMPDIR)/CompositeTool.d
	@ cp $(TMPDIR)/CompositeTool.d /usr/lib/defaults/CompositeTool.d
	@ echo ". . . cleanup files"
	@ rm -r $(TMPDIR)/$(HDFDIR)
	@ rm -f $(TMPDIR)/compositetool.c $(TMPDIR)/compositetool.o $(TMPDIR)/compositetool $(TMPDIR)/CompositeTool.d
	@ echo ". . . done"
