define.bat 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. @echo off
  2. rem tools/define.bat
  3. rem
  4. rem Licensed to the Apache Software Foundation (ASF) under one or more
  5. rem contributor license agreements. See the NOTICE file distributed with
  6. rem this work for additional information regarding copyright ownership. The
  7. rem ASF licenses this file to you under the Apache License, Version 2.0 (the
  8. rem "License"); you may not use this file except in compliance with the
  9. rem License. You may obtain a copy of the License at
  10. rem
  11. rem http://www.apache.org/licenses/LICENSE-2.0
  12. rem
  13. rem Unless required by applicable law or agreed to in writing, software
  14. rem distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
  15. rem WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
  16. rem License for the specific language governing permissions and limitations
  17. rem under the License.
  18. rem Handle command line options
  19. rem [-h] <compiler-path> <def1> [-val <val1>] [<def2> [-val <val2>] [<def3> [-val <val3>] ...]]
  20. rem [-w] [-d] ignored for compatibility with define.sh
  21. set progname=%0
  22. :ArgLoop
  23. if "%1"=="-d" goto :NextArg
  24. if "%1"=="-w" goto :NextArg
  25. if "%1"=="-h" goto :ShowUsage
  26. goto :CheckCompilerPath
  27. :NextArg
  28. shift
  29. goto :ArgLoop
  30. :CheckCompilerPath
  31. if "%1"=="" (
  32. echo Missing compiler path
  33. goto :ShowUsage
  34. )
  35. set ccpath=%1
  36. shift
  37. set compiler=
  38. for /F %%i in ("%ccpath%") do set compiler=%%~ni
  39. if "%1"=="" (
  40. echo Missing definition list
  41. goto :ShowUsage
  42. )
  43. rem Check for some well known, non-GCC Windows native tools that require
  44. rem a special output format as well as special paths
  45. :GetFormat
  46. set fmt=std
  47. if "%compiler%"=="ez8cc" goto :SetZdsFormt
  48. if "%compiler%"=="zneocc" goto :SetZdsFormt
  49. if "%compiler%"=="ez80cc" goto :SetZdsFormt
  50. goto :ProcessDefinitions
  51. :SetZdsFormt
  52. set fmt=zds
  53. rem Now process each directory in the directory list
  54. :ProcessDefinitions
  55. set response=
  56. :DefinitionLoop
  57. if "%1"=="" goto :Done
  58. set varname=%1
  59. shift
  60. rem Handle the output depending on if there is a value for the variable or not
  61. if "%1"=="-val" goto :GetValue
  62. rem Handle the output using the selected format
  63. :NoValue
  64. if "%fmt%"=="zds" goto :NoValueZDS
  65. :NoValueStandard
  66. rem Treat the first definition differently
  67. if "%response%"=="" (
  68. set response=-D%varname%
  69. goto :DefinitionLoop
  70. )
  71. set response=%response% -D%varname%
  72. goto :DefinitionLoop
  73. :NoValueZDS
  74. rem Treat the first definition differently
  75. if "%response%"=="" (
  76. set response=-define:%varname%
  77. goto :DefinitionLoop
  78. )
  79. set response=%response% -define:%varname%
  80. goto :DefinitionLoop
  81. rem Get value following the variable name
  82. :GetValue
  83. shift
  84. set varvalue=%1
  85. shift
  86. rem Handle the output using the selected format
  87. if "%fmt%"=="zds" goto :ValueZDS
  88. :ValueStandard
  89. rem Treat the first definition differently
  90. if "%response%"=="" (
  91. set response=-D%varname%=%varvalue%
  92. goto :DefinitionLoop
  93. )
  94. set response=%response% -D%varname%=%varvalue%
  95. goto :DefinitionLoop
  96. :ValueZds
  97. rem Treat the first definition differently
  98. if "%response%"=="" (
  99. set response=-define:%varname%=%varvalue%
  100. goto :DefinitionLoop
  101. )
  102. set response=%response% -define:%varname%=%varvalue%
  103. goto :DefinitionLoop
  104. :Done
  105. echo %response%
  106. goto :End
  107. :ShowUsage
  108. echo %progname% is a tool for flexible generation of command line pre-processor
  109. echo definitions arguments for a variety of diffent ccpaths in a variety of
  110. echo compilation environments"
  111. echo USAGE:%progname% [-h] ^<compiler-path^> [-val ^<^val1^>] [^<def2^> [-val ^<val2^>] [^<def3^> [-val ^<val3^>] ...]]
  112. echo Where:"
  113. echo ^<compiler-path^>
  114. echo The full path to your ccpath
  115. echo ^<def1^> ^<def2^> ^<def3^> ...
  116. echo A list of pre-preprocesser variable names to be defined.
  117. echo [-val ^<val1^>] [-val ^<val2^>] [-val ^<val3^>] ...
  118. echo optional values to be assigned to each pre-processor variable.
  119. echo If not supplied, the variable will be defined with no explicit value.
  120. echo -h
  121. echo Show this text and exit
  122. :End