; Installiert die neuen Interfaces und compiliert alles neu
; Installs the new interfaces and recompiles everything
;
; © 1994 by Thomas Wagner [tom];  E-Mail: tom@oak.nbg.sub.org
;
; Permission granted to include to Interfaces edited by hartmut Goebel
; and the Amiga Oberon Distribution.
;
; $VER: Compile_All_2 2.1 (12.12.94)
;
; KEINE HAFTUNG
;
; Die Tabulatorlänge sollte auf 4 gesetzt werden, um diesen Text zu lesen/editieren
; set tabsize to 4 to read/edit this text

;
; Die folgenden Angaben muß man an die Distribution anpassen:
; Adapt the following lines to your distribution
;

;(set interfaces-format "archive")        ; Interfaces liegen als Archiv vor
;(set archivename "Interfaces3_6.lha")

(set interfaces-format "dir")             ; Interfaces liegen entpackt in einem Directory
(set intdirname "Interfaces")
(set objdirname "obj")

;
; Strings
;

(if (= @language "deutsch")
(
(if (= interfaces-format "archive")
	(set #start
		(cat "\n© 1994 by Thomas Wagner [tom]\n"
			 "*********************************\n\n"
			 "Mit diesem Skript kann man die Interfaces Version %ld.%ld Oberon %ld.%ld "
			 "installieren und alle System- und Objekt-Files von "
			 "Amiga Oberon neu erzeugen.\n\n"
			 "Da das Archiv entpackt wird, benötigt es LHA im Suchpfad.\n\n"
			 "Wenn der Diskettenname ein '#' enthält, muß die Schublade erst "
			 "z.B. ins RAM: kopiert werden, da LHA das nicht verkraftet."
		)
	)
	(set #start
		(cat "\n© 1994 by Thomas Wagner [tom]\n"
			 "*********************************\n\n"
			 "Mit diesem Skript kann man die Interfaces Version %ld.%ld Oberon %ld.%ld "
			 "installieren und alle System- und Objekt-Files von "
			 "Amiga Oberon neu erzeugen.\n\n"
		)
	)
)

(debug "DIESES SKRIPT NICHT VOM CLI STARTEN, SONST WIRD ES FEHLSCHLAGEN!")

(set #copy-interfaces
	(cat "\n\nSoll ich die Interfaces kopieren?\n\n"
		"Wenn sich die Interfaces auf einem read-only Medium "
		"befinden, müssen Sie beim Compilieren sonst viele Requester "
		"'Laufwerk Bla: ist schreibgeschützt'\nabbrechen. "
		"AmigaOberon versucht nämlich, (nicht-existierende) "
		"alte Fehlerdateien zu löschen."
	)
)

(set #select-comp
	(cat "Jetzt müssen noch die Symbol- und Objekt-Files erstellt werden. "
		 "Bitte wählen Sie, welche Objekt-Files ich erstellen soll."
	)
)

(set #compilation
	(cat "Ich compiliere jetzt mit den von Ihnen gewünschten Parametern.\n\n"
		 "Bitte haben Sie etwas Geduld. Dieser Teil dauert etwas länger...\n\n"
		 "Ich erzeuge gerade die *.obj%s-Files."
	)
)

(set #where-to-interfaces "In welches Verzeichnis soll ich die Interfaces entpacken/kopieren?")
(set #where-are-modules "Wo sind die Module?")
(set #where-are-syms
	(cat "In welchem gemeinsamen (Ober-)Verzeichnis befindet sich sowohl "
		 "das Verzeichnis \"sym\" also auch \"obj\", bzw. wo sollen diese "
		 "angelegt werden?"
	)
)

(set #version-warning
	(cat "Warnung:\n\nDie bereits installierte Version ist gleich oder höher "
		 "als diese Version.\n\nAlt: %ld.%ld\nNeu: %ld.%ld\n\n"
		 "Soll ich wirklich weitermachen?"
	)
)

(set #where-is-list "Welche Compilerversion verwenden sie?")

(set #comp-old "niedriger als 3.10")
(set #comp-new "3.10 oder höher")

(set #where-is-oberon "In welchem Verzeichnis ist der Oberon Compiler?")

(set #extracting "Entpacke Daten ...")
(set #copying "Kopiere Interfaces ...")

))

(if (= @language "english")
(
(if (= interfaces-format "archive")
	(set #start
		(cat "\n© 1994 by Thomas Wagner [tom]\n"
			 "*********************************\n\n"
			 "With this script you can install the interfaces version "
             "%ld.%ld Oberon %ld.%ld and recreate all system and objekt files of "
			 "Amiga Oberon.\n\n"
			 "Thus the archive will be unpacked, it needs LHA in the search path.\n\n"
			 "If the volume name contains '#' the drawer must be copied to e.g. "
			 "RAM: first, because LHA can't handle this."
		)
	)
	(set #start
		(cat "\n© 1994 by Thomas Wagner [tom]\n"
			 "*********************************\n\n"
			 "With this script you can install the interfaces version "
             "%ld.%ld Oberon %ld.%ld and recreate all system and objekt files of "
			 "Amiga Oberon.\n\n"
		)
	)
)

(debug "DO NOT RUN THIS SCRIPT FROM CLI OR IT WILL PROBABLY FAIL!")

(set #copy-interfaces
	(cat "\n\nShould I copy the interfaces?\n\n"
		"If the Interface sources are on a read-only media "
		"you else have to cancel a lot requesters\n"
		"'Volume Bla: is write protected' when compiling, "
		"since AmigaOberon tries to delete (non-existent) "
		"old error files."
	)
)

(set #select-comp
	(cat "Now the symbol and object files have to be created. "
		 "Please select which type of object files should be created."
	)
)

(set #compilation
	(cat "I compile with you selected parameters.\n\n"
		 "Please be patient. This part will take some time...\n\n"
		 "I now create the *.obj%s files."
	)
)

(set #where-to-interfaces "Into which dir I should extract/copy the interfaces?")
(set #where-are-modules "Where are the modules?")
(set #where-are-syms
	(cat "In which common (main-)directory are your \"sym\" AND \"obj\" "
		 "drawer, or in which directory should they be created?"
	)
)

(set #version-warning
	(cat "Warning:\n\nYour installed version ist equal or higher "
		 "than this version.\n\nold: %ld.%ld\nnew: %ld.%ld\n\n"
		 "Should I really proceed?"
	)
)

(set #where-is-list "Which compiler version do you use?")

(set #comp-old "lower than 3.10")
(set #comp-new "3.10 or higher")

(set #where-is-oberon "In which directory is your compiler?")

(set #extracting "Extracting from archive ...")
(set #copying "Copy interfaces ...")

))

;--------------------------------------------------------
; compile modules and interfaces

(set new-vernum (getversion (tackon (pathonly @icon) "interfaces.version")))
(set new-ver (/ new-vernum 65536))
(set new-rev (- new-vernum (* new-ver 65536) ) )

(set incl-vernum (getversion (tackon (pathonly @icon) "includes.version")))
(set incl-ver (/ incl-vernum 65536))
(set incl-rev (- incl-vernum (* incl-ver 65536) ) )

(message (#start incl-ver incl-rev new-ver new-rev))

(welcome)

(set @default-dest "OBERON:")

(if (exists "oberon:interfaces.version")
	(
		(set old-vernum (getversion "oberon:interfaces.version"))
		(set old-ver (/ old-vernum 65536))
		(set old-rev (- old-vernum (* old-ver 65536) ) )
		(if (>= old-vernum new-vernum)
			(if (NOT (askbool
					(prompt (#version-warning old-ver old-rev new-ver new-rev))
					(help @askbool-help)
					(choices "Proceed" "Abort")
				))
				(exit (quiet))
			)
		)
	)
)

(set obfull
	(askdir
		(prompt #where-is-oberon)
		(help @askfile-help)
		(default @default-dest)
;		(newpath)
	)
)

(set comp
	(askoptions
		(prompt #select-comp)
		(help @askoptions-help)
		(choices " <    > (*.obj)"
				 " <-md > (*.objs)"
				 " <-a  > (*.obja)"
				 " <-mda> (*.objsa)"
		)
		(default 15)
	)
)

(set obfull (tackon obfull "Oberon"))

(set copy-interfaces
	(askbool
		(prompt #copy-interfaces)
		(help @askbool-help)
	)
)

(if copy-interfaces
	(set interfaces-dir
		(askdir
			(prompt #where-to-interfaces)
			(help @askdir-help)
			(default (tackon @default-dest "Interfaces"))
		)
	)
)

(set modules-dir
	(askdir
		(prompt #where-are-modules)
		(help @askdir-help)
		(default (tackon @default-dest "Module"))
	)
)

(set sym-dir
	(askdir
		(prompt #where-are-syms)
		(help @askdir-help)
		(default @default-dest)
	)
)

(set list (pathonly @icon))

(if
	(askbool
		(prompt #where-is-list)
		(help @askbool-help)
		(choices (#comp-old) (#comp-new))
	)
    (set list (tackon list "recomp.lst"))
    (set list (tackon list "recomp3_10.lst"))
)

(if (NOT (exists (tackon sym-dir "sym")))
	(makedir (tackon sym-dir "sym") (infos))
)

(if (NOT (exists (tackon sym-dir "obj")))
	(makedir (tackon sym-dir "obj") (infos))
)

(onerror (makeassign "objdir") (makeassign "AO_INSTALL_INTERFACES") (makeassign "AO_INSTALL_MODULES"))

(makeassign "AO_INSTALL_MODULES" modules-dir)

(if copy-interfaces
	(
		(makeassign "AO_INSTALL_INTERFACES" interfaces-dir)
		(makeassign "objdir" (tackon sym-dir "obj"))
    )
    (
		(makeassign "AO_INSTALL_INTERFACES" (tackon (pathonly @icon) intdirname))
		(makeassign "objdir" (tackon (pathonly @icon) objdirname))
    )
)

(if (= interfaces-format "archive")
	(
		(working #extracting)
		(run (cat "lha -x0 e " (tackon (pathonly @icon) archivename) " objdir: *.o"))
		(run (cat "lha -x0 e " (tackon (pathonly @icon) archivename) " AO_INSTALL_INTERFACES: *.mod"))
	)
	(if copy-interfaces
	(
			(copyfiles
				(prompt #copying)
				(source (tackon (pathonly @icon) intdirname))
				(dest "AO_INSTALL_INTERFACES:")
				(optional "askuser")
				(all)
			)
			(copyfiles
				(prompt #copying)
				(source (tackon (pathonly @icon) objdirname))
				(dest "objdir:")
				(optional "askuser")
				(all)
			)
	)
	)
)

(makeassign "objdir")

(set intro (cat "cd " sym-dir "\nstack 30000\n"))

(if (IN comp 0)
	(
		(working (#compilation ""))
		(textfile
			(prompt "")
			(help @textfile-help)
			(dest "T:OBINST")
			(append intro)
			(append (cat obfull " >CON: <" list "\n"))
		)
		(execute "T:OBINST")
		(run "delete T:OBINST")
	)
)

(if (IN comp 1)
	(
		(working (#compilation "s"))
		(textfile
			(prompt "")
			(help @textfile-help)
			(dest "T:OBINST")
			(append intro)
			(append (cat obfull " -md >CON: <" list "\n"))
		)
		(execute "T:OBINST")
		(run "delete T:OBINST")
	)
)

(if (IN comp 2)
	(
		(working (#compilation "a"))
		(textfile
			(prompt "")
			(help @textfile-help)
			(dest "T:OBINST")
			(append intro)
			(append (cat obfull " -a >CON: <" list "\n"))
		)
		(execute "T:OBINST")
		(run "delete T:OBINST")
	)
)

(if (IN comp 3)
	(
		(working (#compilation "sa"))
		(textfile
			(prompt "")
			(help @textfile-help)
			(dest "T:OBINST")
			(append intro)
			(append (cat obfull " -mda >CON: <" list "\n"))
		)
		(execute "T:OBINST")
		(run "delete T:OBINST")
	)
)

(copyfiles
	(prompt #copying)
	(source (tackon (pathonly @icon) "interfaces.version"))
	(dest "oberon:")
)

(copyfiles
	(prompt #copying)
	(source (tackon (pathonly @icon) "includes.version"))
	(dest "oberon:")
)


(makeassign "AO_INSTALL_INTERFACES")
(makeassign "AO_INSTALL_MODULES")
