saturnng/Makefile

217 lines
5.8 KiB
Makefile
Raw Permalink Normal View History

# Simple Makefile to build saturn
2024-08-25 15:30:44 +02:00
#
# The cc-option function and the C{,PP}FLAGS logic were copied from the
# fsverity-utils project.
# https://git.kernel.org/pub/scm/fs/fsverity/fsverity-utils.git/
# The governing license can be found in the LICENSE file or at
# https://opensource.org/license/MIT.
2024-03-20 18:54:37 +01:00
NAME = saturn
VERSION_MAJOR = 5
VERSION_MINOR = 4
PATCHLEVEL = 0
PREFIX ?= /usr
DOCDIR ?= $(PREFIX)/doc/$(NAME)
2024-10-06 16:11:38 +02:00
INFODIR ?= $(PREFIX)/info
2024-08-25 16:52:42 +02:00
LUA_VERSION ?= lua
PKG_CONFIG ?= pkg-config
2024-09-24 13:47:04 +02:00
2024-03-20 18:54:37 +01:00
OPTIM ?= 2
override CFLAGS := -O$(OPTIM) \
2024-09-24 13:47:04 +02:00
-D_GNU_SOURCE=1 \
-DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
2024-09-24 15:45:16 +02:00
-DPATCHLEVEL=$(PATCHLEVEL) \
-I./src/ \
2024-09-27 10:01:51 +02:00
-I./src/libChf/src/ \
$(CFLAGS)
2024-03-20 18:54:37 +01:00
2024-09-27 10:01:51 +02:00
LIBS = -L./src/libChf -lChf
2024-03-20 18:54:37 +01:00
SDLCFLAGS = $(shell "$(PKG_CONFIG)" --cflags sdl2)
SDLLIBS = $(shell "$(PKG_CONFIG)" --libs sdl2)
NCURSESCFLAGS = $(shell "$(PKG_CONFIG)" --cflags ncursesw)
NCURSESLIBS = $(shell "$(PKG_CONFIG)" --libs ncursesw)
2024-09-19 15:39:02 +02:00
### lua
LUACFLAGS = $(shell "$(PKG_CONFIG)" --cflags $(LUA_VERSION))
LUALIBS = $(shell "$(PKG_CONFIG)" --libs $(LUA_VERSION))
2024-09-19 15:39:02 +02:00
2024-03-20 18:54:37 +01:00
FULL_WARNINGS = no
2024-09-24 15:45:16 +02:00
DOTOS = src/cpu.o \
2024-03-20 18:54:37 +01:00
src/dis.o \
src/disk_io.o \
src/disk_io_obj.o \
src/emulator.o \
src/flash49.o \
src/hdw.o \
src/hw_config.o \
src/keyb.o \
src/modules.o \
src/monitor.o \
src/romram.o \
src/romram49.o \
src/serial.o \
src/x_func.o \
2024-09-27 10:10:54 +02:00
src/chf_messages.o \
2024-09-26 10:55:14 +02:00
src/main.o
2024-03-20 18:54:37 +01:00
2024-09-27 10:10:54 +02:00
DOTOS_UI4x = src/ui4x/config.o \
src/ui4x/fonts.o \
src/ui4x/48sx.o \
src/ui4x/48gx.o \
src/ui4x/49g.o \
2024-09-27 10:10:54 +02:00
src/ui4x/common.o \
src/ui4x/sdl2.o \
src/ui4x/ncurses.o \
src/ui4x/emulator.o
HEADERS = src/ui4x/bitmaps_misc.h \
src/ui4x/common.h \
src/ui4x/config.h \
src/ui4x/ncurses.h \
src/ui4x/sdl2.h \
src/ui4x/inner.h \
src/ui4x/emulator.h \
src/disk_io.h \
src/flash49.h \
src/keyb.h \
src/machdep.h \
src/modules.h \
src/monitor.h \
src/serial.h \
src/x_func.h \
src/chf_messages.h \
src/config.h \
src/cpu.h \
src/debug.h
2024-08-25 15:30:44 +02:00
MAKEFLAGS +=-j$(NUM_CORES) -l$(NUM_CORES)
cc-option = $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null > /dev/null 2>&1; \
then echo $(1); fi)
ifeq ($(FULL_WARNINGS), no)
EXTRA_WARNING_FLAGS := -Wno-unused-function \
-Wno-redundant-decls \
$(call cc-option,-Wno-maybe-uninitialized) \
$(call cc-option,-Wno-discarded-qualifiers) \
$(call cc-option,-Wno-uninitialized) \
$(call cc-option,-Wno-ignored-qualifiers)
endif
ifeq ($(FULL_WARNINGS), yes)
EXTRA_WARNING_FLAGS := -Wunused-function \
-Wredundant-decls \
-fsanitize-trap \
$(call cc-option,-Wunused-variable)
endif
override CFLAGS := -std=c11 \
-Wall -Wextra -Wpedantic \
-Wformat=2 -Wshadow \
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition \
-Wnested-externs -Wmissing-include-dirs \
-Wdouble-promotion \
-Wno-sign-conversion \
-Wno-unused-variable \
-Wno-unused-parameter \
-Wno-conversion \
-Wno-format-nonliteral \
$(call cc-option,-Wjump-misses-init) \
$(call cc-option,-Wlogical-op) \
$(call cc-option,-Wno-unknown-warning-option) \
$(EXTRA_WARNING_FLAGS) \
2024-09-19 15:39:02 +02:00
$(SDLCFLAGS) \
$(NCURSESCFLAGS) \
$(LUACFLAGS) \
2024-08-25 15:30:44 +02:00
$(CFLAGS)
override CPPFLAGS := -I./src/ -D_GNU_SOURCE=1 \
$(CPPFLAGS)
2024-08-25 16:52:42 +02:00
.PHONY: all clean clean-all pretty-code install mrproper get-roms install
2024-03-20 18:54:37 +01:00
2024-09-27 10:01:51 +02:00
all: src/libChf/libChf.a dist/$(NAME) docs
2024-03-20 18:54:37 +01:00
2024-03-21 11:25:58 +01:00
# Building
2024-09-27 10:01:51 +02:00
src/libChf/libChf.a:
2024-10-03 15:44:03 +02:00
make -C src/libChf #MT=yes
2024-09-18 14:39:36 +02:00
dist/$(NAME): $(DOTOS) $(DOTOS_UI4x) $(HEADERS) src/libChf/libChf.a
$(CC) $(DOTOS) $(DOTOS_UI4x) src/libChf/libChf.a -o $@ $(CFLAGS) $(LIBS) $(SDLLIBS) $(NCURSESLIBS) $(LUALIBS)
2024-03-20 18:54:37 +01:00
2024-09-27 10:01:51 +02:00
dist/pack: src/pack.o src/disk_io.o src/debug.o src/libChf/libChf.a
2024-09-19 13:33:59 +02:00
# UNUSED
2024-03-20 18:54:37 +01:00
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)
doc:
make -C docs
2024-03-20 18:54:37 +01:00
# Cleaning
clean:
rm -f src/*.o
2024-09-27 10:01:51 +02:00
make -C src/libChf clean
make -C docs clean
2024-03-20 18:54:37 +01:00
mrproper: clean
rm -f dist/$(NAME) dist/pack
2024-08-25 16:52:42 +02:00
make -C dist/ROMs mrproper
2024-09-27 10:01:51 +02:00
make -C src/libChf mrproper
make -C docs mrproper
2024-03-20 18:54:37 +01:00
clean-all: mrproper
# Formatting
pretty-code:
2024-10-03 15:12:04 +02:00
clang-format -i src/*.c src/*.h src/ui4x/*.c src/ui4x/*.h
2024-09-27 10:01:51 +02:00
make -C src/libChf pretty-code
2024-03-20 18:54:37 +01:00
2024-03-21 11:25:58 +01:00
# Dependencies
get-roms:
2024-08-25 16:52:42 +02:00
make -C dist/ROMs get-roms
# Installation
install: dist/$(NAME) doc
2024-08-25 16:52:42 +02:00
install -m 755 -d -- $(DESTDIR)$(PREFIX)/bin
install -c -m 755 dist/$(NAME) $(DESTDIR)$(PREFIX)/bin/$(NAME)
2024-08-29 09:46:34 +02:00
install -c -m 755 dist/saturn48gx $(DESTDIR)$(PREFIX)/bin/saturn48gx
install -c -m 755 dist/saturn48sx $(DESTDIR)$(PREFIX)/bin/saturn48sx
2024-08-29 09:46:34 +02:00
install -c -m 755 dist/saturn40g $(DESTDIR)$(PREFIX)/bin/saturn40g
install -c -m 755 dist/saturn49g $(DESTDIR)$(PREFIX)/bin/saturn49g
2024-08-25 17:26:24 +02:00
install -m 755 -d -- $(DESTDIR)$(PREFIX)/share/$(NAME)
install -c -m 644 dist/hplogo.png $(DESTDIR)$(PREFIX)/share/$(NAME)/hplogo.png
cp -R dist/ROMs/ $(DESTDIR)$(PREFIX)/share/$(NAME)/
2024-08-25 16:52:42 +02:00
install -m 755 -d -- $(DESTDIR)$(DOCDIR)
cp -R COPYING LICENSE README* ./*.png docs-4.1.1.1 docs/*.{dvi,ps,pdf} $(DESTDIR)$(DOCDIR)
2024-10-06 16:11:38 +02:00
install -m 755 -d -- $(DESTDIR)$(INFODIR)
cp docs/*.info $(DESTDIR)$(INFODIR)
2024-08-25 16:52:42 +02:00
2024-08-25 17:20:40 +02:00
install -m 755 -d -- $(DESTDIR)$(PREFIX)/share/applications
sed "s|@PREFIX@|$(PREFIX)|g" dist/saturn48gx.desktop > $(DESTDIR)$(PREFIX)/share/applications/saturn48gx.desktop
sed "s|@PREFIX@|$(PREFIX)|g" dist/saturn48sx.desktop > $(DESTDIR)$(PREFIX)/share/applications/saturn48sx.desktop
2024-08-25 17:39:50 +02:00
sed "s|@PREFIX@|$(PREFIX)|g" dist/saturn49g.desktop > $(DESTDIR)$(PREFIX)/share/applications/saturn49g.desktop
2024-08-25 17:57:17 +02:00
sed "s|@PREFIX@|$(PREFIX)|g" dist/saturn40g.desktop > $(DESTDIR)$(PREFIX)/share/applications/saturn40g.desktop
2024-09-19 15:27:31 +02:00
uninstall:
rm -f $(DESTDIR)$(PREFIX)/bin/$(NAME)
2024-09-19 15:27:31 +02:00
rm -f $(DESTDIR)$(PREFIX)/bin/saturn48gx
2024-09-25 14:41:48 +02:00
rm -f $(DESTDIR)$(PREFIX)/bin/saturn48sx
2024-09-19 15:27:31 +02:00
rm -f $(DESTDIR)$(PREFIX)/bin/saturn40g
rm -f $(DESTDIR)$(PREFIX)/bin/saturn49g
rm -fr $(DESTDIR)$(PREFIX)/share/$(NAME)
2024-09-19 15:27:31 +02:00
rm -fr $(DESTDIR)$(DOCDIR)
rm -f $(DESTDIR)$(PREFIX)/share/applications/saturn48gx.desktop
2024-09-25 14:41:48 +02:00
rm -f $(DESTDIR)$(PREFIX)/share/applications/saturn48sx.desktop
2024-09-19 15:27:31 +02:00
rm -f $(DESTDIR)$(PREFIX)/share/applications/saturn49g.desktop
rm -f $(DESTDIR)$(PREFIX)/share/applications/saturn40g.desktop