libx48ng/Makefile

192 lines
5.2 KiB
Makefile
Raw Normal View History

2023-04-30 18:16:13 +02:00
# Makefile to build x48ng without autotools
PREFIX = /usr
DOCDIR = $(PREFIX)/doc/x48ng
MANDIR = $(PREFIX)/man
VERSION_MAJOR = 0
2024-04-11 21:17:27 +02:00
VERSION_MINOR = 37
2024-06-11 12:14:51 +02:00
PATCHLEVEL = 99
2024-05-21 08:22:37 +02:00
DOTOS = src/emu_serial.o \
src/emu_emulate.o \
src/emu_init.o \
src/emu_keyboard.o \
src/emu_memory.o \
src/emu_register.o \
src/emu_timer.o \
src/debugger.o \
src/config.o \
src/romio.o \
src/ui_text.o \
src/ui.o \
src/main.o
2023-09-01 21:22:19 +02:00
MAKEFLAGS +=-j$(NUM_CORES) -l$(NUM_CORES)
2023-09-26 11:28:15 +02:00
CC ?= gcc
WITH_X11 ?= yes
WITH_SDL ?= yes
OPTIM ?= 2
2024-05-21 08:22:37 +02:00
CFLAGS = -std=c11 -g -O$(OPTIM) -I./src/ -D_GNU_SOURCE=1 -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DPATCHLEVEL=$(PATCHLEVEL)
LIBS = -lm
2023-04-30 16:34:53 +02:00
2024-05-21 08:22:37 +02:00
### lua
CFLAGS += $(shell pkg-config --cflags lua)
LIBS += $(shell pkg-config --libs lua)
### debugger
CFLAGS += $(shell pkg-config --cflags readline)
LIBS += $(shell pkg-config --libs readline)
### Text UI
CFLAGS += $(shell pkg-config --cflags ncursesw) -DNCURSES_WIDECHAR=1
LIBS += $(shell pkg-config --libs ncursesw)
# Warnings
FULL_WARNINGS = no
# Useful warnings
CFLAGS += -Wall -Wextra -Wpedantic \
-Wformat=2 -Wshadow \
-Wwrite-strings -Wstrict-prototypes -Wold-style-definition \
2024-05-21 08:22:37 +02:00
-Wnested-externs -Wmissing-include-dirs \
-Wdouble-promotion
# GCC warnings that Clang doesn't provide:
ifeq ($(CC),gcc)
CFLAGS += -Wjump-misses-init -Wlogical-op
endif
ifeq ($(CC),clang)
CFLAGS += -Wno-unknown-warning-option
endif
# Ok we still disable some warnings for (hopefully) good reasons
2024-05-21 08:22:37 +02:00
# Not useful warnings
CFLAGS += -Wno-sign-conversion
CFLAGS += -Wno-unused-variable
CFLAGS += -Wno-unused-parameter
CFLAGS += -Wno-conversion
# 1. The debugger uses Xprintf format strings declared as char*, triggering this warning
CFLAGS += -Wno-format-nonliteral
ifeq ($(FULL_WARNINGS), no)
2024-05-21 08:22:37 +02:00
CFLAGS += -Wno-unused-function
CFLAGS += -Wno-redundant-decls
ifeq ($(CC),gcc)
CFLAGS += -Wno-maybe-uninitialized
CFLAGS += -Wno-discarded-qualifiers
endif
ifeq ($(CC),clang)
CFLAGS += -Wno-uninitialized
CFLAGS += -Wno-ignored-qualifiers
endif
else
2024-05-21 08:22:37 +02:00
# CFLAGS += -Wunused-variable
# CFLAGS += -Wunused-parameter
CFLAGS += -Wunused-function
CFLAGS += -Wredundant-decls
2024-05-21 08:22:37 +02:00
# CFLAGS += -Wconversion
# CFLAGS += -fsanitize=undefined # this breaks build
CFLAGS += -fsanitize-trap
ifeq ($(CC),clang)
CFLAGS += -Wunused-variable
endif
2023-04-30 18:16:13 +02:00
endif
### X11 UI
ifeq ($(WITH_X11), yes)
2024-05-21 08:22:37 +02:00
X11CFLAGS = $(shell pkg-config --cflags x11 xext) -D_GNU_SOURCE=1
X11LIBS = $(shell pkg-config --libs x11 xext)
2023-09-28 09:46:29 +02:00
2024-05-21 08:22:37 +02:00
CFLAGS += $(X11CFLAGS) -DHAS_X11=1
LIBS += $(X11LIBS)
DOTOS += src/ui_x11.o
endif
### SDL UI
ifeq ($(WITH_SDL), yes)
2024-05-21 08:22:37 +02:00
SDLCFLAGS = $(shell pkg-config --cflags SDL_gfx sdl12_compat)
SDLLIBS = $(shell pkg-config --libs SDL_gfx sdl12_compat)
2023-09-28 09:46:29 +02:00
2024-05-21 08:22:37 +02:00
CFLAGS += $(SDLCFLAGS) -DHAS_SDL=1
LIBS += $(SDLLIBS)
DOTOS += src/ui_sdl.o
endif
2024-05-21 08:22:37 +02:00
# depfiles = $(objects:.o=.d)
# # Have the compiler output dependency files with make targets for each
# # of the object files. The `MT` option specifies the dependency file
# # itself as a target, so that it's regenerated when it should be.
# %.dep.mk: %.c
# $(CC) -M -MP -MT '$(<:.c=.o) $@' $(CPPFLAGS) $< > $@
# # Include each of those dependency files; Make will run the rule above
# # to generate each dependency file (if it needs to).
# -include $(depfiles)
2023-10-04 09:33:52 +02:00
.PHONY: all clean clean-all pretty-code install mrproper
2023-04-30 18:16:13 +02:00
all: dist/mkcard dist/checkrom dist/dump2rom dist/x48ng
# Binaries
dist/mkcard: src/tools/mkcard.o
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)
dist/dump2rom: src/tools/dump2rom.o
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)
dist/checkrom: src/tools/checkrom.o src/romio.o
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)
dist/x48ng: $(DOTOS)
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)
# Cleaning
clean:
2024-05-21 08:22:37 +02:00
rm -f src/*.o src/tools/*.o src/*.dep.mk src/tools/*.dep.mk
mrproper: clean
rm -f dist/mkcard dist/checkrom dist/dump2rom dist/x48ng
2024-08-11 13:44:40 +02:00
make -C dist/ROMs mrproper
clean-all: mrproper
# Formatting
pretty-code:
2023-09-07 16:36:44 +02:00
clang-format -i src/*.c src/*.h src/tools/*.c
2023-04-26 19:46:45 +02:00
# Installing
get-roms:
make -C dist/ROMs
dist/config.lua: dist/x48ng
$^ --print-config > $@
2024-08-11 13:44:40 +02:00
install: all dist/config.lua
2023-04-26 19:46:45 +02:00
install -m 755 -d -- $(DESTDIR)$(PREFIX)/bin
install -c -m 755 dist/x48ng $(DESTDIR)$(PREFIX)/bin/x48ng
2023-04-30 18:16:13 +02:00
install -m 755 -d -- $(DESTDIR)$(PREFIX)/share/x48ng
install -c -m 755 dist/mkcard $(DESTDIR)$(PREFIX)/share/x48ng/mkcard
install -c -m 755 dist/dump2rom $(DESTDIR)$(PREFIX)/share/x48ng/dump2rom
install -c -m 755 dist/checkrom $(DESTDIR)$(PREFIX)/share/x48ng/checkrom
install -c -m 644 dist/hplogo.png $(DESTDIR)$(PREFIX)/share/x48ng/hplogo.png
cp -R dist/ROMs/ $(DESTDIR)$(PREFIX)/share/x48ng/
sed "s|@PREFIX@|$(PREFIX)|g" dist/setup-x48ng-home.sh > $(DESTDIR)$(PREFIX)/share/x48ng/setup-x48ng-home.sh
2023-04-30 18:16:13 +02:00
chmod 755 $(DESTDIR)$(PREFIX)/share/x48ng/setup-x48ng-home.sh
install -m 755 -d -- $(DESTDIR)$(MANDIR)/man1
sed "s|@VERSION@|$(VERSION_MAJOR).$(VERSION_MINOR).$(PATCHLEVEL)|g" dist/x48ng.man.1 > $(DESTDIR)$(MANDIR)/man1/x48ng.1
2023-04-30 18:16:13 +02:00
gzip -9 $(DESTDIR)$(MANDIR)/man1/x48ng.1
2023-04-26 22:49:47 +02:00
2023-04-26 19:46:45 +02:00
install -m 755 -d -- $(DESTDIR)$(DOCDIR)
2023-10-01 13:17:57 +02:00
cp -R AUTHORS LICENSE README* doc* romdump/ $(DESTDIR)$(DOCDIR)
install -c -m 644 dist/config.lua $(DESTDIR)$(DOCDIR)/config.lua
2023-04-26 19:46:45 +02:00
install -m 755 -d -- $(DESTDIR)$(PREFIX)/share/applications
sed "s|@PREFIX@|$(PREFIX)|g" dist/x48ng.desktop > $(DESTDIR)$(PREFIX)/share/applications/x48ng.desktop