Line 2... |
Line 2... |
#
|
#
|
# Filename: Makefile
|
# Filename: Makefile
|
#
|
#
|
# Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
# Project: Zip CPU -- a small, lightweight, RISC CPU soft core
|
#
|
#
|
# Purpose: This makefile builds an assembler and disassembler.
|
# Purpose: This makefile builds an assembler preprocessor (zpp), an
|
|
# assembler (zasm) and a disassembler (zdump). Make with no
|
|
# arguments will produce these files. Other targets include:
|
|
#
|
|
# make clean
|
|
# make test
|
|
# Assembles a test file and then produces a disassembly of it.
|
|
# make depends
|
|
# Doesn't work. Dependencies are currently all hand coded.
|
|
# make optest
|
|
# make tags
|
#
|
#
|
#
|
#
|
# Creator: Dan Gisselquist, Ph.D.
|
# Creator: Dan Gisselquist, Ph.D.
|
# Gisselquist Tecnology, LLC
|
# Gisselquist Tecnology, LLC
|
#
|
#
|
Line 28... |
Line 38... |
# http://www.gnu.org/licenses/gpl.html
|
# http://www.gnu.org/licenses/gpl.html
|
#
|
#
|
#
|
#
|
################################################################################
|
################################################################################
|
#
|
#
|
.PHONY: all
|
|
all: zasm optest zdump
|
|
OBJDIR= obj-pc
|
OBJDIR= obj-pc
|
CXX= g++
|
CXX= g++
|
CC= gcc
|
CC= gcc
|
|
YACC= bison
|
|
LEX= flex
|
YYMMDD=`date +%Y%m%d`
|
YYMMDD=`date +%Y%m%d`
|
DBGFLAGS= -g -O0
|
DBGFLAGS= -g -O0
|
OPTFLAGS= -O3
|
OPTFLAGS= -O3
|
CCFLAGS= $(DBGFLAGS)
|
CCFLAGS= $(DBGFLAGS)
|
PROGRAMS= zasm optest zdump
|
PROGRAMS= zasm optest zdump zpp
|
|
|
.PHONY: programs
|
.PHONY: programs
|
all: $(OBJDIR)/ programs
|
all: $(OBJDIR)/ programs
|
|
|
programs: $(PROGRAMS)
|
programs: $(PROGRAMS)
|
|
|
ZASMSRC= zasm.cpp zopcodes.cpp zparser.cpp twoc.cpp
|
$(OBJDIR)/zpp.cpp: zpp.l
|
ZASMOBJ= $(addprefix $(OBJDIR)/,$(subst .cpp,.o,$(ZASMSRC)))
|
$(LEX) -o $@ $^
|
zasm: $(ZASMOBJ)
|
$(OBJDIR)/zpp.o: $(OBJDIR)/zpp.cpp
|
$(CXX) $(CCFLAGS) $(ZASMOBJ) -o $@
|
$(CXX) -c $(CCFLAGS) $(OBJDIR)/zpp.cpp -o $@
|
|
zpp: $(OBJDIR)/zpp.o
|
|
$(CXX) -o $@ $(CCFLAGS) $^
|
|
|
|
$(OBJDIR)/zasm.tab.h: zasm.y asmdata.h zparser.h
|
|
$(YACC) -b $(OBJDIR)/zasm -d zasm.y
|
|
zasm.output: zasm.y asmdata.h
|
|
$(YACC) -v -b $(OBJDIR)/zasm -d zasm.y
|
|
$(OBJDIR)/zasm.lex.cpp: zasm.l $(OBJDIR)/zasm.tab.h
|
|
$(LEX) -o $@ zasm.l
|
|
$(OBJDIR)/zasm.lex.o: $(OBJDIR)/zasm.lex.cpp
|
|
$(CXX) -c -I. -I$(OBJDIR)/ $(CCFLAGS) $(OBJDIR)/zasm.lex.cpp -o $@
|
|
$(OBJDIR)/zasm.tab.o: $(OBJDIR)/zasm.tab.c
|
|
$(CXX) -c -I. -I$(OBJDIR)/ $(CCFLAGS) $(OBJDIR)/zasm.tab.c -o $@
|
|
$(OBJDIR)/asmdata.o: asmdata.cpp zopcodes.h zparser.h
|
|
$(CXX) -c -I. $(CCFLAGS) asmdata.cpp -o $@
|
|
zasm: $(OBJDIR)/zasm.lex.o $(OBJDIR)/zasm.tab.o $(OBJDIR)/asmdata.o
|
|
zasm: $(OBJDIR)/zparser.o $(OBJDIR)/zopcodes.o $(OBJDIR)/twoc.o
|
|
$(CXX) -o $@ $(CCFLAGS) $^
|
|
|
optest: optest.cpp zopcodes.cpp twoc.cpp twoc.h zopcodes.h
|
optest: optest.cpp zopcodes.cpp twoc.cpp twoc.h zopcodes.h
|
$(CXX) $(CCFLAGS) optest.cpp zopcodes.cpp twoc.cpp -o optest
|
$(CXX) $(CCFLAGS) optest.cpp zopcodes.cpp twoc.cpp -o optest
|
|
|
ZDMPSRC= zdump.cpp zopcodes.cpp twoc.cpp
|
ZDMPSRC= zdump.cpp zopcodes.cpp twoc.cpp
|
Line 63... |
Line 91... |
$(CXX) -c $(CCFLAGS) $< -o $@
|
$(CXX) -c $(CCFLAGS) $< -o $@
|
|
|
$(OBJDIR)/:
|
$(OBJDIR)/:
|
@bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi"
|
@bash -c "if [ ! -e $(OBJDIR) ]; then mkdir -p $(OBJDIR); fi"
|
|
|
|
.PHONY: test
|
|
test: dumpd.txt
|
|
z.out: test.S zasm zdump
|
|
./zasm test.S -o z.out
|
|
dumpd.txt: z.out zdump
|
|
./zdump z.out > dumpd.txt
|
|
|
define build-depends
|
define build-depends
|
@echo "Building dependency file(s)"
|
@echo "Building dependency file(s)"
|
@$(CXX) $(CCFLAGS) -MM *.cpp > xd.txt
|
@$(CXX) -I $(OBJDIR)/ $(CCFLAGS) -MM *.cpp > xd.txt
|
@sed -e 's/^.*.o: /$(OBJDIR)\/&/' < xd.txt > $(OBJDIR)/depends.txt
|
@sed -e 's/^.*.o: /$(OBJDIR)\/&/' < xd.txt > $(OBJDIR)/depends.txt
|
@rm xd.txt
|
@rm xd.txt
|
endef
|
endef
|
|
|
tags: $(SOURCES) $(HEADERS)
|
tags: $(SOURCES) $(HEADERS)
|
Line 78... |
Line 113... |
|
|
.PHONY: depends
|
.PHONY: depends
|
depends: tags
|
depends: tags
|
$(build-depends)
|
$(build-depends)
|
|
|
$(OBJDIR)/depends.txt: $(OBJDIR)/ $(SOURCES) $(HEADERS)
|
$(OBJDIR)/depends.txt: $(SOURCES) $(HEADERS)
|
$(build-depends)
|
$(build-depends)
|
|
|
.PHONY: clean
|
.PHONY: clean
|
clean:
|
clean:
|
rm -rf $(OBJDIR) $(PROGRAMS)
|
rm -rf $(OBJDIR) $(PROGRAMS) z.out dumpd.txt
|
|
|
-include $(OBJDIR)/depends.txt
|
-include $(OBJDIR)/depends.txt
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|