Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue#3 Tidy up Makefile #18

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
170 changes: 63 additions & 107 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,136 +1,92 @@
# ZXEM MAKEFILE
OLEVEL = -O3
CFLAGS = -Isrc/zxem -Isrc/osdep -Isrc/cpu -Wall -pedantic $(OLEVEL) -fomit-frame-pointer
SDL = 1
ZCC = $(ZCC)

## config
CFLAGS = -Isrc/zxem -Isrc/osdep -Isrc/cpu -Wall -Wextra -pedantic -fomit-frame-pointer
CXXFLAGS = -fpermissive

ifdef DEBUG
CFLAGS += -g -O0
else
CFLAGS += -O2
endif

# MULTI CPU CORE!
#CPU = z80emu

# MZ80 - Issues on 64bit :(
# MZ80 BROKEN!
#CPU = mz80
#CPU = deadz80

# Z80CORE
CPU = z80core

TARGET = zxem
TEST_TARGET = tests/zxtest
OBJDIR = obj
ifndef PLAT
PLAT = NATIVE
endif

ifdef DEBUG
OLEVEL = -O0 -g
endif

OSD_SOURCE = src/osdep/dummy.c

## Platform specific config

ifdef SDL
ifeq ($(SDL), 1)
OSD_SOURCE = src/osdep/sdl1.2.c
OSDFLAGS = $(shell sdl-config --cflags)
OSDLIBS = $(shell sdl-config --libs)
endif
ifeq ($(SDL), 2)
OSD_SOURCE = src/osdep/sdl2.c
OSDFLAGS = $(shell sdl2-config --cflags)
OSDLIBS = $(shell sdl2-config --libs)
endif
PLAT ?= NATIVE
ifeq ($(PLAT), NATIVE)
CC ?= gcc
CXX ?= g++
OBJDIR = obj
endif


ifeq ($(PLAT), HTML)
ZCC = emcc
CXX = em++
CC = emcc
OBJDIR = objhtml

AR = emar
OSDFLAGS = -s USE_SDL=$(SDL)
CFLAGS += -s ASM_JS=1 -s USE_SDL=$(SDL)
LINKFLAGS += --preload-file ./roms --emrun
OSDLIBS =
OLEVEL += -s ASM_JS=1
LINKFLAGS = $(OSDFLAGS) $(OLEVEL) --preload-files roms/ --preload-files scr/ --emrun
TARGET := $(TARGET).html
OBJDIR = objhtml
endif

ifeq ($(CPU), z80emu)
CPUOBJ = $(OBJDIR)/z80emu.o
CPUINTC = src/cpu/z80emu/cpuintf.c
endif

## make Rules

ifeq ($(CPU), mz80)
CPUOBJ = $(OBJDIR)/mz80.o
CPUINTC = src/cpu/mz80/cpuintf.c
endif
all: $(OBJDIR) $(TARGET)

ifeq ($(CPU), deadz80)
CPUOBJ = $(OBJDIR)/deadz80.o
CPUINTC = src/cpu/deadz80/cpuintf.c
endif

ifeq ($(CPU), z80core)
CPUOBJ = $(OBJDIR)/z80core_Z80Core.o $(OBJDIR)/z80core_Z80Core_CBOpcodes.o $(OBJDIR)/z80core_Z80Core_DDCB_FDCBOpcodes.o $(OBJDIR)/z80core_Z80Core_DDOpcodes.o $(OBJDIR)/z80core_Z80Core_EDOpcodes.o $(OBJDIR)/z80core_Z80Core_FDOpcodes.o $(OBJDIR)/z80core_Z80Core_MainOpcodes.o $(OBJDIR)/z80core_Z80Core_CInterface.o
CPUINTC = src/cpu/z80core/cpuintf.c

# add permissive for initialising members in class definitions (Z80Core.h)
CFLAGS += -fpermissive

#compile as c++ when using z80 core
ifeq ($(PLAT), HTML)
ZCC = em++
else
ZCC = $(CXX)
endif

endif


all: $(OBJDIR) $(TARGET)
clean:
rm -rf $(OBJDIR)/* $(TARGET) $(TEST_TARGET)

$(OBJDIR):
mkdir $(OBJDIR)

tables.h: maketables.c
$(ZCC) -Wall $< -o maketables
./maketables > $@

# MULTI CPU CORE!
# Z80EMU - BROKEN
$(OBJDIR)/z80emu.o: src/cpu/z80emu/z80emu.c src/cpu/z80emu/z80emu.h src/cpu/z80emu/instructions.h src/cpu/z80emu/macros.h src/cpu/z80emu/tables.h
$(ZCC) $(CFLAGS) -c $< -o $@

# MZ80 - Issues on 64bit :(
$(OBJDIR)/mz80.o: src/cpu/mz80/mz80.c src/cpu/mz80/mz80.h src/cpu/cpuintf.h
$(ZCC) $(CFLAGS) -c $< -o $@

# DEADZ80 - Dead?
$(OBJDIR)/deadz80.o: src/cpu/deadz80/deadz80.c src/cpu/deadz80/deadz80.h src/cpu/deadz80/opcodes.h src/cpu/cpuintf.h
$(ZCC) $(CFLAGS) -c $< -o $@

# Z80CORE - SUCCESS!
$(OBJDIR)/z80core_%.o: src/cpu/z80core/%.cpp
$(ZCC) $(CFLAGS) -c $< -o $@

#$(OBJDIR)/z80core.a: src/cpu/z80core/Z80Core.o src/cpu/z80core/Z80Core_CBOpcodes.o src/cpu/z80core/Z80Core_DDCB_FDCBOpcodes.o src/cpu/z80core/Z80Core_DDOpcodes.o src/cpu/z80core/Z80Core_EDOpcodes.o src/cpu/z80core/Z80Core_FDOpcodes.o src/cpu/z80core/Z80Core_MainOpcodes.o
# $(AR) cr $@ src/cpu/z80core/*.o

$(OBJDIR)/zxem.o: src/zxem/zxem.c src/zxem/zxem.h src/osdep/osdep.h
$(ZCC) $(CFLAGS) $(OSDFLAGS) -c $< -o $@

$(OBJDIR)/zxvid.o: src/zxem/zxvid.c src/zxem/zxem.h src/osdep/osdep.h
$(ZCC) $(CFLAGS) -c $< -o $@
### SDL

$(OBJDIR)/zxio.o: src/zxem/zxio.c src/zxem/zxem.h src/osdep/osdep.h
$(ZCC) $(CFLAGS) -c $< -o $@

$(OBJDIR)/osdep.o: $(OSD_SOURCE) src/zxem/zxem.h src/osdep/osdep.h
$(ZCC) $(CFLAGS) $(OSDFLAGS) -c $(OSD_SOURCE) -o $@

$(OBJDIR)/cpuintf.o: $(CPUINTC)
$(ZCC) $(CFLAGS) -c $< -o $@
SDL ?= 1
ifdef SDL
ifeq ($(SDL), 1)
OSDLIBS ?= $(shell sdl-config --libs)
$(OBJDIR)/osdep.o: src/osdep/sdl1.2.c
$(CC) $(CFLAGS) $(shell sdl-config --cflags) -c $< -o $@
endif
ifeq ($(SDL), 2)
OSDLIBS ?= $(shell sdl2-config --libs)
$(OBJDIR)/osdep.o: src/osdep/sdl2.c
$(CC) $(CFLAGS) $(shell sdl2-config --cflags) -c $< -o $@
endif
else
$(OBJDIR)/osdep.o: src/osdep/dummy.c
$(CC) $(CFLAGS) -c $< -o $@
endif

OBJECT_FILES = $(OBJDIR)/zxem.o $(CPUOBJ) $(OBJDIR)/zxvid.o $(OBJDIR)/zxio.o $(OBJDIR)/osdep.o $(OBJDIR)/cpuintf.o
CPUSRC := $(wildcard ./src/cpu/$(CPU)/*.c) $(wildcard ./src/cpu/$(CPU)/*.cpp)
CPUOBJ := $(CPUSRC:.cpp=.o)
CPUOBJ := $(CPUOBJ:.c=.o)

$(TARGET): $(OBJECT_FILES)
$(ZCC) $(CFLAGS) $(OBJECT_FILES) $(OSDLIBS) $(LINKFLAGS) -o $@
ZXEMSRC := $(wildcard ./src/zxem/*.c)
ZXEMOBJ := $(ZXEMSRC:.c=.o)

$(TEST_TARGET): tests/cputest.c z80emu.h $(OBJDIR)/z80emu.o
$(ZCC) $(CFLAGS) $< $(OBJDIR)/z80emu.o -o $@
$(TARGET): $(OBJDIR)/zxem.a($(ZXEMOBJ)) $(OBJDIR)/$(CPU).a($(CPUOBJ)) $(OBJDIR)/osdep.o
$(CXX) $(CFLAGS) $(CXXFLAGS) $^ $(OSDLIBS) $(LINKFLAGS) -o $@

#TODO test is z80emu specific
$(TEST_TARGET): tests/cputest.c src/cpu/z80emu/z80emu.h $(OBJDIR)/z80emu.o
$(CC) $(CFLAGS) $< $(OBJDIR)/z80emu.o -o $@

clean:
rm $(OBJDIR)/*.o
rm $(TARGET)
.PHONY: clean all
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 0 additions & 7 deletions src/cpu/z80emu/z80emu.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,13 +248,6 @@ typedef struct Z80_STATE_ {
* register_table for 0xdd or 0xfd prefixes.
*/

/* Here are macros for the zextest example. Read/write memory macros have been
* written for a linear 64k RAM. Input/output port macros are used to simulate
* system calls.
*/

#include "zextest.h"

#define Z80_FETCH_BYTE(address, x) \
{ \
(x) = state->readbyte(address); \
Expand Down
2 changes: 1 addition & 1 deletion tests/cputest.c
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// ZXTEST

#include "../z80emu.h"
#include "../src/cpu/z80emu/z80emu.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
Expand Down