1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
|
@echo off
rem tools/define.bat
rem
rem Copyright (C) 2012 Gregory Nutt. All rights reserved.
rem Author: Gregory Nutt <gnutt@nuttx.org>
rem
rem Redistribution and use in source and binary forms, with or without
rem modification, are permitted provided that the following conditions
rem are met:
rem
rem 1. Redistributions of source code must retain the above copyright
rem notice, this list of conditions and the following disclaimer.
rem 2. Redistributions in binary form must reproduce the above copyright
rem notice, this list of conditions and the following disclaimer in
rem the documentation and/or other materials provided with the
rem distribution.
rem 3. Neither the name NuttX nor the names of its contributors may be
rem used to endorse or promote products derived from this software
rem without specific prior written permission.
rem
rem THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
rem "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
rem LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
rem FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
rem COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
rem INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
rem BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
rem OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
rem AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
rem LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
rem ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
rem POSSIBILITY OF SUCH DAMAGE.
rem Handle command line options
rem [-h] <compiler-path> <def1> [-val <val1>] [<def2> [-val <val2>] [<def3> [-val <val3>] ...]]
rem [-w] [-d] ignored for compatibility with define.sh
set progname=%0
:ArgLoop
if "%1"=="-d" goto :NextArg
if "%1"=="-w" goto :NextArg
if "%1"=="-h" goto :ShowUsage
goto :CheckCompilerPath
:NextArg
shift
goto :ArgLoop
:CheckCompilerPath
if "%1"=="" (
echo Missing compiler path
goto :ShowUsage
)
set ccpath=%1
shift
set compiler=
for /F %%i in ("%ccpath%") do set compiler=%%~ni
if "%1"=="" (
echo Missing definition list
goto :ShowUsage
)
rem Check for some well known, non-GCC Windows native tools that require
rem a special output format as well as special paths
:GetFormat
set fmt=std
if "%compiler%"=="ez8cc" goto :SetZdsFormt
if "%compiler%"=="zneocc" goto :SetZdsFormt
if "%compiler%"=="ez80cc" goto :SetZdsFormt
goto :ProcessDefinitions
:SetZdsFormt
set fmt=zds
rem Now process each directory in the directory list
:ProcessDefinitions
set response=
:DefinitionLoop
if "%1"=="" goto :Done
set varname=%1
shift
rem Handle the output depending on if there is a value for the variable or not
if "%1"=="-val" goto :GetValue
rem Handle the output using the selected format
:NoValue
if "%fmt%"=="zds" goto :NoValueZDS
:NoValueStandard
rem Treat the first definition differently
if "%response%"=="" (
set response=-D%varname%
goto :DefinitionLoop
)
set response=%response% -D%varname%
goto :DefinitionLoop
:NoValueZDS
rem Treat the first definition differently
if "%response%"=="" (
set response=-define:%varname%
goto :DefinitionLoop
)
set response=%response% -define:%varname%
goto :DefinitionLoop
rem Get value following the variable name
:GetValue
shift
set varvalue=%1
shift
rem Handle the output using the selected format
if "%fmt%"=="zds" goto :ValueZDS
:ValueStandard
rem Treat the first definition differently
if "%response%"=="" (
set response=-D%varname%=%varvalue%
goto :DefinitionLoop
)
set response=%response% -D%varname%=%varvalue%
goto :DefinitionLoop
:ValueZds
rem Treat the first definition differently
if "%response%"=="" (
set response=-define:%varname%=%varvalue%
goto :DefinitionLoop
)
set response=%response% -define:%varname%=%varvalue%
goto :DefinitionLoop
:Done
echo %response%
goto :End
:ShowUsage
echo %progname% is a tool for flexible generation of command line pre-processor
echo definitions arguments for a variety of diffent ccpaths in a variety of
echo compilation environments"
echo USAGE:%progname% [-h] ^<compiler-path^> [-val ^<^val1^>] [^<def2^> [-val ^<val2^>] [^<def3^> [-val ^<val3^>] ...]]
echo Where:"
echo ^<compiler-path^>
echo The full path to your ccpath
echo ^<def1^> ^<def2^> ^<def3^> ...
echo A list of pre-preprocesser variable names to be defined.
echo [-val ^<val1^>] [-val ^<val2^>] [-val ^<val3^>] ...
echo optional values to be assigned to each pre-processor variable.
echo If not supplied, the variable will be defined with no explicit value.
echo -h
echo Show this text and exit
:End
|