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

Misc minor fixes #182

Merged
merged 15 commits into from
Nov 11, 2021
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
8 changes: 7 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,16 @@
.*.h.P
.*.d
.*.sw?
.gdb_history
*~
*.a
*.bin
*.env
*.C
/.cache/
*.cer
*.E
*.env
*.esl
*.o
*.map
*.pc
Expand All @@ -17,6 +22,7 @@
*.strace
*.tar.*
*.var
compile_commands.json
core.*
cov-int
vgcore.*
Expand Down
31 changes: 15 additions & 16 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,46 +9,40 @@ include $(TOPDIR)/src/include/scan-build.mk

SUBDIRS := src docs

all : | efivar.spec src/include/version.mk
all :
all : | efivar.spec src/include/version.mk prep
all clean install prep :
@set -e ; for x in $(SUBDIRS) ; do \
$(MAKE) -C $$x $@ ; \
done

install :
@set -e ; for x in $(SUBDIRS) ; do \
$(MAKE) -C $$x $@ ; \
done

abidw abicheck efivar efivar-static static:
abicheck abidw efivar efivar-static static : | all
$(MAKE) -C src $@

abiupdate :
$(MAKE) clean all
$(MAKE) -C src abiclean abixml

$(SUBDIRS) :
$(MAKE) -C $@
$(MAKE) -C $@ all

brick : all
@set -e ; for x in $(SUBDIRS) ; do $(MAKE) -C $${x} test ; done
@echo -n $(info this is the rule for brick PWD:$(PWD) MAKECMDGOALS:$(MAKECMDGOALS))
@set -e ; for x in $(SUBDIRS) ; do \
$(MAKE) -C $${x} test ; \
done

a :
@if [ $${EUID} != 0 ]; then \
echo no 1>&2 ; \
exit 1 ; \
fi

.PHONY: $(SUBDIRS) a brick abiupdate

GITTAG = $(shell bash -c "echo $$(($(VERSION) + 1))")

efivar.spec : | Makefile src/include/version.mk

clean :
@set -e ; for x in $(SUBDIRS) ; do \
$(MAKE) -C $$x $@ ; \
done
clean : clean-toplevel
clean-toplevel:
@rm -vf efivar.spec vgcore.* core.*

test : all
Expand Down Expand Up @@ -83,4 +77,9 @@ archive: abicheck bumpver abidw tag efivar.spec
@rm -rf /tmp/efivar-$(GITTAG)
@echo "The archive is in efivar-$(GITTAG).tar.bz2"

.PHONY: $(SUBDIRS)
.PHONY: a abiclean abicheck abidw abiupdate all archive
.PHONY: brick bumpver clean clean-toplevel
.PHONY: efivar efivar-static
.PHONY: install prep tag test test-archive
.NOTPARALLEL:
2 changes: 2 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ all :

clean :

prep :

test :

install :
Expand Down
33 changes: 19 additions & 14 deletions efivar.spec.in
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,21 @@ Name: efivar
Version: @@VERSION@@
Release: 1%{?dist}
Summary: Tools to manage UEFI variables
License: LGPLv2.1
URL: https://github.com/rhinstaller/efivar
License: LGPL-2.1
URL: https://github.com/rhboot/efivar
Requires: %{name}-libs = %{version}-%{release}
ExclusiveArch: %{ix86} x86_64 aarch64

BuildRequires: git glibc-static libabigail
Source0: https://github.com/rhboot/efivar/archive/%{version}.tar.gz
ExclusiveArch: %{efi}

BuildRequires: efi-srpm-macros
BuildRequires: gcc
BuildRequires: git
BuildRequires: glibc-static
BuildRequires: libabigail
BuildRequires: mandoc
BuildRequires: make
# please don't fix this to reflect github's incomprehensible url that goes
# to a different tarball.
Source0: https://github.com/rhboot/efivar/releases/download/%{version}/efivar-%{version}.tar.bz2

%description
efivar provides a simple command line interface to the UEFI variable facility.
Expand Down Expand Up @@ -38,23 +46,20 @@ git config --unset user.email
git config --unset user.name

%build
make LIBDIR=%{_libdir} BINDIR=%{_bindir} CFLAGS="$RPM_OPT_FLAGS -flto" LDFLAGS="$RPM_LD_FLAGS -flto"
%define _lto_cflags %{nil}

make LIBDIR=%{_libdir} BINDIR=%{_bindir} CFLAGS="$RPM_OPT_FLAGS" LDFLAGS="$RPM_LD_FLAGS"

%install
rm -rf $RPM_BUILD_ROOT
%makeinstall

%clean
rm -rf $RPM_BUILD_ROOT
install -m 0644 src/abignore %{buildroot}%{_includedir}/efivar/.abignore

%check
%ifarch x86_64
make abicheck
%endif

%post libs -p /sbin/ldconfig

%postun libs -p /sbin/ldconfig
%ldconfig_scriptlets libs

%files
%{!?_licensedir:%global license %%doc}
Expand Down
56 changes: 39 additions & 17 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,27 @@ LIBEFIVAR_SOURCES = crc32.c dp.c dp-acpi.c dp-hw.c dp-media.c dp-message.c \
lib.c vars.c
LIBEFIVAR_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(LIBEFIVAR_SOURCES)))
EFIVAR_SOURCES = efivar.c
EFIVAR_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(EFIVAR_SOURCES)))
GENERATED_SOURCES = include/efivar/efivar-guids.h guid-symbols.c
MAKEGUIDS_SOURCES = makeguids.c guid.c
MAKEGUIDS_SOURCES = makeguids.c
MAKEGUIDS_OBJECTS = $(patsubst %.S,%.o,$(patsubst %.c,%.o,$(MAKEGUIDS_SOURCES)))
MAKEGUIDS_OUTPUT = guids.bin names.bin $(GENERATED_SOURCES)

ALL_SOURCES=$(LIBEFIBOOT_SOURCES) $(LIBEFIVAR_SOURCES) $(MAKEGUIDS_SOURCES) \
$(sort $(wildcard include/efivar/*.h)) $(GENERATED_SOURCES) $(EFIVAR_SOURCES)

ifneq ($(MAKECMDGOALS),clean)
$(call deps-of,$(ALL_SOURCES)) : | deps
-include $(call deps-of,$(ALL_SOURCES))
endif

all : $(TARGETS)

static : $(STATICTARGETS)

$(BINTARGETS) : | $(LIBTARGETS) $(PCTARGETS)
$(STATICTARGETS) : | $(STATICLIBTARGETS) $(PCTARGETS)

abiclean :
@rm -vf $(patsubst %.so,%.abixml,$@)

Expand All @@ -44,25 +53,37 @@ abidw : $(patsubst %.so,%.abixml,$(LIBTARGETS))

abicheck : $(patsubst %.so,%.abicheck,$(LIBTARGETS))

./guid-symbols.c : include/efivar/efivar-guids.h
./guids.bin : include/efivar/efivar-guids.h
./names.bin : include/efivar/efivar-guids.h
include/efivar/efivar-guids.h : makeguids guids.txt
./makeguids guids.txt guids.bin names.bin \
guid-symbols.c include/efivar/efivar-guids.h

makeguids : CPPFLAGS=$(HOST_CPPFLAGS)
makeguids : LIBS=dl
makeguids : CC=$(HOSTCC)
makeguids : CCLD=$(HOSTCCLD)
makeguids : CFLAGS=$(HOST_CFLAGS)
makeguids : LDFLAGS=$(HOST_LDFLAGS)
makeguids : CCLDFLAGS=$(HOST_CCLDFLAGS)
makeguids : $(MAKEGUIDS_SOURCES)
makeguids : $(MAKEGUIDS_OBJECTS)

$(MAKEGUIDS_OUTPUT) : makeguids
$(MAKEGUIDS_OUTPUT) : guids.txt
@set -e ; \
missing=no ; \
for x in $$(cat guids.txt | awk '{ print $$2 }' | grep -v ^zz) ; do \
if ! grep -q "efi_guid_$${x}" libefivar.map.in ; then \
echo missing symbol "efi_guid_$${x}" ; \
missing=yes ; \
fi ; \
done ; \
if [ "$${missing}" != "no" ]; then \
exit 1 ; \
fi
./makeguids guids.txt guids.bin names.bin \
guid-symbols.c include/efivar/efivar-guids.h

guids.o : | makeguids
guids.o : guids.S guids.bin names.bin

guids.o : guids.S | guids.bin names.bin
prep : makeguids $(GENERATED_SOURCES)

$(LIBEFIVAR_OBJECTS) $(LIBEFIBOOT_OBJECTS) : | $(GENERATED_SOURCES)
$(LIBEFIVAR_OBJECTS) $(LIBEFIBOOT_OBJECTS) : prep

libefivar.a : | $(GENERATED_SOURCES)
libefivar.a : $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS))
Expand All @@ -72,10 +93,10 @@ libefivar.so : | $(GENERATED_SOURCES) libefivar.map
libefivar.so : LIBS=dl
libefivar.so : MAP=libefivar.map

efivar : efivar.c | libefivar.so
efivar : $(EFIVAR_OBJECTS) | libefivar.so
efivar : LIBS=efivar dl

efivar-static : efivar.c $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS))
efivar-static : $(EFIVAR_OBJECTS) $(patsubst %.o,%.static.o,$(LIBEFIVAR_OBJECTS))
efivar-static : | $(GENERATED_SOURCES)
efivar-static : LIBS=dl

Expand Down Expand Up @@ -112,14 +133,15 @@ install : all
$(INSTALL) -d -m 755 $(DESTDIR)$(INCLUDEDIR)/efivar
$(foreach x, $(sort $(wildcard $(TOPDIR)/src/include/efivar/*.h)), $(INSTALL) -m 644 $(x) $(DESTDIR)$(INCLUDEDIR)/efivar/$(notdir $(x));)
$(INSTALL) -d -m 755 $(DESTDIR)$(BINDIR)
$(foreach x, $(BINTARGETS), $(INSTALL) -m 755 $(x) $(DESTDIR)$(BINDIR);)
$(foreach x, $(filter-out %-test,$(BINTARGETS)), $(INSTALL) -m 755 $(x) $(DESTDIR)$(BINDIR);)

test : all
$(MAKE) -C test $@

.PHONY: test deps abiclean abixml
.PHONY: abiclean abicheck abidw abixml all
.PHONY: clean deps install test
.SECONDARY : libefivar.so.1.$(VERSION) libefivar.so.1
.SECONDARY : libefiboot.so.1.$(VERSION) libefiboot.so.1
.SECONDARY : include/efivar/efivar-guids.h guid-symbols.c
.SECONDARY : $(GENERATED_SOURCES)
.INTERMEDIATE : guids.bin names.bin
.PRECIOUS : guid-symbols.o makeguids
.PRECIOUS : makeguids
12 changes: 4 additions & 8 deletions src/guid.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ extern const efi_guid_t efi_guid_zero;
int NONNULL(1, 2) PUBLIC
efi_guid_cmp(const efi_guid_t *a, const efi_guid_t *b)
{
return memcmp(a, b, sizeof (efi_guid_t));
return efi_guid_cmp_(a, b);
}

int NONNULL(1) PUBLIC
Expand All @@ -35,11 +35,7 @@ efi_guid_is_empty(const efi_guid_t *guid)
int NONNULL(1, 2) PUBLIC
efi_str_to_guid(const char *s, efi_guid_t *guid)
{
int rc;
rc = text_to_guid(s, guid);
if (rc < 0)
efi_error("text_to_guid(\"%s\",...)", s);
return rc;
return efi_str_to_guid_(s, guid);
}

int NONNULL(1) PUBLIC
Expand Down Expand Up @@ -91,7 +87,7 @@ cmpguidp(const void *p1, const void *p2)
struct guidname *gn1 = (struct guidname *)p1;
struct guidname *gn2 = (struct guidname *)p2;

return memcmp(&gn1->guid, &gn2->guid, sizeof (gn1->guid));
return efi_guid_cmp_(&gn1->guid, &gn2->guid);
}

static int NONNULL(1, 2)
Expand All @@ -100,7 +96,7 @@ cmpnamep(const void *p1, const void *p2)
struct guidname *gn1 = (struct guidname *)p1;
struct guidname *gn2 = (struct guidname *)p2;

return memcmp(gn1->name, gn2->name, sizeof (gn1->name));
return strncmp(gn1->name, gn2->name, sizeof (gn1->name));
}

static int NONNULL(1, 2)
Expand Down
38 changes: 38 additions & 0 deletions src/guid.h
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,44 @@ struct guidname {
char name[256];
};

static inline int
efi_int_cmp_(uint64_t a, uint64_t b)
{
if (a < b)
return -1;
if (a > b)
return 1;
return 0;
}

static inline int NONNULL(1, 2)
efi_guid_cmp_(const efi_guid_t *a, const efi_guid_t *b)
{
if (a->a != b->a)
return efi_int_cmp_(a->a, b->a);
if (a->b != b->b)
return efi_int_cmp_(a->b, b->b);
if (a->c != b->c)
return efi_int_cmp_(a->c, b->c);
if (a->d != b->d)
return efi_int_cmp_(be16_to_cpu(a->d), be16_to_cpu(b->d));
for (size_t i = 0; i < sizeof(a->e)/sizeof(a->e[0]); i++) {
if (a->e[i] != b->e[i])
return efi_int_cmp_(a->e[i], b->e[i]);
}
return 0;
}

static inline int NONNULL(1, 2)
efi_str_to_guid_(const char *s, efi_guid_t *guid)
{
int rc;
rc = text_to_guid(s, guid);
if (rc < 0)
efi_error("text_to_guid(\"%s\",...)", s);
return rc;
}

#endif /* LIBEFIVAR_GUID */

// vim:fenc=utf-8:tw=75:noet
9 changes: 6 additions & 3 deletions src/include/defaults.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ INCLUDEDIR ?= $(PREFIX)/include
BINDIR ?= $(EXEC_PREFIX)/bin
PCDIR ?= $(LIBDIR)/pkgconfig
DESTDIR ?=
PKGS ?=

CROSS_COMPILE ?=
COMPILER ?= gcc
Expand All @@ -19,12 +20,15 @@ $(call set-if-undefined,CCLD,$(CC))
$(call set-if-undefined,HOSTCC,$(COMPILER))
$(call set-if-undefined,HOSTCCLD,$(HOSTCC))

OPTIMIZE_GCC = -flto
# temporary, see https://sourceware.org/bugzilla/show_bug.cgi?id=28264
#OPTIMIZE_GCC = -flto
OPTIMIZE_GCC =
OPTIMIZE ?= -Og $(call family,OPTIMIZE)
DEBUGINFO ?= -g3
WARNINGS_GCC ?=
WARNINGS_CCC_ANALYZER ?= $(WARNINGS_GCC)
WARNINGS ?= -Wall -Wextra $(call family,WARNINGS)
ERRORS_GCC ?=
ERRORS ?= -Werror $(call family,ERRORS)
CPPFLAGS ?=
override _CPPFLAGS := $(CPPFLAGS)
Expand Down Expand Up @@ -77,6 +81,7 @@ HOST_CPPFLAGS ?= $(CPPFLAGS)
override _HOST_CPPFLAGS := $(HOST_CPPFLAGS)
override HOST_CPPFLAGS = $(_HOST_CPPFLAGS) \
-DEFIVAR_BUILD_ENVIRONMENT $(HOST_MARCH)
HOST_CFLAGS_GCC ?=
HOST_CFLAGS_CLANG ?=
HOST_CFLAGS ?= $(CFLAGS) $(call family,HOST_CFLAGS)
override _HOST_CFLAGS := $(HOST_CFLAGS)
Expand Down Expand Up @@ -107,8 +112,6 @@ RANLIB := $(CROSS_COMPILE)$(COMPILER)-ranlib
ABIDW := abidw
ABIDIFF := abidiff

PKGS =

LDLIBS=$(foreach lib,$(LIBS),-l$(lib)) $(call pkg-config-ldlibs)

COMMIT_ID=$(shell git log -1 --pretty=%H 2>/dev/null || echo master)
Expand Down
Loading