forked from commanderx16/x16-emulator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
182 lines (147 loc) · 7.56 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
##################################################################################################
#
# COMMANDER X16 EMULATOR MAKEFILE
#
##################################################################################################
# the mingw-w64 path on macOS installed through homebrew
ifndef MINGW32
MINGW32=/opt/homebrew/Cellar/mingw-w64/9.0.0_4/toolchain-x86_64/x86_64-w64-mingw32
endif
# the Windows SDL2 path on macOS installed through
# ./configure --host=x86_64-w64-mingw32 --prefix=... && make && make install
ifndef WIN_SDL2
WIN_SDL2=~/tmp/sdl2-win32
endif
ifeq ($(CROSS_COMPILE_WINDOWS),1)
SDL2CONFIG?=$(WIN_SDL2)/bin/sdl2-config --prefix=$(WIN_SDL2)
else
SDL2CONFIG=sdl2-config
endif
CFLAGS=-std=c99 -O3 -Wall -Werror -g $(shell $(SDL2CONFIG) --cflags) -Isrc/extern/include -Isrc/extern/src
LDFLAGS=$(shell $(SDL2CONFIG) --libs) -lm
ODIR = build
SDIR = src
ifdef TRACE
CFLAGS+=-D TRACE
endif
OUTPUT=x16emu
ifeq ($(MAC_STATIC),1)
LIBSDL_FILE?=/opt/homebrew/Cellar/sdl2/2.0.20/lib/libSDL2.a
LDFLAGS=$(LIBSDL_FILE) -lm -liconv -Wl,-framework,CoreAudio -Wl,-framework,AudioToolbox -Wl,-framework,ForceFeedback -lobjc -Wl,-framework,CoreVideo -Wl,-framework,Cocoa -Wl,-framework,Carbon -Wl,-framework,IOKit -Wl,-weak_framework,QuartzCore -Wl,-weak_framework,Metal -Wl,-weak_framework,CoreHaptics -Wl,-weak_framework,GameController
endif
ifeq ($(CROSS_COMPILE_WINDOWS),1)
LDFLAGS+=-L$(MINGW32)/lib
# this enables printf() to show, but also forces a console window
LDFLAGS+=-Wl,--subsystem,console
CC=x86_64-w64-mingw32-gcc
endif
ifdef EMSCRIPTEN
LDFLAGS+=--shell-file webassembly/x16emu-template.html --preload-file rom.bin -s TOTAL_MEMORY=32MB -s ASSERTIONS=1 -s DISABLE_DEPRECATED_FIND_EVENT_TARGET_BEHAVIOR=1
# To the Javascript runtime exported functions
LDFLAGS+=-s EXPORTED_FUNCTIONS='["_j2c_reset", "_j2c_paste", "_j2c_start_audio", _main]' -s EXTRA_EXPORTED_RUNTIME_METHODS='["ccall", "cwrap"]'
OUTPUT=x16emu.html
endif
_OBJS = cpu/fake6502.o memory.o disasm.o video.o i2c.o smc.o rtc.o via.o serial.o ieee.o vera_spi.o audio.o vera_pcm.o vera_psg.o sdcard.o main.o debugger.o javascript_interface.o joystick.o rendertext.o keyboard.o icon.o timing.o wav_recorder.o testbench.o
_HEADERS = audio.h cpu/65c02.h cpu/fake6502.h cpu/instructions.h cpu/mnemonics.h cpu/modes.h cpu/support.h cpu/tables.h debugger.h disasm.h extern/include/gif.h extern/src/ym2151.h glue.h i2c.h icon.h joystick.h keyboard.h ieee.h memory.h rendertext.h rom_symbols.h rtc.h sdcard.h smc.h timing.h utf8.h utf8_encode.h vera_pcm.h vera_psg.h vera_spi.h version.h via.h serial.o video.h wav_recorder.h testbench.h
_OBJS += extern/src/ym2151.o
_HEADERS += extern/src/ym2151.h
OBJS = $(patsubst %,$(ODIR)/%,$(_OBJS))
HEADERS = $(patsubst %,$(SDIR)/%,$(_HEADERS))
ifneq ("$(wildcard ./src/rom_labels.h)","")
HEADERS+=src/rom_labels.h
endif
all: $(OBJS) $(HEADERS)
$(CC) -o $(OUTPUT) $(OBJS) $(LDFLAGS)
$(ODIR)/%.o: $(SDIR)/%.c
@mkdir -p $$(dirname $@)
$(CC) $(CFLAGS) -c $< -o $@
cpu/tables.h cpu/mnemonics.h: cpu/buildtables.py cpu/6502.opcodes cpu/65c02.opcodes
cd cpu && python buildtables.py
# WebASssembly/emscripten target
#
# See webassembly/WebAssembly.md
wasm:
emmake make
clean:
rm -rf $(ODIR) x16emu x16emu.exe x16emu.js x16emu.wasm x16emu.data x16emu.worker.js x16emu.html x16emu.html.mem
##################################################################################################
##################################################################################################
#
# PACKAGING
#
# Packaging is tricky and partially depends on Michael's specific setup. :/
#
# * The Mac build is done on a Mac.
# * The Windows build is cross-compiled on the Mac using mingw. For more info, see:
# https://blog.wasin.io/2018/10/21/cross-compile-sdl2-library-and-app-on-windows-from-macos.html
# * The Linux build is done by sshing into a VMware Ubuntu machine that has the same
# directory tree mounted. Since unlike on Windows and Mac, there are 0 libraries guaranteed
# to be present, a static build would mean linking everything that is not the kernel. And since
# there are always 3 ways of doing something on Linux, it would mean including three graphics
# and three sounds backends. Therefore, the Linux build uses dynamic linking, requires libsdl2
# to be installed and might only work on the version of Linux I used for building, which is the
# current version of Ubuntu.
# * For converting the documentation from Markdown to HTML, pandoc is required:
# brew install pandoc
#
##################################################################################################
# hostname of the Linux VM
LINUX_COMPILE_HOST = ubuntu.local
# path to the equivalent of `pwd` on the Mac
LINUX_BASE_DIR = /tmp/
TMPDIR_NAME=TMP-x16emu-package
define add_extra_files_to_package
# ROMs
cp ../x16-rom/build/x16/rom.bin $(TMPDIR_NAME)
cp ../x16-rom/build/x16/kernal.sym $(TMPDIR_NAME)
cp ../x16-rom/build/x16/keymap.sym $(TMPDIR_NAME)
cp ../x16-rom/build/x16/dos.sym $(TMPDIR_NAME)
cp ../x16-rom/build/x16/geos.sym $(TMPDIR_NAME)
cp ../x16-rom/build/x16/basic.sym $(TMPDIR_NAME)
cp ../x16-rom/build/x16/monitor.sym $(TMPDIR_NAME)
cp ../x16-rom/build/x16/charset.sym $(TMPDIR_NAME)
# Empty SD card image
cp sdcard.img.zip $(TMPDIR_NAME)
# Documentation
mkdir $(TMPDIR_NAME)/docs
pandoc --from gfm --to html -c github-pandoc.css --standalone --metadata pagetitle="Commander X16 Emulator" README.md --output $(TMPDIR_NAME)/docs/README.html
pandoc --from gfm --to html -c github-pandoc.css --standalone --metadata pagetitle="Commander X16 KERNAL/BASIC/DOS ROM" ../x16-rom/README.md --output $(TMPDIR_NAME)/docs/KERNAL-BASIC.html
pandoc --from gfm --to html -c github-pandoc.css --standalone --metadata pagetitle="Commander X16 Programmer's Reference Guide" ../x16-docs/Commander\ X16\ Programmer\'s\ Reference\ Guide.md --output $(TMPDIR_NAME)/docs/Programmer\'s\ Reference\ Guide.html --lua-filter=mdtohtml.lua
for IN in ../x16-docs/X16\ Reference\ *; do \
OUT=$$(basename "$$IN" .md).html; \
pandoc --from gfm --to html -c github-pandoc.css --standalone --metadata pagetitle="Commander X16 Programmer's Reference Guide" "$$IN" --output "$(TMPDIR_NAME)/docs/$$OUT" --lua-filter=mdtohtml.lua; \
done
pandoc --from gfm --to html -c github-pandoc.css --standalone --metadata pagetitle="VERA Programmer's Reference.md" ../x16-docs/VERA\ Programmer\'s\ Reference.md --output $(TMPDIR_NAME)/docs/VERA\ Programmer\'s\ Reference.html
cp github-pandoc.css $(TMPDIR_NAME)/docs
endef
package: package_mac package_win package_linux
make clean
package_mac:
(cd ../x16-rom/; make clean all)
MAC_STATIC=1 make clean all
rm -rf $(TMPDIR_NAME) x16emu_mac.zip
mkdir $(TMPDIR_NAME)
cp x16emu $(TMPDIR_NAME)
$(call add_extra_files_to_package)
(cd $(TMPDIR_NAME)/; zip -r "../x16emu_mac.zip" *)
rm -rf $(TMPDIR_NAME)
package_win:
(cd ../x16-rom/; make clean all)
CROSS_COMPILE_WINDOWS=1 make clean all
rm -rf $(TMPDIR_NAME) x16emu_win.zip
mkdir $(TMPDIR_NAME)
cp x16emu.exe $(TMPDIR_NAME)
cp $(WIN_SDL2)/bin/SDL2.dll $(TMPDIR_NAME)/
$(call add_extra_files_to_package)
(cd $(TMPDIR_NAME)/; zip -r "../x16emu_win.zip" *)
rm -rf $(TMPDIR_NAME)
package_linux:
(cd ../x16-rom/; make clean all)
(cd ..; tar cp x16-rom x16-emulator x16-docs | ssh $(LINUX_COMPILE_HOST) "cd $(LINUX_BASE_DIR); tar xp")
ssh $(LINUX_COMPILE_HOST) "cd $(LINUX_BASE_DIR)/x16-emulator; make clean all"
rm -rf $(TMPDIR_NAME) x16emu_linux.zip
mkdir $(TMPDIR_NAME)
scp $(LINUX_COMPILE_HOST):$(LINUX_BASE_DIR)/x16-emulator/x16emu $(TMPDIR_NAME)
$(call add_extra_files_to_package)
(cd $(TMPDIR_NAME)/; zip -r "../x16emu_linux.zip" *)
rm -rf $(TMPDIR_NAME)