3 # This is bash which supports ANSI-C Quoting
7 # This file is *NOT* generated by GNU Autoconf, but written by NIIBE Yutaka
9 # Copyright (C) 2010, 2011, 2012, 2013, 2014, 2015
10 # Free Software Initiative of Japan
12 # This file is a part of Gnuk, a GnuPG USB Token implementation.
13 # Gnuk is free software: you can redistribute it and/or modify it
14 # under the terms of the GNU General Public License as published by
15 # the Free Software Foundation, either version 3 of the License, or
16 # (at your option) any later version.
18 # Gnuk is distributed in the hope that it will be useful, but WITHOUT
19 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
21 # License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program. If not, see <http://www.gnu.org/licenses/>.
39 if test -d ../.git; then
40 REVISION=`git describe --dirty="-modified"`
42 REVISION=`cat ../VERSION`
48 *=*) optarg=`expr "X$option" : '[^=]*=\(.*\)'` ;;
73 --enable-hid-card-change)
74 hid_card_change=yes ;;
75 --disable-hid-card-change)
79 --disable-sys1-compat)
86 echo "Unrecognized option \`$option'" >&2
87 echo "Try \`$0 --help' for more information." >&2
93 if test "$help" = "yes"; then
97 Defaults for the options are specified in brackets.
100 -h, --help display this help and exit [no]
101 --vidpid=VID:PID specify vendor/product ID [<NONE>]
102 --target=TARGET specify target [FST_01]
103 supported targets are:
111 FST_01_00 (unreleased version with 8MHz XTAL)
112 --enable-debug debug with virtual COM port [no]
114 PIN entry support [no]
115 --enable-certdo support CERT.3 data object [no]
116 --enable-sys1-compat enable SYS 1.0 compatibility [yes]
117 executable is target dependent
118 --disable-sys1-compat disable SYS 1.0 compatibility [no]
119 executable is target independent
120 but requires SYS 2.0 or newer
121 --with-dfu build image for DFU [<target specific>]
126 if test "$vidpid" = "none"; then
127 echo "Please specify Vendor ID and Product ID by --vidpid option."
131 BOARD_HEADER_FILE=board-`echo $target | tr '_[:upper:]' '-[:lower:]'`.h
132 echo Header file is: $BOARD_HEADER_FILE
133 ln -sf ../chopstx/board/$BOARD_HEADER_FILE board.h
135 # Flash page size in byte
137 # Flash memory size in KiB
142 # Settings for TARGET
145 if test "$with_dfu" = "default"; then
157 if test "$with_dfu" = "default"; then
167 # --enable-debug option
168 if test "$debug" = "yes"; then
169 DEBUG_MAKE_OPTION="ENABLE_DEBUG=1"
170 DEBUG_DEFINE="#define DEBUG 1"
171 echo "Debug option enabled"
173 DEBUG_MAKE_OPTION="# ENABLE_DEBUG=1"
174 DEBUG_DEFINE="#undef DEBUG"
175 echo "Debug option disabled"
179 if test "$with_dfu" = "yes"; then
180 if test "$target" = "FST_01" -o "$target" = "FST_01_00"; then
181 echo "FST-01 doesn't have DFU loader, you should not use --with-dfu."
184 echo "Configured for DFU"
186 FLASH_SIZE=`expr $FLASH_SIZE - 12`
187 DFU_DEFINE="#define DFU_SUPPORT 1"
188 HEXOUTPUT_MAKE_OPTION="ENABLE_OUTPUT_HEX=yes"
191 echo "Configured for bare system (no-DFU)"
193 DFU_DEFINE="#undef DFU_SUPPORT"
194 HEXOUTPUT_MAKE_OPTION=""
197 # --enable-pinpad option
201 if test "$pinpad" = "no"; then
202 PINPAD_MAKE_OPTION="# ENABLE_PINPAD="
203 PINPAD_DEFINE="#undef PINPAD_SUPPORT"
204 PINPAD_MORE_DEFINE=""
205 echo "PIN pad option disabled"
207 PINPAD_MAKE_OPTION="ENABLE_PINPAD=$pinpad"
208 PINPAD_DEFINE="#define PINPAD_SUPPORT 1"
209 PINPAD_MORE_DEFINE="#define PINPAD_${pinpad^^[a-z]}_SUPPORT 1"
210 echo "PIN pad option enabled ($pinpad)"
211 if test "$pinpad" = "dnd"; then
213 elif test "$pinpad" = "cir"; then
219 # --enable-certdo option
220 if test "$certdo" = "yes"; then
221 CERTDO_DEFINE="#define CERTDO_SUPPORT 1"
222 echo "CERT.3 Data Object is supported"
224 CERTDO_DEFINE="#undef CERTDO_SUPPORT"
225 echo "CERT.3 Data Object is NOT supported"
228 # --enable-hid-card-change option
229 if test "$hid_card_change" = "yes"; then
230 HID_CARD_CHANGE_DEFINE="#define HID_CARD_CHANGE_SUPPORT 1"
231 echo "Card insert/removal by HID device is supported"
233 HID_CARD_CHANGE_DEFINE="#undef HID_CARD_CHANGE_SUPPORT"
234 echo "Card insert/removal by HID device is NOT supported"
237 ### !!! Replace following string of "FSIJ" to yours !!! ####
238 SERIALNO="FSIJ-`cat ../VERSION | sed -e 's%^[^/]*/%%'`-"
240 SERIALNO_STR_LEN_DEFINE="#define SERIALNO_STR_LEN ${#SERIALNO}"
243 if test "$sys1_compat" = "yes"; then
244 CONFIG="$target:dfu=$with_dfu:debug=$debug:pinpad=$pinpad:certdo=$certdo"
246 if test "$with_dfu" = "yes"; then
247 echo "Common binary can't support DFU loader, don't use --with-dfu."
250 # Override settings for common binary. Safer side.
254 CONFIG="common:debug=$debug:pinpad=$pinpad:certdo=$certdo"
257 output_vid_pid_version () {
258 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 */${nl} 0x\4, 0x\3, /* idProduct */%p"
259 echo $VERSION | sed -n -e "s%^\([0-9a-f][0-9a-f]\)\([0-9a-f][0-9a-f]\)$% 0x\2, 0x\1, /* bcdDevice */%p"
262 output_vendor_product_serial_strings () {
265 echo "static const uint8_t ${prefix}string_vendor[] = {"
266 echo " ${#VENDOR}*2+2, /* bLength */"
267 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
268 echo " /* Manufacturer: \"$VENDOR\" */"
269 echo $VENDOR | sed -n -e "s/\(........\)/\1${nl}/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
272 echo "static const uint8_t ${prefix}string_product[] = {"
273 echo " ${#PRODUCT}*2+2, /* bLength */"
274 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
275 echo " /* Product name: \"$PRODUCT\" */"
276 echo $PRODUCT | sed -n -e "s/\(........\)/\1${nl}/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
279 if test -n "$prefix"; then
281 echo "uint8_t ${prefix}string_serial[] = {"
282 echo " ${#SERIALNO}*2+2+16, /* bLength */"
283 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
284 echo " /* Serial number: \"$SERIALNO\" */"
285 echo $SERIALNO | sed -n -e "s/\(........\)/\1${nl}/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
286 echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,"
287 echo " 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,"
290 echo '#ifdef USB_STRINGS_FOR_GNUK'
291 echo "static const uint8_t ${prefix}revision_detail[] = {"
292 echo " ${#REVISION}*2+2, /* bLength */"
293 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
294 echo " /* revision detail: \"$REVISION\" */"
295 echo $REVISION | sed -n -e "s/\(........\)/\1${nl}/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
298 echo "static const uint8_t ${prefix}config_options[] = {"
299 echo " ${#CONFIG}*2+2, /* bLength */"
300 echo " USB_STRING_DESCRIPTOR_TYPE, /* bDescriptorType */"
301 echo " /* configure options: \"$CONFIG\" */"
302 echo $CONFIG | sed -n -e "s/\(........\)/\1${nl}/gp" | sed -n -e "s/\(.\)/'\1', 0, /g" -e "s/^/ /" -e "s/ $//p"
309 while read VIDPID VERSION PRODUCT VENDOR; do
310 if test "$vidpid" = "$VIDPID"; then
311 output_vid_pid_version > usb-vid-pid-ver.c.inc
312 output_vendor_product_serial_strings gnuk_ >usb-strings.c.inc
315 done; exit 1) < ../GNUK_USB_DEVICE_ID
317 echo "Please specify valid Vendor ID and Product ID."
318 echo "Check ../GNUK_USB_DEVICE_ID."
322 if test "$sys1_compat" = "no"; then
323 # Disable when you are sure that it's sys version 2.1.
324 # Note that Gnuk 1.0 and NeuG (until 0.06) uses sys version 1.0.
325 # Disabling the compatibility, executable will be target independent,
326 # assuming the clock initialization will be done by SYS (before entry).
327 have_sys_h="-DHAVE_SYS_H"
333 sed -e "s%@HAVE_SYS_H@%$have_sys_h%" \
334 -e "s%@DEBUG_MAKE_OPTION@%$DEBUG_MAKE_OPTION%" \
335 -e "s%@PINPAD_MAKE_OPTION@%$PINPAD_MAKE_OPTION%" \
336 -e "s%@HEXOUTPUT_MAKE_OPTION@%$HEXOUTPUT_MAKE_OPTION%" \
337 < Makefile.in > Makefile
338 if test "$certdo" = "yes"; then
339 sed -e "/^@CERTDO_SUPPORT_START@$/ d" -e "/^@CERTDO_SUPPORT_END@$/ d" \
340 -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \
341 -e "s/@MEMORY_SIZE@/$MEMORY_SIZE/" \
342 -e "s/@FLASH_PAGE_SIZE@/$FLASH_PAGE_SIZE/" \
343 -e "s/@MSC_SIZE@/$MSC_SIZE/" \
344 -e "s/@TIM_SIZE@/$TIM_SIZE/" \
345 -e "s/@EXT_SIZE@/$EXT_SIZE/" \
346 < gnuk.ld.in > gnuk.ld
348 sed -e "/^@CERTDO_SUPPORT_START@$/,/^@CERTDO_SUPPORT_END@$/ d" \
349 -e "s/@ORIGIN@/$ORIGIN/" -e "s/@FLASH_SIZE@/$FLASH_SIZE/" \
350 -e "s/@MEMORY_SIZE@/$MEMORY_SIZE/" \
351 -e "s/@FLASH_PAGE_SIZE@/$FLASH_PAGE_SIZE/" \
352 -e "s/@MSC_SIZE@/$MSC_SIZE/" \
353 -e "s/@TIM_SIZE@/$TIM_SIZE/" \
354 -e "s/@EXT_SIZE@/$EXT_SIZE/" \
355 < gnuk.ld.in > gnuk.ld
357 sed -e "s/@DEBUG_DEFINE@/$DEBUG_DEFINE/" \
358 -e "s/@DFU_DEFINE@/$DFU_DEFINE/" \
359 -e "s/@PINPAD_DEFINE@/$PINPAD_DEFINE/" \
360 -e "s/@PINPAD_MORE_DEFINE@/$PINPAD_MORE_DEFINE/" \
361 -e "s/@CERTDO_DEFINE@/$CERTDO_DEFINE/" \
362 -e "s/@HID_CARD_CHANGE_DEFINE@/$HID_CARD_CHANGE_DEFINE/" \
363 -e "s/@SERIALNO_STR_LEN_DEFINE@/$SERIALNO_STR_LEN_DEFINE/" \
364 < config.h.in > config.h