diff options
author | Lauri Leukkunen <lle@rahina.org> | 2007-01-03 00:04:05 +0200 |
---|---|---|
committer | Lauri Leukkunen <lleukkun@leka.rahina.org> | 2007-01-03 00:04:05 +0200 |
commit | f43ab35f21e35deaae84df482330f9a6ccf393a7 (patch) | |
tree | 84273c83fb3838b588e023adabe64a97e36353ed /llbuild | |
parent | 8206fdf74e5dabdda5a2ac45dc5e50a2461cdf77 (diff) |
* update llbuild build system to new non-recursive version
Diffstat (limited to 'llbuild')
-rw-r--r-- | llbuild/Makefile | 12 | ||||
-rw-r--r-- | llbuild/Makefile.build | 3 | ||||
-rw-r--r-- | llbuild/Makefile.include | 141 | ||||
-rw-r--r-- | llbuild/Makefile.subdir-sample | 9 | ||||
-rw-r--r-- | llbuild/Makefile.toplevel-sample | 35 | ||||
-rw-r--r-- | llbuild/README | 38 | ||||
-rw-r--r-- | llbuild/llflock.c | 116 |
7 files changed, 116 insertions, 238 deletions
diff --git a/llbuild/Makefile b/llbuild/Makefile deleted file mode 100644 index 480fd54..0000000 --- a/llbuild/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 7b7aeaa..0000000 --- a/llbuild/Makefile.build +++ /dev/null @@ -1,3 +0,0 @@ -# This is used to kick the build around double inclusion of local Makefile - - diff --git a/llbuild/Makefile.include b/llbuild/Makefile.include index effb768..eb68b45 100644 --- a/llbuild/Makefile.include +++ b/llbuild/Makefile.include @@ -24,86 +24,80 @@ ifndef _LL_BUILD_MAKEFILE_INCLUDE _LL_BUILD_MAKEFILE_INCLUDE=1 -#$(warning Hello, from $(CURDIR)) --include $(TOPDIR)/.config +# this is here to enforce a sensible default target +__kicker_target: all -LLBUILD ?= $(TOPDIR)/llbuild - -built_in_target := built-in.o - -all_objects := $(obj-builtin) -all_objects += $(foreach t,$(extra_targets),$($(t))) - -filter_subdirs := $(shell for d in $(subdirs) $(all_objects) ; do if [ -d $$d ]; then echo $$d; fi; done) +TOPDIR := $(CURDIR) -filter_objects := $(shell for f in $(all_objects) ; do if [ -d $$f ]; then echo $$f/built-in.o; else echo $$f; fi; done) -builtin_filter_objects := $(shell for f in $(obj-builtin) ; do if [ -d $$f ]; then echo $$f/built-in.o; else echo $$f; fi; done) +# import all the subdir Makefiles recursively -real_subdirs := $(foreach dir,$(filter_subdirs),$(shell readlink -f $(CURDIR)/$(dir))) -subdir_deps := $(foreach path,$(real_subdirs),$(dir $(path)).$(notdir $(path).subdir.d)) +define import_dir + subdirs := + objects := + targets := + LLPWD := $(1) + include $(1)/Makefile + dep_files := $$(wildcard $(1)/.*.d) +ifneq ($$(dep_files),) + include $$(dep_files) +endif + all-targets := $$(all-targets) $$(targets) + all-objects := $$(all-objects) $$(patsubst %,$(1)/%,$$(objects)) + tmp := $$(patsubst %,$(1)/%,$$(subdirs)) + perkele := $$(foreach dir,$$(tmp),$$(eval $$(call import_dir,$$(dir)))) +endef -.PRECIOUS: $(filter_objects) +$(foreach dir,$(subdirs),$(eval $(call import_dir,$(dir)))) -LOCK ?= $(LLBUILD)/llflock $@.lock -%.subdir.d: - @if [ ! -e $@.lock ]; then touch $@.lock; fi - @$(LOCK) /bin/sh -c "if [ ! -e $@ ]; then $(MAKE) --no-print-directory -C $(dir $@)$(patsubst .%,%,$(patsubst %.subdir.d,%,$(notdir $@))) -f $(LLBUILD)/Makefile.build ll_subdir && touch $@; fi;" +built_in_target := built-in.o +all_objects := $(obj-builtin) +all_objects += $(foreach t,$(extra_targets),$($(t))) -# these are for handling extra_targets -bin-%: $(filter_objects) - @run_sources="$($@)"; \ - run_target="$(patsubst bin-%,%,$@)"; \ - run_cmd="$(CC) $(CCFLAGS) $(LDFLAGS) -o $(patsubst bin-%,%,$@) $(shell for f in $($@) ; do if [ -d $$f ]; then echo $$f/built-in.o; else echo $$f; fi; done) $(LIBS)"; \ +define llbuild_link_shbin + @run_sources="$^"; \ + run_target="$@"; \ + run_cmd="$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)"; \ run_alias="BIN"; \ $(ll_pretty_run) +endef -cxxbin-%: $(filter_objects) - @run_sources="$($@)"; \ - run_target="$(patsubst cxxbin-%,%,$@)"; \ - run_cmd="$(CXX) $(CFLAGS) $(LDFLAGS) $(CXXFLAGS) -o $(patsubst cxxbin-%,%,$@) $(shell for f in $($@) ; do if [ -d $$f ]; then echo $$f/built-in.o; else echo $$f; fi; done) $(LIBS)"; \ +define llbuild_link_shcxxbin + @run_sources="$^"; \ + run_target="$@"; \ + run_cmd="$(CXX) $(CFLAGS) $(LDFLAGS) $(CXXFLAGS) -o $@ $^ $(LIBS)"; \ run_alias="CXXBIN"; \ $(ll_pretty_run) +endef -shlib-%: $(filter_objects) - @run_sources="$($@)"; \ - run_target="$(patsubst shlib-%,%,$@)"; \ - run_cmd="$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $(patsubst shlib-%,%,$@) $(shell for f in $($@) ; do if [ -d $$f ]; then echo $$f/built-in.o; else echo $$f; fi; done) $(LIBS)"; \ +define llbuild_link_shlib + @run_sources="$^"; \ + run_target="$@"; \ + run_cmd="$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LIBS)"; \ run_alias="SHLIB"; \ $(ll_pretty_run) +endef -ll_mainlevel: - @find $(TOPDIR) -name "*.subdir.d.lock" -o -name "*.subdir.d" | xargs rm -f - @$(MAKE) --no-print-directory -f $(LLBUILD)/Makefile.build ll_subdir - - -ll_subdir: $(subdir_deps) - @$(MAKE) --no-print-directory -f $(LLBUILD)/Makefile.build $(built_in_target) $(extra_targets) - -ifeq ("$(strip $(builtin_filter_objects))", "") -$(built_in_target): - @true -else -$(built_in_target): $(builtin_filter_objects) - $(ll_pretty_link_builtin) -endif +define llbuild_link_archive + @run_sources=""; \ + run_target="$@"; \ + run_cmd="$(CC) -Wl,-r -nostdlib -nodefaultlibs -nostartfiles -o $@ $^"; \ + run_alias="ARCHIVE"; \ + $(ll_pretty_run) +endef -OPT_CURDIR = $(patsubst /%,%,$(strip $(subst $(TOPDIR), , $(CURDIR)))) -ifeq ("$(OPT_CURDIR)","") -OPT_CURDIR="." -endif 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"; \ + echo "$$run_cmd"; echo "$$run_output"; \ false; \ else \ - echo "[$$run_alias] [$(OPT_CURDIR)/$$run_target] $$run_sources"; \ + echo "[$$run_alias] [$$run_target] $$run_sources"; \ echo "$$run_output" | grep " warning: "; \ true ; \ fi @@ -134,59 +128,34 @@ endef define ll_pretty_link_builtin @run_sources="$^"; \ run_target="$@"; \ - run_cmd="$(LD) -r -nostartfiles -o $@ $^"; \ + run_cmd="$(CC) -Wl,-r -nostdlib -nodefaultlibs -nostartfiles -o $@ $^"; \ run_alias="LD"; \ $(ll_pretty_run) endef -define ll_pretty_link_shared_library - @run_sources="$^"; \ - run_target="$@"; \ - run_cmd="$(CC) $(CFLAGS) $(LDFLAGS) -shared -o $@ $^ $(LIBS)"; \ - run_alias="SHLIB"; \ - $(ll_pretty_run) -endef - -define ll_pretty_link_shared_binary - @run_sources="$^"; \ - run_target="$@"; \ - run_cmd="$(CC) $(CFLAGS) $(LDFLAGS) -o $@ $^ $(LIBS)"; \ - run_alias="BIN";\ - $(ll_pretty_run) - echo "after linking shared binary" -endef - -%.o: %.S +%.o:: %.S $(ll_pretty_build_c) -%.o: %.c +%.o:: %.c $(ll_pretty_build_c) -%.o: %.cc +%.o:: %.cc $(ll_pretty_build_cc) -%.o: %.cpp +%.o:: %.cpp $(ll_pretty_build_cc) +%:: %.cc -dep_files = $(wildcard .*.d) +%:: %.c -ifneq ("$(dep_files)", "") - include $(dep_files) -endif +%:: %.o -.PHONY: build $(subdirs) define ll_clean - +@$(MAKE) --no-print-directory -C $(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 $(LLBUILD) MAKEFLAGS= MAKEFILES= - +@$(MAKE) --no-print-directory -f $(LLBUILD)/Makefile.build ll_mainlevel -endef - endif diff --git a/llbuild/Makefile.subdir-sample b/llbuild/Makefile.subdir-sample index 43c8caa..9a81d86 100644 --- a/llbuild/Makefile.subdir-sample +++ b/llbuild/Makefile.subdir-sample @@ -1,10 +1,11 @@ CFLAGS += -Wall -W -fPIC LIBS = -ldl -lm -obj-default = ../lua libsb2.o libsb_env.o sb_alien.o +export CFLAGS LIBS -extra_targets = libsb2.so +obj-builtin = ../lua libsb2.o libsb_env.o sb_alien.o +shlib-libsb2.so = built-in.o + +extra_targets = shlib-libsb2.so -libsb2.so: built-in.o - $(ll_pretty_link_shared_library) diff --git a/llbuild/Makefile.toplevel-sample b/llbuild/Makefile.toplevel-sample index ad7ce88..3ef9cef 100644 --- a/llbuild/Makefile.toplevel-sample +++ b/llbuild/Makefile.toplevel-sample @@ -1,17 +1,24 @@ +# mandatory llbuild variables + +TOPDIR = $(CURDIR) +LLBUILD = $(TOPDIR)/llbuild +MAKEFILES = Makefile $(LLBUILD)/Makefile.include + +export TOPDIR LLBUILD MAKEFILES + +# user customizable variables + 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 LD -export CC CFLAGS MAKEFILES TOPDIR +# define a shared C language binary target -obj-default = lua preload utils -targets = utils/sb2init +bin-sample = main.o sample.o +extra_targets = bin-sample all: build @@ -25,22 +32,16 @@ build: configure @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 + install -d -m 755 $(prefix)/bin + install -c -m 755 sample $(prefix)/bin/ -CLEAN_FILES = $(targets) +CLEAN_FILES = $(extra_targets) clean: $(ll_clean) -include .config -include $(TOPDIR)/llbuild/Makefile.include +include $(LLBUILD)/Makefile.include diff --git a/llbuild/README b/llbuild/README new file mode 100644 index 0000000..46f44f4 --- /dev/null +++ b/llbuild/README @@ -0,0 +1,38 @@ +llbuild guide +************* + +Let's assume you have following directory structure: + +project/ + include/ + src/ + src/subsystem1 + src/sybsystem2 + + +* install the llbuild directory to project/llbuild +* copy project/llbuild/Makefile.toplevel-sample to project/Makefile +* create subdir Makefiles like this: + +project/src/Makefile: + +obj-builtin = subsystem1 subsystem2 + + +project/src/subsystem1/Makefile: + +obj-builtin = file1.o file2.o file3.o + + +project/src/subsystem2/Makefile: + +obj-builtin = file3.o file4.o + + +* Edit the target name in the toplevel Makefile to suit your needs, for example: + +project/Makefile: + +bin-project = src +extra_targets = bin-project + diff --git a/llbuild/llflock.c b/llbuild/llflock.c deleted file mode 100644 index b1bd746..0000000 --- a/llbuild/llflock.c +++ /dev/null @@ -1,116 +0,0 @@ -/* - 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); -} |