Makefile revision 1b8a2eaac9978e1f9a829e5e38dc39c892c77c75
1# Copyright (c) 2002, Intel Corporation. All rights reserved.
2# Created by:  inaky.perez-gonzalez REMOVE-THIS AT intel DOT com
3# This file is licensed under the GPL license.  For the full content
4# of this license, see the COPYING file at the top level of this
5# source tree.
6#
7# Kind of a little bit bastardized automakefile ... This is the
8# temporary glue to hold it all together; once our needs change or we
9# need something more advanced, we'll implement it.
10#
11# So far, I understand Make is not the best language, but I felt lazy
12# today and wanted to use the default rules of automake [did I alredy
13# mentioned I am bastardizing it?].
14#
15# Ok, I don't use Automake any more
16#
17# Added patch from dank REMOVE-THIS AT kegel DOT com
18
19top_builddir = .
20
21LOGFILE = $(top_builddir)/logfile
22
23LDFLAGS := $(shell cat LDFLAGS | grep -v \^\#)
24
25RUN_TESTS := $(shell $(top_builddir)/locate-test \
26             --execs $(top_builddir)/$(POSIX_TARGET))
27BUILD_TESTS := $(shell $(top_builddir)/locate-test \
28               --buildable $(top_builddir)/$(POSIX_TARGET))
29FUNCTIONAL_MAKE := $(shell $(top_builddir)/locate-test --fmake)
30FUNCTIONAL_RUN := $(shell $(top_builddir)/locate-test --frun)
31STRESS_MAKE := $(shell $(top_builddir)/locate-test --smake)
32STRESS_RUN := $(shell $(top_builddir)/locate-test --srun)
33PWD := $(shell pwd)
34
35all: build-tests run-tests 
36
37build-tests: $(BUILD_TESTS:.c=.test)
38run-tests: $(RUN_TESTS:.test=.run-test)
39
40functional-tests: functional-make functional-run
41stress-tests: stress-make stress-run
42
43tests-pretty:
44	$(MAKE) all | column -t -s:
45
46CFLAGS = -g -O2 -Wall -Werror -D_POSIX_C_SOURCE=200112L
47
48# add -std=c99, -std=gnu99 if compiler supports it (gcc-2.95.3 does not).
49check_gcc = $(shell if $(CC) $(1) -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi)
50CFLAGS += $(call check_gcc,-std=c99,)
51CFLAGS += $(call check_gcc,-std=gnu99,)
52
53INCLUDE = -Iinclude
54
55# FIXME: exaust cmd line length
56clean:
57	@rm -f $(LOGFILE)
58# Built runnable tests
59	@find $(top_builddir) -iname \*.test | xargs -n 40 rm -f {}
60	@find $(top_builddir) -iname \*~ -o -iname \*.o | xargs -n 40 rm -f {}
61	@$(foreach DIR,$(FUNCTIONAL_MAKE),make -C $(DIR) clean >> /dev/null 2>&1;) >> /dev/null 2>&1
62
63# Rule to run a build test
64# If the .o doesn't export main, then we don't need to link
65.PRECIOUS: %.test
66%.test: %.o
67	@COMPLOG=$(LOGFILE).$$$$; \
68	[ -f $< ] || exit 0; \
69	nm -g --defined-only $< | grep -q " T main" || exit 0; \
70	if $(CC) $(CFLAGS) $< -o $@ $(LDFLAGS) > $$COMPLOG 2>&1; \
71	then \
72		echo "$(@:.test=): link: PASS" | tee -a $(LOGFILE); \
73	else \
74		( \
75			echo "$(@:.test=): link: FAILED. Linker output: "; \
76			cat $$COMPLOG; \
77		) >> $(LOGFILE); \
78		echo "$(@:.test=): link: FAILED "; \
79	fi; \
80	rm -f $$COMPLOG;
81
82# Rule to run an executable test
83# If it is only a build test, then the binary exist, so we don't need to run
84.PHONY: %.run-test
85%.run-test: %.test
86	@COMPLOG=$(LOGFILE).$$$$; \
87	[ -f $< ] || exit 0; \
88	$< > $$COMPLOG 2>&1; \
89	RESULT=$$?; \
90	if [ $$RESULT == 1 ]; \
91	then \
92		MSG="FAILED"; \
93	fi; \
94	if [ $$RESULT == 2 ]; \
95	then \
96		MSG="UNRESOLVED"; \
97	fi; \
98	if [ $$RESULT == 4 ]; \
99	then \
100		MSG="UNSUPPORTED"; \
101	fi; \
102	if [ $$RESULT == 5 ]; \
103	then \
104		MSG="UNTESTED"; \
105	fi; \
106	if [ $$RESULT == 0 ]; \
107	then \
108		echo "$(@:.run-test=): execution: PASS" | tee -a $(LOGFILE); \
109	else \
110		( \
111			echo "$(@:.run-test=): execution: $$MSG: Output: "; \
112			cat $$COMPLOG; \
113		) >> $(LOGFILE); \
114		echo "$(@:.run-test=): execution: $$MSG "; \
115	fi; \
116	rm -f $$COMPLOG;
117
118%.run-test: %.sh
119	@COMPLOG=$(LOGFILE).$$$$; \
120	chmod +x $<; \
121	if $< > $$COMPLOG 2>&1; \
122	then \
123		echo "$(@:.run-test=): execution: PASS" | tee -a $(LOGFILE);\
124	else \
125		( \
126			echo "$(@:.run-test=): execution: FAILED: Output: ";\
127			cat $$COMPLOG; \
128		) >> $(LOGFILE); \
129		echo "$(@:.run-test=): execution: FAILED "; \
130	fi; \
131	rm -f $$COMPLOG;
132
133
134.PRECIOUS: %.o
135%.o: %.c
136	@COMPLOG=$(LOGFILE).$$$$; \
137	if $(CC) $(CFLAGS) $(INCLUDE) -c $< -o $@ $(LDFLAGS) > $$COMPLOG 2>&1; \
138	then \
139		echo "$(@:.o=): build: PASS" | tee -a $(LOGFILE); \
140	else \
141		( \
142			echo "$(@:.o=): build: FAILED: Compiler output: "; \
143			cat $$COMPLOG; \
144		) >> $(LOGFILE); \
145		echo "$(@:.o=): build: FAILED "; \
146	fi; \
147	rm -f $$COMPLOG;
148
149# Functional/Stress test build and execution
150functional-make:
151	$(foreach DIR,$(FUNCTIONAL_MAKE),make -C $(DIR);)
152
153.PHONY: $(FUNCTIONAL_RUN)
154
155functional-run: $(FUNCTIONAL_RUN)
156
157$(FUNCTIONAL_RUN): 
158	cd $@; ./run.sh
159	cd $(PWD)
160
161stress-make:
162	$(foreach DIR,$(STRESS_MAKE),make -C $(DIR);)
163
164.PHONY: $(STRESS_RUN)
165
166stress-run: $(STRESS_RUN)
167
168$(STRESS_RUN): 
169	cd $@; ./run.sh
170	cd $(PWD)
171
172