diff --git a/README.md b/README.md index 8350d97..d85e3b0 100644 --- a/README.md +++ b/README.md @@ -86,7 +86,18 @@ You should build from a subdirectory of Oscar64 so that references in the makefi * mkdir build * cd build -* make -f ../make/makefile + +To build just the compiler: + +* make -f ../make/makefile compiler + +To build just game demonstrations: + +* make -f ../make/makefile samples + +To build everything: + +* make -f ../make/makefile all ### Compiler arguments diff --git a/autotest/makefile b/autotest/makefile index 29ec3cb..25c626c 100644 --- a/autotest/makefile +++ b/autotest/makefile @@ -1,5 +1,3 @@ -CC=../bin/oscar64 -CXX=$(CC) SRCS=$(filter-out opp_part1.cpp opp_part2.cpp, $(wildcard *.c *.cpp)) EXES=$(patsubst %.c,%,$(SRCS)) EXES:=$(patsubst %.cpp,%,$(EXES)) @@ -7,44 +5,44 @@ EXES:=$(patsubst %.cpp,%,$(EXES)) all: $(EXES) %: %.c - $(CC) -e -bc $< - $(CC) -e -n $< - $(CC) -e -O2 -bc $< - $(CC) -e -O2 -n $< - $(CC) -e -O0 -bc $< - $(CC) -e -O0 -n $< - $(CC) -e -Os -bc $< - $(CC) -e -Os -n $< - $(CC) -e -O3 -bc $< - $(CC) -e -O3 -n $< + $(OSCAR64_CC) -e -bc $< + $(OSCAR64_CC) -e -n $< + $(OSCAR64_CC) -e -O2 -bc $< + $(OSCAR64_CC) -e -O2 -n $< + $(OSCAR64_CC) -e -O0 -bc $< + $(OSCAR64_CC) -e -O0 -n $< + $(OSCAR64_CC) -e -Os -bc $< + $(OSCAR64_CC) -e -Os -n $< + $(OSCAR64_CC) -e -O3 -bc $< + $(OSCAR64_CC) -e -O3 -n $< %: %.cpp - $(CXX) -e -bc $< - $(CXX) -e -n $< - $(CXX) -e -O2 -bc $< - $(CXX) -e -O2 -n $< - $(CXX) -e -O0 -bc $< - $(CXX) -e -O0 -n $< - $(CXX) -e -Os -bc $< - $(CXX) -e -Os -n $< - $(CXX) -e -O3 -bc $< - $(CXX) -e -O3 -n $< + $(OSCAR64_CXX) -e -bc $< + $(OSCAR64_CXX) -e -n $< + $(OSCAR64_CXX) -e -O2 -bc $< + $(OSCAR64_CXX) -e -O2 -n $< + $(OSCAR64_CXX) -e -O0 -bc $< + $(OSCAR64_CXX) -e -O0 -n $< + $(OSCAR64_CXX) -e -Os -bc $< + $(OSCAR64_CXX) -e -Os -n $< + $(OSCAR64_CXX) -e -O3 -bc $< + $(OSCAR64_CXX) -e -O3 -n $< # testb bitshifttest: bitshifttest.c - $(CC) -e -bc $< - $(CC) -e -bc -O2 $< - $(CC) -e -bc -O0 $< - $(CC) -e -bc -Os $< - $(CC) -e -bc -O3 $< - $(CC) -e -n $< + $(OSCAR64_CC) -e -bc $< + $(OSCAR64_CC) -e -bc -O2 $< + $(OSCAR64_CC) -e -bc -O0 $< + $(OSCAR64_CC) -e -bc -Os $< + $(OSCAR64_CC) -e -bc -O3 $< + $(OSCAR64_CC) -e -n $< # testn stripedarraytest: stripedarraytest.c - $(CC) -e -O2 -n $< - $(CC) -e -O0 -n $< - $(CC) -e -Os -n $< - $(CC) -e -O3 -n $< + $(OSCAR64_CC) -e -O2 -n $< + $(OSCAR64_CC) -e -O0 -n $< + $(OSCAR64_CC) -e -Os -n $< + $(OSCAR64_CC) -e -O3 -n $< clean: - $(RM) *.asm *.bcs *.int *.lbl *.map *.prg + @$(RM) *.asm *.bcs *.int *.lbl *.map *.prg diff --git a/make/makefile b/make/makefile index 1b609e6..f493a30 100644 --- a/make/makefile +++ b/make/makefile @@ -1,12 +1,25 @@ - - -sources = $(wildcard ../oscar64/*.cpp) -objects = $(patsubst ../oscar64/%.cpp,%.o,$(sources)) +project_dir := $(abspath $(patsubst %/,%,$(dir $(abspath $(lastword $(MAKEFILE_LIST)))))/../) +sources = $(wildcard $(project_dir)/oscar64/*.cpp) +objects = $(patsubst $(project_dir)/oscar64/%.cpp,%.o,$(sources)) +srcdir := $(if $(srcdir),$(srcdir),$(project_dir)/build) CXX = c++ CPPFLAGS = -g -O2 -std=c++11 -Wno-switch - - $(shell mkdir -p ../bin) +SED = /usr/bin/sed +REMOVE_FORCE_ALL = $(RM) --recursive --dir +export OSCAR64_CC = $(project_dir)/bin/oscar64 +export OSCAR64_CFLAGS = +export OSCAR64_CXX = $(project_dir)/bin/oscar64 +MKDIR_PARENT = /usr/bin/mkdir --parents --mode=755 +INSTALL = /usr/bin/install +INSTALL_PROGRAM = $(INSTALL) --mode=755 +INSTALL_DATA = $(INSTALL) --mode=644 +DESTDIR = +prefix = /usr/local +exec_prefix = $(prefix) +bindir = $(exec_prefix)/bin +includedir = $(prefix)/include + ifdef WINDIR linklibs = -lpthread @@ -23,27 +36,88 @@ else #linklibs = -lversion -lpthread endif endif - -%.o: ../oscar64/%.cpp - $(CXX) -c $(CPPFLAGS) $< -o $@ -%.d: ../oscar64/%.cpp - @set -e; rm -f $@; \ - $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ - sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ - rm -f $@.$$$$ -../bin/oscar64 : $(objects) - $(CXX) $(CPPFLAGS) $(objects) $(linklibs) -o ../bin/oscar64 +all: --prep-build-dir compiler samples tests + + +%.o: $(project_dir)/oscar64/%.cpp + @echo "Compiling compiler file" $@ "..." + @$(CXX) -c $(CPPFLAGS) $< -o $(srcdir)/$@ + + +%.d: $(project_dir)/oscar64/%.cpp + @echo "Transforming file" $@ "..." + @set -e; \ + $(RM) $(srcdir)/$@; \ + @$(CC) -MM $(CPPFLAGS) $< > $(srcdir)/$@.$$$$; \ + $(SED) 's,\($*\)\.o[ :]*,\1.o $(srcdir)/$@ : ,g' < $(srcdir)/$@.$$$$ > $(srcdir)/$@; \ + $(RM) $(srcdir)/$@.$$$$ + + +compiler: $(objects) + @echo "Linking compiler..." + @$(CXX) $(CPPFLAGS) $(objects) $(linklibs) -o $(project_dir)/bin/oscar64 + .PHONY : clean clean : - -rm *.o *.d ../bin/oscar64 + @echo "Cleaning compiler..." + @$(RM) $(srcdir)/*.o + @$(RM) $(srcdir)/*.d + @$(RM) $(project_dir)/bin/oscar64 + @$(MAKE) -C $(project_dir)/samples clean + @$(MAKE) -C $(project_dir)/autotest clean + + +.PHONY : distclean +distclean : + @echo "Distribution cleaning compiler..." + @$(REMOVE_FORCE_ALL) $(srcdir) + @$(REMOVE_FORCE_ALL) $(project_dir)/bin + @$(MAKE) -C $(project_dir)/samples clean + @$(MAKE) -C $(project_dir)/autotest clean + + +samples: compiler + @$(MAKE) -C $(project_dir)/samples all + + +tests: compiler + @$(MAKE) -C $(project_dir)/autotest all + +install: compiler + @echo "Installing to" $(DESTDIR)$(prefix) + @$(MKDIR_PARENT) $(DESTDIR)$(bindir) + $(INSTALL_PROGRAM) $(project_dir)/bin/oscar64 $(DESTDIR)$(bindir) + @$(MKDIR_PARENT) $(DESTDIR)$(includedir)/oscar64/{audio,c64,c128,cx16,gfx,nes,opp,plus4,vic20} + $(INSTALL_DATA) $(project_dir)/include/*.h $(DESTDIR)$(includedir)/oscar64 + $(INSTALL_DATA) $(project_dir)/include/audio/*.h $(DESTDIR)$(includedir)/oscar64/audio + $(INSTALL_DATA) $(project_dir)/include/c64/*.h $(DESTDIR)$(includedir)/oscar64/c64 + $(INSTALL_DATA) $(project_dir)/include/c128/*.h $(DESTDIR)$(includedir)/oscar64/c128 + $(INSTALL_DATA) $(project_dir)/include/cx16/*.h $(DESTDIR)$(includedir)/oscar64/cx16 + $(INSTALL_DATA) $(project_dir)/include/gfx/*.h $(DESTDIR)$(includedir)/oscar64/gfx + $(INSTALL_DATA) $(project_dir)/include/nes/*.h $(DESTDIR)$(includedir)/oscar64/nes + $(INSTALL_DATA) $(project_dir)/include/opp/*.h $(DESTDIR)$(includedir)/oscar64/opp + $(INSTALL_DATA) $(project_dir)/include/plus4/*.h $(DESTDIR)$(includedir)/oscar64/plus4 + $(INSTALL_DATA) $(project_dir)/include/vic20/*.h $(DESTDIR)$(includedir)/oscar64/vic20 + + +uninstall: + @echo "Uninstalling..." + @$(RM) $(DESTDIR)$(bindir)/oscar64 + @$(REMOVE_FORCE_ALL) $(DESTDIR)$(includedir)/oscar64/ + ifeq ($(UNAME_S), Darwin) else -include $(objects:.o=.d) +include $($(srcdir)/objects:.o=.d) endif + + +--prep-build-dir: + @if [[ ! -d $(srcdir) ]]; then $(MKDIR_PARENT) $(srcdir); fi + @if [[ ! -d $(project_dir)/bin ]]; then $(MKDIR_PARENT) $(project_dir)/bin; fi diff --git a/samples/fractals/makefile b/samples/fractals/makefile index 0a81c92..f30655a 100644 --- a/samples/fractals/makefile +++ b/samples/fractals/makefile @@ -1,16 +1,14 @@ -CC=../../bin/oscar64 -CFLAGS=-n - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: mbtext.prg mbtext.prg mbhires.prg mbmulti.prg mbmulti3d.prg mbfixed.prg mbzoom.prg mbfixed.prg: mbfixed.c - $(CC) $(CFLAGS) -O3 $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) -O3 $< mbzoom.prg: mbzoom.c - $(CC) $(CFLAGS) -O3 $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) -O3 $< clean: - $(RM) *.asm *.int *.lbl *.map *.prg + @$(RM) *.asm *.int *.lbl *.map *.prg diff --git a/samples/games/makefile b/samples/games/makefile index 4b89db4..1d31617 100644 --- a/samples/games/makefile +++ b/samples/games/makefile @@ -1,19 +1,17 @@ -CC=../../bin/oscar64 -CFLAGS=-n - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: snake.prg lander.prg maze3d.prg missile.prg breakout.prg connectfour.prg hscrollshmup.prg snake.prg: snake.c - $(CC) $< + @$(OSCAR64_CC) $< missile.prg: missile.c - $(CC) $(CFLAGS) -O3 $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) -O3 $< hscrollshmup.prg: hscrollshmup.c - $(CC) $(CFLAGS) -O2 $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) -O2 $< clean: - $(RM) *.asm *.int *.lbl *.map *.prg *.bcs + @$(RM) *.asm *.int *.lbl *.map *.prg *.bcs diff --git a/samples/hires/makefile b/samples/hires/makefile index 1159dda..6f3e13d 100644 --- a/samples/hires/makefile +++ b/samples/hires/makefile @@ -1,13 +1,11 @@ -CC=../../bin/oscar64 -CFLAGS=-n - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: splitscreen.prg func3d.prg lines.prg polygon.prg bitblit.prg cube3d.prg fractaltree.prg qsort.prg splitscreen.prg: splitscreen.c - $(CC) $< + @$(OSCAR64_CC) $< clean: - $(RM) *.asm *.int *.lbl *.map *.prg *.bcs + @$(RM) *.asm *.int *.lbl *.map *.prg *.bcs diff --git a/samples/hiresmc/makefile b/samples/hiresmc/makefile index 750e15f..61cd4d1 100644 --- a/samples/hiresmc/makefile +++ b/samples/hiresmc/makefile @@ -1,10 +1,8 @@ -CC=../../bin/oscar64 -CFLAGS=-n - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: func3d.prg polygon.prg floodfill.prg paint.prg clean: - $(RM) *.asm *.int *.lbl *.map *.prg + @$(RM) *.asm *.int *.lbl *.map *.prg diff --git a/samples/kernalio/makefile b/samples/kernalio/makefile index 0c921c2..910e6b0 100644 --- a/samples/kernalio/makefile +++ b/samples/kernalio/makefile @@ -1,10 +1,8 @@ -CC=../../bin/oscar64 -CFLAGS= - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: diskdir.prg filewrite.prg fileread.prg charwrite.prg charread.prg hireswrite.prg hiresread.prg clean: - $(RM) *.asm *.int *.lbl *.map *.prg *.bcs + @$(RM) *.asm *.int *.lbl *.map *.prg *.bcs diff --git a/samples/makefile b/samples/makefile index adc9956..e649448 100644 --- a/samples/makefile +++ b/samples/makefile @@ -1,25 +1,25 @@ all: - $(MAKE) -C fractals - $(MAKE) -C games - $(MAKE) -C hires - $(MAKE) -C hiresmc - $(MAKE) -C particles - $(MAKE) -C kernalio - $(MAKE) -C memmap - $(MAKE) -C rasterirq - $(MAKE) -C scrolling - $(MAKE) -C sprites - $(MAKE) -C stdio + @$(MAKE) -C fractals + @$(MAKE) -C games + @$(MAKE) -C hires + @$(MAKE) -C hiresmc + @$(MAKE) -C particles + @$(MAKE) -C kernalio + @$(MAKE) -C memmap + @$(MAKE) -C rasterirq + @$(MAKE) -C scrolling + @$(MAKE) -C sprites + @$(MAKE) -C stdio clean: - $(MAKE) -C fractals $@ - $(MAKE) -C games $@ - $(MAKE) -C hires $@ - $(MAKE) -C hiresmc $@ - $(MAKE) -C particles $@ - $(MAKE) -C kernalio $@ - $(MAKE) -C memmap $@ - $(MAKE) -C rasterirq $@ - $(MAKE) -C scrolling $@ - $(MAKE) -C sprites $@ - $(MAKE) -C stdio $@ + @$(MAKE) -C fractals $@ + @$(MAKE) -C games $@ + @$(MAKE) -C hires $@ + @$(MAKE) -C hiresmc $@ + @$(MAKE) -C particles $@ + @$(MAKE) -C kernalio $@ + @$(MAKE) -C memmap $@ + @$(MAKE) -C rasterirq $@ + @$(MAKE) -C scrolling $@ + @$(MAKE) -C sprites $@ + @$(MAKE) -C stdio $@ diff --git a/samples/memmap/makefile b/samples/memmap/makefile index c14cb6d..00d168a 100644 --- a/samples/memmap/makefile +++ b/samples/memmap/makefile @@ -1,29 +1,27 @@ -CC=../../bin/oscar64 -CFLAGS= - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: largemem.prg allmem.prg charsetlo.prg charsethi.prg charsetcopy.prg charsetexpand.prg \ charsetload.prg easyflash.crt easyflashreloc.crt easyflashshared.crt tsr.prg overlay.prg charsetload.prg: charsetload.c ../resources/charset.bin - $(CC) $(CFLAGS) $< -d64=charsetload.d64 -fz=../resources/charset.bin + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< -d64=charsetload.d64 -fz=../resources/charset.bin easyflash.crt: easyflash.c - $(CC) $(CFLAGS) $< -n -tf=crt + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< -n -tf=crt easyflashreloc.crt: easyflashreloc.c - $(CC) $(CFLAGS) $< -n -tf=crt + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< -n -tf=crt easyflashshared.crt: easyflashshared.c - $(CC) $(CFLAGS) $< -n -tf=crt + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< -n -tf=crt tsr.prg: tsr.c - $(CC) $(CFLAGS) $< -n -dNOFLOAT -dNOLONG + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< -n -dNOFLOAT -dNOLONG overlay.prg: overlay.c - $(CC) $(CFLAGS) $< -n -d64=overlay.d64 + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< -n -d64=overlay.d64 clean: - $(RM) *.asm *.int *.lbl *.map *.prg *.bcs *.d64 *.crt + @$(RM) *.asm *.int *.lbl *.map *.prg *.bcs *.d64 *.crt diff --git a/samples/particles/makefile b/samples/particles/makefile index 3826e7f..e461620 100644 --- a/samples/particles/makefile +++ b/samples/particles/makefile @@ -1,10 +1,8 @@ -CC=../../bin/oscar64 -CFLAGS=-n - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: fireworks_ptr.prg fireworks_hires.prg fireworks_stripe.prg clean: - $(RM) *.asm *.int *.lbl *.map *.prg + @$(RM) *.asm *.int *.lbl *.map *.prg diff --git a/samples/rasterirq/makefile b/samples/rasterirq/makefile index db1239c..165b064 100644 --- a/samples/rasterirq/makefile +++ b/samples/rasterirq/makefile @@ -1,13 +1,11 @@ -CC=../../bin/oscar64 -CFLAGS= - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: colorbars.prg openborder.prg textcrawler.prg movingbars.prg movingbars.prg: movingbars.c - $(CC) $(CFLAGS) $< -n + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< -n clean: - $(RM) *.asm *.int *.lbl *.map *.prg *.bcs + @$(RM) *.asm *.int *.lbl *.map *.prg *.bcs diff --git a/samples/scrolling/makefile b/samples/scrolling/makefile index b20a190..c1e97f0 100644 --- a/samples/scrolling/makefile +++ b/samples/scrolling/makefile @@ -1,10 +1,8 @@ -CC=../../bin/oscar64 -CFLAGS=-n - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: bigfont.prg tunnel.prg grid2d.prg colorram.prg cgrid8way.prg clean: - $(RM) *.asm *.int *.lbl *.map *.prg + @$(RM) *.asm *.int *.lbl *.map *.prg diff --git a/samples/sprites/makefile b/samples/sprites/makefile index b5d8df1..f4ad05b 100644 --- a/samples/sprites/makefile +++ b/samples/sprites/makefile @@ -1,16 +1,14 @@ -CC=../../bin/oscar64 -CFLAGS=-n - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: joycontrol.prg multiplexer.prg creditroll.prg sprmux32.prg sprmux64.prg joycontrol.prg: joycontrol.c - $(CC) $< + @$(OSCAR64_CC) $< sprmux32.prg: sprmux32.c - $(CC) $(CFLAGS) $< -O2 -dVSPRITES_MAX=32 -dNUM_IRQS=28 + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< -O2 -dVSPRITES_MAX=32 -dNUM_IRQS=28 clean: - $(RM) *.asm *.int *.lbl *.map *.prg *.bcs + @$(RM) *.asm *.int *.lbl *.map *.prg *.bcs diff --git a/samples/stdio/makefile b/samples/stdio/makefile index ca86830..e33d992 100644 --- a/samples/stdio/makefile +++ b/samples/stdio/makefile @@ -1,10 +1,8 @@ -CC=../../bin/oscar64 -CFLAGS= - %.prg: %.c - $(CC) $(CFLAGS) $< + @echo "Compiling sample file" $< + @$(OSCAR64_CC) $(OSCAR64_CFLAGS) $< all: helloworld.prg clean: - $(RM) *.asm *.int *.lbl *.map *.prg *.bcs + @$(RM) *.asm *.int *.lbl *.map *.prg *.bcs