uart: fix compilation on recent avr-gcc
[aversive.git] / config / generate_aversive_config
1 #!/bin/sh
2
3 #
4 # usage generate_aversive_config config_file dst_module_file
5 #
6
7
8 # order is important !! High level modules first (defines link order)
9 #
10 MODULES_LIST="CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL,/devices/brushless_motors/brushless_3phase_digital_hall
11               CONFIG_MODULE_BRUSHLESS_3PHASE_DIGITAL_HALL_DOUBLE,/devices/brushless_motors/brushless_3phase_digital_hall_double
12               CONFIG_MODULE_HOSTSIM,base/hostsim
13               CONFIG_MODULE_MENU,ihm/menu
14               CONFIG_MODULE_PARSE,ihm/parse
15               CONFIG_MODULE_RDLINE,ihm/rdline
16               CONFIG_MODULE_VT100,ihm/vt100
17               CONFIG_MODULE_LCD,devices/ihm/lcd
18               CONFIG_MODULE_MULTISERVO,devices/servo/multiservo
19               CONFIG_MODULE_AX12,devices/servo/ax12
20               CONFIG_MODULE_ENCODERS_SPI,devices/encoders/encoders_spi
21               CONFIG_MODULE_ENCODERS_MICROB,devices/encoders/encoders_microb
22               CONFIG_MODULE_ENCODERS_EIRBOT,devices/encoders/encoders_eirbot
23               CONFIG_MODULE_TRAJECTORY_MANAGER,devices/robot/trajectory_manager
24               CONFIG_MODULE_BLOCKING_DETECTION_MANAGER,devices/robot/blocking_detection_manager
25               CONFIG_MODULE_OBSTACLE_AVOIDANCE,devices/robot/obstacle_avoidance
26               CONFIG_MODULE_POSITION_MANAGER,devices/robot/position_manager
27               CONFIG_MODULE_ROBOT_SYSTEM,devices/robot/robot_system
28               CONFIG_MODULE_PID,devices/control_system/filters/pid
29               CONFIG_MODULE_RAMP,devices/control_system/filters/ramp
30               CONFIG_MODULE_QUADRAMP,devices/control_system/filters/quadramp
31               CONFIG_MODULE_QUADRAMP_DERIVATE,devices/control_system/filters/quadramp_derivate
32               CONFIG_MODULE_BIQUAD,devices/control_system/filters/biquad
33               CONFIG_MODULE_CONTROL_SYSTEM_MANAGER,devices/control_system/control_system_manager
34               CONFIG_MODULE_TIME,base/time
35               CONFIG_MODULE_SCHEDULER,base/scheduler
36               CONFIG_MODULE_CALLOUT,base/callout
37               CONFIG_MODULE_SPI,comm/spi
38               CONFIG_MODULE_CC2420,devices/radio/cc2420
39               CONFIG_MODULE_XBEE,devices/radio/xbee
40               CONFIG_MODULE_UART,comm/uart
41               CONFIG_MODULE_I2C,comm/i2c
42               CONFIG_MODULE_MF2_CLIENT,comm/mf2_client
43               CONFIG_MODULE_MF2_SERVER,comm/mf2_server
44               CONFIG_MODULE_PWM,hardware/pwm
45               CONFIG_MODULE_PWM_NG,hardware/pwm_ng
46               CONFIG_MODULE_ADC,hardware/adc
47               CONFIG_MODULE_AES,crypto/aes
48               CONFIG_MODULE_MD5,crypto/md5
49               CONFIG_MODULE_RC4,crypto/rc4
50               CONFIG_MODULE_HAMMING,encoding/hamming
51               CONFIG_MODULE_TIMER,hardware/timer
52               CONFIG_MODULE_BASE64,encoding/base64
53               CONFIG_MODULE_CIRBUF,base/cirbuf
54               CONFIG_MODULE_DIAGNOSTIC,debug/diagnostic
55               CONFIG_MODULE_ERROR,debug/error
56               CONFIG_MODULE_FIXED_POINT,base/math/fixed_point
57               CONFIG_MODULE_TIME_EXT,base/time_ext
58               CONFIG_MODULE_GEOMETRY,base/math/geometry
59               CONFIG_MODULE_VECT2,base/math/vect2"
60
61 echo
62 echo Generating aversive configuration files
63
64 # does the .config file exists ?
65 if [ ! -f $1 ]; then
66     echo "No such file <$1>"
67     exit 1
68 fi
69
70 echo "# Aversive configuration" > $2
71
72 ####
73 ##### MCU, compilation options, output format
74 ####
75
76 echo -n "MCU = " >> $2
77 echo `grep "CONFIG_MCU_.*=y" $1 | sed s,CONFIG_MCU_,, | sed s,=y,, | tr "[A-Z]" "[a-z]"` >> $2
78
79 echo -n "OPT = " >> $2
80 echo `grep "CONFIG_OPTM_.*=y" $1 | sed s,CONFIG_OPTM_,, | sed s,=y,, | tr "[A-Z]" "[a-z]"` >> $2
81
82 if grep "CONFIG_FORMAT_IHEX=y" $1 > /dev/null 2> /dev/null
83     then
84     echo "FORMAT = ihex" >> $2
85     echo "FORMAT_EXTENSION = hex" >> $2
86 fi
87
88 if grep "CONFIG_FORMAT_SREC=y" $1 > /dev/null 2> /dev/null
89     then
90     echo "FORMAT = srec" >> $2
91     echo "FORMAT_EXTENSION = srec" >> $2
92 fi
93
94 if grep "CONFIG_FORMAT_BINARY=y" $1 > /dev/null 2> /dev/null
95     then
96     echo "FORMAT = binary" >> $2
97     echo "FORMAT_EXTENSION = bin" >> $2
98 fi
99
100 ####
101 ##### Math lib and printf
102 ####
103
104 if grep "CONFIG_MATH_LIB=y" $1 > /dev/null 2> /dev/null
105     then
106     echo "MATH_LIB = -lm" >> $2
107 else
108     echo "MATH_LIB = " >> $2
109 fi
110
111 if grep "CONFIG_MINIMAL_PRINTF=y" $1 > /dev/null 2> /dev/null
112     then
113     echo "PRINTF_LDFLAGS = -Wl,-u,vfprintf -lprintf_min" >> $2
114 fi
115
116 if grep "CONFIG_STANDARD_PRINTF=y" $1 > /dev/null 2> /dev/null
117     then
118     echo "PRINTF_LDFLAGS = " >> $2
119 fi
120
121 if grep "CONFIG_ADVANCED_PRINTF=y" $1 > /dev/null 2> /dev/null
122     then
123     echo "PRINTF_LDFLAGS = -Wl,-u,vfprintf -lprintf_flt" >> $2
124 fi
125
126 if grep "CONFIG_FDEVOPEN_COMPAT=y" $1 > /dev/null 2> /dev/null
127     then
128     echo "CFLAGS += -D__STDIO_FDEVOPEN_COMPAT_12" >> $2
129 fi
130
131 if grep "CONFIG_MODULE_HOSTSIM=y" $1 > /dev/null 2> /dev/null
132     then
133     echo "PTHREAD_CFLAGS = -pthread" >> $2
134     echo "PTHREAD_LDFLAGS = -pthread" >> $2
135 fi
136
137
138
139 ####
140 ##### Programmer
141 ####
142
143 if grep "CONFIG_AVRDUDE=y" $1 > /dev/null 2> /dev/null
144     then
145     echo "PROGRAMMER = avrdude" >> $2
146 fi
147
148 echo -n "AVRDUDE_PROGRAMMER = " >> $2
149 echo `grep "CONFIG_AVRDUDE_PROG_.*=y" $1 | sed s,CONFIG_AVRDUDE_PROG_,, | sed s,=y,, | tr [A-Z_] [a-z\-]` >> $2
150
151 echo -n "AVRDUDE_PORT = " >> $2
152 echo `grep "CONFIG_AVRDUDE_PORT" $1 | sed s,CONFIG_AVRDUDE_PORT=,,` >> $2
153
154 echo -n "AVRDUDE_BAUDRATE = " >> $2
155 echo `grep "CONFIG_AVRDUDE_BAUDRATE" $1 | sed s,CONFIG_AVRDUDE_BAUDRATE=,,` >> $2
156
157 if grep "CONFIG_AVRDUDE_CHECK_SIGNATURE=y" $1 > /dev/null 2> /dev/null
158     then
159     echo "AVRDUDE_FLAGS_SIGNATURE_CHECK =" >> $2
160 else
161     echo "AVRDUDE_FLAGS_SIGNATURE_CHECK = -F" >> $2
162 fi
163
164
165 if grep "CONFIG_AVARICE=y" $1 > /dev/null 2> /dev/null
166     then
167     echo "PROGRAMMER = avarice" >> $2
168     if ! grep "CONFIG_FORMAT_BINARY=y" $1 > /dev/null 2> /dev/null
169         then
170         echo "WARNING: With avarice, output format should be binary"
171     fi
172 fi
173
174 if grep "CONFIG_AVARICE_PROG_MKI=y" $1 > /dev/null 2> /dev/null
175     then
176     echo "AVARICE_PROGRAMMER = mkI" >> $2
177 fi
178
179 if grep "CONFIG_AVARICE_PROG_MKII=y" $1 > /dev/null 2> /dev/null
180     then
181     echo "AVARICE_PROGRAMMER = mkII" >> $2
182 fi
183
184 echo -n "AVARICE_PORT = " >> $2
185 echo `grep "CONFIG_AVARICE_PORT" $1 | sed s,CONFIG_AVARICE_PORT=,,` >> $2
186
187 echo -n "AVARICE_DEBUG_PORT = " >> $2
188 echo `grep "CONFIG_AVARICE_DEBUG_PORT" $1 | sed s,CONFIG_AVARICE_DEBUG_PORT=,,` >> $2
189
190
191 ####
192 ##### Generation of the module list
193 ####
194 echo -n "MODULES =" >> $2
195
196 for i in $MODULES_LIST
197 do
198   config=`echo $i | cut -d ',' -f1-1`
199   path=`echo $i | cut -d ',' -f2-2`
200   
201
202   if grep $config=y $1 2>/dev/null >/dev/null
203       then
204       echo -n " "$path >> $2
205   fi
206
207   if grep -q "${config}_CREATE_CONFIG=y" $1; then
208       CONF_FILE=`basename $path`_config.h
209       if [ -f $CONF_FILE ]
210           then
211           echo Cannot create default conf file $CONF_FILE, file exists
212       else
213           if [ ! -f $AVERSIVE_DIR/modules/$path/config/$CONF_FILE ]; then
214               echo Cannot create default conf file $CONF_FILE, no config sample in $AVERSIVE_DIR/modules/$path/config/$CONF_FILE
215           else
216               echo Creating default conf file $CONF_FILE .
217               cp $AVERSIVE_DIR/modules/$path/config/$CONF_FILE .
218           fi
219       fi
220   fi
221 done
222 echo >> $2
223
224
225
226
227 echo >> $2