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 | ifndef WIN
|
---|
26 | ifeq ($(OS), Linux)
|
---|
27 | FLAGS_EMU += -D EMU_LINUX
|
---|
28 | FLAGS_LNK := $(FLAGS) -pthread -Wall -Wextra
|
---|
29 | LIBS := $(SDL2_LIB)/libSDL2.a \
|
---|
30 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
31 | $(SDL2_LIB)/libfreetype.a \
|
---|
32 | -ldl -lm
|
---|
33 | endif
|
---|
34 |
|
---|
35 | ifeq ($(OS), Darwin)
|
---|
36 | FLAGS_EMU += -D EMU_OS_X
|
---|
37 | FLAGS_LNK := $(FLAGS) -Wall -Wextra
|
---|
38 | LIBS := $(SDL2_LIB)/libSDL2.a \
|
---|
39 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
40 | $(SDL2_LIB)/libfreetype.a \
|
---|
41 | -framework AppKit \
|
---|
42 | -framework AudioToolbox \
|
---|
43 | -framework Carbon \
|
---|
44 | -framework CoreAudio \
|
---|
45 | -framework CoreFoundation \
|
---|
46 | -framework CoreGraphics \
|
---|
47 | -framework CoreVideo \
|
---|
48 | -framework ForceFeedback \
|
---|
49 | -framework IOKit \
|
---|
50 | -l iconv
|
---|
51 | endif
|
---|
52 | else
|
---|
53 | FLAGS_EMU += -D EMU_WIN
|
---|
54 | FLAGS_LNK := $(FLAGS) -Wall -Wextra
|
---|
55 | LIBS := -l mingw32 \
|
---|
56 | $(SDL2_LIB)/libSDL2.a \
|
---|
57 | $(SDL2_LIB)/libSDL2main.a \
|
---|
58 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
59 | $(SDL2_LIB)/libfreetype.a \
|
---|
60 | -l gdi32 \
|
---|
61 | -l imm32 \
|
---|
62 | -l ole32 \
|
---|
63 | -l oleaut32 \
|
---|
64 | -l version \
|
---|
65 | -l winmm
|
---|
66 | endif
|
---|
67 |
|
---|
68 | HEADERS := $(wildcard cpu/*.h) $(wildcard emu/*.h)
|
---|
69 |
|
---|
70 | all: buchla
|
---|
71 |
|
---|
72 | build:
|
---|
73 | mkdir build
|
---|
74 |
|
---|
75 | build/gen: | build
|
---|
76 | gcc $(FLAGS) -o build/gen cpu/m68kmake.c
|
---|
77 |
|
---|
78 | GEN_C := m68kopac.c m68kopdm.c m68kopnz.c m68kops.c
|
---|
79 | GEN_H := m68kops.h
|
---|
80 |
|
---|
81 | GEN_CP := $(GEN_C:%=build/%)
|
---|
82 | GEN_HP := $(GEN_H:%=build/%)
|
---|
83 |
|
---|
84 | GEN_O := $(GEN_C:.c=.o)
|
---|
85 | GEN_OP := $(GEN_O:%=build/%)
|
---|
86 |
|
---|
87 | $(GEN_CP) $(GEN_HP): \
|
---|
88 | build/gen | build
|
---|
89 | cd cpu; ../build/gen ../build
|
---|
90 |
|
---|
91 | build/%.o: build/%.c $(HEADERS)
|
---|
92 | $(GCC) $(FLAGS_CPU) -c -o $@ $<
|
---|
93 |
|
---|
94 | CPU_C := m68kcpu.c m68kdasm.c
|
---|
95 | CPU_O := $(CPU_C:.c=.o)
|
---|
96 | CPU_OP := $(CPU_O:%=build/%)
|
---|
97 |
|
---|
98 | build/%.o: cpu/%.c $(HEADERS) $(GEN_HP) | build
|
---|
99 | $(GCC) $(FLAGS_CPU) -c -o $@ $<
|
---|
100 |
|
---|
101 | EMU_C := main.c cpu.c vid.c fpu.c tim.c lcd.c ser.c mid.c fdd.c snd.c \
|
---|
102 | led.c kbd.c sdl.c
|
---|
103 | EMU_O := $(EMU_C:.c=.o)
|
---|
104 | EMU_OP := $(EMU_O:%=build/%)
|
---|
105 |
|
---|
106 | build/%.o: emu/%.c $(HEADERS) | build
|
---|
107 | $(GCC) $(FLAGS_EMU) -c -o $@ $<
|
---|
108 |
|
---|
109 | buchla: $(CPU_OP) $(GEN_OP) $(EMU_OP)
|
---|
110 | $(GCC) $(FLAGS_LNK) -o buchla \
|
---|
111 | $(CPU_OP) $(GEN_OP) $(EMU_OP) \
|
---|
112 | $(LIBS)
|
---|
113 |
|
---|
114 | run: buchla
|
---|
115 | ./buchla
|
---|
116 |
|
---|
117 | val: buchla
|
---|
118 | valgrind --leak-resolution=high --track-fds=yes --leak-check=full \
|
---|
119 | --show-reachable=yes --suppressions=misc/buchla.supp ./buchla
|
---|
120 |
|
---|
121 | clean:
|
---|
122 | rm -rf build
|
---|
123 | rm -f buchla
|
---|