From 35b88760be5b5dbda859f4697702efc0b3cd2663 Mon Sep 17 00:00:00 2001 From: "Bjoern B. Brandenburg" Date: Sat, 6 Nov 2010 14:34:18 -0400 Subject: refactor: switch back from SCons to make We originally switched from make to scons because 1) our makefiles were not very good; 2) SCons promised to make maintaining the build system simpler. Unfortunately, SCons has become more and more difficult to deal with as we moved to supporting several architecture and cross compilation, to the extend that we ended up re-creating make functionality in SCons. So let's switch back to make using a "clean" Makefile. Thanks a lot to Andrea Bastoni and Chris Kenna for feedback on previous iterations of these patches. --- .gitignore | 10 +-- Makefile | 183 ++++++++++++++++++++++++++++++++++++++++++--- SConstruct | 232 --------------------------------------------------------- tests/runner.c | 4 +- 4 files changed, 178 insertions(+), 251 deletions(-) delete mode 100644 SConstruct diff --git a/.gitignore b/.gitignore index f420aa3..7f419d0 100644 --- a/.gitignore +++ b/.gitignore @@ -2,8 +2,11 @@ *.o *.a + + # generated files -tests/__test_catalog.inc +tests/test_catalog.inc +*.d # executables runtests @@ -20,8 +23,5 @@ rtspin cycles measure_syscall -# scons files -.sconsign.dblite -.sconf_temp/* -config.log +# build system files .config diff --git a/Makefile b/Makefile index bb8fffa..5a86b33 100644 --- a/Makefile +++ b/Makefile @@ -1,17 +1,176 @@ -.PHONY: all-32 all-64 all-sparc clean purge +# figure out what kind of host we are running on +host-arch := $(shell uname -m | \ + sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/) -all-32: - echo "Legacy warning: Building is done with scons." - ARCH=x86 scons -all-64: - ARCH=x86_64 scons +# ############################################################################## +# User variables -all-sparc: - ARCH=sparc64 scons +# user variables can be specified in the environment or in a .config file +-include .config + +# ARCH -- what architecture are we compiling for? +ARCH ?= ${host-arch} + +# LITMUS_KERNEL -- where to find the litmus kernel? +LITMUS_KERNEL ?= ../litmus2010 + + +# ############################################################################## +# Internal configuration. + +# compiler flags +flags-debug = -Wall -g -Wdeclaration-after-statement +flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE +flags-link-rt = -static + +# architecture-specific flags +flags-i386 = -m32 +flags-x86_64 = -m64 +flags-sparc64 = -mcpu=v9 -m64 +# default: none + +# name of the directory that has the arch headers in the Linux source +include-i386 = x86 +include-x86_64 = x86 +include-sparc64 = sparc +# default: the arch name +include-${ARCH} ?= ${ARCH} + +# where to find header files +headers = -Iinclude \ + -I${LITMUS_KERNEL}/include/ \ + -I${LITMUS_KERNEL}/arch/${include-${ARCH}}/include + +# combine options +CPPFLAGS = ${flags-api} ${flags-${ARCH}} ${headers} +CFLAGS = ${flags-debug} +LDFLAGS = ${flags-${ARCH}} + +# how to link against liblitmus +liblitmus-flags = -L. -llitmus + +# Force gcc instead of cc, but let the user specify a more specific version if +# desired. +ifeq (${CC},cc) +CC = gcc +endif + +# incorporate cross-compiler (if any) +CC := ${CROSS_COMPILE}${CC} +LD := ${CROSS_COMPILE}${LD} +AR := ${CROSS_COMPILE}${AR} + +# ############################################################################## +# Targets + +all = lib ${rt-apps} +rt-apps = cycles base_task rt_launch rtspin release_ts measure_syscall \ + base_mt_task runtests + +.PHONY: all lib clean dump-config + +all: ${all} + +dump-config: + @echo Build configuration: + @printf "%-15s= %-20s\n" \ + ARCH ${ARCH} \ + LITMUS_KERNEL "${LITMUS_KERNEL}" \ + CROSS_COMPILE "${CROSS_COMPILE}" \ + headers "${headers}" \ + CFLAGS "${CFLAGS}" \ + LDFLAGS "${LDFLAGS}" \ + CPPFLAGS "${CPPFLAGS}" \ + CC "${CC}" \ + CPP "${CPP}" \ + LD "${LD}" \ + AR "${AR}" \ + obj-all "${obj-all}" clean: - echo "Legacy warning: Building is now done with scons." - scons -c + rm -f ${rt-apps} + rm -f *.o *.d *.a test_catalog.inc + + +# ############################################################################## +# liblitmus + +lib: liblitmus.a + +# all .c file in src/ are linked into liblitmus +vpath %.c src/ +obj-lib = $(patsubst src/%.c,%.o,$(wildcard src/*.c)) + +liblitmus.a: ${obj-lib} + ${AR} rcs $@ $+ + +# ############################################################################## +# Tests suite. + +# tests are found in tests/ +vpath %.c tests/ + +src-runtests = $(wildcard tests/*.c) +obj-runtests = $(patsubst tests/%.c,%.o,${src-runtests}) + +# generate list of tests automatically +test_catalog.inc: $(filter-out tests/runner.c,${src-runtests}) + tests/make_catalog.py $+ > $@ + +.SECONDARY: test_catalog.inc + +tests/runner.c: test_catalog.inc + + +# ############################################################################## +# Tools that link with liblitmus + +# these source files are found in bin/ +vpath %.c bin/ + +obj-cycles = cycles.o + +obj-base_task = base_task.o + +obj-base_mt_task = base_mt_task.o +ldf-base_mt_task = -pthread + +obj-rt_launch = rt_launch.o common.o + +obj-rtspin = rtspin.o common.o +lib-rtspin = -lrt + +obj-release_ts = release_ts.o + +obj-measure_syscall = null_call.o +lib-measure_syscall = -lm + +# ############################################################################## +# Build everything that depends on liblitmus. + +.SECONDEXPANSION: +${rt-apps}: $${obj-$$@} liblitmus.a + $(CC) -o $@ $(LDFLAGS) ${ldf-$@} $(filter-out liblitmus.a,$+) $(LOADLIBS) $(LDLIBS) ${lib-$@} ${liblitmus-flags} + +# ############################################################################## +# Dependency resolution. + +vpath %.c bin/ src/ tests/ + +obj-all = ${sort ${foreach target,${all},${obj-${target}}}} + +# rule to generate dependency files (straight from make manual) +%.d: %.c + @set -e; rm -f $@; \ + $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ + sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ + +ifeq ($(MAKECMDGOALS),) +MAKECMDGOALS += all +endif + +ifneq ($(filter-out dump-config clean,$(MAKECMDGOALS)),) +-include ${obj-all:.o=.d} +endif -purge: clean - rm -rf .sconf_temp .sconsign.dblite diff --git a/SConstruct b/SConstruct deleted file mode 100644 index c41e41e..0000000 --- a/SConstruct +++ /dev/null @@ -1,232 +0,0 @@ -Help(""" -============================================= -liblitmus --- The LITMUS^RT Userspace Library - -There are a number of user-configurable build -variables. These can either be set on the -command line (e.g., scons ARCH=x86) or read -from a local configuration file (.config). - -Run 'scons --dump-config' to see the final -build configuration. - -""") - -import os -(ostype, _, _, _, arch) = os.uname() - -# sanity check -if ostype != 'Linux': - print 'Error: Building liblitmus is only supported on Linux.' - Exit(1) - - -# ##################################################################### -# Internal configuration. -DEBUG_FLAGS = '-Wall -g -Wdeclaration-after-statement' -API_FLAGS = '-D_XOPEN_SOURCE=600 -D_GNU_SOURCE' -X86_32_FLAGS = '-m32' -X86_64_FLAGS = '-m64' -V9_FLAGS = '-mcpu=v9 -m64' - -SUPPORTED_ARCHS = { - 'sparc64' : V9_FLAGS, - 'x86' : X86_32_FLAGS, - 'x86_64' : X86_64_FLAGS, -} - -ARCH_ALIAS = { - 'i686' : 'x86' -} - -# name of the directory that has the arch headers in the Linux source -INCLUDE_ARCH = { - 'sparc64' : 'sparc', - 'x86' : 'x86', - 'x86_64' : 'x86', -} - -INCLUDE_DIRS = [ - # library headers - 'include/', - # Linux kernel headers - '${LITMUS_KERNEL}/include/', - # Linux architecture-specific kernel headers - '$LITMUS_KERNEL/arch/${INCLUDE_ARCH}/include' - ] - -# ##################################################################### -# User configuration. - -vars = Variables('.config', ARGUMENTS) - -vars.AddVariables( - PathVariable('LITMUS_KERNEL', - 'Where to find the LITMUS^RT kernel.', - '../litmus2010'), - - EnumVariable('ARCH', - 'Target architecture.', - arch, - SUPPORTED_ARCHS.keys() + ARCH_ALIAS.keys()), -) - -AddOption('--dump-config', - dest='dump', - action='store_true', - default=False, - help="dump the build configuration and exit") - -# ##################################################################### -# Build configuration. - -env = Environment(variables = vars) - -# Check what we are building for. -arch = env['ARCH'] - -# replace if the arch has an alternative name -if arch in ARCH_ALIAS: - arch = ARCH_ALIAS[arch] - env['ARCH'] = arch - -# Get include directory for arch. -env['INCLUDE_ARCH'] = INCLUDE_ARCH[arch] - -arch_flags = Split(SUPPORTED_ARCHS[arch]) -dbg_flags = Split(DEBUG_FLAGS) -api_flags = Split(API_FLAGS) - -# Set up environment -env.Replace( - CC = 'gcc', - CPPPATH = INCLUDE_DIRS, - CCFLAGS = dbg_flags + api_flags + arch_flags, - LINKFLAGS = arch_flags, -) - -def dump_config(env): - def dump(key): - print "%15s = %s" % (key, env.subst("${%s}" % key)) - - dump('ARCH') - dump('LITMUS_KERNEL') - dump('CPPPATH') - dump('CCFLAGS') - dump('LINKFLAGS') - -if GetOption('dump'): - print "\n" - print "Build Configuration:" - dump_config(env) - print "\n" - Exit(0) - -# ##################################################################### -# Build checks. - -def CheckSyscallNr(context): - context.Message('Checking for LITMUS^RT syscall numbers... ') - nrSrc = """ -#include -int main(int argc, char **argv) -{ - return __NR_set_rt_task_param; -} -""" - result = context.TryLink(nrSrc, '.c') - context.Result(result) - return result - - -def abort(msg, help=None): - print "Error: %s" % env.subst(msg) - print "-" * 80 - print "This is the build configuration in use:" - dump_config(env) - if help: - print "-" * 80 - print env.subst(help) - print "\n" - Exit(1) - -# Check compile environment -if not (env.GetOption('clean') or env.GetOption('help')): - print env.subst('Building ${ARCH} binaries.') - # Check for kernel headers. - conf = Configure(env, custom_tests = {'CheckSyscallNr' : CheckSyscallNr}) - - conf.CheckCHeader('linux/unistd.h') or \ - abort("Cannot find kernel headers in '$LITMUS_KERNEL'", - "Please ensure that LITMUS_KERNEL in .config is set to a valid path.") - - conf.CheckCHeader('litmus/rt_param.h') or \ - abort("Cannot find LITMUS^RT headers in '$LITMUS_KERNEL'", - "Please ensure sure that the kernel in '$LITMUS_KERNEL'" - " is a LITMUS^RT kernel.") - - conf.CheckSyscallNr() or \ - abort("The LITMUS^RT syscall numbers are not available.", - "Please ensure sure that the kernel in '$LITMUS_KERNEL'" - " is a LITMUS^RT kernel.") - - env = conf.Finish() - -# ##################################################################### -# Derived environments - -# link with liblitmus -rt = env.Clone( - LIBS = Split('litmus rt'), - LIBPATH = '.' -) -rt.Append(LINKFLAGS = '-static') - - -# link with math lib -rtm = rt.Clone() -rtm.Append(LIBS = ['m']) - -# multithreaded real-time tasks -mtrt = rt.Clone() -mtrt.Append(LINKFLAGS = '-pthread') - -# ##################################################################### -# Targets: liblitmus -# All the files in src/ are part of the library. -env.Library('litmus', - ['src/kernel_iface.c', 'src/litmus.c', - 'src/syscalls.c', 'src/task.c']) - -# ##################################################################### -# Targets: simple tools that do not depend on liblitmus -env.Program('cycles', 'bin/cycles.c') - -# ##################################################################### -# Targets: tools that depend on liblitmus -rt.Program('base_task', 'bin/base_task.c') -mtrt.Program('base_mt_task', 'bin/base_mt_task.c') -rt.Program('rt_launch', ['bin/rt_launch.c', 'bin/common.c']) -rt.Program('rtspin', ['bin/rtspin.c', 'bin/common.c']) -rt.Program('release_ts', 'bin/release_ts.c') -rtm.Program('measure_syscall', 'bin/null_call.c') - - -# ##################################################################### -# Test suite. - -mkc = Builder(action = 'tests/make_catalog.py $SOURCES > $TARGET') -test = mtrt.Clone() -test.Append(BUILDERS = {'TestCatalog' : mkc}) -test.Append(CPPPATH = ['tests/']) - -catalog = test.TestCatalog('tests/__test_catalog.inc', Glob('tests/*.c')) -test.Program('runtests', Glob('tests/*.c')) - -# ##################################################################### -# Additional Help - -Help("Build Variables\n") -Help("---------------\n") -Help(vars.GenerateHelpText(env)) - diff --git a/tests/runner.c b/tests/runner.c index f2e42b2..ccf8d46 100644 --- a/tests/runner.c +++ b/tests/runner.c @@ -7,8 +7,8 @@ #include -/* auto generated by SConstruct */ -#include "__test_catalog.inc" +/* auto generated by Makefile */ +#include "../test_catalog.inc" #include "litmus.h" -- cgit v1.2.2