; vbcc target installer
; written by Frank Wille <frank@phoenix.owl.de>

(set #incdir "vincludeos3")
(set #libdir "vlibos3")


(if (< (/ @installer-version 65536) 43)
  (abort "You are running an old version of Installer.\n\n"
         "Please update to at least version 43, available on Aminet.")
)

(message "You may need the header files from the AmigaOS 3.9 NDK. Please make sure they are already installed before proceeding.")
(welcome)

(if (exists "vbcc:" (noreq))
  (
    (set @default-dest "vbcc:")
    (set #targets (tackon @default-dest "targets"))
    (set #targetname (substr @app-name 5))
    (set #vbccinc (tackon (tackon #targets #targetname) "include"))
    (set #vbcclib (tackon (tackon #targets #targetname) "lib"))

    (if (not (exists #targets)) (makedir #targets))

    (copyfiles
      (prompt "Copying config files.")
      (help @copyfiles-help)
      (source "config")
      (dest (tackon @default-dest "config"))
      (optional "force")
      (all)
    )

    (copyfiles
      (prompt ("Copying include files and libraries for target %s." #targetname))
      (help @copyfiles-help)
      (source (tackon "targets" #targetname))
      (dest (tackon #targets #targetname))
      (optional "force")
      (all)
    )

    (set #stdhdr
      (askdir
        (prompt "Please locate the system headers directory.")
        (help "This directory will be added to vbcc's "
              "standard include path.")
        (default "include:")
        (disk)
      )
    )

    (startup @app-name
      (prompt "Performing changes to User-Startup.")
      (help
        (cat
          "The following commands will be added to your "
          "SYS:S/User-Startup file:\n"
          "1. An assignment " #incdir ":.\n"
          "2. An assignment " #libdir ":.\n"
        )
      )
      (confirm)
      (command (cat "assign >NIL: " #incdir ": " #vbccinc "\n"))
      (command (cat "assign >NIL: " #incdir ": \"" #stdhdr "\" add\n"))
      (command (cat "assign >NIL: " #libdir ": " #vbcclib "\n"))
    )

    (if (not (exists #incdir (noreq)))
      (
        (makeassign #incdir #vbccinc)
        (run (cat "assign >NIL: " #incdir ": \"" #stdhdr "\" add"))
      )
    )
    (if (not (exists #libdir (noreq))) (makeassign #libdir #vbcclib))
  )

  (exit "Please install a vbcc-binary archive first!" (quiet))
)
