aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBjoern B. Brandenburg <bbb@cs.unc.edu>2010-11-06 16:20:13 -0400
committerBjoern B. Brandenburg <bbb@cs.unc.edu>2010-11-09 16:35:32 -0500
commit42e747e4fe5648967c1ead5ae327b5fbbe66f2e5 (patch)
tree44d58ef7b2458d3c71e52f6441077100c218e04f
parent35b88760be5b5dbda859f4697702efc0b3cd2663 (diff)
avoid including header files directly
The kernel warns against including header files directly. For good reason: our previous approach (just -I$KERNEL/include) caused all kinds of files to be included that should have come from /usr/include instead. This patch rewrites the Makfile so that the (few) needed headers are copied into the liblitmus src tree before compiling the library. This avoids having to specify the kernel include directories with -I, and also makes it easier to link against liblitmus (external applications do not need to know where the kernel is). Finally, this allows us to enable -Werror.
-rw-r--r--Makefile48
-rw-r--r--include/litmus.h6
-rw-r--r--src/syscalls.c11
3 files changed, 50 insertions, 15 deletions
diff --git a/Makefile b/Makefile
index 5a86b33..62bcf4e 100644
--- a/Makefile
+++ b/Makefile
@@ -19,9 +19,8 @@ LITMUS_KERNEL ?= ../litmus2010
19# Internal configuration. 19# Internal configuration.
20 20
21# compiler flags 21# compiler flags
22flags-debug = -Wall -g -Wdeclaration-after-statement 22flags-debug = -Wall -Werror -g -Wdeclaration-after-statement
23flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE 23flags-api = -D_XOPEN_SOURCE=600 -D_GNU_SOURCE
24flags-link-rt = -static
25 24
26# architecture-specific flags 25# architecture-specific flags
27flags-i386 = -m32 26flags-i386 = -m32
@@ -36,13 +35,17 @@ include-sparc64 = sparc
36# default: the arch name 35# default: the arch name
37include-${ARCH} ?= ${ARCH} 36include-${ARCH} ?= ${ARCH}
38 37
38# name of the file(s) that holds the actual system call numbers
39unistd-i386 = unistd.h unistd_32.h
40unistd-x86_64 = unistd.h unistd_64.h
41# default: unistd.h
42unistd-${ARCH} ?= unistd.h
43
39# where to find header files 44# where to find header files
40headers = -Iinclude \ 45headers = -Iinclude -Iarch/${include-${ARCH}}/include
41 -I${LITMUS_KERNEL}/include/ \
42 -I${LITMUS_KERNEL}/arch/${include-${ARCH}}/include
43 46
44# combine options 47# combine options
45CPPFLAGS = ${flags-api} ${flags-${ARCH}} ${headers} 48CPPFLAGS = ${flags-api} ${flags-${ARCH}} -DARCH=${ARCH} ${headers}
46CFLAGS = ${flags-debug} 49CFLAGS = ${flags-debug}
47LDFLAGS = ${flags-${ARCH}} 50LDFLAGS = ${flags-${ARCH}}
48 51
@@ -78,6 +81,7 @@ dump-config:
78 LITMUS_KERNEL "${LITMUS_KERNEL}" \ 81 LITMUS_KERNEL "${LITMUS_KERNEL}" \
79 CROSS_COMPILE "${CROSS_COMPILE}" \ 82 CROSS_COMPILE "${CROSS_COMPILE}" \
80 headers "${headers}" \ 83 headers "${headers}" \
84 "kernel headers" "${imported-headers}" \
81 CFLAGS "${CFLAGS}" \ 85 CFLAGS "${CFLAGS}" \
82 LDFLAGS "${LDFLAGS}" \ 86 LDFLAGS "${LDFLAGS}" \
83 CPPFLAGS "${CPPFLAGS}" \ 87 CPPFLAGS "${CPPFLAGS}" \
@@ -90,7 +94,35 @@ dump-config:
90clean: 94clean:
91 rm -f ${rt-apps} 95 rm -f ${rt-apps}
92 rm -f *.o *.d *.a test_catalog.inc 96 rm -f *.o *.d *.a test_catalog.inc
97 rm -f ${imported-headers}
98
99# ##############################################################################
100# Kernel headers.
101# The kernel does not like being #included directly, so let's
102# copy out the parts that we need.
103
104# Litmus headers
105include/litmus/%.h: ${LITMUS_KERNEL}/include/litmus/%.h
106 @mkdir -p ${dir $@}
107 cp $< $@
108
109# asm headers
110arch/${include-${ARCH}}/include/asm/%.h: \
111 ${LITMUS_KERNEL}/arch/${include-${ARCH}}/include/asm/%.h
112 @mkdir -p ${dir $@}
113 cp $< $@
114
115litmus-headers = include/litmus/rt_param.h include/litmus/unistd_32.h \
116 include/litmus/unistd_64.h
117
118unistd-headers = \
119 $(foreach file,${unistd-${ARCH}},arch/${include-${ARCH}}/include/asm/$(file))
120
121
122imported-headers = ${litmus-headers} ${unistd-headers}
93 123
124# Let's not copy these twice.
125.SECONDARY: ${imported-headers}
94 126
95# ############################################################################## 127# ##############################################################################
96# liblitmus 128# liblitmus
@@ -159,8 +191,8 @@ vpath %.c bin/ src/ tests/
159 191
160obj-all = ${sort ${foreach target,${all},${obj-${target}}}} 192obj-all = ${sort ${foreach target,${all},${obj-${target}}}}
161 193
162# rule to generate dependency files (straight from make manual) 194# rule to generate dependency files
163%.d: %.c 195%.d: %.c ${imported-headers}
164 @set -e; rm -f $@; \ 196 @set -e; rm -f $@; \
165 $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \ 197 $(CC) -MM $(CPPFLAGS) $< > $@.$$$$; \
166 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ 198 sed 's,\($*\)\.o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \
diff --git a/include/litmus.h b/include/litmus.h
index b798c92..c4c4129 100644
--- a/include/litmus.h
+++ b/include/litmus.h
@@ -5,13 +5,13 @@
5extern "C" { 5extern "C" {
6#endif 6#endif
7 7
8#include <sys/types.h>
9
8/* Include kernel header. 10/* Include kernel header.
9 * This is required for the rt_param 11 * This is required for the rt_param
10 * and control_page structures. 12 * and control_page structures.
11 */ 13 */
12#include <litmus/rt_param.h> 14#include "litmus/rt_param.h"
13
14#include <sys/types.h>
15 15
16#include "cycles.h" /* for null_call() */ 16#include "cycles.h" /* for null_call() */
17 17
diff --git a/src/syscalls.c b/src/syscalls.c
index 77a6277..c738ac4 100644
--- a/src/syscalls.c
+++ b/src/syscalls.c
@@ -1,13 +1,16 @@
1/* To get syscall() we need to define _GNU_SOURCE 1/* To get syscall() we need to define _GNU_SOURCE
2 * in modern glibc versions. 2 * in modern glibc versions.
3 */ 3 */
4
5/* imported from the kernel source tree */
6#include "asm/unistd.h"
7
8/* for syscall() */
4#include <unistd.h> 9#include <unistd.h>
5#include <linux/unistd.h>
6#include <sys/types.h>
7 10
8#include "litmus.h" 11//#include <sys/types.h>
9 12
10struct np_flag; 13#include "litmus.h"
11 14
12/* Syscall stub for setting RT mode and scheduling options */ 15/* Syscall stub for setting RT mode and scheduling options */
13 16