From 81673d4666d417ab662c91fa093abefada7889e5 Mon Sep 17 00:00:00 2001 From: John Whittington Date: Sun, 4 Jun 2017 10:47:04 +0100 Subject: [PATCH 1/4] Support for generation of project tags file Considering the number of project files spread in different locations when developing an Arduino project, proper use of tags can be difficult; resolving beyond local functions. I've added automatic generation of a tags file, which includes: * Standard ctags source in project dir (.c, .cpp, .h) * Arduino source in project dir (.ide, .pde) * Arduino core based on detected project core from Arduino install. * Included Arduino libraries from user library folder. As a Vim user I find this hugely useful and think it would be a useful addtion for others. Target has been added as `make tags`. --- Arduino.mk | 32 ++++++++++++++++++++++++++++ HISTORY.md | 1 + arduino-mk-vars.md | 52 ++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 85 insertions(+) diff --git a/Arduino.mk b/Arduino.mk index 5b0af0f..8dfd9c5 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -1307,6 +1307,22 @@ $(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS) @$(MKDIR) $(dir $@) $(NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@ +######################################################################## +# Ctags + +# Assume ctags is on path unless has been specified +ifndef CTAGS_EXEC + CTAGS_EXEC = ctags +endif + +# Default to 'tags' unless user has specified a tags file +ifndef TAGS_FILE + TAGS_FILE = tags +endif + +# ctags command: append file with user options before +CTAGS_CMD = $(CTAGS_EXEC) $(CTAGS_OPTS) -auf + ######################################################################## # Avrdude @@ -1562,6 +1578,21 @@ generate_assembly: $(OBJDIR)/$(TARGET).s generated_assembly: generate_assembly @$(ECHO) "\"generated_assembly\" target is deprecated. Use \"generate_assembly\" target instead\n\n" +.PHONY: tags +tags: + rm -f $(shell pwd)/$(TAGS_FILE) + @$(ECHO) "Generating tags for source files: " + $(CTAGS_CMD) $(TAGS_FILE) $(shell find "`pwd`" -name "*.cpp" -o -name "*.h" -o -name "*.c") + @$(ECHO) "Generating tags for IDO an PDE files as C++: " + $(CTAGS_CMD) $(TAGS_FILE) --langmap=c++:.ino --langmap=c++:.pde $(shell find "`pwd`" -name "*.ino" -o -name "*.pde") + @$(ECHO) "Generating tags for project libraries: " + $(CTAGS_CMD) $(TAGS_FILE) $(foreach lib, $(ARDUINO_LIBS),$(USER_LIB_PATH)/$(lib)/*) + @$(ECHO) "Generating tags for Arduino core: " + $(CTAGS_CMD) $(TAGS_FILE) $(ARDUINO_CORE_PATH)/* + @$(ECHO) "Sorting..\n" + @sort $(TAGS_FILE) -o $(TAGS_FILE) + @$(ECHO) "Tag file generation complete, output: $(TAGS_FILE)" + help_vars: @$(CAT) $(ARDMK_DIR)/arduino-mk-vars.md @@ -1593,6 +1624,7 @@ help: generated assembly of the main sketch.\n\ make burn_bootloader - burn bootloader and fuses\n\ make set_fuses - set fuses without burning bootloader\n\ + make tags - generate tags file including project libs and Arduino core\n\ make help_vars - print all variables that can be overridden\n\ make help - show this help\n\ " diff --git a/HISTORY.md b/HISTORY.md index c35d3f8..34bb516 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -13,6 +13,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it - New: Add support for good old cu as monitor command (issue #492) (https://github.com/mwm) - Tweak: Removed tilde from documentation (issue #497). (https://github.com/sej7278) - New: Add a documentation how to setup Makefile for 3rd party boards (issue #499). (https://github.com/MilanV) +- New: Add generation of tags file using ctags, which automatically includes project libs and Arduino core. (https://github.com/tuna-f1sh) ### 1.5.2 (2017-01-11) diff --git a/arduino-mk-vars.md b/arduino-mk-vars.md index 0df7a11..bef58bd 100644 --- a/arduino-mk-vars.md +++ b/arduino-mk-vars.md @@ -11,6 +11,7 @@ The following are the different variables that can be overwritten in the user ma * [Avrdude setting variables](#avrdude-setting-variables) * [Bootloader variables](#bootloader-variables) * [ChipKIT variables](#chipkit-variables) +* [Ctags variables](#ctags-variables) ## Global variables @@ -1402,6 +1403,57 @@ MPIDE_DIR = $(HOME)/mpide ---- +## Ctags variables + +### TAGS_FILE + +**Description:** + +Output file name for tags. Defaults to 'tags'. + +**Example:** + +```Makefile +TAGS_FILE = .tags +``` + +**Requirement:** *Optional* + +---- + +### CTAGS_OPTS + +**Description:** + +Additional options to pass to `ctags` command. + +**Example:** + +```Makefile +# Run ctags in verbose mode +CTAGS_OPTS = -V +``` + +**Requirement:** *Optional* + +---- + +### CTAGS_CMD + +**Description:** + +Location of `ctags` binary. Defaults to user path. + +**Example:** + +```Makefile +CTAGS_CMD = /usr/local/bin/ +``` + +**Requirement:** *Optional* + +---- + ### MPIDE_PREFERENCES_PATH **Description:** From 62f2d7081511ec2563fb511414a8cf8051e38737 Mon Sep 17 00:00:00 2001 From: John Whittington Date: Fri, 1 Sep 2017 12:33:48 +0000 Subject: [PATCH 2/4] Use LOCAL_SRC variable due to proir assert and only scan libs if there are libs --- Arduino.mk | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Arduino.mk b/Arduino.mk index 8dfd9c5..8b674e6 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -1581,17 +1581,17 @@ generated_assembly: generate_assembly .PHONY: tags tags: rm -f $(shell pwd)/$(TAGS_FILE) - @$(ECHO) "Generating tags for source files: " - $(CTAGS_CMD) $(TAGS_FILE) $(shell find "`pwd`" -name "*.cpp" -o -name "*.h" -o -name "*.c") - @$(ECHO) "Generating tags for IDO an PDE files as C++: " - $(CTAGS_CMD) $(TAGS_FILE) --langmap=c++:.ino --langmap=c++:.pde $(shell find "`pwd`" -name "*.ino" -o -name "*.pde") - @$(ECHO) "Generating tags for project libraries: " - $(CTAGS_CMD) $(TAGS_FILE) $(foreach lib, $(ARDUINO_LIBS),$(USER_LIB_PATH)/$(lib)/*) + @$(ECHO) "Generating tags for local sources (IDO an PDE files as C++): " + $(CTAGS_CMD) $(TAGS_FILE) --langmap=c++:.ino --langmap=c++:.pde $(LOCAL_SRCS) +ifneq ($(words $(ARDUINO_LIBS)), 0) + @$(ECHO) "Generating tags for project libraries: " + $(CTAGS_CMD) $(TAGS_FILE) $(foreach lib, $(ARDUINO_LIBS),$(USER_LIB_PATH)/$(lib)/*) +endif @$(ECHO) "Generating tags for Arduino core: " $(CTAGS_CMD) $(TAGS_FILE) $(ARDUINO_CORE_PATH)/* @$(ECHO) "Sorting..\n" @sort $(TAGS_FILE) -o $(TAGS_FILE) - @$(ECHO) "Tag file generation complete, output: $(TAGS_FILE)" + @$(ECHO) "Tag file generation complete, output: $(TAGS_FILE)\n" help_vars: @$(CAT) $(ARDMK_DIR)/arduino-mk-vars.md From 85db740a1c00ebfa61418e6182c85c723f6a8f8c Mon Sep 17 00:00:00 2001 From: John Whittington Date: Sun, 3 Sep 2017 08:52:44 +0100 Subject: [PATCH 3/4] Ido/ino typo in echo when building tags --- Arduino.mk | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Arduino.mk b/Arduino.mk index bc684bd..623db90 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -1581,7 +1581,7 @@ generated_assembly: generate_assembly .PHONY: tags tags: rm -f $(shell pwd)/$(TAGS_FILE) - @$(ECHO) "Generating tags for local sources (IDO an PDE files as C++): " + @$(ECHO) "Generating tags for local sources (INO an PDE files as C++): " $(CTAGS_CMD) $(TAGS_FILE) --langmap=c++:.ino --langmap=c++:.pde $(LOCAL_SRCS) ifneq ($(words $(ARDUINO_LIBS)), 0) @$(ECHO) "Generating tags for project libraries: " From 04f0ee07280c823447afc4bb14b2ec6cf1b8e470 Mon Sep 17 00:00:00 2001 From: John Whittington Date: Sun, 3 Sep 2017 13:19:36 +0100 Subject: [PATCH 4/4] rm old tags file made safer and only if it exists --- Arduino.mk | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Arduino.mk b/Arduino.mk index 623db90..c647aea 100644 --- a/Arduino.mk +++ b/Arduino.mk @@ -1320,7 +1320,7 @@ ifndef TAGS_FILE TAGS_FILE = tags endif -# ctags command: append file with user options before +# ctags command: append, flags unsort (as will be sorted after) and specify filename CTAGS_CMD = $(CTAGS_EXEC) $(CTAGS_OPTS) -auf ######################################################################## @@ -1580,7 +1580,9 @@ generated_assembly: generate_assembly .PHONY: tags tags: - rm -f $(shell pwd)/$(TAGS_FILE) +ifneq ($(words $(wildcard $(TAGS_FILE))), 0) + rm -f $(TAGS_FILE) +endif @$(ECHO) "Generating tags for local sources (INO an PDE files as C++): " $(CTAGS_CMD) $(TAGS_FILE) --langmap=c++:.ino --langmap=c++:.pde $(LOCAL_SRCS) ifneq ($(words $(ARDUINO_LIBS)), 0)