aboutsummaryrefslogtreecommitdiffstats
path: root/Makefile
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 /Makefile
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.
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile48
1 files changed, 40 insertions, 8 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' < $@.$$$$ > $@; \