scheme.tpl 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156
  1. [+ autogen5 template -*- Scheme -*- am +]
  2. [+ #|
  3. scheme.tpl - scheme function definitions to be included by main.tpl
  4. Copyright (C) 2015 Alex Vong
  5. This program is free software; you can redistribute it and/or
  6. modify it under the terms of the GNU General Public License
  7. as published by the Free Software Foundation; either version 2
  8. of the License, or (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software Foundation,
  15. Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |# +]
  16. [+
  17. ;; generate file name converter
  18. ;; evaluate to a function
  19. (define (generate-name-converter text-to-be-appended)
  20. (define (append-path name)
  21. (string-substitute name
  22. " "
  23. text-to-be-appended))
  24. (lambda (. name-list)
  25. (apply string-append (map append-path name-list))))
  26. ;; append `$(srcdir)/src/' to source file name
  27. (define source-name->path-name
  28. (generate-name-converter " $(srcdir)/src/"))
  29. ;; append `$(srcdir)/html/' to html file name
  30. (define html-name->path-name
  31. (generate-name-converter " $(srcdir)/html/"))
  32. ;; append `$(srcdir)/doc/' to documentation file name
  33. (define documentation-name->path-name
  34. (generate-name-converter " $(srcdir)/doc/"))
  35. ;; append `$(srcdir)/patch/' to patch file name
  36. (define patch-name->path-name
  37. (generate-name-converter " $(srcdir)/patch/"))
  38. ;; append `$(srcdir)/scripts/' to script file name
  39. (define script-name->path-name
  40. (generate-name-converter " $(srcdir)/scripts/"))
  41. ;; append `$(srcdir)/am/' to autogen template and definition file name
  42. (define template-name->path-name
  43. (generate-name-converter " $(srcdir)/am/"))
  44. ;; append `$(srcdir)/COPYING.d/' to license file name
  45. (define license-name->path-name
  46. (generate-name-converter " $(srcdir)/COPYING.d/"))
  47. ;; append directory name to object file name
  48. (define (object-name->path-name dir-name . name-list)
  49. (define path (string-append " " dir-name))
  50. (define (append-path name)
  51. (string-substitute name
  52. " "
  53. path))
  54. (apply string-append (map append-path name-list)))
  55. ;; append `../' to the path name
  56. (define (append-prev-dir . name-list)
  57. (define (append-path name)
  58. (string-substitute name
  59. " "
  60. " ../"))
  61. (apply string-append (map append-path name-list)))
  62. ;; change `.c' extension to `.o' extension
  63. (define (source-name->object-name . name-list)
  64. (define (change-extension name)
  65. (string-substitute name
  66. ".c"
  67. ".o"))
  68. (apply string-append (map change-extension name-list)))
  69. ;; argument folding
  70. ;; "abc"-> "abc"
  71. ;; '("a" "b" "c") -> "a b c"
  72. (define (fold-arg arg)
  73. (if (not (list? arg))
  74. arg
  75. (string-join arg)))
  76. ;; list of arguments used by all rules
  77. (define arg-list
  78. '("?target-name?" "?target?" "?ingredient?" "?echo?" "?dir-name?"))
  79. ;; generic rule generator
  80. (define (generate-rule . args)
  81. (string-substitute
  82. (get "rule")
  83. (cons "?command?" arg-list)
  84. (map fold-arg args)))
  85. ;; compilation rule generator
  86. (define (generate-compilation-rule . args)
  87. (define full-arg-list (cons (get "compilation_rule") arg-list))
  88. (string-substitute
  89. (apply generate-rule full-arg-list)
  90. (cons "?ingredient-path-name?" (cons "?compilation-flag?" arg-list))
  91. (map fold-arg args)))
  92. ;; srcipt making rule generator
  93. (define (generate-script-making-rule . args)
  94. (define sed-scripts
  95. (string-join (map (lambda (variable)
  96. (string-substitute (get "sed_script")
  97. "?variable?"
  98. variable))
  99. (car args))))
  100. (define sed-command
  101. (string-substitute (get "make_script_rule")
  102. "?sed-scripts?"
  103. sed-scripts))
  104. (define full-arg-list (cons sed-command arg-list))
  105. (string-substitute
  106. (apply generate-rule full-arg-list)
  107. (cons "?ingredient-path-name?" arg-list)
  108. (map fold-arg (cdr args))))
  109. ;; generate automake conditional
  110. ;; (if-use-threads "I am " "using threads" "not using threads") ->
  111. ;; "if USE_THREADS
  112. ;; I am using threads
  113. ;; else
  114. ;; I am not using threads
  115. ;; endif"
  116. (define (if-use-threads . args)
  117. (define (am_conditional share use-threads do-not-use-threads)
  118. (string-append "if USE_THREADS\n"
  119. share use-threads
  120. "\nelse\n"
  121. share do-not-use-threads
  122. "\nendif"))
  123. (apply am_conditional (map fold-arg args)))
  124. ;; generate sse2, avx and avx2 rules from a single amd64 rule
  125. ;; (amd64-rules->sse2-avx-avx2-rules "capitalize amd64 will give AMD64") ->
  126. ;; "capitalize sse2 will give SSE2
  127. ;; capitalize avx will give AVX
  128. ;; capitalize avx2 will give AVX2"
  129. (define (amd64-rules->sse2-avx-avx2-rules rule)
  130. (define (make-rule instruction)
  131. (string-substitute rule
  132. (list "amd64" "AMD64")
  133. (list instruction (string-upcase instruction))))
  134. (string-join (map make-rule '("sse2" "avx" "avx2")) "\n")) +]