diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..bdc5af0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +*~ +build diff --git a/src/.gitignore b/src/.gitignore deleted file mode 100644 index 9cad110..0000000 --- a/src/.gitignore +++ /dev/null @@ -1,2 +0,0 @@ -*~ -yemu diff --git a/src/6502/6502.c b/src/6502/6502.c index 5974c8e..02d3748 100644 --- a/src/6502/6502.c +++ b/src/6502/6502.c @@ -1,4 +1,4 @@ -#include "6502.h" +#include #include #include diff --git a/src/Makefile b/src/Makefile index 9d6100b..a648dcb 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,14 +1,28 @@ -CC = gcc -CFLAGS= -O2 -pedantic -Wall -Wextra -LFLAGS= +CC=cc -SRCFILES= main.c 6502/6502.c ocpu/ocpu.c -OBJFILES= yemu +SRCFILES!=ls -d */ | sed 's/include\///' | awk 'NF' | sed 's/.*/&\*.c/g' -.PHONY: all clean +BUILDDIR=../build -all: main +CFILES=$(wildcard $(SRCFILES) *.c) +OFILES=$(patsubst %.c, $(BUILDDIR)/%.o, $(CFILES)) +YEMUBIN=$(BUILDDIR)/yemu -main: - $(CC) $(CFLAGS) $(SRCFILES) -o $(OBJFILES) +INCLUDEFLAGS=-Iinclude/ +DEBUGFLAGS=-fsanitize=address -fsanitize=leak -fsanitize=undefined -fsanitize=pointer-compare -lasan +CFLAGS=-Wall -Wextra $(INCLUDEFLAGS) -g +LIBFLAGS= +.PHONY: all clean test +.SUFFIXES: .o .c + +all: $(BUILDDIR) $(YEMUBIN) + +$(BUILDDIR): + mkdir -p $(BUILDDIR) + +$(YEMUBIN): $(CFILES) + $(CC) $(CFILES) -o $@ $(CFLAGS) $(LIBFLAGS) + +clean: + rm -rf $(BUILDDIR) diff --git a/src/6502/6502.h b/src/include/yemu/6502.h similarity index 96% rename from src/6502/6502.h rename to src/include/yemu/6502.h index b6072c9..026ea51 100644 --- a/src/6502/6502.h +++ b/src/include/yemu/6502.h @@ -1,5 +1,8 @@ +#ifndef YEMU_6502_H +#define YEMU_6502_H + #include -#include "../common.h" +#include #define MAX_MEMORY 1024*64 @@ -67,3 +70,5 @@ struct CPU { }; void init6502(FILE *infile); + +#endif diff --git a/src/common.h b/src/include/yemu/common.h similarity index 58% rename from src/common.h rename to src/include/yemu/common.h index 7c29fd4..5b6bf76 100644 --- a/src/common.h +++ b/src/include/yemu/common.h @@ -1,2 +1,7 @@ +#ifndef YEMU_COMMON_H +#define YEMU_COMMON_H + typedef unsigned char byte; // 8 bit typedef unsigned short word; // 16 bit + +#endif diff --git a/src/ocpu/ocpu.h b/src/include/yemu/ocpu.h similarity index 94% rename from src/ocpu/ocpu.h rename to src/include/yemu/ocpu.h index 94597af..dbd0680 100644 --- a/src/ocpu/ocpu.h +++ b/src/include/yemu/ocpu.h @@ -1,5 +1,8 @@ +#ifndef YEMU_OCPU_H +#define YEMU_OCPU_H + #include -#include "../common.h" +#include #define MAX_MEMORY 1024*64 @@ -79,3 +82,5 @@ struct OCPU { }; void initOCPU(FILE *infile); + +#endif diff --git a/src/main.c b/src/main.c index b2457ea..c633cfb 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,6 @@ -#include "common.h" -#include "6502/6502.h" -#include "ocpu/ocpu.h" +#include +#include +#include #include #include #include diff --git a/src/ocpu/ocpu.c b/src/ocpu/ocpu.c index d43d3c4..a6940e0 100644 --- a/src/ocpu/ocpu.c +++ b/src/ocpu/ocpu.c @@ -1,4 +1,4 @@ -#include "ocpu.h" +#include struct OCPU ocpu; struct OCPU_MEMORY ocpu_mem;