RN rnmake  3.0.0
Rules.AtmelMcu.mk
Go to the documentation of this file.
1 ################################################################################
2 #
3 # Rules.AtmelMcu.mk
4 #
5 ifdef RNMAKE_DOXY
6 /*!
7 \file
8 
9 \brief Alternative rules file to support Atmel16 Microcontroller Units.
10 
11 Include this file in each appropriate local make file (usually near the bottom).
12 Only one library or program target is supported per make file, unlike the
13 standard Rules.mk file.
14 
15 \sa Rules.mk for more details on standard make targets.
16 
17 \pkgsynopsis
18 RN Make System
19 
20 \pkgfile{Rules.AtmelMcu.mk}
21 
22 \pkgauthor{Robin Knight,robin.knight@roadnarrows.com}
23 
24 \pkgcopyright{2009-2018,RoadNarrows LLC,http://www.roadnarrows.com}
25 
26 \license{MIT}
27 
28 \EulaBegin
29 \EulaEnd
30 
31 \cond RNMAKE_DOXY
32  */
33 endif
34 #
35 ################################################################################
36 
37 _RULES_ATMEL_MCU_MK = 1
38 
39 #------------------------------------------------------------------------------
40 # Prelims
41 
42 # this makefile is last in the list (must call before any includes from this)
43 RNMAKE_ROOT = $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
44 
45 # version of these makefile rules
46 RNMAKE_RULES_VER_MAJOR := 3
47 RNMAKE_RULES_VER_MINOR := 0
48 
49 # default goal
50 .DEFAULT_GOAL := all
51 
52 # list of command-line goals
53 GOAL_LIST = $(MAKECMDGOALS)
54 
55 # add default if empty
56 ifeq "$(GOAL_LIST)" ""
57  GOAL_LIST = $(.DEFAULT_GOAL)
58 endif
59 
60 # save first and last goals
61 FIRST_GOAL = $(firstword $(GOAL_LIST))
62 LAST_GOAL = $(lastword $(GOAL_LIST))
63 
64 # list of goals with subdirectory traversals
65 GOALS_WITH_SUBDIRS =
66 
67 
68 #------------------------------------------------------------------------------
69 # Environment (Env.mk)
70 #
71 # Parse rnmake specific command-line and environment variables.
72 
73 ifeq ($(_ENV_MK),)
74 include $(RNMAKE_ROOT)/Env.mk
75 endif
76 
77 #------------------------------------------------------------------------------
78 # Standard collection of RN Make System functions and varibbles (Std.mk)
79 
80 ifeq ($(_STD_MK),)
81 include $(RNMAKE_ROOT)/Std.mk
82 endif
83 
84 
85 # -------------------------------------------------------------------------
86 # Architecture Dependent Definitions
87 
88 # Standard rnmake rules do not support the following targets.
89 ifneq "$(findstring $(RNMAKE_ARCH_TAG),atmega16)" ""
90  $(error Rules.mk does not support $(arch) rules)
91 endif
92 
93 # architecture makefile name
94 RNMAKE_ARCH_MKFILE = $(call findReqFile,\
95  $(RNMAKE_ROOT)/Arch/Arch.$(RNMAKE_ARCH_TAG).mk,\
96  See $(RNMAKE_ROOT)/Arch for available architectures)
97 
98 # Include the architecture make file.
99 ifeq ($(_ARCH_$(RNMAKE_ARCH_TAG)_MK),)
100  include $(RNMAKE_ARCH_MKFILE)
101 endif
102 
103 # Included architecture makefile must define RNMAKE_ARCH which defines the
104 # real architecture.
105 ifeq ($(RNMAKE_ARCH),)
106  $(error 'RNMAKE_ARCH': Not defined in including arhitecture makefile)
107 endif
108 
109 
110 #------------------------------------------------------------------------------
111 # Package Master Makefile (required)
112 #
113 
114 # must be defined in including makefile
115 ifeq ($(RNMAKE_PKG_ROOT),)
116  $(error 'RNMAKE_PKG_ROOT': Not defined in including Makefile)
117 endif
118 
119 # package makefile
120 RNMAKE_PKG_MKFILE = $(call findReqFile,$(RNMAKE_PKG_ROOT)/make/Pkg.mk,)
121 
122 # package root absolute path
123 RNMAKE_PKG_ROOT := $(realpath $(RNMAKE_PKG_ROOT))
124 
125 # required
126 ifeq ($(_PKG_MK),)
127 include $(RNMAKE_PKG_MKFILE)
128 endif
129 
130 # Included package master makefile must define RNMAKE_PKG which defines the
131 # package name.
132 ifeq ($(RNMAKE_PKG),)
133  $(error 'RNMAKE_PKG': Not defined in including arhitecture makefile)
134 endif
135 
136 
137 #------------------------------------------------------------------------------
138 # Product Makefile (Optional)
139 
140 ifdef RNMAKE_PROD_MKFILE
141  ifeq ($(_PROD_MK),)
142  # optionally include (no error if not found)
143  -include $(RNMAKE_PROD_MKFILE)
144  endif
145 endif
146 
147 
148 #------------------------------------------------------------------------------
149 # Include helper make files (Cmds.mk, Colors.mk)
150 #
151 # Can conditionally define macros by architecuture definitions included above.
152 #
153 
154 # basic host commands
155 ifeq ($(_CMDS_MK),)
156 include $(RNMAKE_ROOT)/Cmds.mk
157 endif
158 
159 # color schemes
160 ifeq ($(_COLORS_MK),)
161 ifneq "$(color)" "off"
162 include $(RNMAKE_ROOT)/Colors.mk
163 endif
164 endif
165 
166 
167 
168 #------------------------------------------------------------------------------
169 # Install Directories - Override as necessary in including Makefile.
170 # See Also: Arch.<arch>.mk.
171 # Note: These are traditional configuration names - keep the naming convention.
172 #
173 ifndef prefix
174 prefix = /usr/local
175 endif
176 
177 ifndef exec_prefix
178 exec_prefix = $(prefix)
179 endif
180 
181 ifndef bindir
182 bindir = $(exec_prefix)/bin
183 endif
184 
185 ifndef sbindir
186 sbindir = $(exec_prefix)/sbin
187 endif
188 
189 ifndef libexecdir
190 libexecdir = $(exec_prefix)/libexec
191 endif
192 
193 ifndef sysconfdir
194 sysconfdir = $(prefix)/etc
195 endif
196 
197 ifndef localstatedir
198 localstatedir = $(prefix)/var
199 endif
200 
201 ifndef libdir
202 libdir = $(exec_prefix)/lib
203 endif
204 
205 ifndef includedir
206 includedir = $(prefix)/include
207 endif
208 
209 ifndef sharedir
210 sharedir = $(prefix)/share
211 endif
212 
213 ifndef infodir
214 infodir = $(prefix)/info
215 endif
216 
217 ifndef docdir
218 docdir = $(prefix)/share/doc
219 endif
220 
221 ifndef mandir
222 mandir = $(prefix)/man
223 endif
224 
225 
226 #------------------------------------------------------------------------------
227 # Distribution Directories (Architecture Dependent)
228 # Notes:
229 # Documents are architecture independent
230 #
231 DIST_ROOT = $(distroot)
232 DIST_ARCH = $(DIST_ROOT)/dist.$(ARCH)
233 
234 # Product overrides - some tarballs contain files from all packages
235 ifdef PROD_FULL_NAME
236 DIST_NAME_BIN = $(PROD_FULL_NAME)
237 else
238 DIST_NAME_BIN = $(RNMAKE_PKG_FULL_NAME)
239 endif
240 
241 # Distributions Directories
242 DISTDIR_BIN = $(DIST_ARCH)/bin
243 DISTDIR_LIB = $(DIST_ARCH)/lib
244 DISTDIR_INCLUDE = $(DIST_ARCH)/include
245 DISTDIR_ETC = $(DIST_ARCH)/etc
246 DISTDIR_MAN = $(DIST_ARCH)/man
247 DISTDIR_SHARE = $(DIST_ARCH)/share/$(RNMAKE_PKG_FULL_NAME)
248 DISTDIR_DOC = $(DIST_ARCH)/doc/$(RNMAKE_PKG_FULL_NAME)-doc
249 DISTDIR_SRC = $(DIST_ARCH)/src/$(RNMAKE_PKG_FULL_NAME)
250 DISTDIR_TMP = $(DIST_ARCH)/tmp/$(DIST_NAME_BIN)-$(ARCH)
251 DISTDIR_LIST = $(DISTDIR_BIN) \
252  $(DISTDIR_INCLUDE) \
253  $(DISTDIR_LIB) \
254  $(DISTDIR_ETC) \
255  $(DISTDIR_SHARE) \
256  $(DISTDIR_DOC) \
257  $(DISTDIR_SRC) \
258  $(DISTDIR_TMP) \
259  $(DISTDIR_MAN)
260 
261 # documentation subdirectories
262 DIST_SRCDOC = srcdoc
263 DISTDIR_DOC_SRC = $(DISTDIR_DOC)/$(DIST_SRCDOC)
264 DISTDIR_DOC_SRC_IMG = $(DISTDIR_DOC_SRC)/images
265 
266 # tar ball files - source, documentation, binary
267 DIST_TARBALL_SRC = $(RNMAKE_PKG_FULL_NAME)-src.tar.gz
268 DIST_TARBALL_DOC = $(RNMAKE_PKG_FULL_NAME)-doc.tar.gz
269 DIST_TARBALL_BIN = $(DIST_NAME_BIN)-$(ARCH).tar.gz
270 
271 # Object Directory
272 OBJDIR = obj/obj.$(ARCH)
273 
274 # Dependencies Directory
275 DEPSDIR = .deps
276 
277 # Dependencies File
278 DEPSFILE = $(DEPSDIR)/deps.$(ARCH)
279 
280 
281 #------------------------------------------------------------------------------
282 # Build Flags
283 # Merge Architecture, Package and Parent Makefile variables into build flags.
284 #
285 
286 # Include Flags
287 EXTRA_INCLUDES = $(addprefix -I,$(EXTRA_INCDIRS))
288 EXTRA_SYS_INCLUDES= $(addprefix -I,$(EXTRA_SYS_INCDIRS))
289 PKG_INCLUDES = $(addprefix -I,$(RNMAKE_PKG_INCDIRS))
290 PROD_INCLUDES = $(addprefix -I,$(RNMAKE_PROD_INCDIRS))
291 ARCH_INCLUDES = $(addprefix -I,$(RNMAKE_ARCH_INCDIRS))
292 PKG_SYS_INCLUDES = $(addprefix -I,$(RNMAKE_PKG_SYS_INCDIRS))
293 DIST_INCLUDES = -I$(DISTDIR_INCLUDE)
294 INCLUDES = -I. \
295  $(EXTRA_INCLUDES) \
296  $(RNMAKE_PKG_INCLUDES) \
297  $(PROD_INCLUDES) \
298  $(ARCH_INCLUDES) \
299  $(DIST_INCLUDES) \
300  -I$(includedir) \
301  $(EXTRA_SYS_INCLUDES) \
302  $(RNMAKE_PKG_SYS_INCLUDES)
303 
304 # CPP Flags
305 CPPFLAGS = $(EXTRA_CPPFLAGS) \
306  $(RNMAKE_PKG_CPPFLAGS) \
307  $(RNMAKE_ARCH_CPPFLAGS) \
308  -DARCH_$(ARCH) \
309  -DARCH=\"$(ARCH)\"
310 
311 # Assembler Flags
312 ASFLAGS = $(EXTRA_ASFLAGS) $(RNMAKE_PKG_ASFLAGS) $(ARCH_ASFLAGS)
313 
314 # C Flags
315 CFLAGS = $(EXTRA_CFLAGS) $(RNMAKE_PKG_CFLAGS) $(RNMAKE_ARCH_CFLAGS)
316 
317 # CXX Flags
318 CXXFLAGS = $(EXTRA_CXXFLAGS) $(RNMAKE_PKG_CXXFLAGS) $(RNMAKE_ARCH_CXXFLAGS)
319 
320 # Library Path Flags
321 EXTRA_LD_LIBPATHS = $(addprefix -L,$(EXTRA_LD_LIBDIRS))
322 PKG_LD_LIBPATHS = $(addprefix -L,$(RNMAKE_PKG_LD_LIBDIRS))
323 DIST_LD_LIBPATHS = -L$(DISTDIR_LIB)
324 LD_LIBPATHS = $(EXTRA_LD_LIBPATHS) \
325  $(RNMAKE_PKG_LD_LIBPATHS) \
326  $(DIST_LD_LIBPATHS) \
327  -L$(libdir) \
328  $(ARCH_LD_LIBPATHS)
329 
330 # External Libraries
331 LD_LIBS = $(EXTRA_LD_LIBS) $(RNMAKE_PKG_LD_LIBS) $(ARCH_LD_LIBS)
332 
333 LDFLAGS = $(EXTRA_LDFLAGS) $(RNMAKE_PKG_LDFLAGS) $(ARCH_LDFLAGS)
334 
335 # default link-loader is c compiler - override if using C++
336 ifeq "$(LANG)" "C++"
337 LD = $(LD_CXX)
338 endif
339 
340 #------------------------------------------------------------------------------
341 # Build Target Names
342 # Construct build target files and set from parent makefile.
343 #
344 
345 # build either a library or a program, but not both
346 ifdef TGT_LIB
347 TARGET = $(TGT_LIB)
348 BUILD = lib
349 else
350 TARGET = $(TGT_PGM)
351 BUILD = pgm
352 endif
353 
354 # Generate list of obejcts from sources
355 OBJS = $(addprefix $(OBJDIR)/,$($(TARGET).SRC.C:.c=.o) \
356  $($(TARGET).SRC.S:.S=.o))
357 
358 # Output listing files
359 LSTS = $($(TARGET).SRC.C:.c=.lst) $($(TARGET).SRC.S:.S=.lst)
360 
361 # Release files
362 REL_FILES = $(RNMAKE_PKG_REL_FILES) $(EXTRA_REL_FILES)
363 
364 # Release Files
365 FQ_REL_FILES = $(addprefix $(DISTDIR_DOC)/,$(REL_FILES))
366 
367 
368 #------------------------------------------------------------------------------
369 # Target Specific Variables
370 #
371 
372 CURGOAL = $(GOAL)
373 all: CURGOAL := all
374 deps: CURGOAL := deps
375 install: CURGOAL := install
376 install-fw: CURGOAL := install
377 clean: CURGOAL := clean
378 distclean: CURGOAL := distclean
379 distclean-fw: CURGOAL := distclean
380 clobber: CURGOAL := clobber
381 
382 
383 #------------------------------------------------------------------------------
384 # Common Support Functions and Macros
385 #
386 
387 # GNU Make has no boolean functions (why???), fake it.
388 neq = $(filter-out $(1),$(2))
389 eq = $(if $(call neq,$(1),$(2)),,1)
390 
391 # Returns "1" if given entity exists.
392 isFile = $(shell if [ -f $(1) ]; then echo 1; fi)
393 isDir = $(shell if [ -d $(1) ]; then echo 1; fi)
394 
395 
396 # Make obj/obj-<ARCH> in current directory
397 mkobjdir = @test -d $(OBJDIR) || $(MKDIR) $(OBJDIR)
398 
399 
400 ########################### Explicit Rules #####################################
401 
402 # -------------------------------------------------------------------------
403 # Target: all (default)
404 # Desc: Front end to making the [sub]package(s) (libraries, programs, tools,
405 # documents, etc).
406 # Notes: There are two version:
407 # 1) only done once on the first invocation and
408 # 2) for all other invocations.
409 .PHONY: all
410 all: mkdistdirs pkgbanner $(EXTRA_TGT_ALL) pkg footer
411 
412 # -------------------------------------------------------------------------
413 # Target: pkg
414 # Desc: Makes the distribution [sub]package(s) (libraries, programs, tools,
415 # documents, etc).
416 .PHONY: pkg
417 pkg: $(BUILD) hdrs rel subdirs
418 
419 
420 # -------------------------------------------------------------------------
421 # Target: lib (future)
422 # Desc: Makes all libraries in current directory.
423 
424 # Make all libraries
425 .PHONY: lib
426 lib: stlib
427 
428 # Make all static libraries
429 .PHONY: stlibs
430 stlib:
431 
432 
433 # -------------------------------------------------------------------------
434 # Target: pgm
435 # Desc: Makes all firmware programs (images) in current directory.
436 
437 # Make the program
438 .PHONY: pgm $(TGT_PGM)
439 pgm $(TGT_PGM): elf hex eep lss sym cppgm
440 
441 # copy program to distribution directory
442 .PHONY: cppgm
443 cppgm:
444  @$(CP) $(TARGET).hex $(DISTDIR_BIN)/.
445 
446 # -------------------------------------------------------------------------
447 # Target: elf hex eep lss sym
448 # Desc: Make an intermediary file.
449 
450 .PHONY: elf hex eep lss sym
451 
452 elf: $(TARGET).elf
453 hex: $(TARGET).hex
454 eep: $(TARGET).eep
455 lss: $(TARGET).lss
456 sym: $(TARGET).sym
457 
458 # -------------------------------------------------------------------------
459 # Target: AVRDUDE
460 # Desc: Rules to program and debug using avrdude.
461 
462 # The Command
463 AVRDUDE = avrdude
464 
465 # Programming Hardware:
466 #
467 # One of:
468 # alf avr910 avrisp bascom bsd dt006 pavr picoweb pony-stk200 sp12 stk200
469 # stk500 avrispmkII
470 #
471 # Type: 'avrdude -c ?' to get a full listing.
472 #
473 # Override as necessary.
474 #
475 AVRDUDE_PROGRAMMER ?= avrispmkII
476 
477 # Communication Port
478 #
479 # com1 = serial port. Use lpt1 to connect to parallel port.
480 #
481 # Override as necessary.
482 #
483 #AVRDUDE_PORT = com1 # programmer connected to serial device
484 
485 # USB Communication Port
486 #
487 # If only one AVRISP MKII is connected, the the default 'usb' port suffices.
488 # Otherwise, a portion of the the serial number must be specified. Below are the
489 # serial numbers for the two in-house ISPs. The serial number can be found on
490 # the bottom of the ISP.
491 #
492 AVRDUDE_PORT ?= usb
493 #AVRDUDE_PORT = usb:58:68 # usb port with avrispmkII serialno
494 #AVRDUDE_PORT = usb:82:82 # usb port with avrispmkII serialno
495 
496 # Trick to map FORMAT to avrdude file format field
497 AVRDUDE_FLASH_FMT = $(basename $(filter %.$(FORMAT),s.srec r.binary i.ihex))
498 AVRDUDE_FLASH_FMT ?= i
499 
500 # Write Flash Memory Operation
501 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex:$(AVRDUDE_FLASH_FMT)
502 
503 # Write EEPROM Memory Operation
504 AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep
505 
506 # Write Fuse High Byte Memory Operation
507 AVRDUDE_WRITE_HFUSE = -U hfuse:w:$(FUSE_HIGH):m
508 
509 # Write Fuse High Byte Memory Operation
510 AVRDUDE_WRITE_LFUSE = -U lfuse:w:$(FUSE_LOW):m
511 
512 # Uncomment the following if you want avrdude's erase cycle counter.
513 # Note that this counter needs to be initialized first using -Yn,
514 # see avrdude manual.
515 #AVRDUDE_FLAGS_ERASE_COUNTER = -y
516 
517 # Uncomment the following if you do not wish a verification to be
518 # performed after programming the device.
519 #AVRDUDE_FLAGS_NO_VERIFY = -V
520 
521 # Increase verbosity level. Please use this when submitting bug
522 # reports about avrdude. See <http://savannah.nongnu.org/projects/avrdude>
523 # to submit bug reports.
524 AVRDUDE_FLAGS_VERBOSE = -v
525 
526 # Communication flags
527 AVRDUDE_FLAGS_COM = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER)
528 
529 # AVRDUDE common flags
530 AVRDUDE_FLAGS = $(AVRDUDE_FLAGS_COM) \
531  $(AVRDUDE_FLAGS_NO_VERIFY) \
532  $(AVRDUDE_FLAGS_VERBOSE) \
533  $(AVRDUDE_FLAGS_ERASE_COUNTER)
534 
535 # Program device flash
536 .PHONY: flash program
537 flash program: $(TARGET).hex
538  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH)
539 
540 # Program device EEPROM
541 .PHONY: eeprom
542 eeprom: $(TARGET).eep
543  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM)
544 
545 # Program the device fuse high byte.
546 .PHONY: hfuse
547 -hfuse:
548  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_HFUSE)
549 
550 # Program the device fuse low byte.
551 .PHONY: lfuse
552 lfuse:
553  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_LFUSE)
554 
555 # Program the device fuses.
556 .PHONY: fuses
557 fuses:
558  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_HFUSE) \
559  $(AVRDUDE_WRITE_LFUSE)
560 
561 # Program the whole enchilada.
562 .PHONY: program-all
563 program-all: $(TARGET).hex $(TARGET).eep
564  $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) \
565  $(AVRDUDE_WRITE_EEPROM) \
566  $(AVRDUDE_WRITE_HFUSE) \
567  $(AVRDUDE_WRITE_LFUSE)
568 
569 # AVRDUD command-line interface interactive mode
570 avrdude:
571  $(AVRDUDE) $(AVRDUDE_FLAGS) -t
572 
573 
574 # -------------------------------------------------------------------------
575 # Target: hdrs
576 # Desc: Makes interface header files
577 
578 # List of all header tags
579 HDR_TAG_LIST = $(addsuffix .HDRS.H,$(RNMAKE_DIST_HDRS))
580 
581 # Complete list of headers
582 PREREQ_HDRS = $(foreach tag,$(HDR_TAG_LIST),$($(tag)))
583 
584 # Make all distribution headers
585 .PHONY: hdrs
586 hdrs: $(PREREQ_HDRS)
587 
588 # Copy newer headers to distribution include [sub]directory
589 $(PREREQ_HDRS):
590  @for h in $(@); \
591  do\
592  src=$(RNMAKE_PKG_ROOT)/include/$$h; \
593  dst=$(DISTDIR_INCLUDE)/$$h; \
594  hdir=$$(dirname $$dst); \
595  if [ ! -f $$dst -o $$src -nt $$dst ]; \
596  then \
597  echo " $$dst"; \
598  test -d $$hdir || $(MKDIR) $$hdir; \
599  $(CP) $$src $$dst; \
600  fi; \
601  done
602 
603 # -------------------------------------------------------------------------
604 # Target: rel
605 # Desc: Makes all release files
606 # Notes: Release files are only made at top level
607 .PHONY: rel
608 ifeq "$(RNMAKE_PKG_ROOT)" "."
609 rel: $(FQ_REL_FILES)
610 else
611 rel:
612 endif
613 
614 .PHONY: $(DISTDIR_DOC)/VERSION.txt
615 $(DISTDIR_DOC)/VERSION.txt:
616  @echo ""
617  @echo " $@"
618  @echo "$(RNMAKE_PKG) v$(RNMAKE_PKG_VERSION_DOTTED)" > $@
619  @echo "Copyright (C) $(RNMAKE_PKG_VERSION_DATE) RoadNarrows LLC" >> $@
620  @echo "" >> $@
621  @echo "Compiled: `date`" >> $@
622 
623 $(DISTDIR_DOC)/README.md: README.md
624  @echo ""
625  @echo " $@"
626  -$(CP) README.md $@
627 
628 $(DISTDIR_DOC)/README.txt: README.txt
629  @echo ""
630  @echo " $@"
631  -$(CP) README.txt $@
632 
633 $(DISTDIR_DOC)/README.xml: README.xml
634  @echo ""
635  @echo " $@"
636  -$(CP) README.xml $@
637 
638 
639 # -------------------------------------------------------------------------
640 # Target: documents
641 # Desc: Make documentation
642 .PHONY: documents
643 documents: docs-src-gen
644 
645 # documentation generator from source files
646 ifndef HTML_HEADER
647 HTML_HEADER = $(rnmake)/doxy/rnr_doxy_header.html
648 endif
649 
650 ifndef HTML_FOOTER
651 HTML_FOOTER = $(rnmake)/doxy/rnr_doxy_footer.html
652 endif
653 
654 ifndef HTML_STYLESHEET
655 HTML_STYLESHEET = $(rnmake)/doxy/rnr_doxy.css
656 endif
657 
658 ifndef DOXY_IMAGES
659 DOXY_IMAGES = $(rnmake)/doxy/rnr_images
660 endif
661 
662 docs-src-gen:
663  @if [ "$(RNMAKE_DOXY_CONF_FILE)" ]; \
664  then \
665  echo ""; \
666  echo "Making source documentation"; \
667  test -d $(DISTDIR_DOC) || $(MKDIR) $(DISTDIR_DOC); \
668  test -d $(DISTDIR_DOC_SRC_IMG) || $(MKDIR) $(DISTDIR_DOC_SRC_IMG); \
669  $(CP) -p $(DOXY_IMAGES)/* $(DISTDIR_DOC_SRC_IMG)/.; \
670  (cat $(RNMAKE_DOXY_CONF_FILE); \
671  echo "PROJECT_NUMBER=$(RNMAKE_PKG_VERSION_DOTTED)"; \
672  echo "HTML_HEADER=$(HTML_HEADER)"; \
673  echo "HTML_FOOTER=$(HTML_FOOTER)"; \
674  echo "HTML_STYLESHEET=$(HTML_STYLESHEET)"; \
675  echo "EXAMPLE_PATH=$(RNMAKE_PKG_ROOT)/examples"; \
676  echo "OUTPUT_DIRECTORY=$(DISTDIR_DOC)"; \
677  echo "HTML_OUTPUT=$(DIST_SRCDOC)"; \
678  ) | doxygen - >$(RNMAKE_PKG_ROOT)/doxy.out.log 2>$(RNMAKE_PKG_ROOT)/doxy.err.log; \
679  $(rnmake)/utils/doxyindex.sh \
680  -t "$(RNMAKE_PKG) v$(RNMAKE_PKG_VERSION_DOTTED)" \
681  -h $(HTML_HEADER) \
682  >$(DISTDIR_DOC)/$(DIST_SRCDOC)/index.html; \
683  fi
684 
685 
686 # -------------------------------------------------------------------------
687 # Target: mkdistdirs
688 # Desc: Make Distribution Directories
689 .PHONY: mkdistdirs $(DISTDIR_LIST)
690 mkdistdirs: $(DISTDIR_LIST)
691 
692 $(DISTDIR_LIST):
693  @$(MKDIR) $@;
694 
695 # -------------------------------------------------------------------------
696 # Target: install
697 # Desc: Install the distribution
698 .PHONY: install install-fw
699 install install-fw: pkgbanner all $(EXTRA_TGT_INSTALL) install-bin install-lib \
700  install-includes install-docs install-share install-etc \
701  footer
702 
703 # install bin
704 install-bin:
705  @echo ""
706  @echo "Installing executables to $(bindir)"
707  @$(rnmake)/utils/doinstall.sh 755 $(DISTDIR_BIN) $(bindir)
708  $(call POSTINStemplate,$(STRIP_EXE),$(DISTDIR_BIN),$(bindir))
709 
710 # install lib
711 install-lib:
712  @echo ""
713  @echo "Installing libraries to $(libdir)"
714  @$(rnmake)/utils/doinstall.sh 755 $(DISTDIR_LIB) $(libdir)
715  $(call POSTINStemplate,$(STRIP_LIB),$(DISTDIR_LIB),$(libdir))
716 
717 # install includes
718 install-includes:
719  @echo ""
720  @echo "Installing includes to $(includedir)"
721  @$(rnmake)/utils/doinstall.sh 664 $(DISTDIR_INCLUDE) $(includedir)
722 
723 # install documentation
724 install-docs: documents
725  @echo ""
726  @echo "Installing documents to $(docdir)/$(RNMAKE_PKG_FULL_NAME)"
727  @$(rnmake)/utils/doinstall.sh -s 664 $(DISTDIR_DOC) $(docdir)/$(RNMAKE_PKG_FULL_NAME)
728 
729 # install share
730 install-share:
731  @echo ""
732  @echo "Installing system share files to $(sharedir)"
733  @$(rnmake)/utils/doinstall.sh -s 664 $(DISTDIR_SHARE) $(sharedir)/$(RNMAKE_PKG_FULL_NAME)
734 
735 # install etc
736 install-etc:
737  @echo ""
738  @echo "Installing system configuration to $(sysconfdir)"
739  @$(rnmake)/utils/doinstall.sh 664 $(DISTDIR_ETC) $(sysconfdir)
740 
741 # Post-Install directory component template
742 # Usage: POSTINStemplate postprocess source_dir dest_dir
743 define POSTINStemplate
744  @cd $(2); \
745  srclist=$$($(FIND) . -type f); \
746  for src in $$srclist; \
747  do \
748  dst="$(3)/$${src##./}"; \
749  echo " $$dst"; \
750  $(1) $$dst; \
751  done;
752 endef
753 
754 
755 # -------------------------------------------------------------------------
756 # Target: tarballs
757 # Desc: Makes package tar balls
758 # -------------------------------------------------------------------------
759 .PHONY: tarballs
760 tarballs: pkgbanner tarball-bin tarball-doc tarball-src
761 
762 .PHONY: tarball-doc
763 tarball-doc:
764  $(if $(call isDir,$(DISTDIR_DOC)),,\
765  $(error No documentation - Try 'make documents' first))
766  @cd $(DIST_ARCH)/doc; \
767  $(TAR) ../../$(DIST_TARBALL_DOC) $(RNMAKE_PKG_FULL_NAME)-doc
768 
769 .PHONY: tarball-src
770 tarball-src:
771  @test -d $(DISTDIR_SRC) || $(MKDIR) $(DISTDIR_SRC)
772  @$(FIND) $(RNMAKE_PKG_ROOT) \( \
773  -wholename '$(RNMAKE_PKG_ROOT)/dist' -or -wholename dist -or \
774  -wholename '$(RNMAKE_PKG_ROOT)/loc' -or -wholename loc -or \
775  -name '*.svn*' -or -wholename '.svn' -or \
776  -wholename '*.deps*' -or -wholename '.deps' -or \
777  -wholename '*obj*' -or -wholename 'obj' -or -wholename '*.o' -or \
778  -wholename '*.out' -or -wholename '*.log' -or \
779  -wholename '*.pyc' -or -wholename '*.pyo' \
780  \) -prune -or -print | \
781  while read src; \
782  do \
783  $(rnmake)/utils/cppath.sh $$src $(DISTDIR_SRC); \
784  done;
785  @cd $(DIST_ARCH)/src; \
786  $(TAR) ../../$(DIST_TARBALL_SRC) $(RNMAKE_PKG_FULL_NAME)
787 
788 .PHONY: tarball-bin
789 tarball-bin:
790  $(if $(call isDir,$(DIST_ARCH)),,$(error Nothing made - Try 'make' first))
791  @test -d $(DISTDIR_TMP) || $(MKDIR) $(DISTDIR_TMP)
792  @cd $(DIST_ARCH); \
793  $(FIND) bin lib include etc share -print | \
794  while read src; \
795  do \
796  if [ -f $$src ]; \
797  then \
798  $(rnmake)/utils/cppath.sh $$src tmp/$(DIST_NAME_BIN)-$(ARCH); \
799  fi; \
800  done;
801  @cd $(DIST_ARCH)/tmp; \
802  $(TAR) ../../$(DIST_TARBALL_BIN) $(DIST_NAME_BIN)-$(ARCH)
803 
804 # -------------------------------------------------------------------------
805 # Target: deps
806 # Desc: Makes dependencies
807 # -------------------------------------------------------------------------
808 .PHONY: deps
809 deps: pkgbanner mkdepsdir $(EXTRA_TGT_DEPS) hdrdeps libdeps subdirs
810 
811 .PHONY: hdrdeps
812 hdrdeps:
813  @echo "Making dependencies for $(CURDIR)"
814  @echo $(call hdrdeps_sh,$(TGT_LIB) $(TGT_PGM))
815 
816 hdrdeps_sh = \
817  $(shell $(rnmake)/utils/hdrdeps.sh \
818  -c "$(RNMAKE_MAKEDEPS)" \
819  -f $(DEPSFILE) \
820  -o $(OBJDIR) \
821  -d "$(CPPFLAGS)" \
822  $(INCLUDES) \
823  $(foreach f,\
824  $(sort $(addsuffix .SRC.C,$(1)) $(addsuffix .SRC.CXX,$(1))),\
825  $($(f))))
826 
827 libdeps:
828 
829 mkdepsdir:
830  @test -d $(DEPSDIR) || $(MKDIR) $(DEPSDIR)
831 
832 # -------------------------------------------------------------------------
833 # Target: clean
834 # Desc: Deletes generated intermediate files
835 # -------------------------------------------------------------------------
836 .PHONY: clean do-clean
837 clean: pkgbanner do-clean $(EXTRA_TGT_CLEAN) subdirs
838 
839 do-clean:
840  @echo "Cleaning $(CURDIR)"
841  $(RM) *.o *.ii *.c~ *.cxx~ .h~ $(RNMAKE_DIST_PGMS) a.out doxy.*.log
842  $(RM) *.hex *.eep *.cof *.elf *map *.a90 *.sym *.lnk *.lss
843  $(RM) $(LSTS)
844  $(RM) $(OBJDIR)
845 
846 # -------------------------------------------------------------------------
847 # Target: distclean (clobber)
848 # Desc: Cleans plus deletes distribution
849 # -------------------------------------------------------------------------
850 .PHONY: distclean clobber distclean-fw
851 distclean clobber distclean-fw: pkgbanner clean $(EXTRA_TGT_DISTCLEAN)
852  @echo "\nClobbering distribution $(CURDIR)"
853  $(RM) $(DIST_ARCH)
854  $(RM) $(DIST_ROOT)/$(RNMAKE_PKG_FULL_NAME)-$(ARCH).tar.gz
855  $(RM) $(DIST_ROOT)/$(RNMAKE_PKG_FULL_NAME)-doc.tar.gz
856  $(RM) $(DIST_ROOT)/$(RNMAKE_PKG_FULL_NAME)-src.tar.gz
857  $(RM) $(DEPSFILE)
858 
859 # -------------------------------------------------------------------------
860 # Target: subdirs
861 # Desc: Recursively make subdirectories.
862 # -------------------------------------------------------------------------
863 .PHONY: subdirs $(RNMAKE_SUBDIRS)
864 subdirs: $(RNMAKE_SUBDIRS)
865 
866 $(RNMAKE_SUBDIRS):
867  $(call dirbanner,$(@))
868  @$(MAKE) $(EXTRA_MAKE_FLAGS) -C $(@) $(CURGOAL)
869 
870 # -------------------------------------------------------------------------
871 # Pretty Print Support "Targets"
872 # -------------------------------------------------------------------------
873 
874 # Directory Banner Template
875 define dirbanner
876  @if [ "$(1)" != "" ]; then \
877  subdirnam="$(patsubst $(dir $(RNMAKE_PKG_ROOT))%,%,$(CURDIR)/$(1))";\
878  echo ""; \
879  echo "$(dashline)";\
880  echo "Directory: $$subdirnam";\
881  echo "Target: $(CURGOAL)";\
882  echo "$(dashline)";\
883  fi
884 endef
885 
886 # Pretty Print Major Banner
887 .PHONY: pkgbanner
888 pkgbanner:
889  @if [ "$(MAKELEVEL)" = "0" -a "$(CURGOAL)" = "$(GOAL)" ]; then \
890  echo "$(boldline)";\
891  echo "Package: $(RNMAKE_PKG_FULL_NAME)";\
892  echo "Package Root: $(RNMAKE_PKG_ROOT)";\
893  echo "Architecture: $(ARCH)";\
894  echo "Directory: $(CURDIR)";\
895  echo "Target: $(CURGOAL)";\
896  echo "Start: `date`";\
897  echo "$(boldline)";\
898  fi
899 
900 # Pretty Print Footer
901 .PHONY: footer
902 footer:
903  @if [ "$(MAKELEVEL)" = "0" -a "$(CURGOAL)" = "$(GOAL)" ]; then \
904  echo "";\
905  echo " ###";\
906  echo "Finished: `date`";\
907  echo " ###";\
908  fi
909 
910 dashline := \
911  "-----------------------------------------------------------------------------"
912 boldline := \
913  "============================================================================="
914 
915 # Display size of file.
916 HEXSIZE_CMD = $(SIZE) --target=$(FORMAT) $(TARGET).hex
917 ELFSIZE_CMD = $(SIZE) -A $(TARGET).elf
918 
919 sizes:
920  $(call reportsizes)
921 
922 define reportsizes
923  @echo
924  @if [ -f $(TARGET).elf ]; \
925  then \
926  echo "$(TARGET).elf Sizes:"; \
927  $(ELFSIZE_CMD); \
928  fi
929  @if [ -f $(TARGET).hex ]; \
930  then \
931  echo "$(TARGET).hex Sizes:"; \
932  $(HEXSIZE_CMD); \
933  fi
934 endef
935 
936 # -------------------------------------------------------------------------
937 # Include any dependency file
938 # \todo dependency file should only be included if not nodeps
939 #
940 ifeq "$(CURGOAL)" "all"
941 $(call chkdeps)
942 include $(DEPSFILE)
943 endif
944 
945 # check if dependencies have been made unless nodeps is defined
946 chkdeps:
947  $(if $(or $(nodeps),$(call isFile,$(DEPSFILE))),,\
948  $(error No dependencies file - Try 'make deps' first))
949 
950 
951 # force some targets to always make
952 force: ;
953 
954 
955 ########################### Pattern Rules #####################################
956 
957 # Define Information Messages
958 MSG_COFF = Converting to AVR COFF:
959 MSG_EXTENDED_COFF = Converting to AVR Extended COFF:
960 MSG_FLASH = Creating load file for Flash:
961 MSG_EEPROM = Creating load file for EEPROM:
962 MSG_EXTENDED_LISTING = Creating Extended Listing:
963 MSG_SYMBOL_TABLE = Creating Symbol Table:
964 MSG_LINKING = Linking:
965 
966 
967 # Convert ELF to COFF for use in debugging / simulating in AVR Studio or VMLAB.
968 COFFCONVERT=$(OBJCOPY) --debugging \
969 --change-section-address .data-0x800000 \
970 --change-section-address .bss-0x800000 \
971 --change-section-address .noinit-0x800000 \
972 --change-section-address .eeprom-0x810000
973 
974 coff: $(TARGET).elf
975  @echo
976  @echo $(MSG_COFF) $(TARGET).cof
977  $(COFFCONVERT) -O coff-avr $< $(TARGET).cof
978 
979 extcoff: $(TARGET).elf
980  @echo
981  @echo $(MSG_EXTENDED_COFF) $(TARGET).cof
982  $(COFFCONVERT) -O coff-ext-avr $< $(TARGET).cof
983 
984 # Create final output files (.hex, .eep) from ELF output file.
985 %.hex: %.elf
986  @echo
987  @echo $(MSG_FLASH) $@
988  $(OBJCOPY) -O $(FORMAT) -R .eeprom $< $@
989  @echo "$(TARGET).hex Sizes:"
990  $(HEXSIZE_CMD)
991 
992 %.eep: %.elf
993  @echo
994  @echo $(MSG_EEPROM) $@
995  -$(OBJCOPY) -j .eeprom --set-section-flags=.eeprom="alloc,load" \
996  --change-section-lma .eeprom=0 -O $(FORMAT) $< $@
997 
998 # Create extended listing file from ELF output file.
999 %.lss: %.elf
1000  @echo
1001  @echo $(MSG_EXTENDED_LISTING) $@
1002  $(OBJDUMP) -h -S $< > $@
1003 
1004 # Create a symbol table from ELF output file.
1005 %.sym: %.elf
1006  @echo
1007  @echo $(MSG_SYMBOL_TABLE) $@
1008  $(NM) -n $< > $@
1009 
1010 #LDX = -L/opt/pkg/avr32/avr32-gnu-toolchain-linux_x86_64/lib/gcc/avr32/4.4.3 \
1011 # -L/opt/avr32/lib/ucr3
1012 #LDY = /opt/avr32/lib/ucr3/crt0.o
1013 LDY = c
1014 LDX = -L/usr/lib/avr/lib
1015 
1016 # Link: create ELF output file from object files.
1017 .SECONDARY : $(TARGET).elf
1018 .PRECIOUS : $(OBJS)
1019 %.elf: $(OBJS)
1020  @echo
1021  @echo $(MSG_LINKING) $@
1022  $(CC) $(CFLAGS) $(OBJS) --output $@ $(LDFLAGS)
1023  @echo "$(TARGET).elf Sizes:"
1024  $(ELFSIZE_CMD)
1025 
1026 # Assembler Rule: <name>.S -> $(OBJDIR)/<name>.o
1027 $(OBJDIR)/%.o : %.S
1028  $(mkobjdir)
1029  @echo ""
1030  @echo " $(<)"
1031  @echo
1032  $(AS) $(ASFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(@) -c $(<)
1033 
1034 # C Rule: <name>.c -> $(OBJDIR)/<name>.o
1035 $(OBJDIR)/%.o : %.c
1036  $(mkobjdir)
1037  @echo ""
1038  @echo " $(<)"
1039  $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(@) -c $(<)
1040 
1041 # C++ Rule: <name>.cxx -> $(OBJDIR)/<name>.o
1042 $(OBJDIR)/%.o : %.cxx
1043  $(mkobjdir)
1044  @echo ""
1045  @echo " $(<)"
1046  $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(@) -c $(<)
1047 
1048 # C++ Rule: <name>.cpp -> $(OBJDIR)/<name>.o
1049 $(OBJDIR)/%.o : %.cpp
1050  $(mkobjdir)
1051  @echo ""
1052  @echo " $(<)"
1053  $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(@) -c $(<)
1054 
1055 # Compile a single S file. (Nice for debugging)
1056 %.o : %.S force
1057  $(mkobjdir)
1058  @echo ""
1059  @echo " $(<)"
1060  $(AS) $(ASFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(OBJDIR)/$(@) -c $(<)
1061 
1062 # Compile a single c file. (Nice for debugging)
1063 %.o : %.c force
1064  $(mkobjdir)
1065  @echo ""
1066  @echo " $(<)"
1067  $(CC) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(OBJDIR)/$(@) -c $(<)
1068 
1069 # Compile a single cxx file. (Nice for debugging)
1070 %.o : %.cxx force
1071  $(mkobjdir)
1072  @echo ""
1073  @echo " $(<)"
1074  $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(OBJDIR)/$(@) -c $(<)
1075 
1076 # Compile a single cpp file. (Nice for debugging)
1077 %.o : %.cpp force
1078  $(mkobjdir)
1079  @echo ""
1080  @echo " $(<)"
1081  $(CXX) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(OBJDIR)/$(@) -c $(<)
1082 
1083 # C PreProcess Rule: <name>.c -> <name>.ii
1084 # Generate c preprocessor output (useful to debug compiling errors)
1085 # Historically the output suffix is .i but this can interfere with swig
1086 # interface files that also have the .i suffix. So .ii will be used until
1087 # I find another "standard".
1088 %.ii : %.c force
1089  @echo ""
1090  @echo " $(<)"
1091  $(CC) $(CFLAGS_CPP_ONLY) $(CFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(@) -c $(<)
1092 
1093 # C PreProcess Rule: <name>.cpp -> <name>.ii
1094 # Generate c preprocessor output (useful to debug compiling errors)
1095 %.ii : %.cxx force
1096  @echo ""
1097  @echo " $(<)"
1098  $(CXX) $(CXXFLAGS_CPP_ONLY) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(@) -c $(<)
1099 
1100 # C PreProcess Rule: <name>.cpp -> <name>.ii
1101 # Generate c preprocessor output (useful to debug compiling errors)
1102 %.ii : %.cpp force
1103  @echo ""
1104  @echo " $(<)"
1105  $(CXX) $(CXXFLAGS_CPP_ONLY) $(CXXFLAGS) $(CPPFLAGS) $(INCLUDES) -o $(@) -c $(<)
1106 
1107 null:
1108  @echo "null me"
1109 
1110 
1111 # -------------------------------------------------------------------------
1112 # default error rule (doesn't work yet)
1113 
1114 #%::
1115 # @echo "$(@): Unknown target. See 'make help' for help."
1116 
1117 
1118 ifdef RNMAKE_DOXY
1119 /*! \endcond RNMAKE_DOXY */
1120 endif