Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ssusysinfo] Intial implementation. Fixes JB#36977
Device details such as model, designation, manufacturer and pretty name are needed by low level system daemons. The SSU D-Bus interface can't be used early in the boot and libssu is a Qt C++ library - which makes it difficult to use from scripts / daemons written in in plain C. Provide libssusysinfo that duplicates some logic in libssu and makes it possible to query device details without requiring D-Bus IPC or Qt code. Provide ssusysinfo command line utility that can be used to query the information from script files. The intent is that the library and associated binaries can be used both from open source and proprietary components - thus all new code is licensed under LGPL v2.1. Code dealing with ini-file handling is taken from "profiled" tree and uses separate (BSD) license, see lib/inifile.[ch] and lib/symtab.[ch]. Signed-off-by: Simo Piiroinen <simo.piiroinen@jollamobile.com>
- Loading branch information
Showing
22 changed files
with
2,995 additions
and
656 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
bin/ssu-sysinfo.o:\ | ||
bin/ssu-sysinfo.c\ | ||
lib/ssusysinfo.h\ | ||
|
||
bin/ssu-sysinfo.pic.o:\ | ||
bin/ssu-sysinfo.c\ | ||
lib/ssusysinfo.h\ | ||
|
||
lib/inifile.o:\ | ||
lib/inifile.c\ | ||
lib/inifile.h\ | ||
lib/logging.h\ | ||
lib/symtab.h\ | ||
lib/util.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/inifile.pic.o:\ | ||
lib/inifile.c\ | ||
lib/inifile.h\ | ||
lib/logging.h\ | ||
lib/symtab.h\ | ||
lib/util.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/logging.o:\ | ||
lib/logging.c\ | ||
lib/logging.h\ | ||
lib/util.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/logging.pic.o:\ | ||
lib/logging.c\ | ||
lib/logging.h\ | ||
lib/util.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/ssusysinfo.o:\ | ||
lib/ssusysinfo.c\ | ||
lib/inifile.h\ | ||
lib/ssusysinfo.h\ | ||
lib/util.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/ssusysinfo.pic.o:\ | ||
lib/ssusysinfo.c\ | ||
lib/inifile.h\ | ||
lib/ssusysinfo.h\ | ||
lib/util.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/symtab.o:\ | ||
lib/symtab.c\ | ||
lib/symtab.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/symtab.pic.o:\ | ||
lib/symtab.c\ | ||
lib/symtab.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/util.o:\ | ||
lib/util.c\ | ||
lib/logging.h\ | ||
lib/util.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/util.pic.o:\ | ||
lib/util.c\ | ||
lib/logging.h\ | ||
lib/util.h\ | ||
lib/xmalloc.h\ | ||
|
||
lib/xmalloc.o:\ | ||
lib/xmalloc.c\ | ||
lib/xmalloc.h\ | ||
|
||
lib/xmalloc.pic.o:\ | ||
lib/xmalloc.c\ | ||
lib/xmalloc.h\ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
The ini-file parsing logic is derived from profiled sources and | ||
uses slightly modified BSD 3 clause -license. See | ||
- LICENSE.BSD-3CLAUSE | ||
- lib/inifile.c | ||
- lib/inifile.h | ||
- lib/symtab.c | ||
- lib/symtab.h | ||
|
||
The rest of the code uses standard LGPL v2.1 -license. See | ||
- LICENSE.LGPL-v2.1 |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,269 @@ | ||
# ---------------------------------------------------------------------------- | ||
# Package version | ||
# ---------------------------------------------------------------------------- | ||
|
||
VERSION := 0.0.0 | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Shared object version | ||
# ---------------------------------------------------------------------------- | ||
|
||
SOMAJOR := .1 | ||
SOMINOR := .0 | ||
SORELEASE := .0 | ||
|
||
SOLINK := .so | ||
SONAME := .so$(SOMAJOR) | ||
SOVERS := .so$(SOMAJOR)$(SOMINOR)$(SORELEASE) | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Files to build / install | ||
# ---------------------------------------------------------------------------- | ||
|
||
TARGETS_DSO += libssusysinfo$(SOVERS) | ||
TARGETS_BIN += ssu-sysinfo | ||
TARGETS_ALL += $(TARGETS_DSO) $(TARGETS_BIN) libssusysinfo$(SONAME) | ||
|
||
INSTALL_HDR += lib/ssusysinfo.h | ||
INSTALL_PC += pkg-config/ssu-sysinfo.pc | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Installation directories | ||
# ---------------------------------------------------------------------------- | ||
|
||
# Dummy default install dir - override from packaging scripts | ||
DESTDIR ?= /tmp/ssu-sysinfo-test-install | ||
|
||
# Standard install directories | ||
_PREFIX ?= /usr# # /usr | ||
_INCLUDEDIR ?= $(_PREFIX)/include# # /usr/include | ||
_EXEC_PREFIX ?= $(_PREFIX)# # /usr | ||
_BINDIR ?= $(_EXEC_PREFIX)/bin# # /usr/bin | ||
_SBINDIR ?= $(_EXEC_PREFIX)/sbin# # /usr/sbin | ||
_LIBEXECDIR ?= $(_EXEC_PREFIX)/libexec# # /usr/libexec | ||
_LIBDIR ?= $(_EXEC_PREFIX)/lib# # /usr/lib | ||
_SYSCONFDIR ?= /etc# # /etc | ||
_DATADIR ?= $(_PREFIX)/share# # /usr/share | ||
_MANDIR ?= $(_DATADIR)/man# # /usr/share/man | ||
_INFODIR ?= $(_DATADIR)/info# # /usr/share/info | ||
_DEFAULTDOCDIR ?= $(_DATADIR)/doc# # /usr/share/doc | ||
_LOCALSTATEDIR ?= /var# # /var | ||
_UNITDIR ?= /lib/systemd/system# | ||
_TESTSDIR ?= /opt/tests# # /opt/tests | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Default flags | ||
# ---------------------------------------------------------------------------- | ||
|
||
CPPFLAGS += -D_GNU_SOURCE | ||
CPPFLAGS += -D_FILE_OFFSET_BITS=64 | ||
|
||
COMMON += -Wall | ||
COMMON += -Wextra | ||
COMMON += -Werror # DEVEL TIME ONLY - DO NOT LEAVE IN | ||
COMMON += -Os | ||
COMMON += -g | ||
|
||
CFLAGS += $(COMMON) | ||
CFLAGS += -std=c99 | ||
CFLAGS += -Wmissing-prototypes | ||
CFLAGS += -Wno-missing-field-initializers | ||
|
||
CXXFLAGS += $(COMMON) | ||
|
||
LDFLAGS += -g | ||
|
||
LDLIBS += -Wl,--as-needed | ||
|
||
# Options that are useful for weeding out unused functions | ||
#CFLAGS += -O0 -ffunction-sections -fdata-sections | ||
#LDLIBS += -Wl,--gc-sections,--print-gc-sections | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Flags from pkg-config | ||
# ---------------------------------------------------------------------------- | ||
|
||
#PKG_NAMES += glib-2.0 | ||
|
||
# we do not need pkg-config for maintenance targets | ||
maintenance = normalize clean distclean mostlyclean | ||
intersection = $(strip $(foreach w,$1, $(filter $w,$2))) | ||
ifneq ($(call intersection,$(maintenance),$(MAKECMDGOALS)),) | ||
PKG_CONFIG ?= true | ||
endif | ||
|
||
# pkg-config does not grok CFLAGS vs CPPFLAGS ... deal with it | ||
ifneq ($(strip $(PKG_NAMES)),) | ||
PKG_CONFIG ?= pkg-config | ||
PKG_CFLAGS := $(shell $(PKG_CONFIG) --cflags $(PKG_NAMES)) | ||
PKG_LDLIBS := $(shell $(PKG_CONFIG) --libs $(PKG_NAMES)) | ||
PKG_CPPFLAGS := $(filter -D%,$(PKG_CFLAGS)) $(filter -I%,$(PKG_CFLAGS)) | ||
PKG_CFLAGS := $(filter-out -I%, $(filter-out -D%, $(PKG_CFLAGS))) | ||
endif | ||
|
||
CPPFLAGS += $(PKG_CPPFLAGS) | ||
CFLAGS += $(PKG_CFLAGS) | ||
LDLIBS += $(PKG_LDLIBS) | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Top level targets | ||
# ---------------------------------------------------------------------------- | ||
|
||
.PHONY: build install clean distclean mostlyclean | ||
|
||
build:: $(TARGETS_ALL) | ||
|
||
install:: build | ||
|
||
clean:: mostlyclean | ||
$(RM) $(TARGETS_ALL) | ||
|
||
distclean:: clean | ||
|
||
mostlyclean:: | ||
$(RM) *.o *~ *.bak */*.o */*~ */*.bak | ||
|
||
install :: | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Implicit rules | ||
# ---------------------------------------------------------------------------- | ||
|
||
.SUFFIXES: %.c %.o %.pic.o %$(SOVERS) %$(SONAME) | ||
|
||
%.o : %.c | ||
$(CC) -o $@ -c $< $(CPPFLAGS) $(CFLAGS) | ||
|
||
%.pic.o : %.c | ||
$(CC) -o $@ -c $< -fPIC -fvisibility=hidden $(CPPFLAGS) $(CFLAGS) | ||
|
||
%$(SOVERS) : | ||
$(CC) -o $@ -shared -Wl,-soname,$*$(SONAME) $^ $(LDFLAGS) $(LDLIBS) | ||
|
||
%$(SONAME) : %$(SOVERS) | ||
ln -sf $< $@ | ||
|
||
% : bin/%.o | ||
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS) | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Build libssusysinfo$(SOVERS) | ||
# ---------------------------------------------------------------------------- | ||
|
||
libssusysinfo_SRC += lib/ssusysinfo.c | ||
libssusysinfo_SRC += lib/inifile.c | ||
libssusysinfo_SRC += lib/logging.c | ||
libssusysinfo_SRC += lib/symtab.c | ||
libssusysinfo_SRC += lib/util.c | ||
libssusysinfo_SRC += lib/xmalloc.c | ||
|
||
libssusysinfo_OBJ += $(patsubst %.c,%.pic.o,$(libssusysinfo_SRC)) | ||
|
||
libssusysinfo$(SOVERS) : $(libssusysinfo_OBJ) | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Build ssu-sysinfo | ||
# ---------------------------------------------------------------------------- | ||
|
||
ssu_sysinfo_SRC += bin/ssu-sysinfo.c | ||
|
||
ssu_sysinfo_OBJ += $(patsubst %.c,%.o,$(ssu_sysinfo_SRC)) | ||
ssu_sysinfo_OBJ += libssusysinfo$(SONAME) | ||
|
||
ssu-sysinfo : $(ssu_sysinfo_OBJ) | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Statically linked binary for static analysis, not build normally | ||
# ---------------------------------------------------------------------------- | ||
|
||
monolith_OBJ += $(patsubst %.c,%.o,$(ssu_sysinfo_SRC)) | ||
monolith_OBJ += $(patsubst %.c,%.o,$(libssusysinfo_SRC)) | ||
|
||
monolith : $(monolith_OBJ) | ||
$(CC) -o $@ $^ $(LDFLAGS) $(LDLIBS) | ||
clean:: | ||
$(RM) monolith | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Install to $(DESTDIR) | ||
# ---------------------------------------------------------------------------- | ||
|
||
install :: | ||
# binaries | ||
install -d -m 755 $(DESTDIR)$(_BINDIR) | ||
install -m 755 $(TARGETS_BIN) $(DESTDIR)$(_BINDIR)/ | ||
# dynamic libraries | ||
install -d -m 755 $(DESTDIR)$(_LIBDIR) | ||
install -m 644 $(TARGETS_DSO) $(DESTDIR)$(_LIBDIR)/ | ||
# headers | ||
install -d -m 755 $(DESTDIR)$(_INCLUDEDIR)/ssusysinfo | ||
install -m 644 $(INSTALL_HDR) $(DESTDIR)$(_INCLUDEDIR)/ssusysinfo/ | ||
# pkg config | ||
install -d -m 755 $(DESTDIR)$(_LIBDIR)/pkgconfig | ||
install -m 644 $(INSTALL_PC) $(DESTDIR)$(_LIBDIR)/pkgconfig | ||
# symlinks for dynamic linking | ||
for f in $(TARGETS_DSO); do \ | ||
ln -sf $$(basename $$f $(SOVERS))$(SONAME) \ | ||
$(DESTDIR)$(_LIBDIR)/$$(basename $$f $(SOVERS))$(SOLINK); \ | ||
done | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Source code normalization | ||
# ---------------------------------------------------------------------------- | ||
|
||
.PHONY: normalize | ||
normalize:: | ||
normalize_whitespace -M Makefile | ||
normalize_whitespace -a $(wildcard rpm/*.spec */*.pc) | ||
normalize_whitespace -a $(wildcard */*.py */*.sh) | ||
normalize_whitespace -a $(wildcard */*.[ch]) | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Prototype scanning (two phases to allow preprocessing in scratchbox) | ||
# ---------------------------------------------------------------------------- | ||
|
||
.SUFFIXES: %.q %.p %.sp | ||
|
||
%.q : %.c ; gcc -E -o $@ $(CPPFLAGS) $< | ||
%.p : %.q ; cproto < $< | prettyproto.py > $@ && cat $@ | ||
%.sp : %.q ; cproto -s < $< | prettyproto.py > $@ && cat $@ | ||
|
||
mostlyclean:: | ||
$(RM) *.q *.p *.sp | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Header dependecy scanning | ||
# ---------------------------------------------------------------------------- | ||
|
||
.PHONY: depend | ||
|
||
depend:: | ||
$(CC) -MM -MG $(CPPFLAGS) $(wildcard */*.c) | util/depend_filter.py > .depend | ||
|
||
ifneq ($(MAKECMDGOALS),depend) # not while: make depend | ||
ifneq (,$(wildcard .depend)) # not if .depend does not exist | ||
include .depend | ||
endif | ||
endif | ||
|
||
# ---------------------------------------------------------------------------- | ||
# Hunt for excess include statements | ||
# ---------------------------------------------------------------------------- | ||
|
||
.PHONY: headers | ||
.SUFFIXES: %.checked | ||
|
||
headers:: c_headers c_sources | ||
|
||
%.checked : % | ||
find_unneeded_includes.py $(CPPFLAGS) $(CFLAGS) -- $< | ||
@touch $@ | ||
|
||
clean:: | ||
$(RM) */*.checked */*.order | ||
|
||
c_headers:: $(patsubst %,%.checked,$(wildcard */*.h)) | ||
c_sources:: $(patsubst %,%.checked,$(wildcard */*.c)) | ||
|
||
order:: | ||
find_unneeded_includes.py -- $(wildcard */*.h) $(wildcard */*.c) |
Oops, something went wrong.