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