1 ################################################################################ 35 ################################################################################ 37 _RULES_ATMEL_MCU_MK = 1
39 #------------------------------------------------------------------------------ 42 # this makefile is last in the list (must call before any includes from this) 43 RNMAKE_ROOT = $(realpath $(dir $(lastword $(MAKEFILE_LIST))))
45 # version of these makefile rules 46 RNMAKE_RULES_VER_MAJOR := 3
47 RNMAKE_RULES_VER_MINOR := 0
52 # list of command-line goals 53 GOAL_LIST = $(MAKECMDGOALS)
55 # add
default if empty
56 ifeq
"$(GOAL_LIST)" "" 57 GOAL_LIST = $(.DEFAULT_GOAL)
60 # save first and last goals 61 FIRST_GOAL = $(firstword $(GOAL_LIST))
62 LAST_GOAL = $(lastword $(GOAL_LIST))
64 # list of goals with subdirectory traversals 68 #------------------------------------------------------------------------------ 69 # Environment (Env.mk) 71 # Parse rnmake specific command-line and environment variables. 74 include $(RNMAKE_ROOT)/Env.mk
77 #------------------------------------------------------------------------------ 78 # Standard collection of RN Make System functions and varibbles (Std.mk) 81 include $(RNMAKE_ROOT)/Std.mk
85 # ------------------------------------------------------------------------- 86 # Architecture Dependent Definitions 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)
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)
98 # Include the architecture make file. 99 ifeq ($(_ARCH_$(RNMAKE_ARCH_TAG)_MK),)
100 include $(RNMAKE_ARCH_MKFILE)
103 # Included architecture makefile must define RNMAKE_ARCH which defines the 105 ifeq ($(RNMAKE_ARCH),)
106 $(error
'RNMAKE_ARCH': Not defined in including arhitecture makefile)
110 #------------------------------------------------------------------------------
111 # Package Master Makefile (required)
114 # must be defined in including makefile 115 ifeq ($(RNMAKE_PKG_ROOT),)
116 $(error
'RNMAKE_PKG_ROOT': Not defined in including Makefile)
120 RNMAKE_PKG_MKFILE = $(call findReqFile,$(RNMAKE_PKG_ROOT)/make/Pkg.mk,)
122 # package root absolute path
123 RNMAKE_PKG_ROOT := $(realpath $(RNMAKE_PKG_ROOT))
127 include $(RNMAKE_PKG_MKFILE)
130 # Included package master makefile must define RNMAKE_PKG which defines the 132 ifeq ($(RNMAKE_PKG),)
133 $(error
'RNMAKE_PKG': Not defined in including arhitecture makefile)
137 #------------------------------------------------------------------------------
138 # Product Makefile (Optional)
140 ifdef RNMAKE_PROD_MKFILE
142 # optionally include (no error if not found) 143 -include $(RNMAKE_PROD_MKFILE)
148 #------------------------------------------------------------------------------
149 # Include helper make files (Cmds.mk, Colors.mk)
151 # Can conditionally define macros by architecuture definitions included above. 154 # basic host commands 156 include $(RNMAKE_ROOT)/Cmds.mk
160 ifeq ($(_COLORS_MK),)
161 ifneq "$(color)" "off"
162 include $(RNMAKE_ROOT)/Colors.mk
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. 178 exec_prefix = $(prefix)
182 bindir = $(exec_prefix)/bin
186 sbindir = $(exec_prefix)/sbin
190 libexecdir = $(exec_prefix)/libexec
194 sysconfdir = $(prefix)/etc
198 localstatedir = $(prefix)/var
202 libdir = $(exec_prefix)/lib
206 includedir = $(prefix)/include
210 sharedir = $(prefix)/share
214 infodir = $(prefix)/info
218 docdir = $(prefix)/share/doc
222 mandir = $(prefix)/man
226 #------------------------------------------------------------------------------ 227 # Distribution Directories (Architecture Dependent) 229 # Documents are architecture independent 231 DIST_ROOT = $(distroot)
232 DIST_ARCH = $(DIST_ROOT)/dist.$(ARCH)
234 # Product overrides - some tarballs contain files from all packages
236 DIST_NAME_BIN = $(PROD_FULL_NAME)
238 DIST_NAME_BIN = $(RNMAKE_PKG_FULL_NAME)
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) \
261 # documentation subdirectories 263 DISTDIR_DOC_SRC = $(DISTDIR_DOC)/$(DIST_SRCDOC)
264 DISTDIR_DOC_SRC_IMG = $(DISTDIR_DOC_SRC)/images
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
272 OBJDIR = obj/obj.$(ARCH)
274 # Dependencies Directory 278 DEPSFILE = $(DEPSDIR)/deps.$(ARCH)
281 #------------------------------------------------------------------------------ 283 # Merge Architecture, Package and Parent Makefile variables into build 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)
296 $(RNMAKE_PKG_INCLUDES) \
301 $(EXTRA_SYS_INCLUDES) \
302 $(RNMAKE_PKG_SYS_INCLUDES)
305 CPPFLAGS = $(EXTRA_CPPFLAGS) \
306 $(RNMAKE_PKG_CPPFLAGS) \
307 $(RNMAKE_ARCH_CPPFLAGS) \
312 ASFLAGS = $(EXTRA_ASFLAGS) $(RNMAKE_PKG_ASFLAGS) $(ARCH_ASFLAGS) 315 CFLAGS = $(EXTRA_CFLAGS) $(RNMAKE_PKG_CFLAGS) $(RNMAKE_ARCH_CFLAGS) 318 CXXFLAGS = $(EXTRA_CXXFLAGS) $(RNMAKE_PKG_CXXFLAGS) $(RNMAKE_ARCH_CXXFLAGS) 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) \ 331 LD_LIBS = $(EXTRA_LD_LIBS) $(RNMAKE_PKG_LD_LIBS) $(ARCH_LD_LIBS) 333 LDFLAGS = $(EXTRA_LDFLAGS) $(RNMAKE_PKG_LDFLAGS) $(ARCH_LDFLAGS) 335 # default link-loader is c compiler - override if using C++ 340 #------------------------------------------------------------------------------ 342 # Construct build target files and set from parent makefile. 345 # build either a library or a program, but not both 354 # Generate list of obejcts from sources 355 OBJS = $(addprefix $(OBJDIR)/,$($(TARGET).SRC.C:.c=.o) \ 356 $($(TARGET).SRC.S:.S=.o)) 358 # Output listing files 359 LSTS = $($(TARGET).SRC.C:.c=.lst) $($(TARGET).SRC.S:.S=.lst) 362 REL_FILES = $(RNMAKE_PKG_REL_FILES) $(EXTRA_REL_FILES) 365 FQ_REL_FILES = $(addprefix $(DISTDIR_DOC)/,$(REL_FILES)) 368 #------------------------------------------------------------------------------ 369 # Target Specific Variables 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 383 #------------------------------------------------------------------------------ 384 # Common Support Functions and Macros 387 # GNU Make has no boolean functions (why???), fake it. 388 neq = $(filter-out $(1),$(2)) 389 eq = $(if $(call neq,$(1),$(2)),,1) 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) 396 # Make obj/obj-<ARCH> in current directory 397 mkobjdir = @test -d $(OBJDIR) || $(MKDIR) $(OBJDIR) 400 ########################### Explicit Rules ##################################### 402 # ------------------------------------------------------------------------- 403 # Target: all (default) 404 # Desc: Front end to making the [sub]package(s) (libraries, programs, tools, 406 # Notes: There are two version: 407 # 1) only done once on the first invocation and 408 # 2) for all other invocations. 410 all: mkdistdirs pkgbanner $(EXTRA_TGT_ALL) pkg footer 412 # ------------------------------------------------------------------------- 414 # Desc: Makes the distribution [sub]package(s) (libraries, programs, tools, 417 pkg: $(BUILD) hdrs rel subdirs 420 # ------------------------------------------------------------------------- 421 # Target: lib (future) 422 # Desc: Makes all libraries in current directory. 428 # Make all static libraries 433 # ------------------------------------------------------------------------- 435 # Desc: Makes all firmware programs (images) in current directory. 438 .PHONY: pgm $(TGT_PGM) 439 pgm $(TGT_PGM): elf hex eep lss sym cppgm 441 # copy program to distribution directory 444 @$(CP) $(TARGET).hex $(DISTDIR_BIN)/. 446 # ------------------------------------------------------------------------- 447 # Target: elf hex eep lss sym 448 # Desc: Make an intermediary file. 450 .PHONY: elf hex eep lss sym 458 # ------------------------------------------------------------------------- 460 # Desc: Rules to program and debug using avrdude. 465 # Programming Hardware: 468 # alf avr910 avrisp bascom bsd dt006 pavr picoweb pony-stk200 sp12 stk200 471 # Type: 'avrdude -c ?' to get a full listing. 473 # Override as necessary. 475 AVRDUDE_PROGRAMMER ?= avrispmkII 479 # com1 = serial port. Use lpt1 to connect to parallel port. 481 # Override as necessary. 483 #AVRDUDE_PORT = com1 # programmer connected to serial device 485 # USB Communication Port 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. 493 #AVRDUDE_PORT = usb:58:68 # usb port with avrispmkII serialno 494 #AVRDUDE_PORT = usb:82:82 # usb port with avrispmkII serialno 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 500 # Write Flash Memory Operation 501 AVRDUDE_WRITE_FLASH = -U flash:w:$(TARGET).hex:$(AVRDUDE_FLASH_FMT) 503 # Write EEPROM Memory Operation 504 AVRDUDE_WRITE_EEPROM = -U eeprom:w:$(TARGET).eep 506 # Write Fuse High Byte Memory Operation 507 AVRDUDE_WRITE_HFUSE = -U hfuse:w:$(FUSE_HIGH):m 509 # Write Fuse High Byte Memory Operation 510 AVRDUDE_WRITE_LFUSE = -U lfuse:w:$(FUSE_LOW):m 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 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 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 526 # Communication flags 527 AVRDUDE_FLAGS_COM = -p $(MCU) -P $(AVRDUDE_PORT) -c $(AVRDUDE_PROGRAMMER) 529 # AVRDUDE common flags 530 AVRDUDE_FLAGS = $(AVRDUDE_FLAGS_COM) \ 531 $(AVRDUDE_FLAGS_NO_VERIFY) \ 532 $(AVRDUDE_FLAGS_VERBOSE) \ 533 $(AVRDUDE_FLAGS_ERASE_COUNTER) 535 # Program device flash 536 .PHONY: flash program 537 flash program: $(TARGET).hex 538 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_FLASH) 540 # Program device EEPROM 542 eeprom: $(TARGET).eep 543 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_EEPROM) 545 # Program the device fuse high byte. 548 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_HFUSE) 550 # Program the device fuse low byte. 553 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_LFUSE) 555 # Program the device fuses. 558 $(AVRDUDE) $(AVRDUDE_FLAGS) $(AVRDUDE_WRITE_HFUSE) \ 559 $(AVRDUDE_WRITE_LFUSE) 561 # Program the whole enchilada. 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) 569 # AVRDUD command-line interface interactive mode 571 $(AVRDUDE) $(AVRDUDE_FLAGS) -t 574 # ------------------------------------------------------------------------- 576 # Desc: Makes interface header files 578 # List of all header tags 579 HDR_TAG_LIST = $(addsuffix .HDRS.H,$(RNMAKE_DIST_HDRS)) 581 # Complete list of headers 582 PREREQ_HDRS = $(foreach tag,$(HDR_TAG_LIST),$($(tag))) 584 # Make all distribution headers 588 # Copy newer headers to distribution include [sub]directory 592 src=$(RNMAKE_PKG_ROOT)/include/$$h; \ 593 dst=$(DISTDIR_INCLUDE)/$$h; \ 594 hdir=$$(dirname $$dst); \ 595 if [ ! -f $$dst -o $$src -nt $$dst ]; \ 598 test -d $$hdir || $(MKDIR) $$hdir; \ 603 # ------------------------------------------------------------------------- 605 # Desc: Makes all release files 606 # Notes: Release files are only made at top level 608 ifeq "$(RNMAKE_PKG_ROOT)
" ".
" 614 .PHONY: $(DISTDIR_DOC)/VERSION.txt 615 $(DISTDIR_DOC)/VERSION.txt: 618 @echo "$(RNMAKE_PKG) v$(RNMAKE_PKG_VERSION_DOTTED)" > $@
619 @echo "Copyright (C) $(RNMAKE_PKG_VERSION_DATE) RoadNarrows LLC" >> $@
621 @echo "Compiled: `date`" >> $@
623 $(DISTDIR_DOC)/README.md: README.md
628 $(DISTDIR_DOC)/README.txt: README.txt 633 $(DISTDIR_DOC)/README.xml: README.xml 639 # ------------------------------------------------------------------------- 641 # Desc: Make documentation 643 documents: docs-src-gen 645 # documentation generator from source files 647 HTML_HEADER = $(rnmake)/doxy/rnr_doxy_header.html 651 HTML_FOOTER = $(rnmake)/doxy/rnr_doxy_footer.html 654 ifndef HTML_STYLESHEET 655 HTML_STYLESHEET = $(rnmake)/doxy/rnr_doxy.css 659 DOXY_IMAGES = $(rnmake)/doxy/rnr_images 663 @if [ "$(RNMAKE_DOXY_CONF_FILE)" ]; \
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)