use -pthread flags
[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_SPI,comm/spi
37               CONFIG_MODULE_CC2420,devices/radio/cc2420
38               CONFIG_MODULE_UART,comm/uart
39               CONFIG_MODULE_I2C,comm/i2c
40               CONFIG_MODULE_MF2_CLIENT,comm/mf2_client
41               CONFIG_MODULE_MF2_SERVER,comm/mf2_server
42               CONFIG_MODULE_PWM,hardware/pwm
43               CONFIG_MODULE_PWM_NG,hardware/pwm_ng
44               CONFIG_MODULE_ADC,hardware/adc
45               CONFIG_MODULE_AES,crypto/aes
46               CONFIG_MODULE_MD5,crypto/md5
47               CONFIG_MODULE_RC4,crypto/rc4
48               CONFIG_MODULE_HAMMING,encoding/hamming
49               CONFIG_MODULE_TIMER,hardware/timer
50               CONFIG_MODULE_BASE64,encoding/base64
51               CONFIG_MODULE_CIRBUF,base/cirbuf
52               CONFIG_MODULE_DIAGNOSTIC,debug/diagnostic
53               CONFIG_MODULE_ERROR,debug/error
54               CONFIG_MODULE_FIXED_POINT,base/math/fixed_point
55               CONFIG_MODULE_TIME_EXT,base/time_ext
56               CONFIG_MODULE_GEOMETRY,base/math/geometry
57               CONFIG_MODULE_VECT2,base/math/vect2"
58
59 echo
60 echo Generating aversive configuration files
61
62 # does the .config file exists ?
63 if [ ! -f $1 ]; then
64     echo "No such file <$1>"
65     exit 1
66 fi
67
68 echo "# Aversive configuration" > $2
69
70 ####
71 ##### MCU, compilation options, output format
72 ####
73
74 echo -n "MCU = " >> $2
75 echo `grep "CONFIG_MCU_.*=y" $1 | sed s,CONFIG_MCU_,, | sed s,=y,, | tr "[A-Z]" "[a-z]"` >> $2
76
77 echo -n "OPT = " >> $2
78 echo `grep "CONFIG_OPTM_.*=y" $1 | sed s,CONFIG_OPTM_,, | sed s,=y,, | tr "[A-Z]" "[a-z]"` >> $2
79
80 if grep "CONFIG_FORMAT_IHEX=y" $1 > /dev/null 2> /dev/null
81     then
82     echo "FORMAT = ihex" >> $2
83     echo "FORMAT_EXTENSION = hex" >> $2
84 fi
85
86 if grep "CONFIG_FORMAT_SREC=y" $1 > /dev/null 2> /dev/null
87     then
88     echo "FORMAT = srec" >> $2
89     echo "FORMAT_EXTENSION = srec" >> $2
90 fi
91
92 if grep "CONFIG_FORMAT_BINARY=y" $1 > /dev/null 2> /dev/null
93     then
94     echo "FORMAT = binary" >> $2
95     echo "FORMAT_EXTENSION = bin" >> $2
96 fi
97
98 ####
99 ##### Math lib and printf
100 ####
101
102 if grep "CONFIG_MATH_LIB=y" $1 > /dev/null 2> /dev/null
103     then
104     echo "MATH_LIB = -lm" >> $2
105 else
106     echo "MATH_LIB = " >> $2
107 fi
108
109 if grep "CONFIG_MINIMAL_PRINTF=y" $1 > /dev/null 2> /dev/null
110     then
111     echo "PRINTF_LDFLAGS = -Wl,-u,vfprintf -lprintf_min" >> $2
112 fi
113
114 if grep "CONFIG_STANDARD_PRINTF=y" $1 > /dev/null 2> /dev/null
115     then
116     echo "PRINTF_LDFLAGS = " >> $2
117 fi
118
119 if grep "CONFIG_ADVANCED_PRINTF=y" $1 > /dev/null 2> /dev/null
120     then
121     echo "PRINTF_LDFLAGS = -Wl,-u,vfprintf -lprintf_flt" >> $2
122 fi
123
124 if grep "CONFIG_FDEVOPEN_COMPAT=y" $1 > /dev/null 2> /dev/null
125     then
126     echo "CFLAGS += -D__STDIO_FDEVOPEN_COMPAT_12" >> $2
127 fi
128
129 if grep "CONFIG_MODULE_HOSTSIM=y" $1 > /dev/null 2> /dev/null
130     then
131     echo "PTHREAD_CFLAGS = -pthread" >> $2
132     echo "PTHREAD_LDFLAGS = -pthread" >> $2
133 fi
134
135
136
137 ####
138 ##### Programmer
139 ####
140
141 if grep "CONFIG_AVRDUDE=y" $1 > /dev/null 2> /dev/null
142     then
143     echo "PROGRAMMER = avrdude" >> $2
144 fi
145
146 echo -n "AVRDUDE_PROGRAMMER = " >> $2
147 echo `grep "CONFIG_AVRDUDE_PROG_.*=y" $1 | sed s,CONFIG_AVRDUDE_PROG_,, | sed s,=y,, | tr [A-Z_] [a-z\-]` >> $2
148
149 echo -n "AVRDUDE_PORT = " >> $2
150 echo `grep "CONFIG_AVRDUDE_PORT" $1 | sed s,CONFIG_AVRDUDE_PORT=,,` >> $2
151
152 echo -n "AVRDUDE_BAUDRATE = " >> $2
153 echo `grep "CONFIG_AVRDUDE_BAUDRATE" $1 | sed s,CONFIG_AVRDUDE_BAUDRATE=,,` >> $2
154
155 if grep "CONFIG_AVRDUDE_CHECK_SIGNATURE=y" $1 > /dev/null 2> /dev/null
156     then
157     echo "AVRDUDE_FLAGS_SIGNATURE_CHECK =" >> $2
158 else
159     echo "AVRDUDE_FLAGS_SIGNATURE_CHECK = -F" >> $2
160 fi
161
162
163 if grep "CONFIG_AVARICE=y" $1 > /dev/null 2> /dev/null
164     then
165     echo "PROGRAMMER = avarice" >> $2
166     if ! grep "CONFIG_FORMAT_BINARY=y" $1 > /dev/null 2> /dev/null
167         then
168         echo "WARNING: With avarice, output format should be binary"
169     fi
170 fi
171
172 if grep "CONFIG_AVARICE_PROG_MKI=y" $1 > /dev/null 2> /dev/null
173     then
174     echo "AVARICE_PROGRAMMER = mkI" >> $2
175 fi
176
177 if grep "CONFIG_AVARICE_PROG_MKII=y" $1 > /dev/null 2> /dev/null
178     then
179     echo "AVARICE_PROGRAMMER = mkII" >> $2
180 fi
181
182 echo -n "AVARICE_PORT = " >> $2
183 echo `grep "CONFIG_AVARICE_PORT" $1 | sed s,CONFIG_AVARICE_PORT=,,` >> $2
184
185 echo -n "AVARICE_DEBUG_PORT = " >> $2
186 echo `grep "CONFIG_AVARICE_DEBUG_PORT" $1 | sed s,CONFIG_AVARICE_DEBUG_PORT=,,` >> $2
187
188
189 ####
190 ##### Generation of the module list
191 ####
192 echo -n "MODULES =" >> $2
193
194 for i in $MODULES_LIST
195 do
196   config=`echo $i | cut -d ',' -f1-1`
197   path=`echo $i | cut -d ',' -f2-2`
198   
199
200   if grep $config=y $1 2>/dev/null >/dev/null
201       then
202       echo -n " "$path >> $2
203   fi
204
205   if grep -q "${config}_CREATE_CONFIG=y" $1; then
206       CONF_FILE=`basename $path`_config.h
207       if [ -f $CONF_FILE ]
208           then
209           echo Cannot create default conf file $CONF_FILE, file exists
210       else
211           if [ ! -f $AVERSIVE_DIR/modules/$path/config/$CONF_FILE ]; then
212               echo Cannot create default conf file $CONF_FILE, no config sample in $AVERSIVE_DIR/modules/$path/config/$CONF_FILE
213           else
214               echo Creating default conf file $CONF_FILE .
215               cp $AVERSIVE_DIR/modules/$path/config/$CONF_FILE .
216           fi
217       fi
218   fi
219 done
220 echo >> $2
221
222
223
224
225 echo >> $2