;Installation script for Icon V9

(set exec-version (/ (getversion) 65536))

(if (< exec-version 37)
	(abort 
		"Exec version 37 or higher is required to run Icon V9.\n"
	)
)

(set Icon-source (pathonly @icon))

(set @default-dest Icon-source)

(set Icon-location
	(askdir
		(prompt "CHOOSE A DRAWER FOR YOUR ICON INSTALLATION.\n"
			"Please select a location for the Icon root directory. "
			"A drawer named IconV9 will be created there to contain "
			"the files from this distribution.\n"
			"If you downloaded the distribution press the Help button."
                        "                                                        "
		)                


		(help  
			"If you unpacked the IconV9 archive on your hard disk then "
			"you should already have a drawer named IconV9 containing the "
                        "distribution files (and this installer script).  You may "
                        "elect to use this drawer as the Icon root directory by "
                        "choosing the default option.  In this case the files will "
                        "be left where they are."           
		)
		(default (pathonly Icon-source))
	)
)

(set Icon-root (tackon Icon-location "IconV9"))

(set @default-dest Icon-root)

(if (= Icon-root Icon-source) 
	(message
		"Fine. Your files are already in the right place.  "
                "They will be left where they are"
	) 
	(copyfiles
		(prompt "Copying IconV9 files")
		(help @copyfiles-help)
		(source Icon-source)
		(dest Icon-root)
		(all)
		(infos)
		(confirm)
	)
)

(set coprocessor
	(askchoice
		(prompt "CHOOSE WHICH VERSION OF ICONX TO INSTALL.\n"
			"There are two versions of the Icon interpreter iconx "
			"supplied with this package.  One uses the 68881 math "
			"coprocessor for floating point arithmetic operations "
			"while the other does not.  Which version would you like "
			"to use ?"
		)
		(help
			"Both programs will be left on your system.  If you are "
			"not sure which to use, select the 68000 version for now."
		)
		(choices "68000 only"  "68020/68881 or higher")
		(default 0)
	)
)

(if (= coprocessor 1)
	(set iconx-binary (tackon Icon-root "bin/iconx.68881"))
	(set iconx-binary (tackon Icon-root "bin/iconx.68000")) 
)

(run "makelink From " (tackon Icon-root "bin/iconx") "To" iconx-binary )  

(copyfiles
	(prompt "ENABLE CREATION OF WORKBENCH ICONS FOR ICODE FILES.\n"
		"The icon translator will automatically create project icons "
                "for your icode files if a default icon exists in the "
		"drawer \"ENV:Icon\".  You may disable this feature by skipping "
		"this step of the installation."
	)
	(help "The file \"ICON:ENV/def_Icode.info\" will be copied to "
              "the drawer \"ENVARC:Icon\"")
	(source (tackon Icon-source "ENV"))
        (dest "ENVARC:Icon")
        (pattern "def_Icode.info")
	(confirm)
)


(set editor
	(askchoice
		(prompt "ENABLE AUTOMATIC ERROR CORRECTION.\n"
			"IconV9 supports an ARexx interface to automatically "
			"invoke your text editor when an error is encountered.  "
			"This feature is activated by the existence of two "
			"ARexx scripts in your \"ENV:Icon\" drawer.  Two sample "
			"scripts are provided: one calls the memacs editor and "
			"the other uses the SAS/C scmsg utility and se editor"
		)
		(help 
			"Two small scripts will be copied from ICON:ENV "
			"to ENVARC:Icon"
		)
		(choices "memacs" "scmsg/se" "Do not install scripts")
		(default 0)
	)
)

(if (= editor 0)
	(
		(copyfiles
			(prompt "Copying ARexx script for iconx errors")
			(source (tackon Icon-source "ENV"))
		        (dest "ENVARC:Icon")
			(pattern "IconxError.memacs")
			(newname "IconxError.rexx")	
		)
		(copyfiles
			(prompt "Copying ARexx script for icont errors")
			(source (tackon Icon-source "ENV"))
			(dest "ENVARC:Icon")
			(pattern "IcontError.memacs")
			(newname "IcontError.rexx")	
		)
	)
)

(if (= editor 1)
	(
		(copyfiles
			(prompt "Copying ARexx script for iconx errors")
			(source (tackon Icon-source "ENV"))
	                (dest "ENVARC:Icon")
			(pattern "IconxError.se")
			(newname "IconxError.rexx")	
		)
		(copyfiles
			(prompt "Copying ARexx script for icont errors")
			(source (tackon Icon-source "ENV"))
	                (dest "ENVARC:Icon")
			(pattern "IcontError.se")
			(newname "IcontError.rexx")	
		)
	)
)

(set apipe (run "Assign >NIL: APIPE: EXISTS" (safe) ))

(if (= apipe 0)
	(message "GOOD. APIPE: IS ALREADY HERE.\n"
		"IconV9 uses Per Bojsen's APipe-Handler to implement the "
		"\"Pipes\" feature.  This handler is included with the "
		"IconV9 package.  You appear to already have APIPE: "
		"mounted on your system, so no action is necessary."
	)
        (set install-apipe
                (askbool
			(prompt
			"IconV9 uses Per Bojsen's APipe-Handler to implement "
                	"the \"Pipes\" feature.  This handler is included with the "
			"IconV9 package.  You do not appear to have APIPE: mounted "
			"on your system.  Would you like to install APIPE: ?"
			)
			(choices "Install APIPE:"  "Do not install APIPE:")
			(help "Without APIPE: the open\(filename, \"p\"\) command "
                         "will fail.")
                        (default 1)
		)
	)
)

(set icon-assign
	(cat "assign ICON: " Icon-root "\n"
	     "path ICON:bin add\n"
	)
)

(set mount-apipe
	(cat  "Assign >NIL: APIPE: Exists\n" 
	      "IF Warn\n"
	      "  Mount APIPE: from ICON:APipe/DEVS/Mountlist\n"
	      "EndIf\n"
	)
)

(if (= install-apipe 1)
	(set startup-commands (cat icon-assign mount-apipe))
	(set startup-commands icon-assign)
)

(startup "IconV9"
	(prompt
		"A few commands must be added to your \"S:user-startup\""
                 "file in order to run IconV9 programs."
        )
	(help "The commands to be added are:\n"
              startup-commands
	)
	(command startup-commands)
)

(message
	"The Icon interpreter iconx has the same name as the AmigaDOS "
	"command which is used to attach a Workbench icon to a Shell "
	"script.  If you wish to run the Icon interpreter from the Shell "
	"then you should add the line \n\n"
	"alias iconx ICON:bin/iconx\n\n"
	"to your S:Shell-Startup file.  The AmigaDOS command c:iconx has "
	"no effect when run from the command line, so this alias is "
	"harmless.\n\n"
	"YOU SHOULD REBOOT YOUR AMIGA BEFORE USING IconV9"
	)
 
(exit)

