4 # This file is *NOT* generated by GNU Autoconf, but written by NIIBE Yutaka
6 # Copyright (C) 2010, 2011, 2012, 2013, 2014
7 # Free Software Initiative of Japan
9 # This file is a part of Gnuk, a GnuPG USB Token implementation.
10 # Gnuk is free software: you can redistribute it and/or modify it
11 # under the terms of the GNU General Public License as published by
12 # the Free Software Foundation, either version 3 of the License, or
13 # (at your option) any later version.
15 # Gnuk is distributed in the hope that it will be useful, but WITHOUT
16 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
17 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
18 # License for more details.
20 # You should have received a copy of the GNU General Public License
21 # along with this program. If not, see <http://www.gnu.org/licenses/>.
39 *=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;;
70 --disable-sys1-compat)
72 --enable-hid-card-change)
73 hid_card_change=yes ;;
74 --disable-hid-card-change)
81 echo "Unrecognized option \`$option'" >&2
82 echo "Try \`$0 --help' for more information." >&2
88 if test "$help" = "yes"; then
92 Defaults for the options are specified in brackets.
95 -h, --help display this help and exit [no]
96 --vidpid=VID:PID specify vendor/product ID [<NONE>]
97 --target=TARGET specify target [FST_01]
98 supported targets are:
103 FST_01_00 (unreleased version with 8MHz XTAL)
104 --enable-debug debug with virtual COM port [no]
106 PIN entry support [no]
107 --enable-certdo support CERT.3 data object [no]
108 --enable-keygen support key generation [no]
109 --enable-sys1-compat enable SYS 1.0 compatibility [yes]
110 executable is target dependent
111 --disable-sys1-compat disable SYS 1.0 compatibility [no]
112 executable is target independent
113 but requires SYS 2.0 or newer
114 --with-dfu build image for DFU [<target specific>]
119 if test "$vidpid" = "none"; then
120 echo "Please specify Vendor ID and Product ID by --vidpid option."
124 TARGET_DEFINE="#define BOARD_$target 1"
125 BOARD_HEADER_FILE=board-`echo $target | tr '_[:upper:]' '-[:lower:]'`.h
126 echo Header file is: $BOARD_HEADER_FILE
127 ln -sf ../chopstx/board/$BOARD_HEADER_FILE board.h
129 # Flash page size in byte
131 # Flash memory size in KB
136 # Settings for TARGET
139 if test "$with_dfu" = "default"; then
151 if test "$with_dfu" = "default"; then
161 # --enable-debug option
162 if test "$debug" = "yes"; then
163 DEBUG_MAKE_OPTION="ENABLE_DEBUG=1"
164 DEBUG_DEFINE="#define DEBUG 1"
165 echo "Debug option enabled"
167 DEBUG_MAKE_OPTION="# ENABLE_DEBUG=1"
168 DEBUG_DEFINE="#undef DEBUG"
169 echo "Debug option disabled"
173 if test "$with_dfu" = "yes"; then
174 if test "$target" = "FST_01" -o "$target" = "FST_01_00"; then
175 echo "FST-01 doesn't have DFU loader, you should not enable this."
178 echo "Configured for DFU"
180 FLASH_SIZE=`expr $FLASH_SIZE - 12`
181 DFU_DEFINE="#define DFU_SUPPORT 1"
182 HEXOUTPUT_MAKE_OPTION="ENABLE_OUTPUT_HEX=yes"
185 echo "Configured for bare system (no-DFU)"
187 DFU_DEFINE="#undef DFU_SUPPORT"
188 HEXOUTPUT_MAKE_OPTION=""
191 # --enable-pinpad option
195 if test "$pinpad" = "no"; then
196 PINPAD_MAKE_OPTION="# ENABLE_PINPAD="
197 PINPAD_DEFINE="#undef PINPAD_SUPPORT"
198 PINPAD_MORE_DEFINE=""
199 echo "PIN pad option disabled"
201 PINPAD_MAKE_OPTION="ENABLE_PINPAD=$pinpad"
202 PINPAD_DEFINE="#define PINPAD_SUPPORT 1"
203 PINPAD_MORE_DEFINE="#define PINPAD_${pinpad^^[a-z]}_SUPPORT 1"
204 echo "PIN pad option enabled ($pinpad)"
205 if test "$pinpad" = "dnd"; then
207 elif test "$pinpad" = "cir"; then
213 # --enable-certdo option
214 if test "$certdo" = "yes"; then
215 CERTDO_DEFINE="#define CERTDO_SUPPORT 1"
216 echo "CERT.3 Data Object is supported"
218 CERTDO_DEFINE="#undef CERTDO_SUPPORT"
219 echo "CERT.3 Data Object is NOT supported"
222 # --enable-keygen option
223 if test "$keygen" = "yes"; then
224 KEYGEN_SUPPORT="-DKEYGEN_SUPPORT"
225 echo "Key generation on device is supported"
228 echo "Key generation on device is NOT supported"
231 # --enable-hid-card-change option
232 if test "$hid_card_change" = "yes"; then
233 HID_CARD_CHANGE_DEFINE="#define HID_CARD_CHANGE_SUPPORT 1"
234 echo "Card insert/removal by HID device is supported"
236 HID_CARD_CHANGE_DEFINE="#undef HID_CARD_CHANGE_SUPPORT"
237 echo "Card insert/removal by HID device is NOT supported"
240 if test -d ../.git; then
241 REVISION=`git describe --dirty="-modified"`
243 REVISION=`cat ../VERSION`
246 ### !!! Replace following string of "FSIJ" to yours !!! ####
247 SERIALNO="FSIJ-`cat ../VERSION | sed -e 's%^[^/]*/%%'`-"
249 SERIALNO_STR_LEN_DEFINE="#define SERIALNO_STR_LEN ${#SERIALNO}"
252 CONFIG="$target:dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo:keygen=$keygen"
255 while read VIDPID VERSION PRODUCT VENDOR; do
256 if test "$vidpid" = "$VIDPID"; then
257 (echo $VIDPID | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\):\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* idVendor */\n 0x\4, 0x\3, /* idProduct */%p"
258 echo $VERSION | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* bcdDevice */%p"
259 ) > usb-vid-pid-ver.c.inc
260 (echo 'static const uint8_t gnukStringVendor[] = {'
261 echo " ${#VENDOR}*2+2, /* bLength */"
262 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
263 echo " /* Manufacturer: \"$VENDOR\" */"
264 echo $VENDOR | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
267 echo 'static const uint8_t gnukStringProduct[] = {'
268 echo " ${#PRODUCT}*2+2, /* bLength */"
269 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
270 echo " /* Product name: \"$PRODUCT\" */"
271 echo $PRODUCT | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
274 echo 'const uint8_t gnukStringSerial[] = {'
275 echo " ${#SERIALNO}*2+2+16, /* bLength */"
276 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
277 echo " /* Serial number: \"$SERIALNO\" */"
278 echo $SERIALNO | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
279 echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,"
280 echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,"
283 echo '#ifdef USB_STRINGS_FOR_GNUK'
284 echo 'static const uint8_t gnuk_revision_detail[] = {'
285 echo " ${#REVISION}*2+2, /* bLength */"
286 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
287 echo " /* revision detail: \"$REVISION\" */"
288 echo $REVISION | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
291 echo 'static const uint8_t gnuk_config_options[] = {'
292 echo " ${#CONFIG}*2+2, /* bLength */"
293 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
294 echo " /* configure options: \"$CONFIG\" */"
295 echo $CONFIG | sed -n -e "s/\(........\)/\1\n/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
301 done; exit 1) < ../GNUK_USB_DEVICE_ID
303 echo "Please specify valid Vendor ID and Product ID."
304 echo "Check ../GNUK_USB_DEVICE_ID."
308 if test "$sys1_compat" = "no"; then
309 # Disable when you are sure that it's sys version 2.0.
310 # Note that Gnuk 1.0 and Neug (until 0.06) uses sys version 1.0.
311 # Disabling the compatibility, executable will be target independent,
312 # assuming the clock initialization will be done by SYS (before entry).
313 have_sys_h="-DHAVE_SYS_H"
318 sed -e "s%@HAVE_SYS_H@%$have_sys_h%" \
319 -e "s%@DEBUG_MAKE_OPTION@%$DEBUG_MAKE_OPTION%" \
320 -e "s%@PINPAD_MAKE_OPTION@%$PINPAD_MAKE_OPTION%" \
321 -e "s%@KEYGEN_SUPPORT@%$KEYGEN_SUPPORT%" \
322 -e "s%@HEXOUTPUT_MAKE_OPTION@%$HEXOUTPUT_MAKE_OPTION%" \
323 < Makefile.in > Makefile
324 if test "$certdo" = "yes"; then
325 sed -e "/^@CERTDO_SUPPORT_START@$/ d" -e "/^@CERTDO_SUPPORT_END@$/ d" \
326 -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \
327 -e "s/@MEMORY_SIZE@/$MEMORY_SIZE/" \
328 -e "s/@FLASH_PAGE_SIZE@/$FLASH_PAGE_SIZE/" \
329 -e "s/@MSC_SIZE@/$MSC_SIZE/" \
330 -e "s/@TIM_SIZE@/$TIM_SIZE/" \
331 -e "s/@EXT_SIZE@/$EXT_SIZE/" \
332 < gnuk.ld.in > gnuk.ld
334 sed -e "/^@CERTDO_SUPPORT_START@$/,/^@CERTDO_SUPPORT_END@$/ d" \
335 -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \
336 -e "s/@MEMORY_SIZE@/$MEMORY_SIZE/" \
337 -e "s/@FLASH_PAGE_SIZE@/$FLASH_PAGE_SIZE/" \
338 -e "s/@MSC_SIZE@/$MSC_SIZE/" \
339 -e "s/@TIM_SIZE@/$TIM_SIZE/" \
340 -e "s/@EXT_SIZE@/$EXT_SIZE/" \
341 < gnuk.ld.in > gnuk.ld
343 sed -e "s/@DEBUG_DEFINE@/$DEBUG_DEFINE/" \
344 -e "s/@DFU_DEFINE@/$DFU_DEFINE/" \
345 -e "s/@PINPAD_DEFINE@/$PINPAD_DEFINE/" \
346 -e "s/@PINPAD_MORE_DEFINE@/$PINPAD_MORE_DEFINE/" \
347 -e "s/@CERTDO_DEFINE@/$CERTDO_DEFINE/" \
348 -e "s/@HID_CARD_CHANGE_DEFINE@/$HID_CARD_CHANGE_DEFINE/" \
349 -e "s/@SERIALNO_STR_LEN@/$SERIALNO_STR_LEN_DEFINE/" \
350 < config.h.in > config.h