diff --git a/.gitignore b/.gitignore index 9530f0ac..83546027 100644 --- a/.gitignore +++ b/.gitignore @@ -31,3 +31,5 @@ preload/privatewrappers.c preload/privatewrappers.h preload/export.map include/scratchbox2_version.h +build/ +compile_commands.json diff --git a/Makefile b/Makefile index 766e1dbe..daf06ae3 100644 --- a/Makefile +++ b/Makefile @@ -1,53 +1,38 @@ # Copyright (C) 2007 Lauri Leukkunen # Licensed under LGPL 2.1 -TOPDIR = $(CURDIR) +TOPDIR = $(patsubst %/,%,$(CURDIR)) OBJDIR = $(TOPDIR) SRCDIR = $(TOPDIR) -VPATH = $(SRCDIR) +VPATH = $(SRCDIR):$(OBJDIR) + +MAKEFILEDIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) +ifneq ($(MAKEFILEDIR),$(OBJDIR)) +SRCDIR:=$(patsubst %/,%,$(MAKEFILEDIR)) +endif + +prefix = /usr/local +libdir = $(prefix)/lib +bindir = $(prefix)/bin +datarootdir = $(prefix)/share +datadir = $(datarootdir) -MACH := $(shell uname -m) OS := $(shell uname -s) ifeq ($(OS),Linux) LIBSB2_LDFLAGS = -Wl,-soname=$(LIBSB2_SONAME) \ - -Wl,--version-script=preload/export.map + -Wl,--version-script=$(OBJDIR)/preload/export.map SHLIBEXT = so else SHLIBEXT = dylib endif -# pick main build bitness -ifeq ($(MACH),x86_64) -PRI_OBJDIR = obj-64 -else -PRI_OBJDIR = obj-32 -endif - CC = gcc CXX = g++ LD = ld -PACKAGE_VERSION = 2.3.90 - -ifeq ($(shell if [ -d $(SRCDIR)/.git ]; then echo y; fi),y) -GIT_PV_COMMIT := $(shell git --git-dir=$(SRCDIR)/.git log -1 --pretty="format:%h" $(PACKAGE_VERSION) -- 2>/dev/null) -GIT_CUR_COMMIT := $(shell git --git-dir=$(SRCDIR)/.git log -1 --pretty="format:%h" HEAD -- 2>/dev/null) -GIT_MODIFIED := $(shell cd $(SRCDIR); git ls-files -m) -GIT_TAG_EXISTS := $(strip $(shell git --git-dir=$(SRCDIR)/.git tag -l $(PACKAGE_VERSION) 2>/dev/null)) -ifeq ("$(GIT_TAG_EXISTS)","") -# Add -rc to version to signal that the PACKAGE_VERSION release has NOT -# been yet tagged -PACKAGE_VERSION := $(PACKAGE_VERSION)-rc -endif -ifneq ($(GIT_PV_COMMIT),$(GIT_CUR_COMMIT)) -PACKAGE_VERSION := $(PACKAGE_VERSION)-$(GIT_CUR_COMMIT) -endif -ifneq ($(strip "$(GIT_MODIFIED)"),"") -PACKAGE_VERSION := $(PACKAGE_VERSION)-dirty -endif -endif -PACKAGE = "SB2" +PACKAGE_VERSION = +PACKAGE_NAME = LIBSB2_SONAME = "libsb2.so.1" LLBUILD ?= $(SRCDIR)/llbuild PROTOTYPEWARNINGS=-Wmissing-prototypes -Wstrict-prototypes @@ -67,8 +52,6 @@ subdirs = preload luaif sblib pathmapping execs network rule_tree utils sb2d wra CFLAGS += -O2 -g -Wall -W CFLAGS += -I$(OBJDIR)/include -I$(SRCDIR)/include CFLAGS += -D_GNU_SOURCE=1 -D_LARGEFILE_SOURCE=1 -D_LARGEFILE64_SOURCE=1 -CFLAGS += $(MACH_CFLAG) -LDFLAGS += $(MACH_CFLAG) CXXFLAGS = # Uncomment following two lines to activate the "processclock" reports: @@ -77,50 +60,44 @@ CXXFLAGS = include $(LLBUILD)/Makefile.include -ifdef prefix -CONFIGURE_ARGS = --prefix=$(prefix) -else -CONFIGURE_ARGS = -endif +# These targets have to be updated first to not start building +# while configure is running when any of these or their +# dependencies change +DIST_FILES = $(OBJDIR)/config.status \ + $(OBJDIR)/config.mak \ + $(SRCDIR)/include/config.h.in -ifeq ($(MACH),x86_64) -all: multilib -else -all: regular -endif -do-all: $(targets) +all: $(DIST_FILES) .WAIT do-all -.configure: - $(SRCDIR)/configure $(CONFIGURE_ARGS) - @touch .configure - -.PHONY: .version -.version: - @(set -e; \ - if [ -f .version ]; then \ - version=$$(cat .version); \ - if [ "$(PACKAGE_VERSION)" != "$$version" ]; then \ - echo $(PACKAGE_VERSION) > .version; \ - fi \ - else \ - echo $(PACKAGE_VERSION) > .version; \ - fi) - -include/scratchbox2_version.h: .version Makefile - echo "/* Automatically generated file. Do not edit. */" >include/scratchbox2_version.h - echo '#define SCRATCHBOX2_VERSION "'`cat .version`'"' >>include/scratchbox2_version.h - echo '#define LIBSB2_SONAME "'$(LIBSB2_SONAME)'"' >>include/scratchbox2_version.h - -regular: .configure .version - @$(MAKE) -f $(SRCDIR)/Makefile --include-dir=$(SRCDIR) SRCDIR=$(SRCDIR) do-all - -multilib: - @mkdir -p obj-32 - @mkdir -p obj-64 - @$(MAKE) MACH_CFLAG=-m32 -C obj-32 --include-dir=.. -f $(TOPDIR)/Makefile SRCDIR=$(TOPDIR) regular - @$(MAKE) MACH_CFLAG=-m64 -C obj-64 --include-dir=.. -f $(TOPDIR)/Makefile SRCDIR=$(TOPDIR) regular +do-all: $(targets) +# Don't erase these files if make is interrupted while refreshing them. +.PRECIOUS: $(OBJDIR)/config.status +.NOTPARALLEL: $(DIST_FILES) +# Use a proxy timestamp file here since config.mak and config.h +# don't update unless their contents change when the dependencies +# that generate them change, avoid repeated rebuilds after changing +# files such as configure.ac e.g. after checking out a new branch +$(DIST_FILES): $(OBJDIR)/stamp-mak +$(OBJDIR)/stamp-mak: $(SRCDIR)/configure $(SRCDIR)/config.mak.in + $(OBJDIR)/config.status --recheck + echo > $(OBJDIR)/stamp-mak + +$(SRCDIR)/configure: $(SRCDIR)/configure.ac + cd $(SRCDIR); \ + ./autogen.sh + +$(OBJDDIR)/include/config.h: $(OBJDIR)/stamp-h +$(OBJDIR)/stamp-h: $(OBJDIR)/config.h.in $(OBJDIR)/config.status + $(OBJDIR)/config.status $(OBJDDIR)/include/config.h + echo > $(OBJDIR)/stamp-h + +$(OBJDIR)/include/scratchbox2_version.h: $(OBJDIR)/config.mak + mkdir -p $(OBJDIR)/include + echo "/* Automatically generated file. Do not edit. */" >$(OBJDIR)/include/scratchbox2_version.h + echo '#define SCRATCHBOX2_VERSION "'$(PACKAGE_VERSION)'"' >>$(OBJDIR)/include/scratchbox2_version.h + echo '#define LIBSB2_SONAME "'$(LIBSB2_SONAME)'"' >>$(OBJDIR)/include/scratchbox2_version.h gcc_bins = addr2line ar as cc c++ c++filt cpp g++ gcc gcov gdb gdbtui gprof ld nm objcopy objdump ranlib rdi-stub readelf run size strings strip host_prefixed_gcc_bins = $(foreach v,$(gcc_bins),host-$(v)) @@ -134,161 +111,124 @@ tarball: @git archive --format=tar --prefix=sbox2-$(PACKAGE_VERSION)/ $(PACKAGE_VERSION) | bzip2 >sbox2-$(PACKAGE_VERSION).tar.bz2 -install-noarch: regular +install-noarch: all $(P)INSTALL - @if [ -d $(prefix)/bin ] ; \ - then echo "$(prefix)/bin present" ; \ - else install -d -m 755 $(prefix)/bin ; \ - fi - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/lua_scripts - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/modes + $(Q)install -d -m 755 $(DESTDIR)$(bindir) + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/lua_scripts + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/modes $(Q)(set -e; for d in $(sb2_modes); do \ - install -d -m 755 $(prefix)/share/scratchbox2/modes/$$d; \ + install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/modes/$$d; \ for f in $(SRCDIR)/modes/$$d/*; do \ - install -c -m 644 $$f $(prefix)/share/scratchbox2/modes/$$d; \ + install -m 644 $$f $(DESTDIR)$(datadir)/scratchbox2/modes/$$d; \ done; \ done) - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/net_rules + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/net_rules $(Q)(set -e; for d in $(sb2_net_modes); do \ - install -d -m 755 $(prefix)/share/scratchbox2/net_rules/$$d; \ + install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/net_rules/$$d; \ for f in $(SRCDIR)/net_rules/$$d/*; do \ - install -c -m 644 $$f $(prefix)/share/scratchbox2/net_rules/$$d; \ + install -m 644 $$f $(DESTDIR)$(datadir)/scratchbox2/net_rules/$$d; \ done; \ done) # "accel" == "devel" mode in 2.3.x: - $(Q)ln -sf accel $(prefix)/share/scratchbox2/modes/devel + $(Q)ln -sf accel $(DESTDIR)$(datadir)/scratchbox2/modes/devel # Rule libraries - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/rule_lib - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/rule_lib/fs_rules + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/rule_lib + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/rule_lib/fs_rules $(Q)(set -e; for f in $(SRCDIR)/rule_lib/fs_rules/*; do \ - install -c -m 644 $$f $(prefix)/share/scratchbox2/rule_lib/fs_rules; \ + install -m 644 $$f $(DESTDIR)$(datadir)/scratchbox2/rule_lib/fs_rules; \ done) # "scripts" and "wrappers" are visible to the user in some # mapping modes, "lib" is for sb2's internal use - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/lib - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/scripts - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/wrappers - $(Q)install -d -m 755 $(prefix)/share/scratchbox2/tests - @if [ -d $(prefix)/share/man/man1 ] ; \ - then echo "$(prefix)/share/man/man1 present" ; \ - else install -d -m 755 $(prefix)/share/man/man1 ; \ + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/lib + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/scripts + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/wrappers + $(Q)install -d -m 755 $(DESTDIR)$(datadir)/scratchbox2/tests + @if [ -d $(DESTDIR)$(datadir)/man/man1 ] ; \ + then echo "$(DESTDIR)$(datadir)/man/man1 present" ; \ + else install -d -m 755 $(DESTDIR)$(datadir)/man/man1 ; \ fi - @if [ -d $(prefix)/share/man/man7 ] ; \ - then echo "$(prefix)/share/man/man7 present" ; \ - else install -d -m 755 $(prefix)/share/man/man7 ; \ + @if [ -d $(DESTDIR)$(datadir)/man/man7 ] ; \ + then echo "$(DESTDIR)$(datadir)/man/man7 present" ; \ + else install -d -m 755 $(DESTDIR)$(datadir)/man/man7 ; \ fi - $(Q)echo "$(PACKAGE_VERSION)" > $(prefix)/share/scratchbox2/version - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2 $(prefix)/bin/sb2 - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-init $(prefix)/bin/sb2-init - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-config $(prefix)/bin/sb2-config - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-session $(prefix)/bin/sb2-session - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-build-libtool $(prefix)/bin/sb2-build-libtool - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-start-qemuserver $(prefix)/bin/sb2-start-qemuserver - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-qemu-gdbserver-prepare $(prefix)/bin/sb2-qemu-gdbserver-prepare - - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-cmp-checkbuilddeps-output.pl $(prefix)/share/scratchbox2/lib/sb2-cmp-checkbuilddeps-output.pl - - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-upgrade-config $(prefix)/share/scratchbox2/scripts/sb2-upgrade-config - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-parse-sb2-init-args $(prefix)/share/scratchbox2/scripts/sb2-parse-sb2-init-args - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-config-gcc-toolchain $(prefix)/share/scratchbox2/scripts/sb2-config-gcc-toolchain - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-config-debian $(prefix)/share/scratchbox2/scripts/sb2-config-debian - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-check-pkg-mappings $(prefix)/share/scratchbox2/scripts/sb2-check-pkg-mappings - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-exitreport $(prefix)/share/scratchbox2/scripts/sb2-exitreport - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-generate-locales $(prefix)/share/scratchbox2/scripts/sb2-generate-locales - $(Q)install -c -m 755 $(SRCDIR)/utils/sb2-logz $(prefix)/bin/sb2-logz - $(Q)install -c -m 644 $(SRCDIR)/lua_scripts/init*.lua $(prefix)/share/scratchbox2/lua_scripts/ - $(Q)install -c -m 644 $(SRCDIR)/lua_scripts/rule_constants.lua $(prefix)/share/scratchbox2/lua_scripts/ - $(Q)install -c -m 644 $(SRCDIR)/lua_scripts/exec_constants.lua $(prefix)/share/scratchbox2/lua_scripts/ - $(Q)install -c -m 644 $(SRCDIR)/lua_scripts/argvenvp_gcc.lua $(prefix)/share/scratchbox2/lua_scripts/argvenvp_gcc.lua - $(Q)install -c -m 644 $(SRCDIR)/lua_scripts/argvenvp_misc.lua $(prefix)/share/scratchbox2/lua_scripts/argvenvp_misc.lua - $(Q)install -c -m 644 $(SRCDIR)/lua_scripts/create_reverse_rules.lua $(prefix)/share/scratchbox2/lua_scripts/create_reverse_rules.lua - $(Q)install -c -m 644 $(SRCDIR)/lua_scripts/argvmods_loader.lua $(prefix)/share/scratchbox2/lua_scripts/argvmods_loader.lua - $(Q)install -c -m 644 $(SRCDIR)/lua_scripts/add_rules_to_rule_tree.lua $(prefix)/share/scratchbox2/lua_scripts/add_rules_to_rule_tree.lua - - $(Q)install -c -m 644 $(SRCDIR)/tests/* $(prefix)/share/scratchbox2/tests - $(Q)chmod a+x $(prefix)/share/scratchbox2/tests/run.sh - - $(Q)install -c -m 644 $(SRCDIR)/docs/*.1 $(prefix)/share/man/man1 - $(Q)install -c -m 644 $(OBJDIR)/preload/libsb2_interface.7 $(prefix)/share/man/man7 - $(Q)rm -f $(prefix)/share/scratchbox2/host_usr - $(Q)ln -sf /usr $(prefix)/share/scratchbox2/host_usr + $(Q)echo "$(PACKAGE_VERSION)" > $(DESTDIR)$(datadir)/scratchbox2/version + $(Q)install -m 755 $(OBJDIR)/utils/sb2 $(DESTDIR)$(bindir)/sb2 + $(Q)install -m 755 $(OBJDIR)/utils/sb2-init $(DESTDIR)$(bindir)/sb2-init + $(Q)install -m 755 $(OBJDIR)/utils/sb2-config $(DESTDIR)$(bindir)/sb2-config + $(Q)install -m 755 $(SRCDIR)/utils/sb2-session $(DESTDIR)$(bindir)/sb2-session + $(Q)install -m 755 $(SRCDIR)/utils/sb2-build-libtool $(DESTDIR)$(bindir)/sb2-build-libtool + $(Q)install -m 755 $(SRCDIR)/utils/sb2-start-qemuserver $(DESTDIR)$(bindir)/sb2-start-qemuserver + $(Q)install -m 755 $(SRCDIR)/utils/sb2-qemu-gdbserver-prepare $(DESTDIR)$(bindir)/sb2-qemu-gdbserver-prepare + + $(Q)install -m 755 $(SRCDIR)/utils/sb2-cmp-checkbuilddeps-output.pl $(DESTDIR)$(datadir)/scratchbox2/lib/sb2-cmp-checkbuilddeps-output.pl + + $(Q)install -m 755 $(OBJDIR)/utils/sb2-upgrade-config $(DESTDIR)$(datadir)/scratchbox2/scripts/sb2-upgrade-config + $(Q)install -m 755 $(SRCDIR)/utils/sb2-parse-sb2-init-args $(DESTDIR)$(datadir)/scratchbox2/scripts/sb2-parse-sb2-init-args + $(Q)install -m 755 $(OBJDIR)/utils/sb2-config-gcc-toolchain $(DESTDIR)$(datadir)/scratchbox2/scripts/sb2-config-gcc-toolchain + $(Q)install -m 755 $(SRCDIR)/utils/sb2-config-debian $(DESTDIR)$(datadir)/scratchbox2/scripts/sb2-config-debian + $(Q)install -m 755 $(SRCDIR)/utils/sb2-check-pkg-mappings $(DESTDIR)$(datadir)/scratchbox2/scripts/sb2-check-pkg-mappings + $(Q)install -m 755 $(SRCDIR)/utils/sb2-exitreport $(DESTDIR)$(datadir)/scratchbox2/scripts/sb2-exitreport + $(Q)install -m 755 $(SRCDIR)/utils/sb2-generate-locales $(DESTDIR)$(datadir)/scratchbox2/scripts/sb2-generate-locales + $(Q)install -m 755 $(SRCDIR)/utils/sb2-logz $(DESTDIR)$(bindir)/sb2-logz + $(Q)install -m 644 $(SRCDIR)/lua_scripts/init*.lua $(DESTDIR)$(datadir)/scratchbox2/lua_scripts/ + $(Q)install -m 644 $(SRCDIR)/lua_scripts/rule_constants.lua $(DESTDIR)$(datadir)/scratchbox2/lua_scripts/ + $(Q)install -m 644 $(SRCDIR)/lua_scripts/exec_constants.lua $(DESTDIR)$(datadir)/scratchbox2/lua_scripts/ + $(Q)install -m 644 $(SRCDIR)/lua_scripts/argvenvp_gcc.lua $(DESTDIR)$(datadir)/scratchbox2/lua_scripts/argvenvp_gcc.lua + $(Q)install -m 644 $(SRCDIR)/lua_scripts/argvenvp_misc.lua $(DESTDIR)$(datadir)/scratchbox2/lua_scripts/argvenvp_misc.lua + $(Q)install -m 644 $(SRCDIR)/lua_scripts/create_reverse_rules.lua $(DESTDIR)$(datadir)/scratchbox2/lua_scripts/create_reverse_rules.lua + $(Q)install -m 644 $(SRCDIR)/lua_scripts/argvmods_loader.lua $(DESTDIR)$(datadir)/scratchbox2/lua_scripts/argvmods_loader.lua + $(Q)install -m 644 $(SRCDIR)/lua_scripts/add_rules_to_rule_tree.lua $(DESTDIR)$(datadir)/scratchbox2/lua_scripts/add_rules_to_rule_tree.lua + + $(Q)install -m 644 $(SRCDIR)/tests/* $(DESTDIR)$(datadir)/scratchbox2/tests + $(Q)chmod a+x $(DESTDIR)$(datadir)/scratchbox2/tests/run.sh + + $(Q)install -m 644 $(SRCDIR)/docs/*.1 $(DESTDIR)$(datadir)/man/man1 + $(Q)install -m 644 $(OBJDIR)/preload/libsb2_interface.7 $(DESTDIR)$(datadir)/man/man7 + $(Q)rm -f $(DESTDIR)$(datadir)/scratchbox2/host_usr + $(Q)ln -sf /usr $(DESTDIR)$(datadir)/scratchbox2/host_usr @# Wrappers: - $(Q)install -c -m 755 $(SRCDIR)/wrappers/deb-pkg-tools-wrapper $(prefix)/share/scratchbox2/wrappers/dpkg - $(Q)install -c -m 755 $(SRCDIR)/wrappers/deb-pkg-tools-wrapper $(prefix)/share/scratchbox2/wrappers/apt-get - $(Q)install -c -m 755 $(SRCDIR)/wrappers/ldconfig $(prefix)/share/scratchbox2/wrappers/ldconfig - $(Q)install -c -m 755 $(SRCDIR)/wrappers/texi2html $(prefix)/share/scratchbox2/wrappers/texi2html - $(Q)install -c -m 755 $(SRCDIR)/wrappers/dpkg-checkbuilddeps $(prefix)/share/scratchbox2/wrappers/dpkg-checkbuilddeps - $(Q)install -c -m 755 $(SRCDIR)/wrappers/debconf2po-update $(prefix)/share/scratchbox2/wrappers/debconf2po-update - $(Q)install -c -m 755 $(SRCDIR)/wrappers/host-gcc-tools-wrapper $(prefix)/share/scratchbox2/wrappers/host-gcc-tools-wrapper - $(Q)install -c -m 755 $(SRCDIR)/wrappers/gdb $(prefix)/share/scratchbox2/wrappers/gdb - $(Q)install -c -m 755 $(SRCDIR)/wrappers/ldd $(prefix)/share/scratchbox2/wrappers/ldd - $(Q)install -c -m 755 $(SRCDIR)/wrappers/pwd $(prefix)/share/scratchbox2/wrappers/pwd - $(Q)(set -e; cd $(prefix)/share/scratchbox2/wrappers; \ + $(Q)install -m 755 $(SRCDIR)/wrappers/deb-pkg-tools-wrapper $(DESTDIR)$(datadir)/scratchbox2/wrappers/dpkg + $(Q)install -m 755 $(SRCDIR)/wrappers/deb-pkg-tools-wrapper $(DESTDIR)$(datadir)/scratchbox2/wrappers/apt-get + $(Q)install -m 755 $(SRCDIR)/wrappers/ldconfig $(DESTDIR)$(datadir)/scratchbox2/wrappers/ldconfig + $(Q)install -m 755 $(SRCDIR)/wrappers/texi2html $(DESTDIR)$(datadir)/scratchbox2/wrappers/texi2html + $(Q)install -m 755 $(SRCDIR)/wrappers/dpkg-checkbuilddeps $(DESTDIR)$(datadir)/scratchbox2/wrappers/dpkg-checkbuilddeps + $(Q)install -m 755 $(SRCDIR)/wrappers/debconf2po-update $(DESTDIR)$(datadir)/scratchbox2/wrappers/debconf2po-update + $(Q)install -m 755 $(SRCDIR)/wrappers/host-gcc-tools-wrapper $(DESTDIR)$(datadir)/scratchbox2/wrappers/host-gcc-tools-wrapper + $(Q)install -m 755 $(SRCDIR)/wrappers/gdb $(DESTDIR)$(datadir)/scratchbox2/wrappers/gdb + $(Q)install -m 755 $(SRCDIR)/wrappers/ldd $(DESTDIR)$(datadir)/scratchbox2/wrappers/ldd + $(Q)install -m 755 $(SRCDIR)/wrappers/pwd $(DESTDIR)$(datadir)/scratchbox2/wrappers/pwd + $(Q)(set -e; cd $(DESTDIR)$(datadir)/scratchbox2/wrappers; \ for f in $(host_prefixed_gcc_bins); do \ ln -sf host-gcc-tools-wrapper $$f; \ done) -ifeq ($(MACH),x86_64) -install: install-multilib -else -install: do-install -endif - -do-install: install-noarch - $(P)INSTALL - @if [ -d $(prefix)/lib ] ; \ - then echo "$(prefix)/lib present" ; \ - else install -d -m 755 $(prefix)/lib ; \ - fi - $(Q)install -d -m 755 $(prefix)/lib/libsb2 - $(Q)install -d -m 755 $(prefix)/lib/libsb2/wrappers - $(Q)install -c -m 755 $(OBJDIR)/wrappers/fakeroot $(prefix)/lib/libsb2/wrappers/fakeroot - $(Q)install -c -m 755 $(OBJDIR)/preload/libsb2.$(SHLIBEXT) $(prefix)/lib/libsb2/libsb2.so.$(PACKAGE_VERSION) - $(Q)install -c -m 755 $(OBJDIR)/utils/sb2dctl $(prefix)/lib/libsb2/sb2dctl - $(Q)install -c -m 755 $(OBJDIR)/utils/sb2-show $(prefix)/bin/sb2-show - $(Q)install -c -m 755 $(OBJDIR)/utils/sb2-monitor $(prefix)/bin/sb2-monitor - $(Q)install -c -m 755 $(OBJDIR)/sb2d/sb2d $(prefix)/bin/sb2d -ifeq ($(OS),Linux) - $(Q)/sbin/ldconfig -n $(prefix)/lib/libsb2 -endif - -multilib_prefix=$(prefix) - -install-multilib: multilib - @$(MAKE) -C obj-32 --include-dir=.. -f $(TOPDIR)/Makefile SRCDIR=$(TOPDIR) do-install-multilib bitness=32 - @$(MAKE) -C obj-64 --include-dir=.. -f $(TOPDIR)/Makefile SRCDIR=$(TOPDIR) do-install - -do-install-multilib: +install: install-noarch $(P)INSTALL - @if [ -d $(multilib_prefix)/lib$(bitness) ] ; \ - then echo "$(prefix)/lib$(bitness) present" ; \ - else install -d -m 755 $(prefix)/lib$(bitness) ; \ - fi - $(Q)install -d -m 755 $(multilib_prefix)/lib$(bitness)/libsb2 - $(Q)install -c -m 755 preload/libsb2.$(SHLIBEXT) $(multilib_prefix)/lib$(bitness)/libsb2/libsb2.so.$(PACKAGE_VERSION) + $(Q)install -d -m 755 $(DESTDIR)$(libdir)/libsb2 + $(Q)install -d -m 755 $(DESTDIR)$(libdir)/libsb2/wrappers + $(Q)install -m 755 $(OBJDIR)/wrappers/fakeroot $(DESTDIR)$(libdir)/libsb2/wrappers/fakeroot + $(Q)install -m 755 $(OBJDIR)/preload/libsb2.$(SHLIBEXT) $(DESTDIR)$(libdir)/libsb2/libsb2.so.$(PACKAGE_VERSION) + $(Q)install -m 755 $(OBJDIR)/utils/sb2dctl $(DESTDIR)$(libdir)/libsb2/sb2dctl + $(Q)install -m 755 $(OBJDIR)/utils/sb2-show $(DESTDIR)$(bindir)/sb2-show + $(Q)install -m 755 $(OBJDIR)/utils/sb2-monitor $(DESTDIR)$(bindir)/sb2-monitor + $(Q)install -m 755 $(OBJDIR)/sb2d/sb2d $(DESTDIR)$(bindir)/sb2d ifeq ($(OS),Linux) - $(Q)/sbin/ldconfig -n $(multilib_prefix)/lib$(bitness)/libsb2 + $(Q)/sbin/ldconfig -n $(DESTDIR)$(libdir)/libsb2 endif -CLEAN_FILES += $(targets) config.status config.log - -superclean: clean - $(P)CLEAN - $(Q)rm -rf obj-32 obj-64 .configure-multilib .configure - $(Q)rm -rf include/config.h config.mak +CLEAN_FILES += $(targets) \ + $(OBJDIR)/include/config.h \ + $(OBJDIR)/include/scratchbox2_version.h +DISTCLEAN_FILES += $(DIST_FILES) \ + $(OBJDIR)/config.log \ + $(SRCDIR)/configure \ + $(SRCDIR)/include/config.h.in -clean-multilib: +distclean: clean $(P)CLEAN - -$(Q)$(MAKE) -C obj-32 --include-dir=.. -f $(TOPDIR)/Makefile SRCDIR=$(TOPDIR) do-clean - -$(Q)$(MAKE) -C obj-64 --include-dir=.. -f $(TOPDIR)/Makefile SRCDIR=$(TOPDIR) do-clean - -ifeq ($(MACH),x86_64) -clean: clean-multilib do-clean -else -clean: do-clean -endif + $(Q)rm -rf $(DISTCLEAN_FILES) -do-clean: +clean: $(P)CLEAN $(Q)$(ll_clean) diff --git a/autogen.sh b/autogen.sh index 206c7b85..decd64e5 100755 --- a/autogen.sh +++ b/autogen.sh @@ -3,5 +3,7 @@ #automake_version=1.9 rm -rf configure autom4te.cache -autoreconf --verbose --force --install --make +autoreconf --verbose --force --install +echo > stamp-h.in +echo > stamp-mak.in diff --git a/build-aux/git-version-gen b/build-aux/git-version-gen new file mode 100755 index 00000000..780b7e99 --- /dev/null +++ b/build-aux/git-version-gen @@ -0,0 +1,227 @@ +#!/bin/sh +# Print a version string. +scriptversion=2024-07-04.10; # UTC + +# Copyright (C) 2007-2024 Free Software Foundation, Inc. +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see . + +# This script is derived from GIT-VERSION-GEN from GIT: https://git-scm.com/. +# It may be run two ways: +# - from a git repository in which the "git describe" command below +# produces useful output (thus requiring at least one signed tag) +# - from a non-git-repo directory containing a .tarball-version file, which +# presumes this script is invoked like "./git-version-gen .tarball-version". + +# In order to use intra-version strings in your project, you will need two +# separate generated version string files: +# +# .tarball-version - present only in a distribution tarball, and not in +# a checked-out repository. Created with contents that were learned at +# the last time autoconf was run, and used by git-version-gen. Must not +# be present in either $(srcdir) or $(builddir) for git-version-gen to +# give accurate answers during normal development with a checked out tree, +# but must be present in a tarball when there is no version control system. +# Therefore, it cannot be used in any dependencies. GNUmakefile has +# hooks to force a reconfigure at distribution time to get the value +# correct, without penalizing normal development with extra reconfigures. +# +# .version - present in a checked-out repository and in a distribution +# tarball. Usable in dependencies, particularly for files that don't +# want to depend on config.h but do want to track version changes. +# Delete this file prior to any autoconf run where you want to rebuild +# files to pick up a version string change; and leave it stale to +# minimize rebuild time after unrelated changes to configure sources. +# +# As with any generated file in a VC'd directory, you should add +# /.version to .gitignore, so that you don't accidentally commit it. +# .tarball-version is never generated in a VC'd directory, so needn't +# be listed there. +# +# Use the following line in your configure.ac, so that $(VERSION) will +# automatically be up-to-date each time configure is run (and note that +# since configure.ac no longer includes a version string, Makefile rules +# should not depend on configure.ac for version updates). +# +# AC_INIT([GNU project], +# m4_esyscmd([build-aux/git-version-gen .tarball-version]), +# [bug-project@example]) +# +# Then use the following lines in your Makefile.am, so that .version +# will be present for dependencies, and so that .version and +# .tarball-version will exist in distribution tarballs. +# +# EXTRA_DIST = $(top_srcdir)/.version +# BUILT_SOURCES = $(top_srcdir)/.version +# $(top_srcdir)/.version: +# echo '$(VERSION)' > $@-t +# mv $@-t $@ +# dist-hook: +# echo '$(VERSION)' > $(distdir)/.tarball-version + + +me=$0 + +year=`expr "$scriptversion" : '\([^-]*\)'` +version="git-version-gen $scriptversion + +Copyright (C) ${year} Free Software Foundation, Inc. +License GPLv3+: GNU GPL version 3 or later . +This is free software: you are free to change and redistribute it. +There is NO WARRANTY, to the extent permitted by law." + +usage="\ +Usage: $me [OPTION]... \$srcdir/.tarball-version [TAG-NORMALIZATION-SED-SCRIPT] +Print a version string. + +Options: + + --prefix PREFIX prefix of git tags (default 'v') + --fallback VERSION + fallback version to use if \"git --version\" fails + + --help display this help and exit + --version output version information and exit + +Send patches and bug reports to ." + +prefix=v +fallback= + +while test $# -gt 0; do + case $1 in + --help) echo "$usage"; exit 0;; + --version) echo "$version"; exit 0;; + --prefix) shift; prefix=${1?};; + --fallback) shift; fallback=${1?};; + -*) + echo "$0: Unknown option '$1'." >&2 + echo "$0: Try '--help' for more information." >&2 + exit 1;; + *) + if test "x$tarball_version_file" = x; then + tarball_version_file="$1" + elif test "x$tag_sed_script" = x; then + tag_sed_script="$1" + else + echo "$0: extra non-option argument '$1'." >&2 + exit 1 + fi;; + esac + shift +done + +if test "x$tarball_version_file" = x; then + echo "$usage" + exit 1 +fi + +tag_sed_script="${tag_sed_script:-s/x/x/}" + +nl=' +' + +# Avoid meddling by environment variable of the same name. +v= +v_from_git= + +# First see if there is a tarball-only version file. +# then try "git describe", then default. +if test -f $tarball_version_file +then + v=`cat $tarball_version_file` || v= + case $v in + *$nl*) v= ;; # reject multi-line output + esac + test "x$v" = x \ + && echo "$0: WARNING: $tarball_version_file is damaged" 1>&2 +fi + +if test "x$v" != x +then + : # use $v +# Otherwise, if there is at least one git commit involving the working +# directory, and "git describe" output looks sensible, use that to +# derive a version string. +elif test "`git log -1 --pretty=format:x . 2>&1`" = x \ + && v=`git describe --abbrev=4 --match="$prefix*" HEAD 2>/dev/null \ + || git describe --abbrev=4 HEAD 2>/dev/null` \ + && v=`printf '%s\n' "$v" | sed "$tag_sed_script"` \ + && case $v in + $prefix[0-9]*) ;; + *) (exit 1) ;; + esac +then + # Is this a new git that lists number of commits since the last + # tag or the previous older version that did not? + # Newer: v6.10-77-g0f8faeb + # Older: v6.10-g0f8faeb + vprefix=`expr "X$v" : 'X\(.*\)-g[^-]*$'` || vprefix=$v + case $vprefix in + *-*) : git describe is probably okay three part flavor ;; + *) + : git describe is older two part flavor + # Recreate the number of commits and rewrite such that the + # result is the same as if we were using the newer version + # of git describe. + vtag=`echo "$v" | sed 's/-.*//'` + commit_list=`git rev-list "$vtag"..HEAD 2>/dev/null` \ + || { commit_list=failed; + echo "$0: WARNING: git rev-list failed" 1>&2; } + numcommits=`echo "$commit_list" | wc -l` + v=`echo "$v" | sed "s/\(.*\)-\(.*\)/\1-$numcommits-\2/"`; + test "$commit_list" = failed && v=UNKNOWN + ;; + esac + + # Change the penultimate "-" to ".", for version-comparing tools. + # Remove the "g" to save a byte. + v=`echo "$v" | sed 's/-\([^-]*\)-g\([^-]*\)$/.\1-\2/'`; + v_from_git=1 +elif test "x$fallback" = x || git --version >/dev/null 2>&1; then + v=UNKNOWN +else + v=$fallback +fi + +v=`echo "$v" |sed "s/^$prefix//"` + +# Test whether to append the "-dirty" suffix only if the version +# string we're using came from git. I.e., skip the test if it's "UNKNOWN" +# or if it came from .tarball-version. +if test "x$v_from_git" != x; then + # Don't declare a version "dirty" merely because a timestamp has changed. + git update-index --refresh > /dev/null 2>&1 + + dirty=`exec 2>/dev/null;git diff-index --name-only HEAD` || dirty= + case "$dirty" in + '') ;; + *) # Append the suffix only if there isn't one already. + case $v in + *-dirty) ;; + *) v="$v-dirty" ;; + esac ;; + esac +fi + +# Omit the trailing newline, so that m4_esyscmd can use the result directly. +printf %s "$v" + +# Local variables: +# eval: (add-hook 'before-save-hook 'time-stamp nil t) +# time-stamp-start: "scriptversion=" +# time-stamp-format: "%:y-%02m-%02d.%02H" +# time-stamp-time-zone: "UTC0" +# time-stamp-end: "; # UTC" +# End: diff --git a/config.mak.in b/config.mak.in index 7f6880db..b184949d 100644 --- a/config.mak.in +++ b/config.mak.in @@ -1,4 +1,9 @@ prefix=@prefix@ +exec_prefix=@exec_prefix@ +libdir=@libdir@ +datarootdir=@datarootdir@ +datadir=@datadir@ + CC=@CC@ CXX=@CXX@ CFLAGS=@CFLAGS@ @@ -8,3 +13,4 @@ LIBOBJS=@LIBOBJS@ LUA_LIBS=@LUA_LIBS@ LUA_CFLAGS=@LUA_CFLAGS@ +PACKAGE_VERSION=@PACKAGE_VERSION@ diff --git a/configure.ac b/configure.ac index 6f73d645..1b6015a6 100644 --- a/configure.ac +++ b/configure.ac @@ -3,13 +3,21 @@ AC_PREREQ([2.59]) -AC_INIT([sb2],[1.99b],[lle@rahina.org]) +AC_INIT([SB2], + m4_esyscmd([build-aux/git-version-gen --prefix '' .tarball-version]), + [bjorn.bidar@jolla.com], + [scratchbox2], + [https://github.com/sailfishos/scratchbox2]) +AC_CONFIG_AUX_DIR([build-aux]) #AC_CANONICAL_TARGET #AM_INIT_AUTOMAKE #AM_MAINTAINER_MODE #AC_CONFIG_SRCDIR([src/libfakechroot.c]) AC_CONFIG_HEADERS([include/config.h]) AC_CONFIG_FILES([config.mak]) +dnl Generate timestamp so that configure output files timestamps are in sync +AC_CONFIG_FILES([stamp-h], [echo timestamp > stamp-h]) +AC_CONFIG_FILES([stamp-mak], [echo timestamp > stamp-mak]) AC_PROG_CC AC_PROG_CXX @@ -231,9 +239,15 @@ freebsd*) esac AC_C_BIGENDIAN() - AC_SUBST(WORDS_BIGENDIAN, ${WORDS_BIGENDIAN}) -AC_SUBST(PREFIX, ${prefix}) + +AC_SUBST(prefix, ${prefix}) +AC_SUBST(exec_prefix, ${exec_prefix}) +AC_SUBST(bindir, ${bindir}) +AC_SUBST(libdir, ${libdir}) +AC_SUBST(datarootdir, ${datarootdir}) +AC_SUBST(datadir, ${datadir}) + AC_SUBST(CC, ${CC}) AC_SUBST(CXX, ${CXX}) AC_SUBST(CFLAGS, ${CFLAGS}) diff --git a/llbuild/Makefile.include b/llbuild/Makefile.include index d00588e1..c868b501 100644 --- a/llbuild/Makefile.include +++ b/llbuild/Makefile.include @@ -1,4 +1,4 @@ -# ll build system +# ll build system -*- makefile -*- # # Copyright (C) 2006-2007 Lauri Leukkunen # @@ -29,6 +29,12 @@ __kicker_target: all TOPDIR := $(CURDIR) +edit := sed \ + -e 's|@prefix[@]|$(prefix)|g' \ + -e 's|@bindir[@]|$(bindir)|g' \ + -e 's|@libdir[@]|$(libdir)|g' \ + -e 's|@datadir[@]|$(datadir)|g' \ + -e 's|@configure_input[@]|Generated from $@.sh.in; do not edit by hand.|g' # a useful function to expand paths define O @@ -41,15 +47,17 @@ endef define import_dir subdirs := subdirs-y := - objects := - objects-y := + objs := + objs-y := D := $(1) $(shell mkdir -p $(1)) - include $(1)/Makefile - dep_files := $$(wildcard $(1)/.*.d) - include $(dep_files) - all_objects := $$(all_objects) $$(patsubst %,$(1)/%,$$(objects)) - all_objects := $$(all_objects) $$(patsubst %,$(1)/%,$$(objects-y)) + include $(SRCDIR)/$(1)/Makefile + deps := $(join $(subst ./, $(D)/, $(dir $(objs))), $(patsubst %,.%.d,$(notdir $(objs)))) + objs-y := $(join $(subst ./, $(D)/, $(dir $(objs))), $(notdir $(objs))) + objs-all := $(objs-all) \ + $(patsubst %,$(OBJDIR)/%,$(objs-y)) + deps-all := $(deps-all) $(patsubst %,$(OBJDIR)/%,$(deps)) + include $(wildcard $(deps)) subdirs := $$(subdirs) $$(subdirs-y) tmp := $$(patsubst %,$(1)/%,$$(subdirs)) perkele := $$(foreach dir,$$(tmp),$$(eval $$(call import_dir,$$(dir)))) @@ -58,8 +66,9 @@ endef $(foreach dir,$(subdirs),$(eval $(call import_dir,$(dir)))) -all_objects += $(foreach t,$(extra_targets),$($(t))) +objs-all += $(foreach t,$(extra_targets),$($(t))) +CLEAN_FILES += $(deps-all) ifdef V Q = @@ -107,6 +116,11 @@ built-in.o:: %.o %:: %.o +%:: %.sh.in + $(Q)rm -f $(@) $(@).tmp + $(Q)$(edit) $(<) > $(OBJDIR)/$(@).tmp + $(Q)chmod +x,a-w $(@).tmp + $(Q)mv $(@).tmp $(@) define ll_clean $(Q)rm -rf $(CLEAN_FILES) diff --git a/luaif/Makefile b/luaif/Makefile index c2c8a72d..f0d2a0a5 100644 --- a/luaif/Makefile +++ b/luaif/Makefile @@ -12,7 +12,7 @@ luaif/libluaif.a: override LDFLAGS := $(LDFLAGS) luaif/libluaif.a: override LIBS := $(LUA_LIBS) -luaif/sb_log.o: include/scratchbox2_version.h +luaif/sb_log.o: $(OBJDIR)/include/scratchbox2_version.h targets := $(targets) $(D)/libluaif.a diff --git a/preload/Makefile b/preload/Makefile index e3a17ee5..f53900f7 100644 --- a/preload/Makefile +++ b/preload/Makefile @@ -15,7 +15,7 @@ objs := wrappers.o privatewrappers.o \ ifeq ($(shell uname -s),Linux) LIBSB2_LDFLAGS = -Wl,-soname=$(LIBSB2_SONAME) \ - -Wl,--version-script=preload/export.map + -Wl,--version-script=$(OBJDIR)/preload/export.map # DO NOT add any libraries that depend on libpthread to # LIBSB2_LIBS or LIBS!! see the comments in luaif.c. @@ -42,18 +42,23 @@ $(D)/libsb2.$(SHLIBEXT): LIBS := -ldl $(LIBSB2_LIBS) targets := $(targets) $(D)/libsb2.$(SHLIBEXT) -$(D)/libsb2.o $(D)/sb_l10n.o: preload/exported.h -$(D)/exported.h $(D)/ldexportlist: preload/wrappers.c -$(D)/wrappers.c: preload/interface.master preload/gen-interface.pl +$(D)/libsb2.o $(D)/sb_l10n.o: $(OBJDIR)/preload/exported.h +$(OBJDIR)/preload/exported.h $(D)/ldexportlist: $(OBJDIR)/preload/wrappers.c +# Include both paths with $(OBJDIR) and without +# Make doesn't seem to follow the .NOTPARALLEL rule correctly +# without +.NOTPARALLEL: $(OBJDIR)/preload/exported.h +.NOTPARALLEL: preload/exported.h +$(OBJDIR)/preload/wrappers.c: preload/interface.master preload/gen-interface.pl $(MKOUTPUTDIR) $(P)PERL $(Q)$(SRCDIR)/preload/gen-interface.pl \ -n public \ - -W preload/wrappers.c \ - -E preload/exported.h \ - -M preload/export.map \ + -W $(OBJDIR)/preload/wrappers.c \ + -E $(OBJDIR)/preload/exported.h \ + -M $(OBJDIR)/preload/export.map \ -V $(PACKAGE_VERSION) \ - -m preload/libsb2_interface.7 \ + -m $(OBJDIR)/preload/libsb2_interface.7 \ <$(SRCDIR)/preload/interface.master $(D)/privatewrappers.h: preload/privatewrappers.c @@ -62,11 +67,18 @@ $(D)/privatewrappers.c: preload/interface.private preload/gen-interface.pl $(P)PERL $(Q)$(SRCDIR)/preload/gen-interface.pl \ -n private \ - -W preload/privatewrappers.c \ - -E preload/privatewrappers.h \ + -W $(OBJDIR)/preload/privatewrappers.c \ + -E $(OBJDIR)/preload/privatewrappers.h \ <$(SRCDIR)/preload/interface.private -generated := preload/wrappers.c preload/exported.h preload/ldexportlist +generated := $(OBJDIR)/preload/wrappers.c \ + $(OBJDIR)/preload/exported.h \ + $(OBJDIR)/preload/ldexportlist \ + $(OBJDIR)/preload/export.map \ + $(OBJDIR)/preload/privatewrappers.c \ + $(OBJDIR)/preload/privatewrappers.h \ + $(OBJDIR)/preload/libsb2_interface.7 + .PRECIOUS: $(generated) CLEAN_FILES += $(generated) diff --git a/preload/interface.master b/preload/interface.master index d4326c07..a83f9e65 100644 --- a/preload/interface.master +++ b/preload/interface.master @@ -185,30 +185,30 @@ GATE: pid_t waitpid(pid_t pid, int *status, int options) GATE: int __open(const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map(pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map(pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int __open64(const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map(pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map(pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int open(const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map(pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map(pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ create_nomap_nolog_version \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int open64(const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map(pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map(pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) -- open; variants witout varargs GATE: int __open_2(const char *pathname, int flags) : \ @@ -216,29 +216,29 @@ GATE: int __open_2(const char *pathname, int flags) : \ map(pathname) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int __open64_2(const char *pathname, int flags) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ map(pathname) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) -- openat: GATE: int openat(int dirfd, const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map_at(dirfd,pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map_at(dirfd,pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ create_nomap_nolog_version \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int openat64(int dirfd, const char *pathname, int flags, ...) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ - map_at(dirfd,pathname) optional_arg_is_create_mode(flags&O_CREAT) \ + map_at(dirfd,pathname) optional_arg_is_create_mode(__OPEN_NEEDS_MODE(flags)) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) -- openat; variants witout varargs GATE: int __openat_2(int dirfd, const char *pathname, int flags) : \ @@ -246,13 +246,13 @@ GATE: int __openat_2(int dirfd, const char *pathname, int flags) : \ map_at(dirfd,pathname) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) GATE: int __openat64_2(int dirfd, const char *pathname, int flags) : \ dont_resolve_final_symlink_if(flags&O_NOFOLLOW) \ map_at(dirfd,pathname) \ postprocess(pathname) \ check_and_fail_if_readonly(flags&OPEN_FLAGS_RW_MODE,pathname,-1,EROFS) \ - class(OPEN) conditionally_class(flags&O_CREAT,CREAT) + class(OPEN) conditionally_class(__OPEN_NEEDS_MODE(flags),CREAT) -- close: WRAP: int close(int fd) : \ diff --git a/rpm/scratchbox2.spec b/rpm/scratchbox2.spec index 1299ff3a..69dc641e 100644 --- a/rpm/scratchbox2.spec +++ b/rpm/scratchbox2.spec @@ -1,11 +1,10 @@ -Summary: Scratchbox2 crosscompiling environment +Summary: Crosscompiling environment License: LGPLv2 URL: https://git.sailfishos.org/mer-core/scratchbox2 Name: scratchbox2 Version: 2.3.90+git58 Release: 0 Source: %{name}-%{version}.tar.gz -Prefix: /usr ExclusiveArch: %{ix86} %{x86_64} BuildRequires: make BuildRequires: autoconf @@ -31,36 +30,49 @@ Scratchbox2 preload library. %package docs Summary: Scratchbox2 docs +BuildArch: noarch %description docs Scratchbox2 man pages. %prep %autosetup +# Tell autoconf the package version +# Note we don't strip the version here not remove the indicator +# for a development build +echo %{version} > .tarball-version + %build ./autogen.sh -%configure -touch .configure -# Can't use %{?_smp_mflags} here: race condition in build system -%{__make} %{_make_output_sync} %{_make_verbose} +# FIXME: switch to vpath macros once we have them +mkdir -p build +%global _configure ../configure +( + cd build + %configure +) +%make_build -C build -f ../Makefile %install -%__make install prefix=%{buildroot}/usr +%make_install -C build -f ../Makefile install -D -m 644 utils/sb2.bash %{buildroot}/etc/bash_completion.d/sb2.bash +%check +# Rpmlint suggest to add it even thou we don't +# have any checks so far + %files %{_bindir}/sb2* +%dir %{_datadir}/scratchbox2 %{_datadir}/scratchbox2/* %config %{_sysconfdir}/bash_completion.d/sb2.bash %files docs -%doc %attr(0444,root,root) /usr/share/man/man1/* -%doc %attr(0444,root,root) /usr/share/man/man7/* +%doc /usr/share/man/man1/* +%doc /usr/share/man/man7/* %files -n libsb2 +%dir %{_libdir}/libsb2 %{_libdir}/libsb2/* -%ifarch x86_64 -/usr/lib32/libsb2/* -%endif diff --git a/sblib/Makefile b/sblib/Makefile index b8836d52..aebcc820 100644 --- a/sblib/Makefile +++ b/sblib/Makefile @@ -12,7 +12,7 @@ sblib/libsblib.a: override CFLAGS := $(CFLAGS) $(LUA_CFLAGS) -O2 -g -fPIC -Wall sblib/libsblib.a: override LDFLAGS := $(LDFLAGS) sblib/libsblib.a: override LIBS := -sblib/sb_log.o: include/scratchbox2_version.h +sblib/sb_log.o: $(OBJDIR)/include/scratchbox2_version.h targets := $(targets) $(D)/libsblib.a diff --git a/utils/Makefile b/utils/Makefile index ccd56601..aff36416 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -59,5 +59,13 @@ $(D)/sb2-interp-wrapper: $(D)/sb2-interp-wrapper.o preload/libsb2.$(SHLIBEXT) $(P)LD $(Q)$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ -ldl +scripts = \ + sb2 \ + sb2-config \ + sb2-config-gcc-toolchain \ + sb2-init \ + sb2-upgrade-config -targets := $(targets) $(D)/sb2-show $(D)/sb2-monitor $(D)/sb2-ruletree + + +targets := $(targets) $(D)/sb2-show $(D)/sb2-monitor $(D)/sb2-ruletree $(call O,$(scripts)) diff --git a/utils/sb2-check-pkg-mappings b/utils/sb2-check-pkg-mappings index 13c16930..fe787fac 100755 --- a/utils/sb2-check-pkg-mappings +++ b/utils/sb2-check-pkg-mappings @@ -9,7 +9,7 @@ # Author: Lauri T. Aarnio # Licensed under LGPL version 2.1, see top level LICENSE file for details. -function usage() +usage() { cat <$sb2_pkg_chk if [ $? != 0 ]; then - num_failed=`expr $num_failed + 1` + num_failed=$(expr $num_failed + 1) if [ -n "$verbose" ]; then echo " $pkg is not available" else @@ -222,7 +222,7 @@ for pkg in $pkgs2check; do else echo -n "." fi - num_ok=`expr $num_ok + 1` + num_ok=$(expr $num_ok + 1) add_pkg_to_status_file elif [ $pathlist_mappings_result == 2 ]; then # package can be used, as long as it is installed to @@ -232,13 +232,13 @@ for pkg in $pkgs2check; do else echo -n "." fi - num_both_required=`expr $num_both_required + 1` + num_both_required=$(expr $num_both_required + 1) add_pkg_to_status_file if [ $check_all_pkgs = "yes" ]; then echo $pkg >>$bothreq_file fi else - num_failed=`expr $num_failed + 1` + num_failed=$(expr $num_failed + 1) if [ -n "$verbose" ]; then echo " $pkg can not be used in this mode ($sbox_mapmode)" else diff --git a/utils/sb2-config-debian b/utils/sb2-config-debian index 0a698cca..899c215f 100755 --- a/utils/sb2-config-debian +++ b/utils/sb2-config-debian @@ -19,13 +19,13 @@ fi mapping_mode_for_dpkg_utils=accel -function log_config_action() +log_config_action() { - tstamp=`/bin/date '+%Y-%m-%d %H:%M:%S'` + tstamp=$(/bin/date '+%Y-%m-%d %H:%M:%S') echo "$tstamp $*" >>$SBOX_CONFIG_DIR/CONFIG-LOG } -function usage() +usage() { cat </dev/null) -if [ $? != 0 ]; then +if ! DPKG_ARCHITECTURE_FULLPATH=$(sb2 -t $TARGET -m $mapping_mode_for_dpkg_utils which dpkg-architecture 2>/dev/null); then # Can't locate or run dpkg-architecture. Set the values here. # FIXME: I'm still not sure if these settings are sane, # they ought to be the same as they have been in sb2 diff --git a/utils/sb2-config-gcc-toolchain b/utils/sb2-config-gcc-toolchain.sh.in similarity index 81% rename from utils/sb2-config-gcc-toolchain rename to utils/sb2-config-gcc-toolchain.sh.in index a0c64d16..e834f7aa 100755 --- a/utils/sb2-config-gcc-toolchain +++ b/utils/sb2-config-gcc-toolchain.sh.in @@ -5,22 +5,14 @@ # Copyright (C) 2007 Lauri Leukkunen # Licensed under GPL version 2 -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - -function log_config_action() +log_config_action() { - tstamp=`/bin/date '+%Y-%m-%d %H:%M:%S'` + tstamp=$(/bin/date '+%Y-%m-%d %H:%M:%S') echo "$tstamp $*" >>$SBOX_CONFIG_DIR/CONFIG-LOG } # Get the original arguments that were specified to sb2-init from -function usage() +usage() { cat < /dev/null 2>&1 != 0 ]; then +if ! $GCC -v > /dev/null 2>&1; then echo "Invalid compiler specified: $GCC" exit 1 fi @@ -243,11 +234,11 @@ case "$(basename $GCC)" in ;; esac -SBOX_CROSS_GCC_VERSION=`$GCC -dumpversion` +SBOX_CROSS_GCC_VERSION=$($GCC -dumpversion) # Create a version string with two digits -SBOX_CROSS_GCC_SHORTVERSION=`echo $SBOX_CROSS_GCC_VERSION | - sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\)\..*/\1/'` +SBOX_CROSS_GCC_SHORTVERSION=$(echo $SBOX_CROSS_GCC_VERSION | + sed -e 's/^\([0-9][0-9]*\.[0-9][0-9]*\)\..*/\1/') GCC_TARGET=$($GCC -dumpmachine) @@ -286,21 +277,21 @@ fi SBOX_CROSS_GCC_SPECS_FILE="" SBOX_EXTRA_CROSS_COMPILER_STDINC="" -# FIXME: SBOX_CROSS_GCC_SPECS_FILE may point to $SBOX_DIR/share/scratchbox2/modes +# FIXME: SBOX_CROSS_GCC_SPECS_FILE may point to $SBOX_DATADIR/scratchbox2/modes # after this. It should point to a session-specific location, but we don't have any # mechanism for that currently. if [ -n "$GCC_SPECS" ]; then # the file was specified on the command line SBOX_CROSS_GCC_SPECS_FILE="$GCC_SPECS" # else try to locate a specs file which was provided with gcc -elif [ -f $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH ]; then - SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH" -elif [ -f $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs ]; then - SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs" -elif [ -f $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs ]; then - SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs" -elif [ -f $SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-specs ]; then - SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DIR/share/scratchbox2/modes/$MAPPING_MODE/gcc-specs" +elif [ -f $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH ]; then + SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs-$ARCH" +elif [ -f $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs ]; then + SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_VERSION-specs" +elif [ -f $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs ]; then + SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-$SBOX_CROSS_GCC_SHORTVERSION-specs" +elif [ -f $SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-specs ]; then + SBOX_CROSS_GCC_SPECS_FILE="$SBOX_DATADIR/scratchbox2/modes/$MAPPING_MODE/gcc-specs" else SBOX_EXTRA_CROSS_COMPILER_STDINC="-I/usr/include" fi @@ -313,7 +304,7 @@ SBOX_EXTRA_CROSS_COMPILER_ARGS="$SBOX_EXTRA_CROSS_COMPILER_ARGS -L@SBOX_TARGET_R # usage ("gcc -E -Wno-poison-system-directories" is not a reliable way for # testing this; instead check if ld has the related flag) # Ensure its bin directory is in PATH to prevent "unable to find 'ld'" error. -txt=`PATH="$(dirname $GCC_FULLPATH):$PATH" $GCC_FULLPATH -Wl,--help | grep no-poison-system-directories` +txt=$(PATH="$(dirname $GCC_FULLPATH):$PATH" $GCC_FULLPATH -Wl,--help | grep no-poison-system-directories) case "$txt" in (*no-poison-system-directories*) # option is available SBOX_EXTRA_CROSS_COMPILER_ARGS="$SBOX_EXTRA_CROSS_COMPILER_ARGS -Wno-poison-system-directories" diff --git a/utils/sb2-config b/utils/sb2-config.sh.in similarity index 80% rename from utils/sb2-config rename to utils/sb2-config.sh.in index e1019b44..251de456 100755 --- a/utils/sb2-config +++ b/utils/sb2-config.sh.in @@ -2,22 +2,15 @@ # Copyright (C) 2006,2007 Lauri Leukkunen # Licensed under GPL version 2 -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - -function log_config_action() + +log_config_action() { mkdir -p $SBOX_CONFIG_DIR - tstamp=`/bin/date '+%Y-%m-%d %H:%M:%S'` + tstamp=$(/bin/date '+%Y-%m-%d %H:%M:%S') echo "$tstamp $*" >>$SBOX_CONFIG_DIR/CONFIG-LOG } -function usage() +usage() { cat <&2 exit 1 fi - list=$(find $HOME/.scratchbox2/ -maxdepth 2 -mindepth 2 \ - -type f -and -name "sb2.config" 2>/dev/null | sort) - if [ $? != 0 ]; then + if ! list=$(find $HOME/.scratchbox2/ -maxdepth 2 -mindepth 2 \ + -type f -and -name "sb2.config" 2>/dev/null | sort); then echo "Error occured while getting list of targets" >&2 exit 2 fi @@ -73,21 +65,21 @@ function list_targets() fi for f in $list; do if [ $all_targets -ge 1 ]; then - echo $(basename $(dirname $f)) + echo "$(basename "$(dirname $f)")" else - . $f + . "$f" if [ -d "$SBOX_TARGET_ROOT" ]; then - echo $(basename $(dirname $f)) + echo "$(basename "$(dirname $f)")" fi fi done } -function show_config_log() +show_config_log() { target=$1 - if [ "$target" == "-" ]; then + if [ "$target" = "-" ]; then # use default target if [ -f $HOME/.scratchbox2/config ]; then . $HOME/.scratchbox2/config @@ -116,7 +108,7 @@ function show_config_log() exit 0 } -function write_config() +write_config() { echo " DEFAULT_TARGET=$DEFAULT_TARGET @@ -124,7 +116,7 @@ DEFAULT_TARGET=$DEFAULT_TARGET log_config_action "sb2-config: this is now the default target." } -function setenv_var() +setenv_var() { varname="$1" [ -z "$varname" ] && usage @@ -138,7 +130,7 @@ function setenv_var() log_config_action "sb2-config: setenv $varname=$value" } -function clearenv_var() +clearenv_var() { varname="$1" [ -z "$varname" ] && usage @@ -152,7 +144,7 @@ function clearenv_var() log_config_action "sb2-config: clearenv $varname" } -function unsetenv_var() +unsetenv_var() { varname="$1" [ -z "$varname" ] && usage @@ -167,16 +159,16 @@ function unsetenv_var() } -function showenv_vars() +showenv_vars() { if [ -d $SBOX_CONFIG_DIR/env_vars ]; then - count=$( ls $SBOX_CONFIG_DIR/env_vars/* 2>/dev/null | wc -l ) + count=$(find "$SBOX_SESSION_DIR/env_vars" -print x | wc -c ) if [ "$count" -gt 0 ]; then for i in $SBOX_CONFIG_DIR/env_vars/*; do if [ -s "$i" ]; then - echo declare -x `cat "$i"` + echo declare -x "$(cat "$i")" else - echo unset `basename "$i"` + echo unset "$(basename "$i")" fi done fi @@ -184,10 +176,10 @@ function showenv_vars() # else there are none. } -SBOX_DIR=$(readlink -f $(dirname $(readlink -f $my_path))/..) +SBOX_DATADIR=@datadir@ WRITE_CONFIG=0 -if [ $# == 0 ]; then +if [ $# = 0 ]; then # No parameters usage fi @@ -210,7 +202,7 @@ do done shift $(($OPTIND - 1)) -if [ $WRITE_CONFIG == 1 ]; then +if [ $WRITE_CONFIG = 1 ]; then write_config fi @@ -242,10 +234,10 @@ fi case "$command" in showtarget) echo $targetname;; -showenv) showenv_vars $*;; -setenv) setenv_var $*;; -clearenv) clearenv_var $*;; -unsetenv) unsetenv_var $*;; +showenv) showenv_vars "$@";; +setenv) setenv_var "$@";; +clearenv) clearenv_var "$@";; +unsetenv) unsetenv_var "$@";; showlog) show_config_log $targetname;; *) usage;; esac diff --git a/utils/sb2-exitreport b/utils/sb2-exitreport index c0cfb466..f00c599c 100755 --- a/utils/sb2-exitreport +++ b/utils/sb2-exitreport @@ -14,13 +14,13 @@ exit_reason=$1 exit_status=$2 -if [ -z "$SBOX_MAPPING_LOGFILE" -o \ - -z "$exit_reason" -o -z "$exit_status" ]; then +if [ -z "$SBOX_MAPPING_LOGFILE" ] || \ + [ -z "$exit_reason" ] || [ -z "$exit_status" ]; then echo "ERROR: $0 is an internal tool for sb2, do not use directly" exit 1 fi -if [ "$exit_reason" == "exit" ]; then +if [ "$exit_reason" = "exit" ]; then # Normal exit ret=$exit_status else @@ -33,13 +33,11 @@ fi # Turn off accounting, if it was enabled in the beginning. if [ -n "$SBOX_COLLECT_ACCT_DATA" ]; then # First try to deactivate it directly - sb2-show acct_off 2>/dev/null - if [ $? != 0 ]; then + if ! sb2-show acct_off 2>/dev/null ; then if [ -z "$SBOX_QUIET" ]; then echo "WARNING: Can't deactivate process accounting. Retrying with 'sudo', password may be needed." fi - sudo sb2-show acct_off 2>/dev/null - if [ $? != 0 ]; then + if ! sudo sb2-show acct_off 2>/dev/null ; then if [ -z "$SBOX_QUIET" ]; then echo "ERROR: Failed to deactivate process accounting. Please do it manually!" fi @@ -72,7 +70,7 @@ if [ -s "$SBOX_MAPPING_LOGFILE" ]; then -E $SBOX_LOG_AND_GRAPH_DIR/exec.dot \ < $SBOX_MAPPING_LOGFILE >/dev/null fi - path_to_dot=`which dot 2>/dev/null` + path_to_dot=$(command -v dot 2>/dev/null) if [ -z "$path_to_dot" ]; then if [ -z "$SBOX_QUIET" ]; then echo "Warning: 'dot' was not found, can't create .pdf files" @@ -118,7 +116,7 @@ if [ -f $SBOX_SESSION_DIR/.joinable-session ]; then echo >/dev/null else # cleanup - if [ -n "$SBOX_SESSION_DIR" -a -d "$SBOX_SESSION_DIR" ]; then + if [ -n "$SBOX_SESSION_DIR" ] && [ -d "$SBOX_SESSION_DIR" ]; then rm -rf $SBOX_SESSION_DIR fi fi diff --git a/utils/sb2-init b/utils/sb2-init.sh.in similarity index 86% rename from utils/sb2-init rename to utils/sb2-init.sh.in index 22186039..0fb0527c 100755 --- a/utils/sb2-init +++ b/utils/sb2-init.sh.in @@ -2,22 +2,14 @@ # sb2-init - Copyright (C) 2007 Lauri Leukkunen # Licensed under GPL version 2 -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - -function log_config_action() +log_config_action() { - tstamp=`/bin/date '+%Y-%m-%d %H:%M:%S'` + tstamp=$(/bin/date '+%Y-%m-%d %H:%M:%S') echo "$tstamp $*" >>$SBOX_CONFIG_DIR/CONFIG-LOG } # Get the original arguments that were specified to sb2-init from -function show_existing_config_info() +show_existing_config_info() { has_targets="no" echo "Already initialized targets:" @@ -27,8 +19,8 @@ function show_existing_config_info() SBOX_CONFIG_VERSION=0 . $f has_targets="yes" - targetdir=`dirname $f` - targetname=`basename $targetdir` + targetdir=$(dirname $f) + targetname=$(basename $targetdir) echo "Target $targetname:" if [ -d "$SBOX_TARGET_ROOT" ]; then if [ "$SBOX_CONFIG_VERSION" -lt 5 ]; then @@ -44,12 +36,12 @@ function show_existing_config_info() echo fi done - if [ has_targets = "no" ]; then + if [ $has_targets = "no" ]; then echo "none." fi } -function usage() +usage() { cat < $HOME/.scratchbox2/$TARGET/sb2.config < $HOME/.scratchbox2/$TARGET/sbrsh.config <$SBOX_CONFIG_DIR/sb2-init-args if [ -z "$SB2INIT_COMPILERS" ]; then @@ -393,7 +386,7 @@ if ! expr "$ARCH" : "$HOST_ARCH" > /dev/null ; then else # ...try to use the default CPU transparency. _cputransp=$(which $DEFAULT_CPUTRANSP) - if [ -n "$_cputransp" -a -e "$_cputransp" ]; then + if [ -n "$_cputransp" ] && [ -e "$_cputransp" ]; then SB2INIT_CPUTRANSP=$_cputransp else echo "sb2-init: WARNING:" @@ -406,7 +399,7 @@ if ! expr "$ARCH" : "$HOST_ARCH" > /dev/null ; then fi if [ -n "$SB2INIT_CPUTRANSP" ]; then if [ -e "$SB2INIT_CPUTRANSP" ]; then - case `file $SB2INIT_CPUTRANSP` in + case $(file $SB2INIT_CPUTRANSP) in *dynamically*) # This is OK. ;; @@ -453,7 +446,7 @@ fi mkdir -p $HOME/.scratchbox2 -if [ -z "$($SBOX_DIR/bin/sb2-config -l)" ]; then +if [ -z "$($SBOX_BINDIR/sb2-config -l)" ]; then # force this as default anyway as there are no # other existing targets SB2INIT_SET_AS_DEFAULT=1 @@ -469,8 +462,8 @@ if [ -n "$SB2INIT_TOOLS_ROOT" ]; then fi _host_gcc=$(which gcc) -if [ -n "$_host_gcc" -a -e "$_host_gcc" ]; then - HOST_GCC_INC=$(echo "#include " | gcc -M -E - | SBOX_DIR=$SBOX_DIR perl -e 'while() { $foo{$1} = 1 if m/\/usr([^[:space:]]*\/include)/;}; foreach my $k (keys %foo) {print " -isystem $ENV{SBOX_DIR}/share/scratchbox2/host_usr$k"};') +if [ -n "$_host_gcc" ] && [ -e "$_host_gcc" ]; then + HOST_GCC_INC=$(echo "#include " | gcc -M -E - | SBOX_DATADIR=$SBOX_DATADIR perl -e 'while() { $foo{$1} = 1 if m/\/usr([^[:space:]]*\/include)/;}; foreach my $k (keys %foo) {print " -isystem $ENV{SBOX_DATADIR}/scratchbox2/host_usr$k"};') SB2INIT_SBOX_HOST_GCC_NAME=host-gcc SB2INIT_SBOX_HOST_GCC_PREFIX_LIST=host- else @@ -497,15 +490,14 @@ fi # The target can be used now; it is possible to # finalize the configuration by running programs in the new environment. -if [ $SB2INIT_SET_AS_DEFAULT == 1 ]; then - $SBOX_DIR/bin/sb2-config -d $TARGET +if [ $SB2INIT_SET_AS_DEFAULT = 1 ]; then + $SBOX_BINDIR/sb2-config -d $TARGET fi # if the target system is (based on) debian, # DEB_* environment variables are needed. We'll set them in any case: echo "sb2-init: Creating Debian build system settings for this target:" -$SBOX_DIR/share/scratchbox2/scripts/sb2-config-debian -t $TARGET -if [ $? != 0 ]; then +if ! $SBOX_DATADIR/scratchbox2/scripts/sb2-config-debian -t $TARGET ;then log_config_action "sb2-init: failed run sb2-config-debian" echo "sb2-init: sb2-config-debian failed." exit 1 @@ -519,27 +511,25 @@ fi # We do the same check for tools here and generate necessary # localization files if they are missing. # -if [ $SB2INIT_WITH_LOCALES == 1 ]; then +if [ $SB2INIT_WITH_LOCALES = 1 ]; then if [ -n "$SB2INIT_TOOLS_ROOT" ]; then - $SBOX_DIR/bin/sb2 -t $TARGET \ - $SBOX_DIR/share/scratchbox2/scripts/sb2-generate-locales -T + $SBOX_BINDIR/sb2 -t $TARGET \ + $SBOX_DATADIR/scratchbox2/scripts/sb2-generate-locales -T fi if [ -z "$SB2INIT_CPUTRANSP" ]; then - $SBOX_DIR/bin/sb2 -t $TARGET \ - $SBOX_DIR/share/scratchbox2/scripts/sb2-generate-locales + $SBOX_BINDIR/sb2 -t $TARGET \ + $SBOX_DATADIR/scratchbox2/scripts/sb2-generate-locales fi fi -if [ $SB2INIT_WITH_LIBTOOL == 1 ]; then +if [ $SB2INIT_WITH_LIBTOOL = 1 ]; then echo "sb2-init: configuring libtool for this target:" - $SBOX_DIR/bin/sb2 -t $TARGET $SBOX_DIR/bin/sb2-build-libtool - TEST=$? printf "\n\n" - if [ $TEST == 0 ]; then + if $SBOX_BINDIR/sb2 -t $TARGET $SBOX_BINDIR/sb2-build-libtool ; then echo "sb2-init completed successfully, have fun!" else - echo "Running $SBOX_DIR/bin/sb2-build-libtool failed" + echo "Running $SBOX_BINDIR/sb2-build-libtool failed" echo "You can run this manually later, otherwise your" echo "sb2 environment is correctly setup and ready to use" fi diff --git a/utils/sb2-qemu-gdbserver-prepare b/utils/sb2-qemu-gdbserver-prepare index 0049de97..8fbcf2dd 100755 --- a/utils/sb2-qemu-gdbserver-prepare +++ b/utils/sb2-qemu-gdbserver-prepare @@ -14,7 +14,7 @@ # Licensed under GPL version 2 # prog="$0" -progbase=`basename $0` +progbase=$(basename $prog) usage() { @@ -64,8 +64,7 @@ check_mode_and_cpu_transparency() return $? } -check_mode_and_cpu_transparency -if [ $? -ne 0 ]; then +if ! check_mode_and_cpu_transparency ; then echo "SB2: $progbase: This script can be only used inside" echo "emulation mode where cpu transparency is set to sb2-qemu-arm" exit 1 @@ -104,4 +103,4 @@ fi # Run sb2-show and prepare output so that it is suitable for # remote debugging. # -exec /usr/bin/sb2-show qemu-debug-exec -g $port $@ +exec /usr/bin/sb2-show qemu-debug-exec -g $port "$@" diff --git a/utils/sb2-ruletree.c b/utils/sb2-ruletree.c index d642503b..4899f2f0 100644 --- a/utils/sb2-ruletree.c +++ b/utils/sb2-ruletree.c @@ -47,10 +47,18 @@ void sblog_printf_line_to_logfile(const char *file, int line, va_end(ap); } -extern int open_nomap_nolog(const char *pathname, int flags, mode_t mode); +extern int open_nomap_nolog(const char *pathname, int flags, ...); -int open_nomap_nolog(const char *pathname, int flags, mode_t mode) +int open_nomap_nolog(const char *pathname, int flags, ...) { + mode_t mode = 0; + if(__OPEN_NEEDS_MODE(flags)) { + va_list arg; + va_start (arg, flags); + mode = va_arg (arg, int); + va_end (arg); + } + return open(pathname, flags, mode); } diff --git a/utils/sb2-session b/utils/sb2-session index 6b4f8720..52f2d3ff 100755 --- a/utils/sb2-session +++ b/utils/sb2-session @@ -12,7 +12,7 @@ # Licensed under GPL version 2 # prog="$0" -progbase=`basename $0` +progbase=$(basename $prog) session_save_dir="$HOME/.scratchbox2/saved_sessions" usage() @@ -117,7 +117,7 @@ attach_session() shift fi - if [ -z "$session" -o "$session" = "--" ]; then + if [ -z "$session" ] || [ "$session" = "--" ]; then # # No session id given. This means that there should # only be one session and we should use that. @@ -142,21 +142,23 @@ attach_session() save_session() { - echo -n "Session description: " + printf "%s" "Session description: " read session_descr write_session_info "$session_descr" } list_sessions() { - for s in $( ls $session_save_dir/session.* 2>/dev/null ); do - session_file=$(basename $s) - session_descr=$( grep SBOX_SESSION_DESCRIPTION $s | \ - sed 's/SBOX_SESSION_DESCRIPTION="\([^"]*\)"/\1/' ) - session_target=$( grep SBOX_TARGET $s | \ - sed 's/SBOX_TARGET=\([^"]*\)/\1/' ) - printf "%s\t%s\t%s\n" "$session_file" "$session_target" \ - "$session_descr" + for s in $session_save_dir/session.* ; do + if [ -e $s ] ; then + session_file=$(basename $s) + session_descr=$( grep SBOX_SESSION_DESCRIPTION $s | \ + sed 's/SBOX_SESSION_DESCRIPTION="\([^"]*\)"/\1/' ) + session_target=$( grep SBOX_TARGET $s | \ + sed 's/SBOX_TARGET=\([^"]*\)/\1/' ) + printf "%s\t%s\t%s\n" "$session_file" "$session_target" \ + "$session_descr" + fi done } @@ -191,10 +193,7 @@ set_env_var() show_env_vars() { if [ $inside_sb2 -eq 1 ]; then - count=$( ls $SBOX_SESSION_DIR/env_vars/* 2>/dev/null | wc -l ) - if [ "$count" -gt 0 ]; then - cat $SBOX_SESSION_DIR/env_vars/* - fi + find "$SBOX_SESSION_DIR/env_vars" -type f cat {} \; else die "'sb2-session showenv' must be used inside existing session!" $? fi @@ -225,11 +224,11 @@ case "$command" in ;; attach) if [ $inside_sb2 -ne 0 ]; then - echo -n "'attach' command cannot be run from inside " + printf "%s" "'attach' command cannot be run from inside " echo "sb2 session" exit 1 fi - attach_session $* + attach_session "${@}" ;; save) @@ -239,7 +238,7 @@ case "$command" in # it. # if [ $inside_sb2 -ne 1 ]; then - echo -n "'save' command can only be run from inside " + printf "%s" "'save' command can only be run from inside " echo "sb2 session" exit 1 fi @@ -255,7 +254,7 @@ case "$command" in delete) if [ $inside_sb2 -ne 0 ]; then - echo -n "'delete' command cannot be run from inside " + printf "%s" "'delete' command cannot be run from inside " echo "sb2 session" exit 1 fi @@ -264,7 +263,7 @@ case "$command" in ;; setenv) - set_env_var $* + set_env_var "${@}" ;; showenv) diff --git a/utils/sb2-upgrade-config b/utils/sb2-upgrade-config.sh.in similarity index 92% rename from utils/sb2-upgrade-config rename to utils/sb2-upgrade-config.sh.in index f45b25b3..e7fef6f4 100755 --- a/utils/sb2-upgrade-config +++ b/utils/sb2-upgrade-config.sh.in @@ -8,16 +8,8 @@ # Copyright (C) 2009 Nokia Corporation. # Licensed under GPL version 2 -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - -SBOX_SHARE_DIR=$(readlink -f $(dirname $(readlink -f $my_path))/..) -SBOX_DIR=$(readlink -f $SBOX_SHARE_DIR/../..) +SBOX_DATADIR=@datadir@ +SBOX_DIR=@prefix@ SBOX_TARGET=$1 SBOX_CONFIG_DIR=~/.scratchbox2/$SBOX_TARGET/sb2.config.d @@ -66,7 +58,7 @@ get_sb2_init_arguments_from_old_config_file() -n '/^SBOX_TARGET_ROOT/ s/^SBOX_TARGET_ROOT=(.*)/\1/ p' $OLD_CONFIG_FILE) export SB2INIT_TARGET_ROOT=$SBOX_TARGET_ROOT - $SBOX_SHARE_DIR/scripts/sb2-parse-sb2-init-args $SBOX_INIT_ORIG_ARGS \ + $SBOX_DATADIR/scratchbox2/scripts/sb2-parse-sb2-init-args $SBOX_INIT_ORIG_ARGS \ > $SBOX_CONFIG_DIR/sb2-init-args log_config_action "Config upgrade: arguments of original sb2-init restored from old config file" } @@ -85,22 +77,22 @@ update_toolchain_configs() else gccconfig_arch_option2="" fi - for compiler_path in $*; do + for compiler_path in "$@"; do # echo "Updating compiler $compiler_path" log_config_action "Config upgrade: settings for compiler $compiler_path" - $SBOX_SHARE_DIR/scripts/sb2-config-gcc-toolchain \ + if ! $SBOX_DATADIR/scratchbox2/scripts/sb2-config-gcc-toolchain \ $secondary_compiler \ $gccconfig_arch_option \ $gccconfig_arch_option2 \ -R "$SB2INIT_TARGET_ROOT" \ - -S "$SBOX_SHARE_DIR/../.." \ + -S "$SBOX_DATADIR" \ -t "$SB2INIT_TARGET" \ -m "$SB2INIT_MAPPING_MODE" \ -C "$SB2INIT_SBOX_EXTRA_CROSS_COMPILER_ARGS" \ -L "$SB2INIT_SBOX_EXTRA_CROSS_LD_ARGS" \ -- \ $compiler_path - if [ $? != 0 ]; then + then log_config_action "failed to configure $compiler_path" echo "Failed to configure $compiler_path" exit 1 @@ -160,7 +152,7 @@ update_host_ld_library_path() update_debian_config() { - $SBOX_DIR/share/scratchbox2/scripts/sb2-config-debian -t $SBOX_TARGET + $SBOX_DATADIR/scratchbox2/scripts/sb2-config-debian -t $SBOX_TARGET } if [ ! -d $SBOX_CONFIG_DIR ]; then diff --git a/utils/sb2 b/utils/sb2.sh.in similarity index 90% rename from utils/sb2 rename to utils/sb2.sh.in index 6e7e13c9..b4faea1a 100755 --- a/utils/sb2 +++ b/utils/sb2.sh.in @@ -5,23 +5,13 @@ # "sb2" script, the command-line interface to Scratchbox 2. # -# This *must* be the first thing in this file: -my_path=$_ -if [ $(basename $my_path) != $(basename $0) ]; then - my_path=$0 - if [ $(basename $my_path) = $my_path ]; then - my_path=$(which $my_path) - fi -fi - - SBOX_LIBSB2="libsb2.so.1" - + # Show version. # (called to process a command-line option) show_version() { - cat $SBOX_DIR/share/scratchbox2/version + cat $SBOX_DATADIR/scratchbox2/version } show_usage_and_exit() @@ -160,12 +150,12 @@ locate_target_nsswitch_conf() { __SB2_BINARYNAME="sb2:LocatingNsswitchConf" \ sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ which /etc/nsswitch.conf \ >$SBOX_SESSION_DIR/path_to_nsswitch.conf __SB2_BINARYNAME="sb2:LocatingNscdSocket" \ sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ which /var/run/nscd/socket \ >$SBOX_SESSION_DIR/path_to_nscd_socket.conf read -r NSSWITCH_CONF_PATH < $SBOX_SESSION_DIR/path_to_nsswitch.conf @@ -230,7 +220,11 @@ load_configuration() . ~/.scratchbox2/$SBOX_TARGET/sb2.config if [ ! -d "$SBOX_TARGET_ROOT" ]; then - exit_error "Cannot access target root '$SBOX_TARGET_ROOT', aborting." + exit_error "Cannot access target root '$SBOX_TARGET_ROOT', aborting." + fi + + if [ ! -d "$SBOX_DATADIR/scratchbox2/modes/$SBOX_MAPMODE" ]; then + exit_error "Configured mode doesn't '$SBOX_MAPMODE' for target doesn't exist, aborting." fi LD_LIBRARY_PATH=$saved_LD_LIBRARY_PATH @@ -272,9 +266,7 @@ load_configuration() # check if we need to upgrade configuration: if [ -z "$OPT_DONT_UPGRADE_CONFIGURATION" ]; then if [ ! -f ~/.scratchbox2/$SBOX_TARGET/sb2.config.d/config-stamp.20 ]; then - $SBOX_DIR/share/scratchbox2/scripts/sb2-upgrade-config \ - $SBOX_TARGET - if [ $? != 0 ]; then + if ! $SBOX_DIR/share/scratchbox2/scripts/sb2-upgrade-config $SBOX_TARGET; then echo "Failed to upgrade configuration files" >&2 exit 1 fi @@ -302,7 +294,7 @@ load_configuration() exit 1 fi if [ -e "$_cputransp" ]; then - SBOX_CPUTRANSPARENCY_CMD=$($SBOX_DIR/bin/sb2-show realpath $_cputransp) + SBOX_CPUTRANSPARENCY_CMD=$($SBOX_BINDIR/sb2-show realpath $_cputransp) fi fi @@ -320,7 +312,7 @@ load_configuration() exit 1 fi if [ -e "$_cputransp" ]; then - SBOX_CPUTRANSPARENCY_NATIVE_CMD=$($SBOX_DIR/bin/sb2-show realpath $_cputransp) + SBOX_CPUTRANSPARENCY_NATIVE_CMD=$($SBOX_BINDIR/sb2-show realpath $_cputransp) export SBOX_NATIVE_HAS_CPUTRANSP=1 fi fi @@ -356,17 +348,17 @@ clone_target_root_dir_from() echo "Copying target root from $source_directory..." # cp -Rp does not preserve hard links, but cpio does - (cd $source_directory; find . -depth -print | - cpio -pamd $SBOX_SESSION_DIR/target_root) - if [ $? != 0 ]; then + + if ! (cd $source_directory; find . -depth -print \ + | cpio -pamd $SBOX_SESSION_DIR/target_root) ; then exit_error "Failed to clone target_root" fi # There is a bug in gnu cpio: timestamps of directories # will not be set correctly on the first run, # but they will be corrected by another round: - (cd $source_directory; find . -depth -type d -print | - cpio -pamd $SBOX_SESSION_DIR/target_root) - if [ $? != 0 ]; then + + if ! (cd $source_directory; find . -depth -type d -print \ + | cpio -pamd $SBOX_SESSION_DIR/target_root) ; then exit_error "Failed to fix directory permissions in target_root clone" fi # @@ -449,7 +441,7 @@ sboxify_environment() if [ -z "$SBOX_MODE_PATH" ]; then new_PATH=$HOME/.scratchbox2/$SBOX_TARGET/bin - new_PATH+=:${CCACHE_TOOLS_PATH+$CCACHE_TOOLS_PATH:}$SBOX_DIR/bin:$PATH + new_PATH+=:${CCACHE_TOOLS_PATH+$CCACHE_TOOLS_PATH:}$SBOX_BINDIR:$PATH PATH=$new_PATH:/sbin:/usr/sbin:$SBOX_TARGET_ROOT/bin PATH+=:$SBOX_TARGET_ROOT/usr/bin:$SBOX_TARGET_ROOT/usr/local/bin else @@ -652,7 +644,7 @@ write_ld_library_path_replacement_to_exec_config() # ---- Step 2. Directories under $rootdir # First, make sure that libsb2 is searched - liblocations="$SBOX_DIR/lib/libsb2 /usr/lib/libsb2" + liblocations="$sbox_liblocations" # Include directories listed in ld.so.conf if [ -f $rootdir/etc/ld.so.conf ]; then @@ -661,7 +653,7 @@ write_ld_library_path_replacement_to_exec_config() fi # Include directories listed in ld.so.conf.d/* if [ -d $rootdir/etc/ld.so.conf.d ]; then - for ld_so_conf in "$root"/etc/ld.so.conf.d/* ; do + for ld_so_conf in "$rootdir"/etc/ld.so.conf.d/* ; do if [ -e "$ld_so_conf" ] ; then lloc2=$(grep --extended-regexp --only-matching '^/' "$rootdir"/etc/ld.so.conf.d/* ) break @@ -716,20 +708,20 @@ write_ld_library_path_replacement_to_exec_config() # can be executed in the sb2'ed environment. check_qemu_features() { - qemu_path=$($SBOX_DIR/bin/sb2-show realpath $1) + qemu_path=$($SBOX_BINDIR/sb2-show realpath $1) shift qemu_options=$* # Use "sb2-show" to find out how qemu should be executed # (qemu might be under tools_root => it might need to # use ld.so and libraries from tools) - __SB2_BINARYNAME="sb2:CheckingQemuExec" \ - sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + if ! __SB2_BINARYNAME="sb2:CheckingQemuExec" \ + sb2-monitor \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ -- exec-cmdline \ $qemu_path $qemu_options \ >$SBOX_SESSION_DIR/qemu_cmdline - if [ $? != 0 ]; then + then exit_error "Failed to find out how $qemu_path should be started" fi @@ -740,7 +732,7 @@ check_qemu_features() -L $SBOX_LIBSB2 -- \ $qemu_cmdline -h \ >$SBOX_SESSION_DIR/qemu_help - # we don't test $? here, qemu -h returns with a non-zero + # we don't test the exit status here, qemu -h returns with a non-zero # argument anyway # @@ -886,7 +878,7 @@ check_ld_so_features() locate_shell() { __SB2_BINARYNAME="sb2:TestingBash" sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ which /bin/bash \ >$SBOX_SESSION_DIR/path_to_shell.conf read -r SHELL_PATH < $SBOX_SESSION_DIR/path_to_shell.conf @@ -895,7 +887,7 @@ locate_shell() SHELL=/bin/bash else __SB2_BINARYNAME="sb2:LocatingShell" sb2-monitor \ - -L $SBOX_LIBSB2 -- $SBOX_DIR/bin/sb2-show \ + -L $SBOX_LIBSB2 -- $SBOX_BINDIR/sb2-show \ which /bin/sh \ >$SBOX_SESSION_DIR/path_to_shell.conf # Default to /bin/sh @@ -916,13 +908,18 @@ locate_shell() guess_ld_so() { local prefix="$1" - - if [ "$(uname -m)" = 'x86_64' -a -r "$prefix/lib/ld-linux-x86-64.so.2" ] - then - printf "$prefix/lib/ld-linux-x86-64.so.2" - else - printf "$prefix/lib/ld-linux.so.2" + local ld_so_conf=$prefix/lib/ld-linux.so.2 + if [ "$(getconf LONG_BIT)" -ge 64 ] ; then + # 64-bit architecture all append the name of the arch to the same of + # ld.so + ld_so_conf_base=ld-linux-$(uname -m).so.2 + for libdir in $sbox_libdirs; do + if [ -r $prefix/$libdir/$ld_so_conf ] ; then + ld_so_conf=$prefix/$libdir/$ld_so_conf_base + fi + done fi + printf "$ld_so_conf" } # Locate libsb2.so.1 library which must be used; Several @@ -954,18 +951,21 @@ write_libsb2_and_ld_so_state_to_exec_config() # Check if ld.so can be used from $rootdir by # checking that libsb2 has been installed to tools - if [ -d $rootdir/$SBOX_DIR/lib/libsb2 ]; then - sbox_dir_2=$rootdir/$SBOX_DIR - elif [ -d $rootdir/usr/lib/libsb2 ]; then - sbox_dir_2=$rootdir/usr - else - sbox_dir_2="" - fi + sbox_dir_2="" + + for liblocation in $sbox_liblocations ; do + [ -d $rootdir$liblocation ] || continue + # assume the prefix is under libdir: ../libdir + liblocation=${liblocation%/*} + sbox_dir_2=$rootdir${liblocation%/*} + sbox_libdir=$rootdir$liblocation + if [ -z "$libsb2_path" ]; then + libsb2_path=$rootdir$liblocation/$SBOX_LIBSB2 + libsb2_dirname="" + fi + break + done - if [ -z "$libsb2_path" ]; then - libsb2_path=$sbox_dir_2/lib/libsb2/libsb2.so.1 - libsb2_dirname="" - fi if [ -f $libsb2_path ]; then libsb2_dir=$(dirname $libsb2_path) @@ -996,7 +996,7 @@ write_libsb2_and_ld_so_state_to_exec_config() # First try if it exists in the same directory where # libsb2.so is: ld_so_candidate2=$libsb2_dirname/$ld_so_with_version - if [ -n "$libsb2_dirname" -a -f $ld_so_candidate2 ]; then + if [ -n "$libsb2_dirname" ] && [ -f $ld_so_candidate2 ]; then check_ld_so_features $rootdir \ $ld_so_candidate2 @@ -1006,7 +1006,7 @@ write_libsb2_and_ld_so_state_to_exec_config() fi if [ "$ld_so_argv_flag_works" != "true" ]; then - ld_so_candidate2=$SBOX_DIR/lib/libsb2/$ld_so_with_version + ld_so_candidate2=${sbox_libdir:-$SBOX_DIR/lib/libsb2}/$ld_so_with_version if [ -f "$ld_so_candidate2" ]; then check_ld_so_features $rootdir \ $ld_so_candidate2 @@ -1117,7 +1117,7 @@ write_locale_and_gconv_paths_to_exec_config() #------------ gconv: gconv_path="" - for rootdir_gconvs in "$rootdir/usr/lib/gconv" \ + for rootdir_gconvs in "$SBOX_LIBDIR $rootdir/usr/lib/gconv" \ "$rootdir/usr/share/gconv" do if [ -d "$rootdir_gconvs" ]; then @@ -1151,10 +1151,15 @@ END -- CPU transparency settings. Automatically generated file, do not edit. END - library_interface=$(LD_LIBRARY_PATH=$SBOX_DIR/lib/libsb2:$LD_LIBRARY_PATH $SBOX_DIR/bin/sb2-show libraryinterface) + for liblocation in $sbox_liblocations ; do + if [ -d $liblocation ] ; then + break + fi + done + library_interface=$(LD_LIBRARY_PATH=$liblocation:$LD_LIBRARY_PATH $SBOX_BINDIR/sb2-show libraryinterface) # 1. Exec settings for tools - if [ -n "$SBOX_TOOLS_ROOT" -a "$SBOX_TOOLS_ROOT" != "/" ]; then + if [ -n "$SBOX_TOOLS_ROOT" ] && [ "$SBOX_TOOLS_ROOT" != "/" ]; then tools_basename=$(basename $SBOX_TOOLS_ROOT) write_ld_library_path_replacement_to_exec_config \ $SBOX_TOOLS_ROOT conf_tools_ld_so_library_path \ @@ -1204,7 +1209,7 @@ END fi # 2. Exec settings for rootstrap - if [ "$SBOX_CPUTRANSPARENCY_METHOD" == "" ]; then + if [ "$SBOX_CPUTRANSPARENCY_METHOD" = "" ]; then # CPU transparency method has not been set: # host CPU == target CPU if [ -n "$SBOX_CLONED_TARGET_ROOT" ]; then @@ -1332,8 +1337,8 @@ get_SBOX_SESSION_DIR_from_file() exit_error "'$file' is not a valid SB2 session information file" fi - if [ ! -d "$SBOX_SESSION_DIR" -o \ - ! -f $SBOX_SESSION_DIR/.joinable-session ]; then + if [ ! -d "$SBOX_SESSION_DIR" ] || \ + [ ! -f $SBOX_SESSION_DIR/.joinable-session ]; then exit_error "Session '$SBOX_SESSION_DIR' does not exist" fi # else the session seems to be valid. @@ -1344,7 +1349,7 @@ get_SBOX_SESSION_DIR_from_file() # (called to process a command-line option) add_map_mode() { - if [ ! -d "$SBOX_DIR/share/scratchbox2/modes/$1" ]; then + if [ ! -d "$SBOX_DATADIR/scratchbox2/modes/$1" ]; then exit_error "Invalid mode '$1', aborting." fi @@ -1385,8 +1390,8 @@ add_map_mode() initialize_new_sb2_session() { # Create a new session - if [ -n "$SBOX_WRITE_SESSION_INFO_TO_FILE" -a \ - -f "$SBOX_WRITE_SESSION_INFO_TO_FILE" ]; then + if [ -n "$SBOX_WRITE_SESSION_INFO_TO_FILE" ] && \ + [ -f "$SBOX_WRITE_SESSION_INFO_TO_FILE" ]; then exit_error "File '$SBOX_WRITE_SESSION_INFO_TO_FILE' already exists." fi @@ -1396,16 +1401,14 @@ initialize_new_sb2_session() else # Create session directories date_and_time_now=$(date +%Y%m%d-%H%M%S) - SBOX_SESSION_DIR=$(mktemp -d /tmp/sb2-$USER-$date_and_time_now.XXXXXX) - if [ $? != 0 ]; then + if ! SBOX_SESSION_DIR=$(mktemp -d /tmp/sb2-$USER-$date_and_time_now.XXXXXX) ; then exit_error "Failed to create directory for session (problems with /tmp ?)" fi fi # resolve possible symlinks in SBOX_SESSION_DIR SBOX_SESSION_DIR=$(readlink -f $SBOX_SESSION_DIR) - mkdir -p $SBOX_SESSION_DIR - if [ $? != 0 ]; then + if ! mkdir -p $SBOX_SESSION_DIR; then exit_error "Failed to create directory for session" fi mkdir $SBOX_SESSION_DIR/tmp @@ -1442,12 +1445,12 @@ initialize_new_sb2_session() # For mknod() simulation in some modes: mkdir $SBOX_SESSION_DIR/dev - ln -s $SBOX_DIR/bin $SBOX_SESSION_DIR/bin - ln -s $SBOX_DIR/share $SBOX_SESSION_DIR/share + ln -s $SBOX_BINDIR $SBOX_SESSION_DIR/bin + ln -s $SBOX_DATADIR $SBOX_SESSION_DIR/share # FIXME: This should link only selected modes, not all: - ln -s $SBOX_DIR/share/scratchbox2/modes/* $SBOX_SESSION_DIR/modes + ln -s $SBOX_DATADIR/scratchbox2/modes/* $SBOX_SESSION_DIR/modes - ln -s $SBOX_DIR/share/scratchbox2/rule_lib $SBOX_SESSION_DIR + ln -s $SBOX_DATADIR/scratchbox2/rule_lib $SBOX_SESSION_DIR if [ -n "$SBOX_WRITE_SESSION_INFO_TO_FILE" ]; then cat >$SBOX_WRITE_SESSION_INFO_TO_FILE </dev/null - ln -s $SBOX_DIR/lib/libsb2/wrappers/* \ - $SBOX_SESSION_DIR/wrappers.$w_mode 2>/dev/null + if [ "$SBOX_WRAPPERS" = 'ALL' ]; then + for wrapper in $SBOX_DATADIR/ ; do + if [ -e $wrapper ]; then + ln -s $wrapper \ + $SBOX_SESSION_DIR/wrappers.$w_mode + fi + done + # Pick the first liblocation found any link wrappers + # to the session + for wrapper_dir in $sbox_liblocations ; do + if [ -e $wrapper_dir ] ; then + for wrapper in $wrapper_dir/* ; do + if [ -e $wrapper ] ; then + ln -s $wrapper \ + $SBOX_SESSION_DIR/wrappers.$w_mode + fi + done + break + fi + done else for ammw in $SBOX_WRAPPERS; do - if [ -f $SBOX_DIR/share/scratchbox2/wrappers/$ammw ]; then - ln -s $SBOX_DIR/share/scratchbox2/wrappers/$ammw \ - $SBOX_SESSION_DIR/wrappers.$w_mode - elif [ -f $SBOX_DIR/lib/libsb2/wrappers/$ammw ]; then - ln -s $SBOX_DIR/lib/libsb2/wrappers/$ammw \ - $SBOX_SESSION_DIR/wrappers.$w_mode - else + wrapper_found=nil + for wrapper_dir in $SBOX_DATADIR/scratchbox2 \ + $sbox_liblocations \ + ; do + if [ -f $wrapper_dir/wrappers/$ammw ]; then + ln -s $wrapper_dir/wrappers/$ammw \ + $SBOX_SESSION_DIR/wrappers.$w_mode + wrapper_found=t + break + fi + done + if [ $wrapper_found = nil ] ; then exit_error "There is no wrapper for $ammw" fi done @@ -1556,13 +1579,13 @@ write_configfiles_and_rules_for_new_session() SB2_ALL_NET_MODES="" # Create links to network rules - for netr in $SBOX_DIR/share/scratchbox2/net_rules/*; do + for netr in $SBOX_DATADIR/scratchbox2/net_rules/*; do ln -s $netr $SBOX_SESSION_DIR/net_rules netr_b=$(basename $netr) SB2_ALL_NET_MODES="$SB2_ALL_NET_MODES $netr_b" done # Create a link to the default mode - ln -s $SBOX_DIR/share/scratchbox2/net_rules/$SBOX_DEFAULT_NETWORK_MODE $SBOX_SESSION_DIR/net_rules/Default + ln -s $SBOX_DATADIR/scratchbox2/net_rules/$SBOX_DEFAULT_NETWORK_MODE $SBOX_SESSION_DIR/net_rules/Default ##if [ -n "$SB2_EXTERNAL_RULEFILES" ]; then ## for ammf in $SB2_EXTERNAL_RULEFILES; do @@ -1620,7 +1643,10 @@ SBOX_MAPMODE="" NUM_MAPMODES=0 SB2_INTERNAL_MAPMODES="" -SBOX_DIR=$(readlink -f $(dirname $(readlink -f $my_path))/..) +SBOX_DIR=@prefix@ +SBOX_BINDIR=@bindir@ +SBOX_LIBDIR=@libdir@ +SBOX_DATADIR=@datadir@ SBOX_WORKDIR=$(readlink -f "$PWD") SBOX_ROOT_SIMULATION="" SBOX_MODE_SPECIFIC_OPTIONS="" @@ -1638,6 +1664,13 @@ VPERM_ROOT_PRIVILEGE_FLAG="" SB2D_OPTIONS="" OPT_DONT_DELETE_SESSION="" +# Only check use /lib and /lib64 as paths without $SBOX_DIR outside +# /usr as systems with UsrMove should have /usr/lib -> /lib +# symlinks +sbox_libdirs="$SBOX_DIR/lib /lib $SBOX_LIBDIR /lib64" +sbox_liblocations="$SBOX_DIR/lib/libsb2 /usr/lib/libsb2 $SBOX_LIBDIR/libsb2 $SBOX_DIR/lib64/libsb2 /usr/lib64/libsb2" + + while getopts vdht:em:n:s:L:Q:M:ZrRU:pS:J:D:P:W:O:cC:T:uf:gG:B:b:qx:N foo do case $foo in @@ -1684,7 +1717,7 @@ done shift $(($OPTIND - 1)) -if [ -n "$SBOX_SESSION_DIR" -a -d "$SBOX_SESSION_DIR/rules" ]; then +if [ -n "$SBOX_SESSION_DIR" ] && [ -d "$SBOX_SESSION_DIR/rules" ]; then # already inside an sb2 session; ignore all options and just exec the command. echo "WARNING: recursive calls to sb2 are not supported (session already exists)" echo "WARNING: going to execute '$*' in this session" @@ -1693,7 +1726,7 @@ fi #----------- Check parameters -# First check that we are not running under "fakeroot"; it +# First check that we are not running under "fakeroot"; it # will just mess up things and must not be combined with SB2. case "$LD_PRELOAD" in (*fakeroot*) @@ -1709,18 +1742,17 @@ esac if [ -n "$SBOX_LOG_AND_GRAPH_DIR" ]; then if [ ! -d "$SBOX_LOG_AND_GRAPH_DIR" ]; then - mkdir -p "$SBOX_LOG_AND_GRAPH_DIR" - if [ $? != 0 ]; then + if ! mkdir -p "$SBOX_LOG_AND_GRAPH_DIR"; then exit_error "Failed to create directory $SBOX_LOG_AND_GRAPH_DIR" fi else exit_error "directory $SBOX_LOG_AND_GRAPH_DIR already exists" fi - SBOX_LOG_AND_GRAPH_DIR=$($SBOX_DIR/bin/sb2-show realpath $SBOX_LOG_AND_GRAPH_DIR) + SBOX_LOG_AND_GRAPH_DIR=$($SBOX_BINDIR/sb2-show realpath $SBOX_LOG_AND_GRAPH_DIR) export SBOX_LOG_AND_GRAPH_DIR export SBOX_COLLECT_ACCT_DATA - if [ "$SBOX_MAPPING_DEBUG" != "1" -a -n "$SBOX_LOG_AND_GRAPH_DIR" ]; then + if [ "$SBOX_MAPPING_DEBUG" != "1" ] && [ -n "$SBOX_LOG_AND_GRAPH_DIR" ]; then # Log & graphs requested, but log isn't active. export SBOX_MAPPING_DEBUG=1 export SBOX_MAPPING_LOGLEVEL=info @@ -1729,13 +1761,13 @@ if [ -n "$SBOX_LOG_AND_GRAPH_DIR" ]; then if [ -n "$SBOX_COLLECT_ACCT_DATA" ]; then # First try to activate it directly touch $SBOX_LOG_AND_GRAPH_DIR/acct-data - $SBOX_DIR/bin/sb2-show acct_on $SBOX_LOG_AND_GRAPH_DIR/acct-data 2>/dev/null - if [ $? != 0 ]; then + if ! $SBOX_BINDIR/sb2-show acct_on \ + $SBOX_LOG_AND_GRAPH_DIR/acct-data 2>/dev/null; then if [ -z "$SBOX_QUIET" ]; then echo "WARNING: Can't activate process accounting. Retrying with 'sudo', password may be needed." fi - sudo $SBOX_DIR/bin/sb2-show acct_on $SBOX_LOG_AND_GRAPH_DIR/acct-data 2>/dev/null - if [ $? != 0 ]; then + if ! sudo $SBOX_BINDIR/sb2-show acct_on \ + $SBOX_LOG_AND_GRAPH_DIR/acct-data 2>/dev/null; then if [ -z "$SBOX_QUIET" ]; then echo "WARNING: Failed to activate process accounting. Acct data won't be included in the graphs." fi @@ -1757,7 +1789,7 @@ else fi if [ -n "$SBOX_NETWORK_MODE" ]; then - if [ ! -d "$SBOX_DIR/share/scratchbox2/net_rules/$SBOX_NETWORK_MODE" ]; then + if [ ! -d "$SBOX_DATADIR/scratchbox2/net_rules/$SBOX_NETWORK_MODE" ]; then exit_error "'$SBOX_NETWORK_MODE' is not a valid networking mode." fi fi @@ -1855,7 +1887,7 @@ export SBOX_SESSION_DIR sboxify_environment -if [ -z "$SB2_INTERNAL_MAPMODES" -a -z "$SB2_EXTERNAL_RULEFILES" ]; then +if [ -z "$SB2_INTERNAL_MAPMODES" ] && [ -z "$SB2_EXTERNAL_RULEFILES" ]; then # mapping mode was not specified by an option, SBOX_MAPMODE has been # set from the config file by sboxify_environment SB2_INTERNAL_MAPMODES=$SBOX_MAPMODE @@ -1887,14 +1919,13 @@ if [ -z "$SBOX_JOIN_SESSION_FILE" ]; then # deleted when session is terminated.) # # sb2d will execute "init.lua" before returning. - SB2_DEFAULT_NETWORK_MODE="$SBOX_DEFAULT_NETWORK_MODE" \ - SB2_ALL_NET_MODES="$SB2_ALL_NET_MODES" \ - SB2_ALL_MODES="$SB2_INTERNAL_MAPMODES" \ + if ! SB2_DEFAULT_NETWORK_MODE="$SBOX_DEFAULT_NETWORK_MODE" \ + SB2_ALL_NET_MODES="$SB2_ALL_NET_MODES" \ + SB2_ALL_MODES="$SB2_INTERNAL_MAPMODES" \ sb2d -s $SBOX_SESSION_DIR -p $SBOX_SESSION_DIR/sb2d.pid \ -l - $SB2D_OPTIONS \ >$SBOX_SESSION_DIR/sb2d.out \ - 2>$SBOX_SESSION_DIR/sb2d.err - if [ $? != 0 ]; then + 2>$SBOX_SESSION_DIR/sb2d.err ; then grep ERROR $SBOX_SESSION_DIR/sb2d.out cat $SBOX_SESSION_DIR/sb2d.err exit_error "startup of sb2d failed." @@ -1931,7 +1962,7 @@ if [ -z "$SBOX_JOIN_SESSION_FILE" ]; then # to the rule tree. # (this step needs to be syncronous; sb2dctl won't return # before init2.lua is completed) - ctl_result=$($SBOX_DIR/lib/libsb2/sb2dctl -n -s $SBOX_SESSION_DIR init2) + ctl_result=$($SBOX_LIBDIR/libsb2/sb2dctl -n -s $SBOX_SESSION_DIR init2) case "$ctl_result" in *OK*) # Startup OK @@ -1969,7 +2000,7 @@ fi # (If logging was activated earlier, # several bogus errors would be logged because of # missing auto-generated rules) -if [ $# -gt 0 -o "$STDIN" = true ] ; then +if [ $# -gt 0 ] || [ "$STDIN" = true ] ; then initialize_sb_logging $(echo $1 | sed -e 's/\//_/g' -e 's/^\.//') "$args" else initialize_sb_logging sb2 @@ -2011,7 +2042,7 @@ SBOX_CONFIG_DIR=$HOME/.scratchbox2/$SBOX_TARGET/sb2.config.d # __SB2_BINARYNAME="sb2:StartupTrampoline" export __SB2_BINARYNAME -if [ $# -gt 0 -o "$STDIN" = true ]; then +if [ $# -gt 0 ] || [ "$STDIN" = true ]; then binary="$1" shift 1 @@ -2020,15 +2051,15 @@ if [ $# -gt 0 -o "$STDIN" = true ]; then orig_args_array=("$@") exec sb2-monitor $OPTS_FOR_SB2_MONITOR \ -L $SBOX_LIBSB2 \ - -X $SBOX_DIR/share/scratchbox2/scripts/sb2-exitreport \ + -X $SBOX_DATADIR/scratchbox2/scripts/sb2-exitreport \ -e $SBOX_CONFIG_DIR/env_vars \ -- \ - $SBOX_DIR/bin/sb2-show start -- $binary "${orig_args_array[@]}" + $SBOX_BINDIR/sb2-show start -- $binary "${orig_args_array[@]}" else exec sb2-monitor $OPTS_FOR_SB2_MONITOR \ -L $SBOX_LIBSB2 \ - -X $SBOX_DIR/share/scratchbox2/scripts/sb2-exitreport \ + -X $SBOX_DATADIR/scratchbox2/scripts/sb2-exitreport \ -e $SBOX_CONFIG_DIR/env_vars \ -- \ - $SBOX_DIR/bin/sb2-show start -- $SHELL --noprofile --norc + $SBOX_BINDIR/sb2-show start -- $SHELL --noprofile --norc fi