Modified the windows makefile for cmockery to enable debug mode.
[platform/upstream/cmocka.git] / windows / makefile
1 #
2 # Copyright 2008 Google Inc.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 # Microsoft Windows namke file which builds the cmockery library and example 
17 # applications.
18 #
19 # To use this makefile...
20 # Select Start->Run and run "cmd.exe" to open the command line.
21 # Run "vsvars.bat" located in Microsoft Visual Studio's directory.
22 # Run "nmake" to build the cmockery library and example applications.
23 # Run "nmake clean" to delete all files built by this makefile.
24
25 # Target directories.
26 !IFNDEF EXECUTABLE_DIR
27 EXECUTABLE_DIR=.
28 !ENDIF # EXECUTABLE_DIR
29
30 !IFNDEF LIBRARY_DIR
31 LIBRARY_DIR=.
32 !ENDIF # LIBRARY_DIR
33
34 !IFNDEF OBJECT_DIR
35 OBJECT_DIR=.
36 !ENDIF # OBJECT_DIR
37
38 # Tools
39 !IFNDEF LIBTOOL
40 LIBTOOL=lib.exe
41 !ENDIF # LIBTOOL
42
43 !IFNDEF LINK
44 LINK=link.exe
45 !ENDIF # LINK
46
47 # Source directories.
48 !IFNDEF LIBRARY_SOURCE_DIRECTORY
49 LIBRARY_SOURCE_DIRECTORY=..\src
50 !ENDIF # LIBRARY_SOURCE_DIRECTORY
51 !IFNDEF EXAMPLE_SOURCE_DIRECTORY
52 EXAMPLE_SOURCE_DIRECTORY=..\src\example
53 !ENDIF # EXAMPLE_SOURCE_DIRECTORY
54
55 # Compiler flags and commands.
56 CC_COMMAND=$(CC) /nologo /c /D_WIN32_WINNT=0x501 /DHAVE_MALLOC_H \
57         /I$(LIBRARY_SOURCE_DIRECTORY)\google $(CFLAGS) $(**) /Fo$(@)
58 CC_COMMAND_UNIT_TEST=$(CC_COMMAND) /DUNIT_TESTING=1 \
59         /I$(EXAMPLE_SOURCE_DIRECTORY)
60
61 # If debugging is enabled compile with symbols and stop on exceptions.
62 !IFDEF UNIT_TESTING_DEBUG
63 CC_COMMAND=$(CC_COMMAND) /DUNIT_TESTING_DEBUG=1 /Zi /Od
64 LFLAGS=$(LFLAGS) /DEBUG
65 !ENDIF # UNIT_TESTING_DEBUG
66
67 LIBLINKFLAGS=/NOLOGO
68
69 # Library archiver flags and command.
70 LIB_COMMAND=$(LIBTOOL) $(LIBLINKFLAGS) $(LIBFLAGS) $(**) /OUT:$(@)
71
72 # Linker flags and command. 
73 LINK_COMMAND=$(LINK) $(LIBLINKFLAGS) /SUBSYSTEM:console \
74         libcmt.lib kernel32.lib /NODEFAULTLIB:libc.lib \
75         $(LFLAGS) $(**) /OUT:$(@)
76
77 .SUFFIXES: .exe .lib .obj .c
78
79 all: $(EXECUTABLE_DIR) $(LIBRARY_DIR) $(OBJECT_DIR) \
80         $(LIBRARY_DIR)\cmockery.lib examples
81
82 $(EXECUTABLE_DIR):
83         mkdir $@
84
85 !IF "$(LIBRARY_DIR)" != "$(EXECUTABLE_DIR)"
86 $(LIBRARY_DIR):
87         mkdir $*
88 !ENDIF
89
90 !IF "$(OBJECT_DIR)" != "$(LIBRARY_DIR)" && \
91         "$(OBJECT_DIR)" != "$(EXECUTABLE_DIR)"
92 $(OBJECT_DIR):
93         mkdir $@
94 !ENDIF
95
96 examples: \
97         $(EXECUTABLE_DIR)\calculator.exe \
98         $(EXECUTABLE_DIR)\calculator_test.exe \
99         $(EXECUTABLE_DIR)\allocate_module_test.exe \
100         $(EXECUTABLE_DIR)\assert_macro_test.exe \
101         $(EXECUTABLE_DIR)\customer_database_test.exe \
102         $(EXECUTABLE_DIR)\key_value_test.exe \
103         $(EXECUTABLE_DIR)\product_database_test.exe \
104         $(EXECUTABLE_DIR)\run_tests.exe
105
106 clean:
107         -cmd /c "@for %A in (\
108                 $(LIBRARY_DIR)\cmockery.lib \
109                         $(OBJECT_DIR)\cmockery.obj \
110                 $(EXECUTABLE_DIR)\calculator.exe \
111                         $(OBJECT_DIR)\calculator.obj \
112                 $(EXECUTABLE_DIR)\calculator_test.exe \
113                         $(OBJECT_DIR)\calculator_test.obj \
114                         $(OBJECT_DIR)\calculator_test-calculator.obj \
115                 $(EXECUTABLE_DIR)\allocate_module_test.exe \
116                         $(OBJECT_DIR)\allocate_module_test.obj \
117                         $(OBJECT_DIR)\allocate_module.obj \
118                 $(EXECUTABLE_DIR)\assert_macro_test.exe \
119                         $(OBJECT_DIR)\assert_macro_test.obj \
120                         $(OBJECT_DIR)\assert_macro.obj \
121                 $(EXECUTABLE_DIR)\customer_database_test.exe \
122                         $(OBJECT_DIR)\customer_database_test.obj \
123                         $(OBJECT_DIR)\customer_database.obj \
124                 $(EXECUTABLE_DIR)\key_value_test.exe \
125                         $(OBJECT_DIR)\key_value_test.obj \
126                         $(OBJECT_DIR)\key_value.obj \
127                 $(EXECUTABLE_DIR)\product_database_test.exe \
128                         $(OBJECT_DIR)\product_database_test.obj \
129                         $(OBJECT_DIR)\product_database.obj \
130                 $(EXECUTABLE_DIR)\run_tests.exe \
131                         $(OBJECT_DIR)\run_tests.obj) do @del %A 2>NUL"
132         -rmdir $(EXECUTABLE_DIR) $(OBJECT_DIR) $(LIBRARY_DIR) 2>NUL
133
134 # Rules for the cmockery library.
135 $(LIBRARY_DIR)\cmockery.lib: $(OBJECT_DIR)\cmockery.obj
136 $(OBJECT_DIR)\cmockery.obj: $(LIBRARY_SOURCE_DIRECTORY)\cmockery.c
137
138 # Rules for the calculator application.
139 $(EXECUTABLE_DIR)\calculator.exe: $(OBJECT_DIR)\calculator.obj
140
141 $(OBJECT_DIR)\calculator.obj: $(EXAMPLE_SOURCE_DIRECTORY)\calculator.c
142         $(CC_COMMAND)
143
144 # Rules for the calculator test application.
145 $(EXECUTABLE_DIR)\calculator_test.exe: \
146                 $(OBJECT_DIR)\calculator_test.obj \
147                 $(OBJECT_DIR)\calculator_test-calculator.obj \
148                 $(LIBRARY_DIR)\cmockery.lib
149         $(LINK_COMMAND)
150
151 $(OBJECT_DIR)\calculator_test.obj: \
152         $(EXAMPLE_SOURCE_DIRECTORY)\calculator_test.c
153
154 $(OBJECT_DIR)\calculator_test-calculator.obj: \
155         $(EXAMPLE_SOURCE_DIRECTORY)\calculator.c
156         $(CC_COMMAND_UNIT_TEST)
157
158 # Sample code applications.
159 $(EXECUTABLE_DIR)\allocate_module_test.exe: \
160                 $(OBJECT_DIR)\allocate_module_test.obj \
161                 $(OBJECT_DIR)\allocate_module.obj \
162                 $(LIBRARY_DIR)\cmockery.lib
163         $(LINK_COMMAND)
164
165 $(OBJECT_DIR)\allocate_module_test.obj: \
166         $(EXAMPLE_SOURCE_DIRECTORY)\allocate_module_test.c
167 $(OBJECT_DIR)\allocate_module.obj: \
168         $(EXAMPLE_SOURCE_DIRECTORY)\allocate_module.c
169
170 $(EXECUTABLE_DIR)\assert_macro_test.exe: \
171                 $(OBJECT_DIR)\assert_macro_test.obj \
172                 $(OBJECT_DIR)\assert_macro.obj \
173                 $(LIBRARY_DIR)\cmockery.lib
174         $(LINK_COMMAND)
175
176 $(OBJECT_DIR)\assert_macro_test.obj: \
177         $(EXAMPLE_SOURCE_DIRECTORY)\assert_macro_test.c
178 $(OBJECT_DIR)\assert_macro.obj: $(EXAMPLE_SOURCE_DIRECTORY)\assert_macro.c
179
180 $(EXECUTABLE_DIR)\customer_database_test.exe: \
181                 $(OBJECT_DIR)\customer_database_test.obj \
182                 $(OBJECT_DIR)\customer_database.obj \
183                 $(LIBRARY_DIR)\cmockery.lib
184         $(LINK_COMMAND)
185
186 $(OBJECT_DIR)\customer_database_test.obj: \
187         $(EXAMPLE_SOURCE_DIRECTORY)\customer_database_test.c
188 $(OBJECT_DIR)\customer_database.obj: \
189         $(EXAMPLE_SOURCE_DIRECTORY)\customer_database.c
190
191 $(EXECUTABLE_DIR)\key_value_test.exe: \
192                 $(OBJECT_DIR)\key_value_test.obj \
193                 $(OBJECT_DIR)\key_value.obj \
194                 $(LIBRARY_DIR)\cmockery.lib
195         $(LINK_COMMAND)
196
197 $(OBJECT_DIR)\key_value_test.obj: $(EXAMPLE_SOURCE_DIRECTORY)\key_value_test.c
198 $(OBJECT_DIR)\key_value.obj: $(EXAMPLE_SOURCE_DIRECTORY)\key_value.c
199
200 $(EXECUTABLE_DIR)\product_database_test.exe: \
201                 $(OBJECT_DIR)\product_database_test.obj \
202                 $(OBJECT_DIR)\product_database.obj \
203                 $(LIBRARY_DIR)\cmockery.lib
204         $(LINK_COMMAND)
205
206 $(OBJECT_DIR)\product_database_test.obj: \
207         $(EXAMPLE_SOURCE_DIRECTORY)\product_database_test.c
208 $(OBJECT_DIR)\product_database.obj: \
209         $(EXAMPLE_SOURCE_DIRECTORY)\product_database.c
210
211 $(EXECUTABLE_DIR)\run_tests.exe: \
212                 $(OBJECT_DIR)\run_tests.obj $(LIBRARY_DIR)\cmockery.lib
213         $(LINK_COMMAND)
214
215 $(OBJECT_DIR)\run_tests.obj: $(EXAMPLE_SOURCE_DIRECTORY)\run_tests.c
216
217 # Inference rules.
218 {$(OBJECT_DIR)\}.obj{$(EXECUTABLE_DIR)\}.exe:
219         $(LINK_COMMAND)
220
221 {$(OBJECT_DIR)\}.obj{$(LIBRARY_DIR)\}.lib:
222         $(LIB_COMMAND)
223
224 {$(LIBRARY_SOURCE_DIRECTORY)\}.c{$(OBJECT_DIR)\}.obj:
225         $(CC_COMMAND)
226
227 {$(EXAMPLE_SOURCE_DIRECTORY)\}.c{$(OBJECT_DIR)\}.obj:
228         $(CC_COMMAND_UNIT_TEST)