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