PageRenderTime 17ms CodeModel.GetById 11ms RepoModel.GetById 1ms app.codeStats 0ms

/source/core/frontend/BuildParams.ooc

http://github.com/nddrylliog/oc
Unknown | 96 lines | 78 code | 18 blank | 0 comment | 0 complexity | 297352e692e4f9020a5cd2d21f8c89da MD5 | raw file
  1. import io/File, os/Env, text/StringTokenizer
  2. import structs/[ArrayList, HashMap]
  3. import backend/Backend
  4. import DynamicLoader
  5. BUILD_DATE: extern CString
  6. BuildParams: class {
  7. VERSION := static "0.0"
  8. self := ""
  9. home := "."
  10. verbose := 0
  11. dump? := false
  12. leftOver: HashMap<String, String>
  13. sourcepath := ["."] as ArrayList<String>
  14. outpath := "oc_tmp"
  15. backend: Backend = null
  16. backendString := ""
  17. frontendString := ""
  18. init: func (map: HashMap<String, String>) {
  19. map each(|key, val| match key {
  20. case "sourcepath" =>
  21. sourcepath = val
  22. case "outpath" =>
  23. outpath = val
  24. case "frontend" =>
  25. frontendString = val
  26. case "backend" =>
  27. backendString = val
  28. case "dump" =>
  29. dump? = true
  30. case "v" || "verbose" =>
  31. verbose += 1
  32. case "V" =>
  33. "oc v%s - built on %s" printfln(VERSION, BUILD_DATE)
  34. exit(0)
  35. case "self" =>
  36. self = val
  37. case =>
  38. "Unknown option '%s', DO YOU KNOW THINGS THAT WE DON'T?" printfln(key)
  39. leftOver put(key, val)
  40. })
  41. locateHome()
  42. if(backendString == "") {
  43. if(verbose > 0) "No backend selected, using C89 backend" println()
  44. backendString = "c89"
  45. }
  46. if(frontendString == "") {
  47. if(verbose > 0) "No frontend selected, using nagaqueen backend" println()
  48. frontendString = "nagaqueen"
  49. }
  50. }
  51. locateHome: func {
  52. if(verbose > 0) "Should locate position of oc. Self = %s" printfln(self)
  53. selfFile := File new(self)
  54. if(selfFile exists?()) {
  55. // okay so we have a direct path to the exec - let's back out of bin/
  56. guess1 := selfFile getAbsoluteFile() parent() parent()
  57. if(verbose > 0) "Guess from direct path is %s" printfln(guess1 path)
  58. home = guess1 path
  59. return
  60. }
  61. // hmm let's search the path then
  62. path := Env get("PATH")
  63. if(path) {
  64. path split(File pathDelimiter) each(|folder|
  65. if(verbose > 0) "Looking in %s" printfln(folder)
  66. // whoever thought of adding '.exe' to executable files wasn't in his right mind -.-
  67. f := File new(folder, self)
  68. if(!f exists?()) {
  69. f = File new(folder, self + ".exe")
  70. if(!f exists?()) return
  71. }
  72. guess2 := f getAbsoluteFile() parent() parent()
  73. if(verbose > 0) "Guess from binary path is %s" printfln(guess2 path)
  74. home = guess2 path
  75. )
  76. }
  77. }
  78. }