################################################################################
|
################################################################################
|
##
|
##
|
## Filename: Makefile (sw/dev)
|
## Filename: Makefile (sw/dev)
|
##
|
##
|
## Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
## Project: CMod S6 System on a Chip, ZipCPU demonstration project
|
##
|
##
|
## Purpose: This makefile supports (directs) the building of the various
|
## Purpose: This makefile supports (directs) the building of the various
|
## software for the S6 Cmod board.
|
## software for the S6 Cmod board.
|
##
|
##
|
## Targets:
|
## Targets:
|
##
|
##
|
## (all) Builds all of the program files
|
## (all) Builds all of the program files
|
##
|
##
|
## clean Removes all object files, the dependency file,
|
## clean Removes all object files, the dependency file,
|
## and any programs that have been built.
|
## and any programs that have been built.
|
##
|
##
|
## depends Builds a master dependency file
|
## depends Builds a master dependency file
|
##
|
##
|
## Creator: Dan Gisselquist, Ph.D.
|
## Creator: Dan Gisselquist, Ph.D.
|
## Gisselquist Technology, LLC
|
## Gisselquist Technology, LLC
|
##
|
##
|
################################################################################
|
################################################################################
|
##
|
##
|
## Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
## Copyright (C) 2015-2016, Gisselquist Technology, LLC
|
##
|
##
|
## This program is free software (firmware): you can redistribute it and/or
|
## This program is free software (firmware): you can redistribute it and/or
|
## modify it under the terms of the GNU General Public License as published
|
## modify it under the terms of the GNU General Public License as published
|
## by the Free Software Foundation, either version 3 of the License, or (at
|
## by the Free Software Foundation, either version 3 of the License, or (at
|
## your option) any later version.
|
## your option) any later version.
|
##
|
##
|
## This program is distributed in the hope that it will be useful, but WITHOUT
|
## This program is distributed in the hope that it will be useful, but WITHOUT
|
## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
## ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or
|
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
## for more details.
|
## for more details.
|
##
|
##
|
## You should have received a copy of the GNU General Public License along
|
## You should have received a copy of the GNU General Public License along
|
## with this program. (It's in the $(ROOT)/doc directory, run make with no
|
## with this program. (It's in the $(ROOT)/doc directory, run make with no
|
## target there if the PDF file isn't present.) If not, see
|
## target there if the PDF file isn't present.) If not, see
|
## for a copy.
|
## for a copy.
|
##
|
##
|
## License: GPL, v3, as defined and found on www.gnu.org,
|
## License: GPL, v3, as defined and found on www.gnu.org,
|
## http://www.gnu.org/licenses/gpl.html
|
## http://www.gnu.org/licenses/gpl.html
|
##
|
##
|
##
|
##
|
################################################################################
|
################################################################################
|
##
|
##
|
##
|
##
|
|
# Declare "all" to be the default target
|
all:
|
all:
|
PROGRAMS := helloworld doorbell doorbell2 kptest blinky
|
PROGRAMS := helloworld doorbell doorbell2 kptest blinky cputest uartecho
|
all: $(OBJDIR)/ $(PROGRAMS)
|
all: $(OBJDIR)/ $(PROGRAMS)
|
|
|
|
|
OBJDIR := obj-zip
|
OBJDIR := obj-zip
|
CROSS := zip
|
CROSS := zip
|
CC := $(CROSS)-gcc
|
CC := $(CROSS)-gcc
|
AS := $(CROSS)-as
|
AS := $(CROSS)-as
|
LD := $(CROSS)-ld
|
LD := $(CROSS)-ld
|
SED := sed
|
SED := sed
|
OBJDUMP := $(CROSS)-objdump
|
OBJDUMP := $(CROSS)-objdump
|
|
|
# Not for build, for for building tags and dependency files, we need to know
|
# Not for build, for for building tags and dependency files, we need to know
|
# what the sources and headers are
|
# what the sources and headers are
|
DEVDRVR:= keypad.c display.c rtcsim.c txfns.c
|
DEVDRVR:= keypad.c display.c rtcsim.c txfns.c
|
SOURCES:= helloworld.c doorbell.c doorbell2.c kptest.c $(DEVDRVR)
|
SOURCES:= helloworld.c doorbell.c doorbell2.c kptest.c uartecho.c $(DEVDRVR)
|
HEADERS:= board.h
|
HEADERS:= board.h
|
OBJDRVR := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(DEVDRVR)))
|
OBJDRVR := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(DEVDRVR)))
|
|
|
CPPFLAGS := -I../zipos -I.
|
CPPFLAGS := -I../zipos -I.
|
DUMPFLAGS := # -fdump-rtl-all
|
DUMPFLAGS := # -fdump-rtl-all
|
CFLAGS := $(CPPFLAGS) $(DUMPFLAGS) -O3 -Wall -Wextra -nostdlib -fno-builtin -Wa,-nocis
|
CFLAGS := $(CPPFLAGS) $(DUMPFLAGS) -O3 -Wall -Wextra -nostdlib -fno-builtin
|
LDFLAGS = -T cmod.ld -Wl,-Map,$(OBJDIR)/$@.map -Wl,--unresolved-symbols=report-all -nostdlib
|
LDFLAGS = -T cmod.ld -Wl,-Map,$(OBJDIR)/$@.map -Wl,--unresolved-symbols=report-all -nostdlib
|
|
STARTUP := resetdump.s
|
|
STARTOBJ:= $(addprefix $(OBJDIR)/,$(subst .s,.o,$(STARTUP)))
|
|
|
$(OBJDIR)/:
|
$(OBJDIR)/:
|
$(mk-objdir)
|
$(mk-objdir)
|
|
|
%.o: $(OBJDIR)/%.o
|
%.o: $(OBJDIR)/%.o
|
|
|
$(OBJDIR)/%.o: %.c
|
$(OBJDIR)/%.o: %.c
|
$(mk-objdir)
|
$(mk-objdir)
|
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
$(OBJDIR)/cputest.o: cputest.c
|
|
$(mk-objdir)
|
|
$(CC) $(CFLAGS) -Wa,-nocis -c $< -o $@
|
|
$(OBJDIR)/cputestcis.o: cputest.c
|
|
$(mk-objdir)
|
|
$(CC) $(CFLAGS) -Wa,-cis -c $< -o $@
|
$(OBJDIR)/%.o: ../zipos/%.c
|
$(OBJDIR)/%.o: ../zipos/%.c
|
$(mk-objdir)
|
$(mk-objdir)
|
$(CC) $(CFLAGS) -c $< -o $@
|
$(CC) $(CFLAGS) -c $< -o $@
|
|
$(OBJDIR)/%.o: %.s
|
|
$(mk-objdir)
|
|
$(AS) -nocis $< -o $@
|
|
|
$(OBJDIR)/%.s: %.c
|
$(OBJDIR)/%.s: %.c
|
$(mk-objdir)
|
$(mk-objdir)
|
$(CC) -S $(CFLAGS) -c $< -o $@
|
$(CC) -S $(CFLAGS) -c $< -o $@
|
|
|
$(OBJDIR)/%.txt: $(OBJDIR)/%.o
|
$(OBJDIR)/%.txt: $(OBJDIR)/%.o
|
$(mk-objdir)
|
$(mk-objdir)
|
$(OBJDUMP) -dr $^ > $@
|
$(OBJDUMP) -dr $^ > $@
|
%.txt: %
|
%.txt: %
|
$(OBJDUMP) -Dr $< > $@
|
$(OBJDUMP) -Dr $< > $@
|
|
|
|
|
helloworld: $(OBJDIR)/helloworld.o cmod.ld
|
helloworld: $(OBJDIR)/helloworld.o $(STARTOBJ) cmod.ld
|
$(CC) $(LDFLAGS) $(OBJDIR)/helloworld.o -o $@
|
$(CC) $(LDFLAGS) $(STARTOBJ) $(OBJDIR)/helloworld.o -o $@
|
$(OBJDIR)/helloworld.txt: helloworld
|
$(OBJDIR)/helloworld.txt: helloworld
|
$(OBJDUMP) -dr $^ > $@
|
$(OBJDUMP) -dr $^ > $@
|
|
|
doorbell: $(OBJDIR)/doorbell.o cmod.ld
|
uartecho: $(OBJDIR)/uartecho.o $(STARTOBJ) cmod.ld
|
$(CC) $(LDFLAGS) $(OBJDIR)/doorbell.o -o $@
|
$(CC) $(LDFLAGS) $(STARTOBJ) $(OBJDIR)/uartecho.o -o $@
|
|
|
doorbell2: $(OBJDIR)/doorbell2.o $(OBJDRVR) $(OBJDIR)/string.o cmod.ld
|
doorbell: $(OBJDIR)/doorbell.o $(STARTOBJ) cmod.ld
|
$(CC) $(LDFLAGS) $(OBJDIR)/doorbell2.o $(OBJDRVR) $(OBJDIR)/string.o -o $@
|
$(CC) $(LDFLAGS) $(STARTOBJ) $(OBJDIR)/doorbell.o -o $@
|
|
|
|
doorbell2: $(OBJDIR)/doorbell2.o $(OBJDRVR) $(STARTOBJ) $(OBJDIR)/string.o cmod.ld
|
|
$(CC) $(LDFLAGS) $(STARTOBJ) $(OBJDIR)/doorbell2.o $(OBJDRVR) $(OBJDIR)/string.o -o $@
|
$(OBJDIR)/doorbell2.txt: doorbell2
|
$(OBJDIR)/doorbell2.txt: doorbell2
|
$(OBJDUMP) -dr $^ > $@
|
$(OBJDUMP) -dr $^ > $@
|
|
|
KPSRCS := kptest.c keypad.c txfns.c
|
KPSRCS := kptest.c keypad.c txfns.c
|
KPOBJS := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(KPSRCS)))
|
KPOBJS := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(KPSRCS)))
|
kptest: $(KPOBJS) cmod.ld
|
kptest: $(KPOBJS) $(STARTOBJ) cmod.ld
|
$(CC) $(LDFLAGS) $(KPOBJS) -o $@
|
$(CC) $(LDFLAGS) $(STARTOBJ) $(KPOBJS) -o $@
|
$(OBJDIR)/kptest.txt: kptest
|
$(OBJDIR)/kptest.txt: kptest
|
$(OBJDUMP) -dr $^ > $@
|
$(OBJDUMP) -dr $^ > $@
|
|
|
blinky: $(OBJDIR)/blinky.o cmod.ld
|
blinky: $(OBJDIR)/blinky.o cmod.ld
|
$(CC) $(LDFLAGS) $(OBJDIR)/blinky.o -o $@
|
$(CC) $(LDFLAGS) $(STARTOBJ) $(OBJDIR)/blinky.o -o $@
|
|
|
|
cputest: $(OBJDIR)/cputest.o cmod.ld
|
|
$(CC) $(LDFLAGS) $(OBJDIR)/cputest.o -o $@
|
|
|
|
cputestcis: $(OBJDIR)/cputestcis.o cmod.ld
|
|
$(CC) $(LDFLAGS) $(OBJDIR)/cputestcis.o -o $@
|
|
|
define mk-objdir
|
define mk-objdir
|
@bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi"
|
@bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi"
|
endef
|
endef
|
|
|
define build-depends
|
define build-depends
|
@echo "Building dependency file(s)"
|
@echo "Building dependency file(s)"
|
$(CC) $(CPPFLAGS) -MM $(SOURCES) > $(OBJDIR)/xdep.txt
|
$(CC) $(CPPFLAGS) -MM $(SOURCES) > $(OBJDIR)/xdep.txt
|
$(SED) -e 's/^.*.o: /$(OBJDIR)\/&/' < $(OBJDIR)/xdep.txt > $(OBJDIR)/depends.txt
|
$(SED) -e 's/^.*.o: /$(OBJDIR)\/&/' < $(OBJDIR)/xdep.txt > $(OBJDIR)/depends.txt
|
@rm $(OBJDIR)/xdep.txt
|
@rm $(OBJDIR)/xdep.txt
|
endef
|
endef
|
|
|
.PHONY: depends
|
.PHONY: depends
|
depends: $(OBJDIR)/ tags
|
depends: $(OBJDIR)/ tags
|
$(build-depends)
|
$(build-depends)
|
|
|
tags: $(SOURCES) $(HEADERS)
|
tags: $(SOURCES) $(HEADERS)
|
@echo "Generating tags"
|
@echo "Generating tags"
|
@ctags $(SOURCES) $(HEADERS)
|
@ctags $(SOURCES) $(HEADERS)
|
|
|
.PHONY: clean
|
.PHONY: clean
|
clean:
|
clean:
|
rm -rf $(OBJDIR)/ $(PROGRAMS)
|
rm -rf $(OBJDIR)/ $(PROGRAMS)
|
|
|
-include $(OBJDIR)/depends.txt
|
-include $(OBJDIR)/depends.txt
|
|
|