764b277612fd7a2dc1e37e00a369ecd7b7be9409
[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 LIBRARY_SOURCE_DIRECTORY=..\src
49 EXAMPLE_SOURCE_DIRECTORY=..\src\example
50
51 # Compiler flags and commands.
52 CC_COMMAND=$(CC) /nologo /c /D_WIN32_WINNT=0x501 \
53         /I$(LIBRARY_SOURCE_DIRECTORY)\google $(CFLAGS) $(**) /Fo$(@)
54 CC_COMMAND_UNIT_TEST=$(CC_COMMAND) /DUNIT_TESTING=1 \
55         /I$(EXAMPLE_SOURCE_DIRECTORY)
56
57 LIBLINKFLAGS=/NOLOGO
58
59 # Library archiver flags and command.
60 LIB_COMMAND=$(LIBTOOL) $(LIBLINKFLAGS) $(LIBFLAGS) $(**) /OUT:$(@)
61
62 # Linker flags and command. 
63 LINK_COMMAND=$(LINK) $(LIBLINKFLAGS) /SUBSYSTEM:console \
64         libcmt.lib kernel32.lib /NODEFAULTLIB:libc.lib \
65         $(LFLAGS) $(**) /OUT:$(@)
66
67 .SUFFIXES: .exe .lib .obj .c
68
69 all: $(EXECUTABLE_DIR) $(LIBRARY_DIR) $(OBJECT_DIR) \
70         $(LIBRARY_DIR)\cmockery.lib examples
71
72 $(EXECUTABLE_DIR):
73         mkdir $@
74
75 !IF "$(LIBRARY_DIR)" != "$(EXECUTABLE_DIR)"
76 $(LIBRARY_DIR):
77         mkdir $*
78 !ENDIF
79
80 !IF "$(OBJECT_DIR)" != "$(LIBRARY_DIR)" && \
81         "$(OBJECT_DIR)" != "$(EXECUTABLE_DIR)"
82 $(OBJECT_DIR):
83         mkdir $@
84 !ENDIF
85
86 examples: \
87         $(EXECUTABLE_DIR)\calculator.exe \
88         $(EXECUTABLE_DIR)\calculator_test.exe \
89         $(EXECUTABLE_DIR)\allocate_module_test.exe \
90         $(EXECUTABLE_DIR)\assert_macro_test.exe \
91         $(EXECUTABLE_DIR)\customer_database_test.exe \
92         $(EXECUTABLE_DIR)\key_value_test.exe \
93         $(EXECUTABLE_DIR)\product_database_test.exe \
94         $(EXECUTABLE_DIR)\run_tests.exe
95
96 clean:
97         -cmd /c "@for %A in (\
98                 $(LIBRARY_DIR)\cmockery.lib \
99                         $(OBJECT_DIR)\cmockery.obj \
100                 $(EXECUTABLE_DIR)\calculator.exe \
101                         $(OBJECT_DIR)\calculator.obj \
102                 $(EXECUTABLE_DIR)\calculator_test.exe \
103                         $(OBJECT_DIR)\calculator_test.obj \
104                         $(OBJECT_DIR)\calculator_test-calculator.obj \
105                 $(EXECUTABLE_DIR)\allocate_module_test.exe \
106                         $(OBJECT_DIR)\allocate_module_test.obj \
107                         $(OBJECT_DIR)\allocate_module.obj \
108                 $(EXECUTABLE_DIR)\assert_macro_test.exe \
109                         $(OBJECT_DIR)\assert_macro_test.obj \
110                         $(OBJECT_DIR)\assert_macro.obj \
111                 $(EXECUTABLE_DIR)\customer_database_test.exe \
112                         $(OBJECT_DIR)\customer_database_test.obj \
113                         $(OBJECT_DIR)\customer_database.obj \
114                 $(EXECUTABLE_DIR)\key_value_test.exe \
115                         $(OBJECT_DIR)\key_value_test.obj \
116                         $(OBJECT_DIR)\key_value.obj \
117                 $(EXECUTABLE_DIR)\product_database_test.exe \
118                         $(OBJECT_DIR)\product_database_test.obj \
119                         $(OBJECT_DIR)\product_database.obj \
120                 $(EXECUTABLE_DIR)\run_tests.exe \
121                         $(OBJECT_DIR)\run_tests.obj) do @del %A 2>NUL"
122         -rmdir $(EXECUTABLE_DIR) $(OBJECT_DIR) $(LIBRARY_DIR) 2>NUL
123
124 # Rules for the cmockery library.
125 $(LIBRARY_DIR)\cmockery.lib: $(OBJECT_DIR)\cmockery.obj
126 $(OBJECT_DIR)\cmockery.obj: $(LIBRARY_SOURCE_DIRECTORY)\cmockery.c
127
128 # Rules for the calculator application.
129 $(EXECUTABLE_DIR)\calculator.exe: $(OBJECT_DIR)\calculator.obj
130
131 $(OBJECT_DIR)\calculator.obj: $(EXAMPLE_SOURCE_DIRECTORY)\calculator.c
132         $(CC_COMMAND)
133
134 # Rules for the calculator test application.
135 $(EXECUTABLE_DIR)\calculator_test.exe: \
136                 $(OBJECT_DIR)\calculator_test.obj \
137                 $(OBJECT_DIR)\calculator_test-calculator.obj \
138                 $(LIBRARY_DIR)\cmockery.lib
139         $(LINK_COMMAND)
140
141 $(OBJECT_DIR)\calculator_test.obj: \
142         $(EXAMPLE_SOURCE_DIRECTORY)\calculator_test.c
143
144 $(OBJECT_DIR)\calculator_test-calculator.obj: \
145         $(EXAMPLE_SOURCE_DIRECTORY)\calculator.c
146         $(CC_COMMAND_UNIT_TEST)
147
148 # Sample code applications.
149 $(EXECUTABLE_DIR)\allocate_module_test.exe: \
150                 $(OBJECT_DIR)\allocate_module_test.obj \
151                 $(OBJECT_DIR)\allocate_module.obj \
152                 $(LIBRARY_DIR)\cmockery.lib
153         $(LINK_COMMAND)
154
155 $(OBJECT_DIR)\allocate_module_test.obj: \
156         $(EXAMPLE_SOURCE_DIRECTORY)\allocate_module_test.c
157 $(OBJECT_DIR)\allocate_module.obj: \
158         $(EXAMPLE_SOURCE_DIRECTORY)\allocate_module.c
159
160 $(EXECUTABLE_DIR)\assert_macro_test.exe: \
161                 $(OBJECT_DIR)\assert_macro_test.obj \
162                 $(OBJECT_DIR)\assert_macro.obj \
163                 $(LIBRARY_DIR)\cmockery.lib
164         $(LINK_COMMAND)
165
166 $(OBJECT_DIR)\assert_macro_test.obj: \
167         $(EXAMPLE_SOURCE_DIRECTORY)\assert_macro_test.c
168 $(OBJECT_DIR)\assert_macro.obj: $(EXAMPLE_SOURCE_DIRECTORY)\assert_macro.c
169
170 $(EXECUTABLE_DIR)\customer_database_test.exe: \
171                 $(OBJECT_DIR)\customer_database_test.obj \
172                 $(OBJECT_DIR)\customer_database.obj \
173                 $(LIBRARY_DIR)\cmockery.lib
174         $(LINK_COMMAND)
175
176 $(OBJECT_DIR)\customer_database_test.obj: \
177         $(EXAMPLE_SOURCE_DIRECTORY)\customer_database_test.c
178 $(OBJECT_DIR)\customer_database.obj: \
179         $(EXAMPLE_SOURCE_DIRECTORY)\customer_database.c
180
181 $(EXECUTABLE_DIR)\key_value_test.exe: \
182                 $(OBJECT_DIR)\key_value_test.obj \
183                 $(OBJECT_DIR)\key_value.obj \
184                 $(LIBRARY_DIR)\cmockery.lib
185         $(LINK_COMMAND)
186
187 $(OBJECT_DIR)\key_value_test.obj: $(EXAMPLE_SOURCE_DIRECTORY)\key_value_test.c
188 $(OBJECT_DIR)\key_value.obj: $(EXAMPLE_SOURCE_DIRECTORY)\key_value.c
189
190 $(EXECUTABLE_DIR)\product_database_test.exe: \
191                 $(OBJECT_DIR)\product_database_test.obj \
192                 $(OBJECT_DIR)\product_database.obj \
193                 $(LIBRARY_DIR)\cmockery.lib
194         $(LINK_COMMAND)
195
196 $(OBJECT_DIR)\product_database_test.obj: \
197         $(EXAMPLE_SOURCE_DIRECTORY)\product_database_test.c
198 $(OBJECT_DIR)\product_database.obj: \
199         $(EXAMPLE_SOURCE_DIRECTORY)\product_database.c
200
201 $(EXECUTABLE_DIR)\run_tests.exe: \
202                 $(OBJECT_DIR)\run_tests.obj $(LIBRARY_DIR)\cmockery.lib
203         $(LINK_COMMAND)
204
205 $(OBJECT_DIR)\run_tests.obj: $(EXAMPLE_SOURCE_DIRECTORY)\run_tests.c
206
207 # Inference rules.
208 {$(OBJECT_DIR)\}.obj{$(EXECUTABLE_DIR)\}.exe:
209         $(LINK_COMMAND)
210
211 {$(OBJECT_DIR)\}.obj{$(LIBRARY_DIR)\}.lib:
212         $(LIB_COMMAND)
213
214 {$(LIBRARY_SOURCE_DIRECTORY)\}.c{$(OBJECT_DIR)\}.obj:
215         $(CC_COMMAND)
216
217 {$(EXAMPLE_SOURCE_DIRECTORY)\}.c{$(OBJECT_DIR)\}.obj:
218         $(CC_COMMAND_UNIT_TEST)