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`.
This commit is contained in:
John Whittington 2017-06-04 10:47:04 +01:00
parent ba96840399
commit 81673d4666
3 changed files with 85 additions and 0 deletions

View file

@ -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\
"

View file

@ -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)

View file

@ -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:**