Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve Makefile configurability #22

Merged
merged 7 commits into from
Aug 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -338,3 +338,26 @@ consider it more useful to permit linking proprietary applications with the
library. If this is what you want to do, use the GNU Lesser General
Public License instead of this License.

---

Copyright 2019 the fsverity-utils authors

Permission is hereby granted, free of charge, to any person
obtaining a copy of this software and associated documentation files
(the "Software"), to deal in the Software without restriction,
including without limitation the rights to use, copy, modify, merge,
publish, distribute, sublicense, and/or sell copies of the Software,
and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
150 changes: 71 additions & 79 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
# Makefile to build x48ng without autotools
#
# 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.
TARGETS = dist/mkcard dist/checkrom dist/dump2rom dist/x48ng

PREFIX = /usr
DOCDIR = $(PREFIX)/doc/x48ng
MANDIR = $(PREFIX)/man

CFLAGS ?= -g -O2
FULL_WARNINGS = no
PKG_CONFIG ?= pkg-config
WITH_X11 ?= yes
WITH_SDL ?= yes

VERSION_MAJOR = 0
VERSION_MINOR = 37
PATCHLEVEL = 99
Expand All @@ -24,94 +37,78 @@ DOTOS = src/emu_serial.o \

MAKEFLAGS +=-j$(NUM_CORES) -l$(NUM_CORES)

CC ?= gcc
cc-option = $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null > /dev/null 2>&1; \
then echo $(1); fi)

WITH_X11 ?= yes
WITH_SDL ?= yes
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

OPTIM ?= 2
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) \
$(CFLAGS)

override CPPFLAGS := -I./src/ -D_GNU_SOURCE=1 \
-DVERSION_MAJOR=$(VERSION_MAJOR) \
-DVERSION_MINOR=$(VERSION_MINOR) \
-DPATCHLEVEL=$(PATCHLEVEL) \
$(CPPFLAGS)

CFLAGS += -std=c11 -g -O$(OPTIM) -I./src/ -D_GNU_SOURCE=1 -DVERSION_MAJOR=$(VERSION_MAJOR) -DVERSION_MINOR=$(VERSION_MINOR) -DPATCHLEVEL=$(PATCHLEVEL)
LIBS = -lm

### lua
CFLAGS += $(shell pkg-config --cflags lua)
LIBS += $(shell pkg-config --libs lua)
override 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)
override 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 \
-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
# 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)
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
# CFLAGS += -Wunused-variable
# CFLAGS += -Wunused-parameter
CFLAGS += -Wunused-function
CFLAGS += -Wredundant-decls
# CFLAGS += -Wconversion
# CFLAGS += -fsanitize=undefined # this breaks build
CFLAGS += -fsanitize-trap
ifeq ($(CC),clang)
CFLAGS += -Wunused-variable
endif
endif
override CFLAGS += $(shell "$(PKG_CONFIG)" --cflags ncursesw) -DNCURSES_WIDECHAR=1
LIBS += $(shell "$(PKG_CONFIG)" --libs ncursesw)

### X11 UI
ifeq ($(WITH_X11), yes)
X11CFLAGS = $(shell pkg-config --cflags x11 xext) -D_GNU_SOURCE=1
X11LIBS = $(shell pkg-config --libs x11 xext)
X11CFLAGS = $(shell "$(PKG_CONFIG)" --cflags x11 xext) -D_GNU_SOURCE=1
X11LIBS = $(shell "$(PKG_CONFIG)" --libs x11 xext)

CFLAGS += $(X11CFLAGS) -DHAS_X11=1
override CFLAGS += $(X11CFLAGS) -DHAS_X11=1
LIBS += $(X11LIBS)
DOTOS += src/ui_x11.o
endif

### SDL UI
ifeq ($(WITH_SDL), yes)
SDLCFLAGS = $(shell pkg-config --cflags SDL_gfx sdl12_compat)
SDLLIBS = $(shell pkg-config --libs SDL_gfx sdl12_compat)
SDLCFLAGS = $(shell "$(PKG_CONFIG)" --cflags SDL_gfx sdl12_compat)
SDLLIBS = $(shell "$(PKG_CONFIG)" --libs SDL_gfx sdl12_compat)

CFLAGS += $(SDLCFLAGS) -DHAS_SDL=1
override CFLAGS += $(SDLCFLAGS) -DHAS_SDL=1
LIBS += $(SDLLIBS)
DOTOS += src/ui_sdl.o
endif
Expand All @@ -130,27 +127,23 @@ endif

.PHONY: all clean clean-all pretty-code install mrproper

all: dist/mkcard dist/checkrom dist/dump2rom dist/x48ng

# Binaries
dist/mkcard: src/tools/mkcard.o
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)
all: $(TARGETS)

dist/dump2rom: src/tools/dump2rom.o
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)

dist/mkcard: src/tools/mkcard.o
dist/checkrom: src/tools/checkrom.o src/romio.o
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)

dist/x48ng: $(DOTOS)
$(CC) $^ -o $@ $(CFLAGS) $(LIBS)

# Binaries
$(TARGETS):
$(CC) $^ -o $@ $(CPPFLAGS) $(CFLAGS) $(LDFLAGS) $(LIBS)

# Cleaning
clean:
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
rm -f $(TARGETS)
make -C dist/ROMs mrproper

clean-all: mrproper
Expand Down Expand Up @@ -181,7 +174,6 @@ install: all dist/config.lua

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
gzip -9 $(DESTDIR)$(MANDIR)/man1/x48ng.1

install -m 755 -d -- $(DESTDIR)$(DOCDIR)
cp -R AUTHORS LICENSE README* doc* romdump/ $(DESTDIR)$(DOCDIR)
Expand Down
2 changes: 1 addition & 1 deletion dist/ROMs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
get-roms: sxrom-a sxrom-b sxrom-c sxrom-d sxrom-e sxrom-j gxrom-l gxrom-m gxrom-p gxrom-r

mrproper:
-rm ./sxrom-a ./sxrom-b ./sxrom-c ./sxrom-d ./sxrom-e ./sxrom-j ./gxrom-l ./gxrom-m ./gxrom-p ./gxrom-r
rm -f ./sxrom-a ./sxrom-b ./sxrom-c ./sxrom-d ./sxrom-e ./sxrom-j ./gxrom-l ./gxrom-m ./gxrom-p ./gxrom-r

sxrom-a:
curl "https://www.hpcalc.org/hp48/pc/emulators/sxrom-a.zip" --output - | funzip > "sxrom-a"
Expand Down
Loading