summaryrefslogtreecommitdiff
path: root/llbuild
diff options
context:
space:
mode:
authorLauri Leukkunen <lle@rahina.org>2006-08-27 09:44:52 +0300
committerLauri Leukkunen <lleukkun@leka.rahina.org>2006-08-27 09:44:52 +0300
commit86f43567b64b163768417646e709328c5569db20 (patch)
tree59d3a2fc8a8a827e1b0f34cfa81420c2492317f7 /llbuild
parentbcbf5b67a013180c9bbccff31e8e20ec098d4c28 (diff)
* restructure llbuild to its own subdir, add llflock to provide locking
for all host environments
Diffstat (limited to 'llbuild')
-rw-r--r--llbuild/Makefile12
-rw-r--r--llbuild/Makefile.build3
-rw-r--r--llbuild/Makefile.include133
-rw-r--r--llbuild/Makefile.sample46
-rw-r--r--llbuild/llflock.c116
5 files changed, 310 insertions, 0 deletions
diff --git a/llbuild/Makefile b/llbuild/Makefile
new file mode 100644
index 0000000..480fd54
--- /dev/null
+++ b/llbuild/Makefile
@@ -0,0 +1,12 @@
+HOSTCC ?= gcc
+
+targets = llflock
+
+all: $(targets)
+
+llflock: llflock.c
+ @$(HOSTCC) -o llflock llflock.c
+
+clean:
+ @rm -f *.o $(targets)
+
diff --git a/llbuild/Makefile.build b/llbuild/Makefile.build
new file mode 100644
index 0000000..7b7aeaa
--- /dev/null
+++ b/llbuild/Makefile.build
@@ -0,0 +1,3 @@
+# This is used to kick the build around double inclusion of local Makefile
+
+
diff --git a/llbuild/Makefile.include b/llbuild/Makefile.include
new file mode 100644
index 0000000..ee26c04
--- /dev/null
+++ b/llbuild/Makefile.include
@@ -0,0 +1,133 @@
+# ll build system
+#
+# Copyright (C) 2006 Lauri Leukkunen <lle@rahina.org>
+#
+# Permission is hereby granted, free of charge, to any person obtaining a copy
+# of this software and associated documentation files (the "Software"), to deal
+# in the Software without restriction, including without limitation the rights
+# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+# copies of the Software, and to permit persons to whom the Software is
+# furnished to do so, subject to the following conditions:
+#
+# The above copyright notice and this permission notice shall be included in
+# all copies or substantial portions of the Software.
+#
+# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
+# SOFTWARE.
+
+
+# Make sure this file is only included once per make invocation
+ifndef _LL_BUILD_MAKEFILE_INCLUDE
+_LL_BUILD_MAKEFILE_INCLUDE=1
+
+-include $(TOPDIR)/.config
+
+built_in_target := built-in.o
+
+filter_subdirs := $(shell for d in $(obj-default) ; do if [ -d $$d ]; then echo $$d; fi; done)
+filter_objects := $(shell for f in $(obj-default) ; do if [ -d $$f ]; then echo $$f/built-in.o; else echo $$f; fi; done)
+
+clean_subdirs := $(foreach dir,$(filter_subdirs),$(CURDIR)/$(dir))
+subdir_deps := $(patsubst %,%.subdir.d,$(clean_subdirs))
+
+LOCK ?= $(TOPDIR)/llbuild/llflock $@.lock
+
+%.subdir.d:
+ @if [ ! -e $@.lock ]; then touch $@.lock; fi
+ @$(LOCK) /bin/sh -c "if [ ! -e $@ ]; then $(MAKE) --no-print-directory -C $(patsubst %.subdir.d,%,$@) -f $(TOPDIR)/llbuild/Makefile.build ll_subdir && touch $@; fi;"
+
+
+ll_mainlevel:
+ @find $(TOPDIR) -name "*.subdir.d.lock" -o -name "*.subdir.d" | xargs rm -f
+ @$(MAKE) --no-print-directory -f $(TOPDIR)/llbuild/Makefile.build $(subdir_deps)
+
+
+ll_subdir: $(subdir_deps)
+ @$(MAKE) --no-print-directory -f $(TOPDIR)/llbuild/Makefile.build $(built_in_target) $(extra_targets)
+
+ifeq ("$(strip $(filter_objects))", "")
+$(built_in_target):
+ @true
+else
+$(built_in_target): $(filter_objects)
+ $(ll_pretty_link_builtin)
+endif
+
+OPT_CURDIR = $(patsubst /%,%,$(strip $(subst $(TOPDIR), , $(CURDIR))))
+
+ifndef ll_verbose
+define ll_pretty_run
+ run_output=$$($$run_cmd 2>&1); \
+ if [ $$? -ne 0 ]; then \
+ echo $$run_cmd; echo $(OPT_CURDIR)/$$run_output; \
+ false; \
+ else \
+ echo [$$run_alias] [$(OPT_CURDIR)/$@] $^; \
+ echo "$$run_output" | grep " warning: "; \
+ true ; \
+ fi
+endef
+else
+define ll_pretty_run
+ echo $$run_cmd; \
+ $$run_cmd;
+endef
+endif
+
+define ll_pretty_build_c
+ @run_cmd="$(CC) $(CFLAGS) -Wp,-MD,$(dir $(@))/.$(notdir $(@)).d -o $@ -c $<"; \
+ run_alias="CC"; \
+ $(ll_pretty_run)
+endef
+
+define ll_pretty_link_builtin
+ @run_cmd="$(LD) -r -nostartfiles -o $@ $^"; \
+ run_alias="LD"; \
+ $(ll_pretty_run)
+endef
+
+define ll_pretty_link_shared_library
+ @run_cmd="$(CC) $(LDFLAGS) -shared -o $@ $^ $(LIBS)"; \
+ run_alias="SHLIB"; \
+ $(ll_pretty_run)
+endef
+
+define ll_pretty_link_shared_binary
+ @run_cmd="$(CC) $(LDFLAGS) -o $@ $^ $(LIBS)"; \
+ run_alias="BIN";\
+ $(ll_pretty_run)
+endef
+
+%.o: %.S
+ $(ll_pretty_build_c)
+
+%.o: %.c
+ $(ll_pretty_build_c)
+
+
+dep_files = $(wildcard .*.d)
+
+ifneq ("$(dep_files)", "")
+ include $(dep_files)
+endif
+
+.PHONY: build $(subdirs)
+
+define ll_clean
+ +@$(MAKE) --no-print-directory -C $(TOPDIR)/llbuild MAKEFLAGS= MAKEFILES= clean
+ rm -rf $(CLEAN_FILES)
+ find . -name "*.[oasd]" -o -name ".*.d" -o -name "*.*~" -o -name "*~" -o -name "*.lock" | xargs rm -rf
+endef
+
+define ll_toplevel_build
+ +@$(MAKE) --no-print-directory -C $(TOPDIR)/llbuild MAKEFLAGS= MAKEFILES=
+ +@$(MAKE) --no-print-directory -f $(TOPDIR)/llbuild/Makefile.build ll_mainlevel
+endef
+
+endif
+
diff --git a/llbuild/Makefile.sample b/llbuild/Makefile.sample
new file mode 100644
index 0000000..ad7ce88
--- /dev/null
+++ b/llbuild/Makefile.sample
@@ -0,0 +1,46 @@
+CC = gcc
+LD = ld
+PACKAGE_VERSION = "1.99b"
+PACKAGE = "SB2"
+CFLAGS = -Wall -W -I$(TOPDIR)/include -D_LARGEFILE_SOURCE -D_LARGEFILE64_SOURCE
+
+TOPDIR = $(CURDIR)
+
+MAKEFILES = Makefile $(TOPDIR)/llbuild/Makefile.include
+
+export CC CFLAGS MAKEFILES TOPDIR
+
+obj-default = lua preload utils
+targets = utils/sb2init
+
+
+all: build
+
+configure: configure.ac
+ ./autogen.sh
+ ./configure
+
+build: configure
+ $(ll_toplevel_build)
+ @echo Build completed successfully!
+
+install: build
+ install -d -m 755 $(prefix)/scratchbox/bin
+ install -d -m 755 $(prefix)/scratchbox/lib
+ install -d -m 755 $(prefix)/scratchbox/redir_scripts
+ install -c -m 755 preload/libsb2.so $(prefix)/scratchbox/lib/libsb2.so
+ install -c -m 755 utils/sb2init $(prefix)/scratchbox/bin/sb2init
+ install -c -m 755 scripts/login.sh $(prefix)/login.sh
+ install -c -m 755 scripts/sb2rc $(prefix)/scratchbox/sb2rc
+ install -c -m 644 redir_scripts/main.lua $(prefix)/scratchbox/redir_scripts/main.lua
+
+
+CLEAN_FILES = $(targets)
+
+clean:
+ $(ll_clean)
+
+-include .config
+include $(TOPDIR)/llbuild/Makefile.include
+
+
diff --git a/llbuild/llflock.c b/llbuild/llflock.c
new file mode 100644
index 0000000..b1bd746
--- /dev/null
+++ b/llbuild/llflock.c
@@ -0,0 +1,116 @@
+/*
+ flock - acquires a file lock and executes a command with the lock held.
+ Usage: flock [--shared | --timeout=seconds] lockfile program [args...]
+
+ Written by Adam J. Richter
+ Copyright (C) 2004 Yggdrasil Computing, 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 2 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, write to the Free Software
+ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+*/
+
+/*
+ * lle: Removed the localisation support to cut off unnecessary dependencies
+ */
+
+#include <sys/file.h>
+#include <sys/types.h>
+#include <sys/wait.h>
+#include <getopt.h>
+#include <unistd.h>
+#include <stdlib.h> /* exit */
+#include <signal.h> /* kill */
+#include <stdio.h>
+
+static int non_blocking = 0;
+static int shared = LOCK_EX;
+
+static const struct option options[] = {
+ {"shared", no_argument, &shared, LOCK_SH },
+ {"timeout", required_argument, NULL, 't' },
+ {NULL, 0, NULL, 0 },
+};
+
+int main(int argc, char **argv)
+{
+ int fd;
+ int opt;
+ int pid;
+ int child_status;
+ int option_index;
+ int timeout = 0;
+
+ do {
+ opt = getopt_long(argc, argv, "+", options, &option_index);
+ switch(opt) {
+ case '?':
+ fprintf (stderr,
+ "flock: unknown option, aborting.\n");
+ exit(1);
+ break;
+ case 't':
+ timeout = atoi(optarg);
+ if (timeout == 0)
+ non_blocking |= LOCK_NB;
+ break;
+ default:
+ break;
+ }
+ } while (opt != -1);
+
+ argc -= optind;
+ argv += optind;
+
+ if (argc < 2) {
+ fprintf(stderr,
+ "Usage flock [--shared | --timeout=seconds] "
+ "filename command {arg arg...}\n");
+ exit(2);
+ }
+
+ fd = open(argv[0], O_RDONLY);
+ if (fd < 0) {
+ perror(argv[0]);
+ exit(3);
+ }
+
+ alarm(timeout);
+ if (flock(fd, shared | non_blocking) != 0) {
+ perror("flock");
+ exit(4);
+ }
+ alarm(0);
+
+ pid = fork();
+ if (pid < 0) {
+ perror("fork");
+ exit(5);
+ }
+ if (pid == 0) {
+ execvp(argv[1], argv+1);
+ perror(argv[1]);
+ exit(6);
+ }
+ waitpid(pid, &child_status, 0);
+
+ /* flock(fd, LOCK_UN); */
+ /* No need to explicitly release the flock, since we are just
+ going to exit now anyhow. */
+
+ /* Lame attempt to simulate child's mode of death. */
+ if (WIFSIGNALED(child_status))
+ kill(0, WTERMSIG(child_status));
+
+ return WEXITSTATUS(child_status);
+}