]> rtime.felk.cvut.cz Git - omk.git/blob - tests/programs-cflags
Add failing test
[omk.git] / tests / programs-cflags
1 #!/bin/bash
2
3 . ./wvtest.sh
4
5 create_files() {
6     cat > 'test.c' <<'EOF'
7 #include <stdio.h>
8
9 int main()
10 {
11 #ifdef NUMBER
12         printf("NUMBER is %d\n", NUMBER);
13 #endif
14         return 0;
15 }
16 EOF
17     cat > 'Makefile.omk' <<'EOF'
18 bin_PROGRAMS = test
19 test_SOURCES = test.c
20 EOF
21 }
22
23 grepbinout() {
24     if [ $OMK_RULES = linux ]; then
25         # The following should work only with Linux rules
26         local bin=$1
27         shift
28         _compiled/bin/$bin|grep $@
29     fi
30 }
31 grepout() {
32     grepbinout test $@
33 }
34
35 set -o pipefail
36
37 WVSTART "OMK_CFLAGS"
38 create_files
39 needs_valid_CC
40 WVPASS make OMK_CFLAGS=-DNUMBER=123
41 WVPASS grepout 123
42
43 WVSTART "CFLAGS override OMK_CFLAGS"
44 create_files
45 WVPASS make OMK_CFLAGS=-DNUMBER=123 CFLAGS=-DNUMBER=321
46 WVPASS grepout 321
47
48
49 WVSTART "OMK_CFLAGS in config.omk"
50 create_files
51 echo "OMK_CFLAGS=-DNUMBER=123" > config.omk
52 WVPASS make
53 WVPASS grepout 123
54
55 WVSTART "Target specific CFLAGS"
56 create_files
57 cat > 'Makefile.omk' <<'EOF'
58 bin_PROGRAMS = test
59 test_SOURCES = test.c
60 test_CFLAGS = -DNUMBER=123
61 EOF
62 WVPASS make V=1
63 WVPASS grepout 123
64
65 WVSTART "Target specific CFLAGS override OMK_CFLAGS"
66 create_files
67 cat > 'Makefile.omk' <<'EOF'
68 bin_PROGRAMS = test
69 test_SOURCES = test.c
70 test_CFLAGS = -DNUMBER=123
71 OMK_CFLAGS   = -DNUMBER=456
72 EOF
73 WVPASS make V=1
74 WVPASS grepout 123
75
76 WVSTART "Same source compiled twice with different CFLAGS"
77 create_files
78 cat > 'Makefile.omk' <<'EOF'
79 bin_PROGRAMS = a b
80 a_SOURCES = test.c
81 a_CFLAGS = -DNUMBER=123
82 b_SOURCES = test.c
83 b_CFLAGS = -DNUMBER=456
84 EOF
85 WVPASS make V=1
86 WVPASS grepbinout a 123
87 WVPASS grepbinout b 456
88
89 WVSTART "CFLAGS is not set by default"
90 create_files
91 WVPASS sh -c '! make -qp|grep "^CFLAGS ="'