diff options
author | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-11-06 14:34:18 -0400 |
---|---|---|
committer | Bjoern B. Brandenburg <bbb@cs.unc.edu> | 2010-11-09 16:35:32 -0500 |
commit | 35b88760be5b5dbda859f4697702efc0b3cd2663 (patch) | |
tree | c8dd81078242dc41f4f5e765b52e59e944996873 | |
parent | b8c51805f5c71d1921ac7315125723b1e175ca5e (diff) |
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.
-rw-r--r-- | .gitignore | 10 | ||||
-rw-r--r-- | Makefile | 183 | ||||
-rw-r--r-- | SConstruct | 232 | ||||
-rw-r--r-- | tests/runner.c | 4 |
4 files changed, 178 insertions, 251 deletions
@@ -2,8 +2,11 @@ | |||
2 | *.o | 2 | *.o |
3 | *.a | 3 | *.a |
4 | 4 | ||
5 | |||
6 | |||
5 | # generated files | 7 | # generated files |
6 | tests/__test_catalog.inc | 8 | tests/test_catalog.inc |
9 | *.d | ||
7 | 10 | ||
8 | # executables | 11 | # executables |
9 | runtests | 12 | runtests |
@@ -20,8 +23,5 @@ rtspin | |||
20 | cycles | 23 | cycles |
21 | measure_syscall | 24 | measure_syscall |
22 | 25 | ||
23 | # scons files | 26 | # build system files |
24 | .sconsign.dblite | ||
25 | .sconf_temp/* | ||
26 | config.log | ||
27 | .config | 27 | .config |
@@ -1,17 +1,176 @@ | |||
1 | .PHONY: all-32 all-64 all-sparc clean purge | 1 | # figure out what kind of host we are running on |
2 | host-arch := $(shell uname -m | \ | ||
3 | sed -e s/i.86/i386/ -e s/sun4u/sparc64/ -e s/arm.*/arm/) | ||
2 | 4 | ||
3 | all-32: | 5 | # ############################################################################## |
4 | echo "Legacy warning: Building is done with scons." | 6 | # User variables |
5 | ARCH=x86 scons | ||
6 | all-64: | ||
7 | ARCH=x86_64 scons | ||
8 | 7 | ||
9 | all-sparc: | 8 | # user variables can be specified in the environment or in a .config file |
10 | ARCH=sparc64 scons | 9 | -include .config |
10 | |||
11 | # ARCH -- what architecture are we compiling for? | ||
12 | ARCH ?= ${host-arch} | ||
13 | |||
14 | # LITMUS_KERNEL -- where to find the litmus kernel? | ||
15 | LITMUS_KERNEL ?= ../litmus2010 | ||
16 | |||
17 | |||
18 | # ############################################################################## | ||
19 | # Internal configuration. | ||
20 | |||
21 | # compiler flags | ||
22 | flags-debug = -Wall -g -Wdeclaration-after-statement | ||
23 | flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE | ||
24 | flags-link-rt = -static | ||
25 | |||
26 | # architecture-specific flags | ||
27 | flags-i386 = -m32 | ||
28 | flags-x86_64 = -m64 | ||
29 | flags-sparc64 = -mcpu=v9 -m64 | ||
30 | # default: none | ||
31 | |||
32 | # name of the directory that has the arch headers in the Linux source | ||
33 | include-i386 = x86 | ||
34 | include-x86_64 = x86 | ||
35 | include-sparc64 = sparc | ||
36 | # default: the arch name | ||
37 | include-${ARCH} ?= ${ARCH} | ||
38 | |||
39 | # where to find header files | ||
40 | headers = -Iinclude \ | ||
41 | -I${LITMUS_KERNEL}/include/ \ | ||
42 | -I${LITMUS_KERNEL}/arch/${include-${ARCH}}/include | ||
43 | |||
44 | # combine options | ||
45 | CPPFLAGS = ${flags-api} ${flags-${ARCH}} ${headers} | ||
46 | CFLAGS = ${flags-debug} | ||
47 | LDFLAGS = ${flags-${ARCH}} | ||
48 | |||
49 | # how to link against liblitmus | ||
50 | liblitmus-flags = -L. -llitmus | ||
51 | |||
52 | # Force gcc instead of cc, but let the user specify a more specific version if | ||
53 | # desired. | ||
54 | ifeq (${CC},cc) | ||
55 | CC = gcc | ||
56 | endif | ||
57 | |||
58 | # incorporate cross-compiler (if any) | ||
59 | CC := ${CROSS_COMPILE}${CC} | ||
60 | LD := ${CROSS_COMPILE}${LD} | ||
61 | AR := ${CROSS_COMPILE}${AR} | ||
62 | |||
63 | # ############################################################################## | ||
64 | # Targets | ||
65 | |||
66 | all = lib ${rt-apps} | ||
67 | rt-apps = cycles base_task rt_launch rtspin release_ts measure_syscall \ | ||
68 | base_mt_task runtests | ||
69 | |||
70 | .PHONY: all lib clean dump-config | ||
71 | |||
72 | all: ${all} | ||
73 | |||
74 | dump-config: | ||
75 | @echo Build configuration: | ||
76 | @printf "%-15s= %-20s\n" \ | ||
77 | ARCH ${ARCH} \ | ||
78 | LITMUS_KERNEL "${LITMUS_KERNEL}" \ | ||
79 | CROSS_COMPILE "${CROSS_COMPILE}" \ | ||
80 | headers "${headers}" \ | ||
81 | CFLAGS "${CFLAGS}" \ | ||
82 | LDFLAGS "${LDFLAGS}" \ | ||
83 | CPPFLAGS "${CPPFLAGS}" \ | ||
84 | CC "${CC}" \ | ||
85 | CPP "${CPP}" \ | ||
86 | LD "${LD}" \ | ||
87 | AR "${AR}" \ | ||
88 | obj-all "${obj-all}" | ||
11 | 89 | ||
12 | clean: | 90 | clean: |
13 | echo "Legacy warning: Building is now done with scons." | 91 | rm -f ${rt-apps} |
14 | scons -c | 92 | rm -f *.o *.d *.a test_catalog.inc |
93 | |||
94 | |||
95 | # ############################################################################## | ||
96 | # liblitmus | ||
97 | |||
98 | lib: liblitmus.a | ||
99 | |||
100 | # all .c file in src/ are linked into liblitmus | ||
101 | vpath %.c src/ | ||
102 | obj-lib = $(patsubst src/%.c,%.o,$(wildcard src/*.c)) | ||
103 | |||
104 | liblitmus.a: ${obj-lib} | ||
105 | ${AR} rcs $@ $+ | ||
106 | |||
107 | # ############################################################################## | ||
108 | # Tests suite. | ||
109 | |||
110 | # tests are found in tests/ | ||
111 | vpath %.c tests/ | ||
112 | |||
113 | src-runtests = $(wildcard tests/*.c) | ||
114 | obj-runtests = $(patsubst tests/%.c,%.o,${src-runtests}) | ||
115 | |||
116 | # generate list of tests automatically | ||
117 | test_catalog.inc: $(filter-out tests/runner.c,${src-runtests}) | ||
118 | tests/make_catalog.py $+ > $@ | ||
119 | |||
120 | .SECONDARY: test_catalog.inc | ||
121 | |||
122 | tests/runner.c: test_catalog.inc | ||
123 | |||
124 | |||
125 | # ############################################################################## | ||
126 | # Tools that link with liblitmus | ||
127 | |||
128 | # these source files are found in bin/ | ||
129 | vpath %.c bin/ | ||
130 | |||
131 | obj-cycles = cycles.o | ||
132 | |||
133 | obj-base_task = base_task.o | ||
134 | |||
135 | obj-base_mt_task = base_mt_task.o | ||
136 | ldf-base_mt_task = -pthread | ||
137 | |||
138 | obj-rt_launch = rt_launch.o common.o | ||
139 | |||
140 | obj-rtspin = rtspin.o common.o | ||
141 | lib-rtspin = -lrt | ||
142 | |||
143 | obj-release_ts = release_ts.o | ||
144 | |||
145 | obj-measure_syscall = null_call.o | ||
146 | lib-measure_syscall = -lm | ||
147 | |||
148 | # ############################################################################## | ||
149 | # Build everything that depends on liblitmus. | ||
150 | |||
151 | .SECONDEXPANSION: | ||
152 | ${rt-apps}: $${obj-$$@} liblitmus.a | ||
153 | $(CC) -o $@ $(LDFLAGS) ${ldf-$@} $(filter-out liblitmus.a,$+) $(LOADLIBS) $(LDLIBS) ${lib-$@} ${liblitmus-flags} | ||
154 | |||
155 | # ############################################################################## | ||
156 | # Dependency resolution. | ||
157 | |||
158 | vpath %.c bin/ src/ tests/ | ||
159 | |||
160 | obj-all = ${sort ${foreach target,${all},${obj-${target}}}} | ||
161 | |||
162 | # rule to generate dependency files (straight from make manual) | ||
163 | %.d: %.c | ||
164 | @set -e; rm -f $@; \ | ||
165 | $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ | ||
166 | sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ | ||
167 | rm -f $@.$$$$ | ||
168 | |||
169 | ifeq ($(MAKECMDGOALS),) | ||
170 | MAKECMDGOALS += all | ||
171 | endif | ||
172 | |||
173 | ifneq ($(filter-out dump-config clean,$(MAKECMDGOALS)),) | ||
174 | -include ${obj-all:.o=.d} | ||
175 | endif | ||
15 | 176 | ||
16 | purge: clean | ||
17 | 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 @@ | |||
1 | Help(""" | ||
2 | ============================================= | ||
3 | liblitmus --- The LITMUS^RT Userspace Library | ||
4 | |||
5 | There are a number of user-configurable build | ||
6 | variables. These can either be set on the | ||
7 | command line (e.g., scons ARCH=x86) or read | ||
8 | from a local configuration file (.config). | ||
9 | |||
10 | Run 'scons --dump-config' to see the final | ||
11 | build configuration. | ||
12 | |||
13 | """) | ||
14 | |||
15 | import os | ||
16 | (ostype, _, _, _, arch) = os.uname() | ||
17 | |||
18 | # sanity check | ||
19 | if ostype != 'Linux': | ||
20 | print 'Error: Building liblitmus is only supported on Linux.' | ||
21 | Exit(1) | ||
22 | |||
23 | |||
24 | # ##################################################################### | ||
25 | # Internal configuration. | ||
26 | DEBUG_FLAGS = '-Wall -g -Wdeclaration-after-statement' | ||
27 | API_FLAGS = '-D_XOPEN_SOURCE=600 -D_GNU_SOURCE' | ||
28 | X86_32_FLAGS = '-m32' | ||
29 | X86_64_FLAGS = '-m64' | ||
30 | V9_FLAGS = '-mcpu=v9 -m64' | ||
31 | |||
32 | SUPPORTED_ARCHS = { | ||
33 | 'sparc64' : V9_FLAGS, | ||
34 | 'x86' : X86_32_FLAGS, | ||
35 | 'x86_64' : X86_64_FLAGS, | ||
36 | } | ||
37 | |||
38 | ARCH_ALIAS = { | ||
39 | 'i686' : 'x86' | ||
40 | } | ||
41 | |||
42 | # name of the directory that has the arch headers in the Linux source | ||
43 | INCLUDE_ARCH = { | ||
44 | 'sparc64' : 'sparc', | ||
45 | 'x86' : 'x86', | ||
46 | 'x86_64' : 'x86', | ||
47 | } | ||
48 | |||
49 | INCLUDE_DIRS = [ | ||
50 | # library headers | ||
51 | 'include/', | ||
52 | # Linux kernel headers | ||
53 | '${LITMUS_KERNEL}/include/', | ||
54 | # Linux architecture-specific kernel headers | ||
55 | '$LITMUS_KERNEL/arch/${INCLUDE_ARCH}/include' | ||
56 | ] | ||
57 | |||
58 | # ##################################################################### | ||
59 | # User configuration. | ||
60 | |||
61 | vars = Variables('.config', ARGUMENTS) | ||
62 | |||
63 | vars.AddVariables( | ||
64 | PathVariable('LITMUS_KERNEL', | ||
65 | 'Where to find the LITMUS^RT kernel.', | ||
66 | '../litmus2010'), | ||
67 | |||
68 | EnumVariable('ARCH', | ||
69 | 'Target architecture.', | ||
70 | arch, | ||
71 | SUPPORTED_ARCHS.keys() + ARCH_ALIAS.keys()), | ||
72 | ) | ||
73 | |||
74 | AddOption('--dump-config', | ||
75 | dest='dump', | ||
76 | action='store_true', | ||
77 | default=False, | ||
78 | help="dump the build configuration and exit") | ||
79 | |||
80 | # ##################################################################### | ||
81 | # Build configuration. | ||
82 | |||
83 | env = Environment(variables = vars) | ||
84 | |||
85 | # Check what we are building for. | ||
86 | arch = env['ARCH'] | ||
87 | |||
88 | # replace if the arch has an alternative name | ||
89 | if arch in ARCH_ALIAS: | ||
90 | arch = ARCH_ALIAS[arch] | ||
91 | env['ARCH'] = arch | ||
92 | |||
93 | # Get include directory for arch. | ||
94 | env['INCLUDE_ARCH'] = INCLUDE_ARCH[arch] | ||
95 | |||
96 | arch_flags = Split(SUPPORTED_ARCHS[arch]) | ||
97 | dbg_flags = Split(DEBUG_FLAGS) | ||
98 | api_flags = Split(API_FLAGS) | ||
99 | |||
100 | # Set up environment | ||
101 | env.Replace( | ||
102 | CC = 'gcc', | ||
103 | CPPPATH = INCLUDE_DIRS, | ||
104 | CCFLAGS = dbg_flags + api_flags + arch_flags, | ||
105 | LINKFLAGS = arch_flags, | ||
106 | ) | ||
107 | |||
108 | def dump_config(env): | ||
109 | def dump(key): | ||
110 | print "%15s = %s" % (key, env.subst("${%s}" % key)) | ||
111 | |||
112 | dump('ARCH') | ||
113 | dump('LITMUS_KERNEL') | ||
114 | dump('CPPPATH') | ||
115 | dump('CCFLAGS') | ||
116 | dump('LINKFLAGS') | ||
117 | |||
118 | if GetOption('dump'): | ||
119 | print "\n" | ||
120 | print "Build Configuration:" | ||
121 | dump_config(env) | ||
122 | print "\n" | ||
123 | Exit(0) | ||
124 | |||
125 | # ##################################################################### | ||
126 | # Build checks. | ||
127 | |||
128 | def CheckSyscallNr(context): | ||
129 | context.Message('Checking for LITMUS^RT syscall numbers... ') | ||
130 | nrSrc = """ | ||
131 | #include <linux/unistd.h> | ||
132 | int main(int argc, char **argv) | ||
133 | { | ||
134 | return __NR_set_rt_task_param; | ||
135 | } | ||
136 | """ | ||
137 | result = context.TryLink(nrSrc, '.c') | ||
138 | context.Result(result) | ||
139 | return result | ||
140 | |||
141 | |||
142 | def abort(msg, help=None): | ||
143 | print "Error: %s" % env.subst(msg) | ||
144 | print "-" * 80 | ||
145 | print "This is the build configuration in use:" | ||
146 | dump_config(env) | ||
147 | if help: | ||
148 | print "-" * 80 | ||
149 | print env.subst(help) | ||
150 | print "\n" | ||
151 | Exit(1) | ||
152 | |||
153 | # Check compile environment | ||
154 | if not (env.GetOption('clean') or env.GetOption('help')): | ||
155 | print env.subst('Building ${ARCH} binaries.') | ||
156 | # Check for kernel headers. | ||
157 | conf = Configure(env, custom_tests = {'CheckSyscallNr' : CheckSyscallNr}) | ||
158 | |||
159 | conf.CheckCHeader('linux/unistd.h') or \ | ||
160 | abort("Cannot find kernel headers in '$LITMUS_KERNEL'", | ||
161 | "Please ensure that LITMUS_KERNEL in .config is set to a valid path.") | ||
162 | |||
163 | conf.CheckCHeader('litmus/rt_param.h') or \ | ||
164 | abort("Cannot find LITMUS^RT headers in '$LITMUS_KERNEL'", | ||
165 | "Please ensure sure that the kernel in '$LITMUS_KERNEL'" | ||
166 | " is a LITMUS^RT kernel.") | ||
167 | |||
168 | conf.CheckSyscallNr() or \ | ||
169 | abort("The LITMUS^RT syscall numbers are not available.", | ||
170 | "Please ensure sure that the kernel in '$LITMUS_KERNEL'" | ||
171 | " is a LITMUS^RT kernel.") | ||
172 | |||
173 | env = conf.Finish() | ||
174 | |||
175 | # ##################################################################### | ||
176 | # Derived environments | ||
177 | |||
178 | # link with liblitmus | ||
179 | rt = env.Clone( | ||
180 | LIBS = Split('litmus rt'), | ||
181 | LIBPATH = '.' | ||
182 | ) | ||
183 | rt.Append(LINKFLAGS = '-static') | ||
184 | |||
185 | |||
186 | # link with math lib | ||
187 | rtm = rt.Clone() | ||
188 | rtm.Append(LIBS = ['m']) | ||
189 | |||
190 | # multithreaded real-time tasks | ||
191 | mtrt = rt.Clone() | ||
192 | mtrt.Append(LINKFLAGS = '-pthread') | ||
193 | |||
194 | # ##################################################################### | ||
195 | # Targets: liblitmus | ||
196 | # All the files in src/ are part of the library. | ||
197 | env.Library('litmus', | ||
198 | ['src/kernel_iface.c', 'src/litmus.c', | ||
199 | 'src/syscalls.c', 'src/task.c']) | ||
200 | |||
201 | # ##################################################################### | ||
202 | # Targets: simple tools that do not depend on liblitmus | ||
203 | env.Program('cycles', 'bin/cycles.c') | ||
204 | |||
205 | # ##################################################################### | ||
206 | # Targets: tools that depend on liblitmus | ||
207 | rt.Program('base_task', 'bin/base_task.c') | ||
208 | mtrt.Program('base_mt_task', 'bin/base_mt_task.c') | ||
209 | rt.Program('rt_launch', ['bin/rt_launch.c', 'bin/common.c']) | ||
210 | rt.Program('rtspin', ['bin/rtspin.c', 'bin/common.c']) | ||
211 | rt.Program('release_ts', 'bin/release_ts.c') | ||
212 | rtm.Program('measure_syscall', 'bin/null_call.c') | ||
213 | |||
214 | |||
215 | # ##################################################################### | ||
216 | # Test suite. | ||
217 | |||
218 | mkc = Builder(action = 'tests/make_catalog.py $SOURCES > $TARGET') | ||
219 | test = mtrt.Clone() | ||
220 | test.Append(BUILDERS = {'TestCatalog' : mkc}) | ||
221 | test.Append(CPPPATH = ['tests/']) | ||
222 | |||
223 | catalog = test.TestCatalog('tests/__test_catalog.inc', Glob('tests/*.c')) | ||
224 | test.Program('runtests', Glob('tests/*.c')) | ||
225 | |||
226 | # ##################################################################### | ||
227 | # Additional Help | ||
228 | |||
229 | Help("Build Variables\n") | ||
230 | Help("---------------\n") | ||
231 | Help(vars.GenerateHelpText(env)) | ||
232 | |||
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 @@ | |||
7 | #include <stdio.h> | 7 | #include <stdio.h> |
8 | 8 | ||
9 | 9 | ||
10 | /* auto generated by SConstruct */ | 10 | /* auto generated by Makefile */ |
11 | #include "__test_catalog.inc" | 11 | #include "../test_catalog.inc" |
12 | 12 | ||
13 | #include "litmus.h" | 13 | #include "litmus.h" |
14 | 14 | ||