More awk-related changes. mawk hangs on the parser scripts, so try gawk; it's what we'll need for cygwin anyway.

git-svn-id: https://arducopter.googlecode.com/svn/trunk@1367 f9c3cf11-9bcb-44bc-f272-b75c42450872
This commit is contained in:
DrZiplok 2010-12-30 03:20:33 +00:00
parent 0620d0c631
commit 6fe8418253

View File

@ -116,6 +116,8 @@ endif
ifeq ($(SYSTYPE),Darwin) ifeq ($(SYSTYPE),Darwin)
# use the tools that come with Arduino # use the tools that come with Arduino
TOOLPATH := $(ARDUINOS)/hardware/tools/avr/bin TOOLPATH := $(ARDUINOS)/hardware/tools/avr/bin
# use BWK awk
AWK = awk
endif endif
ifeq ($(SYSTYPE),Linux) ifeq ($(SYSTYPE),Linux)
# expect that tools are on the path # expect that tools are on the path
@ -123,16 +125,22 @@ ifeq ($(SYSTYPE),Linux)
endif endif
FIND_TOOL = $(firstword $(wildcard $(addsuffix /$(1),$(TOOLPATH)))) FIND_TOOL = $(firstword $(wildcard $(addsuffix /$(1),$(TOOLPATH))))
CXX = $(call FIND_TOOL,avr-g++) CXX := $(call FIND_TOOL,avr-g++)
CC = $(call FIND_TOOL,avr-gcc) CC := $(call FIND_TOOL,avr-gcc)
AS = $(call FIND_TOOL,avr-gcc) AS := $(call FIND_TOOL,avr-gcc)
AR = $(call FIND_TOOL,avr-ar) AR := $(call FIND_TOOL,avr-ar)
LD = $(call FIND_TOOL,avr-gcc) LD := $(call FIND_TOOL,avr-gcc)
OBJCOPY = $(call FIND_TOOL,avr-objcopy) OBJCOPY := $(call FIND_TOOL,avr-objcopy)
ifeq ($(CXX),) ifeq ($(CXX),)
$(error ERROR: cannot find the compiler tools anywhere on the path $(TOOLPATH)) $(error ERROR: cannot find the compiler tools anywhere on the path $(TOOLPATH))
endif endif
# Find awk
AWK ?= gawk
ifeq ($(shell which $(AWK)),)
$(error ERROR: cannot find $(AWK) - you may need to install GNU awk)
endif
# #
# Tool options # Tool options
# #
@ -419,11 +427,11 @@ $(CORELIB): $(CORELIBOBJS)
# #
$(SKETCHCPP): $(SKETCHCPP_SRC) $(BUILDROOT) $(SKETCHCPP): $(SKETCHCPP_SRC) $(BUILDROOT)
$(RULEHDR) $(RULEHDR)
$(v)awk -v mode=header '$(SKETCH_SPLITTER)' $(SKETCHCPP_SRC) > $@ $(v)$(AWK) -v mode=header '$(SKETCH_SPLITTER)' $(SKETCHCPP_SRC) > $@
$(v)echo "#line 1 \"autogenerated\"" >> $@ $(v)echo "#line 1 \"autogenerated\"" >> $@
$(v)echo "#include \"WProgram.h\"" >> $@ $(v)echo "#include \"WProgram.h\"" >> $@
$(v)awk '$(SKETCH_PROTOTYPER)' $(SKETCHCPP_SRC) >> $@ $(v)$(AWK) '$(SKETCH_PROTOTYPER)' $(SKETCHCPP_SRC) >> $@
$(v)awk -v mode=body '$(SKETCH_SPLITTER)' $(SKETCHCPP_SRC) >> $@ $(v)$(AWK) -v mode=body '$(SKETCH_SPLITTER)' $(SKETCHCPP_SRC) >> $@
# delete the sketch.cpp file if a processing error occurs # delete the sketch.cpp file if a processing error occurs
.DELETE_ON_ERROR: $(SKETCHCPP) .DELETE_ON_ERROR: $(SKETCHCPP)
@ -437,6 +445,8 @@ $(SKETCHCPP): $(SKETCHCPP_SRC) $(BUILDROOT)
# Note that # and $ require special treatment here to avoid upsetting # Note that # and $ require special treatment here to avoid upsetting
# make. # make.
# #
# This script requires BWK or GNU awk.
#
define SKETCH_SPLITTER define SKETCH_SPLITTER
BEGIN { \ BEGIN { \
scanning = 1; \ scanning = 1; \
@ -446,10 +456,10 @@ define SKETCH_SPLITTER
(FNR == 1) && printing { \ (FNR == 1) && printing { \
printf "#line %d \"%s\"\n", FNR, FILENAME; \ printf "#line %d \"%s\"\n", FNR, FILENAME; \
} \ } \
/^[ \t\n\r]*\/\*/,/\*\// { \ /^[[:space:]]*\/\*/,/\*\// { \
toggles = 0; \ toggles = 0; \
} \ } \
/^[ \t\n\r]*$$/ || /^[ \t\n\r]*\/\/.*/ || /^\#.*$$/ { \ /^[[:space:]]*$$/ || /^[[:space:]]*\/\/.*/ || /^\#.*$$/ { \
toggles = 0; \ toggles = 0; \
} \ } \
scanning && toggles { \ scanning && toggles { \
@ -477,23 +487,16 @@ endef
# and backslashes are doubled in the partial patterns to satisfy # and backslashes are doubled in the partial patterns to satisfy
# escaping rules. # escaping rules.
# #
# The space/alnum variables are used to work around the lack of the # This script requires BWK or GNU awk.
# [:space:] and [:alnum:] classes in mawk, commonly found on Linux
# systems. We cheat and sneak _ into the class as well.
# #
define SKETCH_PROTOTYPER define SKETCH_PROTOTYPER
BEGIN { \ BEGIN { \
RS="{"; \ RS="{"; \
space = "[ \\t\\n\\r]"; \ type = "((\\n)|(^))[[:space:]]*[[:alnum:]_]+[[:space:]]+"; \
spaces = space "+"; \ qualifiers = "([[:alnum:]_\\*&]+[[:space:]]*)*"; \
spaceok = space "*"; \ name = "[[:alnum:]_]+[[:space:]]*"; \
alnum = "[0-9a-zA-Z_]"; \ args = "\\([[:space:][:alnum:]_,&\\*\\[\\]]*\\)"; \
alnums = alnum "+"; \ bodycuddle = "[[:space:]]*$$"; \
type = "((\\n)|(^))" spaceok alnums spaces; \
qualifiers = "([0-9a-zA-Z_\\*&]+" spaceok ")*"; \
name = alnums spaceok; \
args = "\\([ \\t\\n\\r0-9a-zA-Z_,&\\*\\[\\]]*\\)"; \
bodycuddle = "[ \\t\\n\\r]*$$"; \
pattern = type qualifiers name args bodycuddle; \ pattern = type qualifiers name args bodycuddle; \
} \ } \
match($$0, pattern) { \ match($$0, pattern) { \