Makefile: allow user CFLAGS to override out warning flags
The cc-option filters out unknown flags which make the compiler error out. Note that Clang enables Wunused-command-line-argument by default and merely emits a warning but incurs no error, when it encounters such a flag. GCC on the other hand exits unsuccessfully when it is passed a flag of the form -Wunknown-warning, but no diagnostic is produced for -Wno-unknown-warning unless other diagnostics are produced.
This commit is contained in:
parent
ed745f139f
commit
71acf45a04
2 changed files with 77 additions and 59 deletions
23
LICENSE
23
LICENSE
|
@ -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.
|
||||
|
|
113
Makefile
113
Makefile
|
@ -1,9 +1,20 @@
|
|||
# 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.
|
||||
|
||||
PREFIX = /usr
|
||||
DOCDIR = $(PREFIX)/doc/x48ng
|
||||
MANDIR = $(PREFIX)/man
|
||||
|
||||
CFLAGS ?= -g -O2
|
||||
FULL_WARNINGS = no
|
||||
WITH_X11 ?= yes
|
||||
WITH_SDL ?= yes
|
||||
|
||||
VERSION_MAJOR = 0
|
||||
VERSION_MINOR = 37
|
||||
PATCHLEVEL = 99
|
||||
|
@ -24,82 +35,66 @@ DOTOS = src/emu_serial.o \
|
|||
|
||||
MAKEFLAGS +=-j$(NUM_CORES) -l$(NUM_CORES)
|
||||
|
||||
WITH_X11 ?= yes
|
||||
WITH_SDL ?= yes
|
||||
cc-option = $(shell if $(CC) $(1) -c -x c /dev/null -o /dev/null > /dev/null 2>&1; \
|
||||
then echo $(1); fi)
|
||||
|
||||
OPTIM ?= 2
|
||||
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 \
|
||||
-I./src/ -D_GNU_SOURCE=1 \
|
||||
-DVERSION_MAJOR=$(VERSION_MAJOR) \
|
||||
-DVERSION_MINOR=$(VERSION_MINOR) \
|
||||
-DPATCHLEVEL=$(PATCHLEVEL) \
|
||||
-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)
|
||||
|
||||
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)
|
||||
override CFLAGS += $(shell pkg-config --cflags lua)
|
||||
LIBS += $(shell pkg-config --libs lua)
|
||||
|
||||
### debugger
|
||||
CFLAGS += $(shell pkg-config --cflags 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
|
||||
override 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
|
||||
|
||||
### X11 UI
|
||||
ifeq ($(WITH_X11), yes)
|
||||
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
|
||||
|
@ -109,7 +104,7 @@ ifeq ($(WITH_SDL), yes)
|
|||
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
|
||||
|
|
Loading…
Reference in a new issue