1 | OS := $(shell uname)
|
---|
2 |
|
---|
3 | SDL2 := /opt/sdl2
|
---|
4 | SDL2_INC := $(SDL2)/include
|
---|
5 | SDL2_LIB := $(SDL2)/lib
|
---|
6 |
|
---|
7 | FLAGS := -std=c99 -O2 -gdwarf-4
|
---|
8 |
|
---|
9 | FLAGS_CPU := $(FLAGS) -pthread -I cpu -I build
|
---|
10 |
|
---|
11 | FLAGS_EMU := $(FLAGS) -pthread \
|
---|
12 | -fno-strict-aliasing -fno-inline -fno-omit-frame-pointer \
|
---|
13 | -Wall -Wextra \
|
---|
14 | -Wpedantic -Wconversion -Wsign-conversion -Wshadow \
|
---|
15 | -Wstrict-prototypes -Wmissing-declarations -Wredundant-decls \
|
---|
16 | -I cpu -I emu -I build -I $(SDL2_INC)
|
---|
17 |
|
---|
18 | ifeq ($(OS), Linux)
|
---|
19 | FLAGS_EMU += -D EMU_LINUX
|
---|
20 | FLAGS_LNK := $(FLAGS) -pthread -Wall -Wextra
|
---|
21 | LIBS := $(SDL2_LIB)/libSDL2.a \
|
---|
22 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
23 | $(SDL2_LIB)/libfreetype.a \
|
---|
24 | -ldl -lm
|
---|
25 | endif
|
---|
26 |
|
---|
27 | ifeq ($(OS), Darwin)
|
---|
28 | FLAGS_EMU += -D EMU_OS_X
|
---|
29 | FLAGS_LNK := $(FLAGS) -Wall -Wextra
|
---|
30 | LIBS := $(SDL2_LIB)/libSDL2.a \
|
---|
31 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
32 | $(SDL2_LIB)/libfreetype.a \
|
---|
33 | -framework AppKit \
|
---|
34 | -framework AudioToolbox \
|
---|
35 | -framework Carbon \
|
---|
36 | -framework CoreAudio \
|
---|
37 | -framework CoreFoundation \
|
---|
38 | -framework CoreGraphics \
|
---|
39 | -framework CoreVideo \
|
---|
40 | -framework ForceFeedback \
|
---|
41 | -framework IOKit \
|
---|
42 | -l iconv
|
---|
43 | endif
|
---|
44 |
|
---|
45 | HEADERS := $(wildcard cpu/*.h) $(wildcard emu/*.h)
|
---|
46 |
|
---|
47 | all: buchla
|
---|
48 |
|
---|
49 | build:
|
---|
50 | mkdir build
|
---|
51 |
|
---|
52 | build/gen: | build
|
---|
53 | gcc $(FLAGS) -o build/gen cpu/m68kmake.c
|
---|
54 |
|
---|
55 | GEN_C := m68kopac.c m68kopdm.c m68kopnz.c m68kops.c
|
---|
56 | GEN_H := m68kops.h
|
---|
57 |
|
---|
58 | GEN_CP := $(GEN_C:%=build/%)
|
---|
59 | GEN_HP := $(GEN_H:%=build/%)
|
---|
60 |
|
---|
61 | GEN_O := $(GEN_C:.c=.o)
|
---|
62 | GEN_OP := $(GEN_O:%=build/%)
|
---|
63 |
|
---|
64 | $(GEN_CP) $(GEN_HP): \
|
---|
65 | build/gen | build
|
---|
66 | cd cpu; ../build/gen ../build
|
---|
67 |
|
---|
68 | build/%.o: build/%.c $(HEADERS)
|
---|
69 | gcc $(FLAGS_CPU) -c -o $@ $<
|
---|
70 |
|
---|
71 | CPU_C := m68kcpu.c m68kdasm.c
|
---|
72 | CPU_O := $(CPU_C:.c=.o)
|
---|
73 | CPU_OP := $(CPU_O:%=build/%)
|
---|
74 |
|
---|
75 | build/%.o: cpu/%.c $(HEADERS) $(GEN_HP) | build
|
---|
76 | gcc $(FLAGS_CPU) -c -o $@ $<
|
---|
77 |
|
---|
78 | EMU_C := main.c cpu.c vid.c fpu.c tim.c lcd.c ser.c mid.c fdd.c snd.c \
|
---|
79 | led.c kbd.c sdl.c
|
---|
80 | EMU_O := $(EMU_C:.c=.o)
|
---|
81 | EMU_OP := $(EMU_O:%=build/%)
|
---|
82 |
|
---|
83 | build/%.o: emu/%.c $(HEADERS) | build
|
---|
84 | gcc $(FLAGS_EMU) -c -o $@ $<
|
---|
85 |
|
---|
86 | buchla: $(CPU_OP) $(GEN_OP) $(EMU_OP)
|
---|
87 | gcc $(FLAGS_LNK) -o buchla \
|
---|
88 | $(CPU_OP) $(GEN_OP) $(EMU_OP) \
|
---|
89 | $(LIBS)
|
---|
90 |
|
---|
91 | run: buchla
|
---|
92 | ./buchla
|
---|
93 |
|
---|
94 | val: buchla
|
---|
95 | valgrind --leak-resolution=high --track-fds=yes --leak-check=full \
|
---|
96 | --show-reachable=yes --suppressions=misc/buchla.supp ./buchla
|
---|
97 |
|
---|
98 | clean:
|
---|
99 | rm -rf build
|
---|
100 | rm -f buchla
|
---|