1 | OS := $(shell uname)
|
---|
2 |
|
---|
3 | ifndef WIN
|
---|
4 | GCC := gcc
|
---|
5 | SDL2 := /opt/sdl2
|
---|
6 | else
|
---|
7 | GCC := x86_64-w64-mingw32-gcc
|
---|
8 | SDL2 := /opt/sdl2-win
|
---|
9 | endif
|
---|
10 |
|
---|
11 | SDL2_INC := $(SDL2)/include
|
---|
12 | SDL2_LIB := $(SDL2)/lib
|
---|
13 |
|
---|
14 | FLAGS := -std=c99 -O2 -gdwarf-4
|
---|
15 |
|
---|
16 | FLAGS_CPU := $(FLAGS) -pthread -I cpu -I build
|
---|
17 |
|
---|
18 | FLAGS_EMU := $(FLAGS) -pthread \
|
---|
19 | -fno-strict-aliasing -fno-inline -fno-omit-frame-pointer \
|
---|
20 | -Wall -Wextra \
|
---|
21 | -Wpedantic -Wconversion -Wsign-conversion -Wshadow \
|
---|
22 | -Wstrict-prototypes -Wmissing-declarations -Wredundant-decls \
|
---|
23 | -I cpu -I emu -I build -I $(SDL2_INC)
|
---|
24 |
|
---|
25 | FLAGS_AUX := $(FLAGS) -Wall -Wextra \
|
---|
26 | -Wpedantic -Wconversion -Wsign-conversion -Wshadow \
|
---|
27 | -Wstrict-prototypes -Wmissing-declarations -Wredundant-decls
|
---|
28 |
|
---|
29 | ifndef WIN
|
---|
30 | ifeq ($(OS), Linux)
|
---|
31 | FLAGS_EMU += -D EMU_LINUX
|
---|
32 | FLAGS_LNK := $(FLAGS) -pthread -Wall -Wextra
|
---|
33 | LIBS := $(SDL2_LIB)/libSDL2.a \
|
---|
34 | $(SDL2_LIB)/libSDL2_net.a \
|
---|
35 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
36 | $(SDL2_LIB)/libfreetype.a \
|
---|
37 | -ldl -lm
|
---|
38 | endif
|
---|
39 |
|
---|
40 | ifeq ($(OS), Darwin)
|
---|
41 | FLAGS_EMU += -D EMU_OS_X
|
---|
42 | FLAGS_LNK := $(FLAGS) -Wall -Wextra
|
---|
43 | LIBS := $(SDL2_LIB)/libSDL2.a \
|
---|
44 | $(SDL2_LIB)/libSDL2_net.a \
|
---|
45 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
46 | $(SDL2_LIB)/libfreetype.a \
|
---|
47 | -framework AppKit \
|
---|
48 | -framework AudioToolbox \
|
---|
49 | -framework Carbon \
|
---|
50 | -framework CoreAudio \
|
---|
51 | -framework CoreFoundation \
|
---|
52 | -framework CoreGraphics \
|
---|
53 | -framework CoreVideo \
|
---|
54 | -framework ForceFeedback \
|
---|
55 | -framework IOKit \
|
---|
56 | -l iconv
|
---|
57 | endif
|
---|
58 | else
|
---|
59 | FLAGS_EMU += -D EMU_WIN
|
---|
60 | FLAGS_LNK := $(FLAGS) -Wall -Wextra
|
---|
61 | LIBS := -l mingw32 \
|
---|
62 | $(SDL2_LIB)/libSDL2.a \
|
---|
63 | $(SDL2_LIB)/libSDL2main.a \
|
---|
64 | $(SDL2_LIB)/libSDL2_net.a \
|
---|
65 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
66 | $(SDL2_LIB)/libfreetype.a \
|
---|
67 | -l gdi32 \
|
---|
68 | -l imm32 \
|
---|
69 | -l iphlpapi \
|
---|
70 | -l ole32 \
|
---|
71 | -l oleaut32 \
|
---|
72 | -l version \
|
---|
73 | -l winmm \
|
---|
74 | -l ws2_32
|
---|
75 | endif
|
---|
76 |
|
---|
77 | HEADERS := $(wildcard cpu/*.h) $(wildcard emu/*.h)
|
---|
78 |
|
---|
79 | all: buchla buchla.disk
|
---|
80 |
|
---|
81 | build:
|
---|
82 | mkdir build
|
---|
83 |
|
---|
84 | build/gen: | build
|
---|
85 | gcc $(FLAGS) -o build/gen cpu/m68kmake.c
|
---|
86 |
|
---|
87 | GEN_C := m68kopac.c m68kopdm.c m68kopnz.c m68kops.c
|
---|
88 | GEN_H := m68kops.h
|
---|
89 |
|
---|
90 | GEN_CP := $(GEN_C:%=build/%)
|
---|
91 | GEN_HP := $(GEN_H:%=build/%)
|
---|
92 |
|
---|
93 | GEN_O := $(GEN_C:.c=.o)
|
---|
94 | GEN_OP := $(GEN_O:%=build/%)
|
---|
95 |
|
---|
96 | $(GEN_CP) $(GEN_HP): \
|
---|
97 | build/gen | build
|
---|
98 | cd cpu; ../build/gen ../build
|
---|
99 |
|
---|
100 | build/%.o: build/%.c $(HEADERS)
|
---|
101 | $(GCC) $(FLAGS_CPU) -c -o $@ $<
|
---|
102 |
|
---|
103 | CPU_C := m68kcpu.c m68kdasm.c
|
---|
104 | CPU_O := $(CPU_C:.c=.o)
|
---|
105 | CPU_OP := $(CPU_O:%=build/%)
|
---|
106 |
|
---|
107 | build/%.o: cpu/%.c $(HEADERS) $(GEN_HP) | build
|
---|
108 | $(GCC) $(FLAGS_CPU) -c -o $@ $<
|
---|
109 |
|
---|
110 | EMU_C := main.c cpu.c vid.c fpu.c tim.c lcd.c ser.c mid.c fdd.c snd.c \
|
---|
111 | led.c kbd.c sdl.c gdb.c
|
---|
112 | EMU_O := $(EMU_C:.c=.o)
|
---|
113 | EMU_OP := $(EMU_O:%=build/%)
|
---|
114 |
|
---|
115 | build/%.o: emu/%.c $(HEADERS) | build
|
---|
116 | $(GCC) $(FLAGS_EMU) -c -o $@ $<
|
---|
117 |
|
---|
118 | buchla: $(CPU_OP) $(GEN_OP) $(EMU_OP)
|
---|
119 | $(GCC) $(FLAGS_LNK) -o buchla \
|
---|
120 | $(CPU_OP) $(GEN_OP) $(EMU_OP) \
|
---|
121 | $(LIBS)
|
---|
122 |
|
---|
123 | mkdisk: emu/mkdisk.c
|
---|
124 | $(GCC) $(FLAGS_AUX) -o mkdisk emu/mkdisk.c
|
---|
125 |
|
---|
126 | buchla.disk: mkdisk midas.abs
|
---|
127 | ./mkdisk
|
---|
128 |
|
---|
129 | run: buchla buchla.disk
|
---|
130 | ./buchla ${EMU_OPTS}
|
---|
131 |
|
---|
132 | val: buchla buchla.disk
|
---|
133 | valgrind --leak-resolution=high --track-fds=yes --leak-check=full \
|
---|
134 | --show-reachable=yes --suppressions=misc/buchla.supp \
|
---|
135 | ./buchla ${EMU_OPTS}
|
---|
136 |
|
---|
137 | clean:
|
---|
138 | rm -rf build
|
---|
139 | rm -f buchla
|
---|
140 | rm -f mkdisk
|
---|
141 | rm -f buchla.disk
|
---|