forked from zhuomingliang/dyncall
-
Notifications
You must be signed in to change notification settings - Fork 8
/
configure.rc
executable file
·234 lines (198 loc) · 5.85 KB
/
configure.rc
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
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
#!/bin/rc
#//////////////////////////////////////////////////////////////////////////////
#
# Copyright (c) 2007-2010 Daniel Adler <[email protected]>,
# Tassilo Philipp <[email protected]>
#
# Permission to use, copy, modify, and distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#//////////////////////////////////////////////////////////////////////////////
# --- configure settings ------------------------------------------------------
PACKAGE=dyncall
CONFIG_PREFIX=/usr/local #@@@
# --- output error message ----------------------------------------------------
fn error {
echo error: $*
exit 1
}
# --- output warning message --------------------------------------------------
fn warning {
echo warning: $*
}
# --- output info message -----------------------------------------------------
fn info {
echo $*
}
# --- print usage -------------------------------------------------------------
fn usage {
echo $PACKAGE' configuration shell-script'
echo 'Usage:'
echo ' configure [ options ]'
echo
echo 'Options:'
echo ' --help'
echo ' -h print this page'
#echo
#echo ' --target-x86 build for x86 architecture platform'
#echo ' --target-x64 build for x64 architecture platform'
#echo ' --target-ppc32 build for ppc32 architecture platform'
#echo ' --target-arm-arm build for ARM architecture platform (ARM mode)'
#echo ' --target-arm-thumb build for ARM architecture platform (THUMB mode)'
#echo
#echo ' --tool-pcc use Portable C Compiler'
#echo
#echo ' --asm-xa use Plan9 Assemblers (0a, 1a, 2a, etc.)'
#echo
#echo ' --config-release build release version (default)'
#echo ' --config-debug build debug version'
echo
exit 0
}
# --- guess operating system -------------------------------------------------
CONFIG_OS=()
fn guess_os {
CONFIG_OS='plan9'
info 'guess os '$CONFIG_OS
}
# --- guess architecture -----------------------------------------------------
CONFIG_ARCH=()
fn guess_arch {
CONFIG_ARCH='x86'
switch($cputype) {
case 386
CONFIG_ARCH='x86'
case amd64
CONFIG_ARCH='x64'
case arm
CONFIG_ARCH='arm32_arm'
case power
CONFIG_ARCH='ppc32'
case mips
CONFIG_ARCH='mips32'
case *
warning 'unknown architecture '$cputype' - using default (x86)'
}
info 'guess arch '$CONFIG_ARCH
}
# --- guess tool chain -------------------------------------------------------
CONFIG_TOOL=()
fn guess_tool {
#CONFIG_TOOL=`{grep CC /$objtype/mkfile | sed s/CC.//}
CONFIG_TOOL='pcc'
info 'guess tool '$CONFIG_TOOL
}
# --- guess assembler --------------------------------------------------------
CONFIG_ASM=()
fn guess_asm {
CONFIG_ASM=`{grep AS /$objtype/mkfile | sed s/AS.//}
info 'guess assembler '$CONFIG_ASM
}
# --- process arguments ------------------------------------------------------
fn args {
while(! ~ $#* 0 && ~ $1 -*) {
OPT=$1
shift
switch($OPT) {
case --help -h
usage
#case --target-x86
#CONFIG_ARCH='x86'
#case --target-x64
#CONFIG_ARCH='x64'
#case --target-ppc32
#CONFIG_ARCH='ppc32'
#case --target-arm-arm
#CONFIG_ARCH='arm32_arm'
#case --target-arm-thumb
#CONFIG_ARCH='arm32_thumb'
#case --tool-pcc
#CONFIG_TOOL=pcc
#CONFIG_ASM=2a
#case --tool-xa
#CONFIG_ASM=2a
#case --config-release
#CONFIG_CONFIG=release
#case --config-debug
#CONFIG_CONFIG=debug
case *
warning 'unknown option '$OPT
}
}
}
# --- guess variables --------------------------------------------------------
fn guess {
if(~ $#CONFIG_OS 0) {
guess_os
if(~ $#CONFIG_OS 0) {
error 'unsupported operating system '$OS
}
}
if(~ $#CONFIG_ARCH 0) {
guess_arch
if(~ $#CONFIG_ARCH 0) {
error 'unsupported architecture '$ARCH
}
}
if(~ $#CONFIG_TOOL 0) {
guess_tool
if(~ $#CONFIG_TOOL 0) {
error 'no tool'
}
}
if(~ $#CONFIG_ASM 0) {
guess_asm
if(~ $#CONFIG_ASM 0) {
error 'no assembler tool'
}
}
if(~ $#CONFIG_CONFIG 0) {
CONFIG_CONFIG=release
}
}
# --- set default variables --------------------------------------------------
fn set_defaults {
CONFIG_HOST=$CONFIG_OS
}
# --- derive variables -------------------------------------------------------
fn derive_vars {
BUILD_HOST=$CONFIG_HOST
if(! ~ $CONFIG_HOST $CONFIG_OS) {
BUILD_HOST=$CONFIG_HOST'_'$CONFIG_OS
}
}
# --- write ConfigVars files ------------------------------------------------
fn output {
echo '#auto-generated by '$PACKAGE'/configure' >$1
echo 'CONFIG_PACKAGE='$PACKAGE >>$1
echo 'CONFIG_HOST='$CONFIG_HOST >>$1
echo 'CONFIG_OS='$CONFIG_OS >>$1
echo 'CONFIG_ARCH='$CONFIG_ARCH >>$1
echo 'CONFIG_TOOL='$CONFIG_TOOL >>$1
echo 'CONFIG_ASM='$CONFIG_ASM >>$1
echo 'CONFIG_CONFIG='$CONFIG_CONFIG >>$1
echo 'CONFIG_PREFIX='$CONFIG_PREFIX >>$1
if(! ~ $#CONFIG_BUILDPREFIX 0) {
echo 'CONFIG_BUILDPREFIX='$CONFIG_BUILDPREFIX >>$1
}
echo '' >>$1
}
# --- main -------------------------------------------------------------------
fn main {
args $*
info '* configure package '$PACKAGE
guess
set_defaults
derive_vars
output ConfigVars
}
main $*