2023-10-25 07:50:14 +00:00
|
|
|
|
|
|
|
# GCC is default -- simply because it's faster!
|
|
|
|
CC = gcc
|
|
|
|
SHELL = /bin/bash
|
|
|
|
# This is where (g)make looks for the source files for implicit rules
|
2024-01-20 12:05:26 +00:00
|
|
|
VPATH := src src/format src/drivers contrib
|
|
|
|
VPATH += ui_gl
|
2023-10-25 07:50:14 +00:00
|
|
|
|
|
|
|
CPPFLAGS += -Isrc -Isrc/format -Isrc/roms -Isrc/drivers
|
2024-01-20 12:05:26 +00:00
|
|
|
CPPFLAGS += -Icontrib
|
2023-10-25 07:50:14 +00:00
|
|
|
CPPFLAGS += -Ilibmish/src
|
2024-01-20 12:05:26 +00:00
|
|
|
CPPFLAGS += -Ilibmui/mui
|
|
|
|
|
|
|
|
OPTIMIZE ?= -O2 -march=native
|
|
|
|
CFLAGS += --std=gnu99 -Wall -Wextra -g
|
|
|
|
CFLAGS += -fno-omit-frame-pointer
|
|
|
|
CFLAGS += $(OPTIMIZE)
|
2023-10-25 07:50:14 +00:00
|
|
|
CFLAGS += -Wno-unused-parameter -Wno-unused-function
|
2024-01-20 12:05:26 +00:00
|
|
|
LDLIBS += -lX11 -lGL -lGLU
|
|
|
|
LDLIBS += -lpthread -lutil -lm
|
|
|
|
|
2024-03-13 08:45:11 +00:00
|
|
|
VERSION := ${shell \
|
|
|
|
echo $$(git describe --tags --abbrev=0 2>/dev/null || \
|
|
|
|
echo "(dev)") \
|
|
|
|
$$(git log -1 --date=short --pretty="%h %cd")}
|
2024-01-20 12:05:26 +00:00
|
|
|
CPPFLAGS += -DMII_VERSION="\"$(VERSION)\""
|
2023-10-25 07:50:14 +00:00
|
|
|
|
|
|
|
HAS_ALSA := $(shell pkg-config --exists alsa && echo 1)
|
|
|
|
ifeq ($(HAS_ALSA),1)
|
|
|
|
LDLIBS += $(shell pkg-config --libs alsa)
|
|
|
|
CPPFLAGS += $(shell pkg-config --cflags alsa) -DHAS_ALSA
|
|
|
|
else
|
|
|
|
${warning ALSA not found, no sound support}
|
|
|
|
endif
|
|
|
|
|
|
|
|
O := build-$(shell $(CC) -dumpmachine)
|
|
|
|
BIN := $(O)/bin
|
|
|
|
LIB := $(O)/lib
|
|
|
|
OBJ := $(O)/obj
|
|
|
|
|
2024-01-20 12:05:26 +00:00
|
|
|
all : $(BIN)/mii_emu_gl
|
2023-10-25 07:50:14 +00:00
|
|
|
|
|
|
|
MII_SRC := $(wildcard src/*.c src/format/*.c \
|
|
|
|
src/drivers/*.c contrib/*.c)
|
2024-01-20 12:05:26 +00:00
|
|
|
UI_SRC := $(wildcard ui_gl/*.c)
|
|
|
|
|
2023-10-25 07:50:14 +00:00
|
|
|
SRC := $(MII_SRC) $(UI_SRC)
|
|
|
|
ALL_OBJ := ${patsubst %, ${OBJ}/%, ${notdir ${SRC:.c=.o}}}
|
|
|
|
|
2024-01-20 12:05:26 +00:00
|
|
|
CPPFLAGS += ${shell pkg-config --cflags pixman-1}
|
|
|
|
LDLIBS += ${shell pkg-config --libs pixman-1}
|
|
|
|
|
|
|
|
$(BIN)/mii_emu_gl : $(ALL_OBJ) | mui mish
|
|
|
|
$(BIN)/mii_emu_gl : $(LIB)/libmish.a
|
|
|
|
$(BIN)/mii_emu_gl : $(LIB)/libmui.a
|
2023-10-25 07:50:14 +00:00
|
|
|
|
2024-01-20 12:05:26 +00:00
|
|
|
.PHONY : mish mui
|
|
|
|
mish : $(LIB)/libmish.a
|
2023-10-25 07:50:14 +00:00
|
|
|
LDLIBS += $(LIB)/libmish.a
|
2024-01-20 12:05:26 +00:00
|
|
|
$(LIB)/libmish.a : ${wildcard libmish/src/*} | $(LIB) $(OBJ) $(BIN)
|
|
|
|
mkdir -p $(OBJ)/libmish && \
|
|
|
|
make -j -C libmish O="../" CC="$(CC)" V="$(V)" static
|
|
|
|
|
|
|
|
LDLIBS += $(LIB)/libmui.a
|
|
|
|
mui : $(LIB)/libmui.a
|
|
|
|
$(LIB)/libmui.a : ${wildcard libmui/mui/*} | $(LIB) $(OBJ) $(BIN)
|
|
|
|
mkdir -p $(OBJ)/libmui && \
|
|
|
|
make -j -C libmui BUILD_DIR="../" CC="$(CC)" \
|
|
|
|
V="$(V)" OPTIMIZE="$(OPTIMIZE)" static
|
2023-10-25 07:50:14 +00:00
|
|
|
|
|
|
|
# Smartport firmware needs the assembler first
|
|
|
|
test/asm/%.bin : test/asm/%.asm | $(BIN)/mii_asm
|
|
|
|
$(BIN)/mii_asm -v -o $@ $<
|
|
|
|
# And it also INCBIN the firmware driver
|
|
|
|
$(OBJ)/mii_smarport.o : test/asm/mii_smartport_driver.bin
|
|
|
|
|
|
|
|
clean :
|
2024-01-20 12:05:26 +00:00
|
|
|
rm -rf $(O); make -C libmui clean; make -C libmish clean
|
2023-10-25 07:50:14 +00:00
|
|
|
|
|
|
|
# This is for development purpose. This will recompile the project
|
|
|
|
# everytime a file is modified.
|
|
|
|
watch :
|
|
|
|
while true; do \
|
|
|
|
clear; $(MAKE) -j all tests; \
|
2024-01-20 12:05:26 +00:00
|
|
|
inotifywait -qre close_write src src/format ui_gl test \
|
|
|
|
libmui libmui/mui; \
|
2023-10-25 07:50:14 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
tests : $(BIN)/mii_test $(BIN)/mii_cpu_test $(BIN)/mii_asm
|
|
|
|
|
|
|
|
# Just the library for mii, not any of the UI stuff
|
|
|
|
TEST_OBJ := ${patsubst %, ${OBJ}/%, ${notdir ${MII_SRC:.c=.o}}}
|
|
|
|
VPATH += test
|
|
|
|
# Base test without the UI, for performance testing
|
|
|
|
$(BIN)/mii_test : $(TEST_OBJ)
|
|
|
|
$(BIN)/mii_test : $(OBJ)/mii_test.o $(OBJ)/mii_mish.o
|
2024-02-04 09:09:28 +00:00
|
|
|
$(OBJ)/mii_test.o : CFLAGS := -O0 -Og ${filter-out -O%, $(CFLAGS)}
|
2023-10-25 07:50:14 +00:00
|
|
|
|
2024-02-04 09:09:28 +00:00
|
|
|
$(OBJ)/mii_cpu_test.o : CFLAGS := -O0 -Og ${filter-out -O%, $(CFLAGS)}
|
2023-10-25 07:50:14 +00:00
|
|
|
$(BIN)/mii_cpu_test : $(OBJ)/mii_cpu_test.o $(TEST_OBJ)
|
|
|
|
|
2024-02-04 09:09:28 +00:00
|
|
|
# Assembler for the 6502
|
2023-10-25 07:50:14 +00:00
|
|
|
$(BIN)/mii_asm : $(OBJ)/mii_asm.o $(TEST_OBJ)
|
|
|
|
|
|
|
|
ifeq ($(V),1)
|
|
|
|
Q :=
|
|
|
|
else
|
|
|
|
Q := @
|
|
|
|
endif
|
|
|
|
|
2024-01-20 12:05:26 +00:00
|
|
|
$(OBJ)/%.o : %.c | $(OBJ)
|
2024-02-04 09:09:28 +00:00
|
|
|
@echo " CC" ${filter -O%, $(CPPFLAGS) $(CFLAGS)} "$<"
|
2023-10-25 07:50:14 +00:00
|
|
|
$(Q)$(CC) -MMD $(CPPFLAGS) $(CFLAGS) -c -o $@ $<
|
|
|
|
|
|
|
|
$(BIN)/% : | $(BIN)
|
|
|
|
@echo " LD $@"
|
|
|
|
$(Q)$(CC) $(LDFLAGS) -o $@ $^ $(LDLIBS)
|
|
|
|
|
|
|
|
$(OBJ) $(BIN) $(LIB) :
|
|
|
|
@mkdir -p $@
|
|
|
|
|
|
|
|
# Generates the necessary file to help clangd index the files properly.
|
|
|
|
# This currently has to be done manually, but helps a lot if you use 'kate'
|
2024-01-20 12:05:26 +00:00
|
|
|
# editor or anthing else that is compatible with the LSP protocol (vscode too)
|
2023-10-25 07:50:14 +00:00
|
|
|
compile_commands.json: lsp
|
|
|
|
lsp:
|
|
|
|
{ $$(which gmake) CC=gcc V=1 --always-make --dry-run all tests; \
|
2024-01-20 12:05:26 +00:00
|
|
|
$$(which gmake) CC=gcc V=1 --always-make --dry-run -C libmish ; \
|
|
|
|
$$(which gmake) CC=gcc V=1 --always-make --dry-run -C libmui ; } | \
|
2023-10-25 07:50:14 +00:00
|
|
|
sh utils/clangd_gen.sh >compile_commands.json
|
|
|
|
|
|
|
|
-include $(O)/*.d
|
|
|
|
-include $(O)/obj/*.d
|
2024-01-20 12:05:26 +00:00
|
|
|
|
2024-02-18 10:32:33 +00:00
|
|
|
DESTDIR := /usr/local
|
2024-01-20 12:05:26 +00:00
|
|
|
|
|
|
|
install:
|
|
|
|
mkdir -p $(DESTDIR)/bin
|
|
|
|
cp $(BIN)/mii_emu_gl $(DESTDIR)/bin/
|
2024-02-18 10:32:33 +00:00
|
|
|
|
|
|
|
avail:
|
|
|
|
mkdir -p $(DESTDIR)/bin
|
|
|
|
rm -f $(DESTDIR)/bin/mii_emu_gl && \
|
|
|
|
ln -sf $(realpath $(BIN)/mii_emu_gl) $(DESTDIR)/bin/mii_emu_gl
|