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_LNK := $(FLAGS) -pthread -Wall -Wextra
|
---|
20 | LIBS := $(SDL2_LIB)/libSDL2.a \
|
---|
21 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
22 | $(SDL2_LIB)/libfreetype.a \
|
---|
23 | -ldl -lm
|
---|
24 | endif
|
---|
25 |
|
---|
26 | ifeq ($(OS), Darwin)
|
---|
27 | FLAGS_LNK := $(FLAGS) -Wall -Wextra
|
---|
28 | LIBS := $(SDL2_LIB)/libSDL2.a \
|
---|
29 | $(SDL2_LIB)/libSDL2_ttf.a \
|
---|
30 | $(SDL2_LIB)/libfreetype.a \
|
---|
31 | -framework AppKit \
|
---|
32 | -framework AudioToolbox \
|
---|
33 | -framework Carbon \
|
---|
34 | -framework CoreAudio \
|
---|
35 | -framework CoreFoundation \
|
---|
36 | -framework CoreGraphics \
|
---|
37 | -framework CoreVideo \
|
---|
38 | -framework ForceFeedback \
|
---|
39 | -framework IOKit \
|
---|
40 | -l iconv
|
---|
41 | endif
|
---|
42 |
|
---|
43 | HEADERS := $(wildcard cpu/*.h) $(wildcard emu/*.h)
|
---|
44 |
|
---|
45 | all: buchla
|
---|
46 |
|
---|
47 | build:
|
---|
48 | mkdir build
|
---|
49 |
|
---|
50 | build/gen: | build
|
---|
51 | gcc $(FLAGS) -o build/gen cpu/m68kmake.c
|
---|
52 |
|
---|
53 | GEN_C := m68kopac.c m68kopdm.c m68kopnz.c m68kops.c
|
---|
54 | GEN_H := m68kops.h
|
---|
55 |
|
---|
56 | GEN_CP := $(GEN_C:%=build/%)
|
---|
57 | GEN_HP := $(GEN_H:%=build/%)
|
---|
58 |
|
---|
59 | GEN_O := $(GEN_C:.c=.o)
|
---|
60 | GEN_OP := $(GEN_O:%=build/%)
|
---|
61 |
|
---|
62 | $(GEN_CP) $(GEN_HP): \
|
---|
63 | build/gen | build
|
---|
64 | cd cpu; ../build/gen ../build
|
---|
65 |
|
---|
66 | build/%.o: build/%.c $(HEADERS)
|
---|
67 | gcc $(FLAGS_CPU) -c -o $@ $<
|
---|
68 |
|
---|
69 | CPU_C := m68kcpu.c m68kdasm.c
|
---|
70 | CPU_O := $(CPU_C:.c=.o)
|
---|
71 | CPU_OP := $(CPU_O:%=build/%)
|
---|
72 |
|
---|
73 | build/%.o: cpu/%.c $(HEADERS) $(GEN_HP) | build
|
---|
74 | gcc $(FLAGS_CPU) -c -o $@ $<
|
---|
75 |
|
---|
76 | EMU_C := main.c cpu.c vid.c fpu.c tim.c lcd.c ser.c mid.c fdd.c snd.c \
|
---|
77 | led.c kbd.c sdl.c
|
---|
78 | EMU_O := $(EMU_C:.c=.o)
|
---|
79 | EMU_OP := $(EMU_O:%=build/%)
|
---|
80 |
|
---|
81 | build/%.o: emu/%.c $(HEADERS) | build
|
---|
82 | gcc $(FLAGS_EMU) -c -o $@ $<
|
---|
83 |
|
---|
84 | buchla: $(CPU_OP) $(GEN_OP) $(EMU_OP)
|
---|
85 | gcc $(FLAGS_LNK) -o buchla \
|
---|
86 | $(CPU_OP) $(GEN_OP) $(EMU_OP) \
|
---|
87 | $(LIBS)
|
---|
88 |
|
---|
89 | run: buchla
|
---|
90 | ./buchla
|
---|
91 |
|
---|
92 | val: buchla
|
---|
93 | valgrind --leak-resolution=high --track-fds=yes --leak-check=full \
|
---|
94 | --show-reachable=yes --suppressions=misc/buchla.supp ./buchla
|
---|
95 |
|
---|
96 | clean:
|
---|
97 | rm -rf build
|
---|
98 | rm -f buchla
|
---|