;;; -*- Lisp-Interaction -*-	  ;;;  Version: 05-Dec-94	;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  GNU C Installation script for AmigaDOS
;;;
;;;  This program is free software; you can redistribute it and/or modify
;;;  it under the terms of the GNU General Public License as published by
;;;  the Free Software Foundation; either version 2 of the License, or
;;;  (at your option) any later version.
;;;
;;;  This program is distributed in the hope that it will be useful,
;;;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
;;;  GNU General Public License for more details.
;;;
;;;  You should have received a copy of the GNU General Public License
;;;  along with this program; if not, write to the Free Software
;;;  Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
;;;
;;;
;;;  Author:   Jochen Wiedmann
;;;	 Am Eisteich 9
;;;	 72555 Metzingen
;;;	 Germany
;;;
;;;	 Phone: (0049) +7123 / 14881
;;;	 Internet: jochen.wiedmann@uni-tuebingen.de
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Variable settings
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set @GNUC-Version "2.6.0")
(set @GNUC-Version-Short "gcc260")

(transcript "Installing AmigaDOS-GNU Version " @GNUC-Version "...")


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Check, if we are running OS2.04 or higher
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(set ver (/ (getversion "exec.library" (resident)) 65536))
(if (< ver 37)
    (abort "Sorry, gcc needs Kickstart/Workbench 2.04 or higher.")
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Startup message
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(message "GNU C:    The GNU Project C and C++ Compiler\n\n"
    "V" @GNUC-Version "     1994 Free Software Foundation  \n\n"
    "This program is FREE SOFTWARE; you can redistribute it and/or "
    "modify it under the terms of the GNU General Public License as "
    "published by the Free Software Foundation; either version 2 "
    "or any later version.\n\n"
    "This program is distributed in the hope that it will be useful, "
    "but WITHOUT ANY WARRANTY! See the GNU General Public License "
    "(in the file COPYING) for details."
)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Check, if GNU: or GCC: already exists.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (<> "" (getassign "GNU" "vad"))
    (   (set @GNUC-installed-Dir (getassign "GNU" "vad"))
	(set @default-dest (pathonly @GNUC-installed-Dir))
	(set @GNUC-installed 1)
)
(   (if (<> "" (getassign "GCC" "vad"))
    (   (set @GNUC-installed-Dir (getassign "GCC" "vad"))
	(set @default-dest (pathonly @GNUC-installed-Dir))
	(set @GNUC-installed 1)
    )
    (   (set @default-dest "SYS:")
	(set @GNUC-installed 0)
    ))
))


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Let the user select a place for "GNU:"
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(message "GNU C is completely installed in one directory called GNU. "
    "Typical places are Work:GNU or similar."
    "\n\nWe start with selecting the parent directory of GNU, "
    "so that I can unarchive the LhA files to this place."
    "\nAn assign GNU: will lead to this directory later, binaries "
    "will be in GNU:bin, link libraries in GNU:lib and so on."
    "\n\nIf you have any problems with this installation script, send "
    "mail to"
    "\njochen.wiedmann@zdv.uni-tuebingen.de"
)
(set @GNU-dir-Parent (askdir
    (prompt "Please select the directory the installation directory. "
	    "(A subdirectory GNU will be created.)"
    )
    (help "GNU C is installed in a directory called `GNU:'. For "
	  "example, binaries go into `GNU:bin', link libraries in "
	  "`GNU:lib' and so on.\n\n"
	  "A typical place is something like `Work:GNU' or something "
	  "similar. In this example you should select the directory "
	  "`Work:'.\n\n"
	  @askdir-help)
    (default @default-dest)
    (newpath)
))
(set @GNU-dir (tackon @GNU-dir-Parent "GNU"))
(complete 5)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Deinstall previous GNU C versions.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(procedure Delete-File
(   (if (exists Delete-File-Name)
    (   (run ("C:Delete %s ALL QUIET FORCE" Delete-File-Name)
	     (prompt ("\n\nDeleting %s ..." Delete-File-Name))
	)
    ))
))

(if @GNUC-installed
(   (set @GNU-installed-LibDir (tackon @GNU-dir "lib/gcc-lib"))
    (if (patmatch @GNU-dir @GNUC-installed-Dir)
    (   (if (exists @GNU-installed-LibDir)
	(   (if (askbool
		    (prompt "\nYou seem to have installed a previous version "
			    "of GNU C in `" @GNUC-installed-Dir "'."
			    "\n\nShould I deinstall it? (Delete directory "
			    (tackon @GNU-dir "lib/gcc-lib") "?"
		    )
		    (help "`GNU:' or `GCC:' is already assigned to `"
			  @GNUC-installed-Dir "'. "
			  "I suppose that this directory contains a previous "
			  "version of GNU C. Most files and directories are just "
			  "overwritten in what follows except for `"
			  @GNU-installed-LibDir "'."
			  "\n\nYou might wish to delete this directory now "
			  "in order to safe disk space."
			  "\n\n"
			  @askbool-help
		    )
		    (default 1)
		)
	    (   (set Delete-File-Name @GNU-installed-LibDir)
		(Delete-File)
		(set Delete-File-Name (tackon @GNU-dir "lib/libamiga.a"))
		(Delete-File)
		(set Delete-File-Name (tackon @GNU-dir "lib/libb/libamiga.a"))
		(Delete-File)
	    ))
	))
    )
    (   (if (askbool
		(prompt "\nYou seem to have installed a previous version "
			"of GNU C in `" @GNUC-installed-Dir "'."
			"\n\nShould I delete this directory?"
		)
		(help "GNU: or GCC: is already assigned to `"
		      @GNUC-installed-Dir "'. "
		      "I suppose that this directory contains a previous "
		      "version of GNU C."
		      "\n\nIf this is true, you might delete it now in "
		      "order to safe disk space."
		      "\n\n" @askbool-help
		)
		(default 1)
	    )
	(   (set Delete-File-Name (tackon @GNUC-installed-Dir "#?"))
	    (Delete-File)
	    (message "\nOk, I have deleted all subdirectories and files "
		     "in " @GNUC-installed-Dir "."
		     "\n\nNote, that I cannot remove `" @GNUC-installed-Dir
		     "'itself, because the assign `GNU:' is still valid."
		     "\n\nYou should do this manually."
	    )
	))
    ))
))
(complete 10)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Let the user decide, if the script should unarchive.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (askbool
	(prompt "\n\nShould I unpack the archives for you?")
	(help "GNU C is distributed in different archives. These "
	      "must be unpacked using the program LhA. We'll do "
	      "this now in case you didn't already."
	)
	(default 1)
    )
(   (complete 15)
    (set @loop 1)
    (while @loop
    (   (set LHA-PROG (askfile
	    (prompt "Please select your LhA program.")
	    (help "Unfortunately the Installer program ignores "
		  "your path settings. Thus I need to know the "
		  "complete path of your LhA program.\n\n"
		  @askfile-help
	    )
	    (default "C:")
	))
	(if (exists LHA-PROG)
	(   (set @loop 0)
	))
    ))
    (complete 20)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Let the user select, which parts of gcc should be installed.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (set @GNUC-packages (askoptions
	    (prompt "Which parts of gcc should be installed?")
	    (choices "Base distribution"
		     "Includes & Libraries"
		     "C"
		     "C++"
		     "Objective-C"
		     "Additional Utilities"
		     "On-line Documentation"
		     "Utilities On-line Documentation"
		     "Source Diffs"
		     "Documentation sources")
	    (default 71)
	    (help "gcc is distributed in different LhA archives. "
		  "I will unarchive those parts to " @GNU-Dir
		  " that you select.\n\n"
		  "A minimal installation requires base distribution, "
		  "Includes & Libraries and the C distribution. This will take "
		  "about 7.5 MB of harddisk space. However, I recommend at least "
		  "adding the on-line documentation, so you get a minimum of "
		  "10 MB.\n\n"
		  @askoptions-help)
	)
    )
    (complete 25)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Ask the user, if he wants the 68020 binaries.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (set Install-020 "")
    (if (AND (NOT (OR (= (database "cpu") "68000")
		      (= (database "cpu") "68010")
	     ))
	    (BITAND @GNUC-packages 30)
	)
    (   (if (askbool
		(prompt "\n\nWould you like to have the 68020 binaries installed?")
		(help "The GNU C distribution offers two different binary versions. "
		      "If your machine's CPU is a 68020 or above, then you should "
		      "install the 68020 binaries. (Note, that this doesn't affect "
		      "the binaries created by you.)\n\n"
		      "Otherwise you should select `No'.\n\n"
		      @askbool-help
		)
		(default 0)
	    )
	(   (set Install-020 "-020")
	))
    ))
    (complete 30)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Unpack the archives
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
    (set @Default-Archive-Path "")
    (if (<> (substr @GNU-Dir-Parent (- (strlen @GNU-Dir-Parent) 1)) ":")
    (   (set @GNU-Dir-Parent (cat @GNU-Dir-Parent "/"))
    ))
    (set LHA-COMMAND (cat LHA-PROG " x -q -I \"%s\" " @GNU-Dir-Parent))

    (procedure UnPack-Archive
    (   (set @loop 1)
	(while @loop
	(   (set Install-Archive (askfile
		(prompt ("Please select the archive file %s for unpacking."
			 Install-Archive-Name
		))
		(help (cat ("Please select the archive file %s. "
			    Install-Archive-Name)
			   "I will unpack this archive to " @GNU-Dir ".\n\n"
			   @askfile-help
		))
		(default (tackon @Default-Archive-Path Install-Archive-Name))
	    ))
	    (set @Default-Archive-Path (pathonly Install-Archive))
	    (if (exists Install-Archive)
	    (   (set @loop 0)
		(if (run (LHA-COMMAND Install-Archive)
			(prompt ("\n\nUnpacking %s ..." Install-Archive))
		    )
		(   (abort "\n\n" (LHA-COMMAND Install-Archive) "\n\nshowed an error.")
		))
	    )
	    (   (message "File " Install-Archive " does not exist.")
		(set Install-Archive "")
	    ))
	))
    ))


    (set n 0)
    (set complete-level 40)
    (set bit 1)
    (while (set Install-Archive-Name (select n
		(cat @GNUC-Version-Short "-base.lha")
		(cat @GNUC-Version-Short "-inclib" Install-020 ".lha")
		(cat @GNUC-Version-Short "-c" Install-020 ".lha")
		(cat @GNUC-Version-Short "-c++" Install-020 ".lha")
		(cat @GNUC-Version-Short "-objc" Install-020 ".lha")
		(cat @GNUC-Version-Short "-utils.lha")
		(cat @GNUC-Version-Short "-doc.lha")
		(cat @GNUC-Version-Short "-utilsdoc.lha")
		(cat @GNUC-Version-Short "-diffs.lha")
		(cat @GNUC-Version-Short "-texi.lha")
		""
	   ))
    (   (if (BITAND @GNUC-packages bit)
	(   (UnPack-Archive)
	))
	(complete complete-level)
	(set complete-level (+ complete-level 5))
	(set bit (shiftleft bit 1))
	(set n (+ n 1))
    ))
))
(complete 85)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Copying environment variables
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if @GNUC-installed
(   (copyfiles
	(prompt "Installing environment variables in `ENVARC:' ...\n\n")
	(help "You seem to have already installed GNU C.\n\n"
	      "If you have modified certain environment variables "
	      "like LESSCHARSET, PAGER or TERM, you might keep this "
	      "modifications instead of overwriting them with my "
	      "default values. In that case you should compare "
	      "`GNU:envarc' with `ENVARC:' manually.\n\n"
	      @copyfiles-help)
	(confirm)
	(source (tackon @GNU-Dir "envarc"))
	(dest "ENVARC:")
	(all)
    )
))
(complete 90)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Modifying s:User-Startup
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(startup "GNU stuff"
    (command "Assign GNU: " @GNU-Dir "\n")
    (command "Execute GNU:s/User-Startup\n")
    (prompt "The following lines should be added to your s:User-Startup:\n\n"
	    "Assign GNU: " @GNU-Dir "\n"
	    "Execute GNU:s/User-Startup\n\n"
	    "Shall I do this now?"
    )
    (help "gcc needs a special environment, some assigns for example. "
	  "The easiest way to get this environment is to modify your "
	  "User-Startup file, so that it is created automatically when "
	  "your machine boots.\n\n"
	  @startup-help
    )
)
(complete 95)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Creating needed Links
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(if (askbool
	(prompt "\n\nSome files may be installed either as soft links "
		"or copied."
		"\n\nDo you want to use links?"
	)
	(help "\n\nAmigaDOS is still having problems with soft links. "
	      "Specifically the `Dir' and `List' commands don't know "
	      "them and show them as directories. (GNU ls, however, "
	      "is alright.) Thus you might prefer to copy files."
	      "\n\nOn the other hand soft links save disk space. "
	      "(Not very much.)"
	      @askbool-help
	)
	(default 0)
    )
(   (set MakeLink (cat "\"" (tackon @GNU-Dir "c/MakeLink") " SOFT FORCE\""))
)
(   (set MakeLink "\"C:Copy ALL QUIET\" COPY")
))
(execute (cat (tackon @GNU-Dir "s/RestoreLinks") " " @GNU-Dir " " MakeLink)
    (prompt "Creating Links ...")
)
(complete 100)


;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;
;;;  Done; tell the user to reboot.
;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(message "Now you have to reboot to activate new environment.\n"
	 "In case of errors, problems or whatever, please contact me at:"
	 "\n\nemail: phb@colombo.telesys-innov.fr"
	 "\nfidonet: 2:320/104.21 Ramses The Amiga Flying BBS"
)

