Skip to content

Commit 81673d4

Browse files
committed
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`.
1 parent ba96840 commit 81673d4

File tree

3 files changed

+85
-0
lines changed

3 files changed

+85
-0
lines changed

Arduino.mk

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1307,6 +1307,22 @@ $(OBJDIR)/%.sym: $(OBJDIR)/%.elf $(COMMON_DEPS)
13071307
@$(MKDIR) $(dir $@)
13081308
$(NM) --size-sort --demangle --reverse-sort --line-numbers $< > $@
13091309

1310+
########################################################################
1311+
# Ctags
1312+
1313+
# Assume ctags is on path unless has been specified
1314+
ifndef CTAGS_EXEC
1315+
CTAGS_EXEC = ctags
1316+
endif
1317+
1318+
# Default to 'tags' unless user has specified a tags file
1319+
ifndef TAGS_FILE
1320+
TAGS_FILE = tags
1321+
endif
1322+
1323+
# ctags command: append file with user options before
1324+
CTAGS_CMD = $(CTAGS_EXEC) $(CTAGS_OPTS) -auf
1325+
13101326
########################################################################
13111327
# Avrdude
13121328

@@ -1562,6 +1578,21 @@ generate_assembly: $(OBJDIR)/$(TARGET).s
15621578
generated_assembly: generate_assembly
15631579
@$(ECHO) "\"generated_assembly\" target is deprecated. Use \"generate_assembly\" target instead\n\n"
15641580

1581+
.PHONY: tags
1582+
tags:
1583+
rm -f $(shell pwd)/$(TAGS_FILE)
1584+
@$(ECHO) "Generating tags for source files: "
1585+
$(CTAGS_CMD) $(TAGS_FILE) $(shell find "`pwd`" -name "*.cpp" -o -name "*.h" -o -name "*.c")
1586+
@$(ECHO) "Generating tags for IDO an PDE files as C++: "
1587+
$(CTAGS_CMD) $(TAGS_FILE) --langmap=c++:.ino --langmap=c++:.pde $(shell find "`pwd`" -name "*.ino" -o -name "*.pde")
1588+
@$(ECHO) "Generating tags for project libraries: "
1589+
$(CTAGS_CMD) $(TAGS_FILE) $(foreach lib, $(ARDUINO_LIBS),$(USER_LIB_PATH)/$(lib)/*)
1590+
@$(ECHO) "Generating tags for Arduino core: "
1591+
$(CTAGS_CMD) $(TAGS_FILE) $(ARDUINO_CORE_PATH)/*
1592+
@$(ECHO) "Sorting..\n"
1593+
@sort $(TAGS_FILE) -o $(TAGS_FILE)
1594+
@$(ECHO) "Tag file generation complete, output: $(TAGS_FILE)"
1595+
15651596
help_vars:
15661597
@$(CAT) $(ARDMK_DIR)/arduino-mk-vars.md
15671598

@@ -1593,6 +1624,7 @@ help:
15931624
generated assembly of the main sketch.\n\
15941625
make burn_bootloader - burn bootloader and fuses\n\
15951626
make set_fuses - set fuses without burning bootloader\n\
1627+
make tags - generate tags file including project libs and Arduino core\n\
15961628
make help_vars - print all variables that can be overridden\n\
15971629
make help - show this help\n\
15981630
"

HISTORY.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ I tried to give credit whenever possible. If I have missed anyone, kindly add it
1313
- New: Add support for good old cu as monitor command (issue #492) (https://github.com/mwm)
1414
- Tweak: Removed tilde from documentation (issue #497). (https://github.com/sej7278)
1515
- New: Add a documentation how to setup Makefile for 3rd party boards (issue #499). (https://github.com/MilanV)
16+
- New: Add generation of tags file using ctags, which automatically includes project libs and Arduino core. (https://github.com/tuna-f1sh)
1617

1718
### 1.5.2 (2017-01-11)
1819

arduino-mk-vars.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ The following are the different variables that can be overwritten in the user ma
1111
* [Avrdude setting variables](#avrdude-setting-variables)
1212
* [Bootloader variables](#bootloader-variables)
1313
* [ChipKIT variables](#chipkit-variables)
14+
* [Ctags variables](#ctags-variables)
1415

1516
## Global variables
1617

@@ -1402,6 +1403,57 @@ MPIDE_DIR = $(HOME)/mpide
14021403

14031404
----
14041405

1406+
## Ctags variables
1407+
1408+
### TAGS_FILE
1409+
1410+
**Description:**
1411+
1412+
Output file name for tags. Defaults to 'tags'.
1413+
1414+
**Example:**
1415+
1416+
```Makefile
1417+
TAGS_FILE = .tags
1418+
```
1419+
1420+
**Requirement:** *Optional*
1421+
1422+
----
1423+
1424+
### CTAGS_OPTS
1425+
1426+
**Description:**
1427+
1428+
Additional options to pass to `ctags` command.
1429+
1430+
**Example:**
1431+
1432+
```Makefile
1433+
# Run ctags in verbose mode
1434+
CTAGS_OPTS = -V
1435+
```
1436+
1437+
**Requirement:** *Optional*
1438+
1439+
----
1440+
1441+
### CTAGS_CMD
1442+
1443+
**Description:**
1444+
1445+
Location of `ctags` binary. Defaults to user path.
1446+
1447+
**Example:**
1448+
1449+
```Makefile
1450+
CTAGS_CMD = /usr/local/bin/
1451+
```
1452+
1453+
**Requirement:** *Optional*
1454+
1455+
----
1456+
14051457
### MPIDE_PREFERENCES_PATH
14061458

14071459
**Description:**

0 commit comments

Comments
 (0)