Windows makefiles: forced rebuild when build tag changes
[public/netxms.git] / Makefile.inc.w32
1 # Common settings for Win32 builds
2 # This makefile expects that path to build tools and environment variables
3 # LIB and INCLUDE for target architecture set before running make
4 # They can be set using build\msvc_setenv_* scripts
5
6 CC = cl
7 CXX = cl
8 LD = link
9 PERL = perl
10 LEX = flex
11 YACC = bison
12 MC = mc
13
14 # Source base path
15 # Default location is C:\Source\NetXMS
16 # It can be changed by setting NETXMS_BASE environment variable
17 !ifndef NETXMS_BASE
18 NETXMS_BASE = C:\Source\NetXMS
19 !endif
20
21 # Architecture
22 !ifndef ARCH
23 ARCH = x64
24 !endif
25
26 !if "$(ARCH)" == "x64"
27 WINDDK_ARCH = amd64
28 OBJDIR = amd64
29 !endif
30
31 !if "$(ARCH)" == "x86"
32 OBJDIR = i386
33 !endif
34
35 # SDK locations
36 !ifndef OPENSSL_BASE
37 OPENSSL_BASE = C:\SDK\OpenSSL
38 !endif
39 !ifndef CURL_BASE
40 CURL_BASE = C:\SDK\cURL
41 !endif
42 !ifndef JDK_BASE
43 JDK_BASE = C:\Program Files\Java\jdk1.8.0_121
44 !endif
45
46 # Binaries directory
47 NETXMS_LIBDIR = $(NETXMS_BASE)\bin\$(OBJDIR)
48 BINDIR = $(NETXMS_LIBDIR)
49
50 # Component specific settings
51 !if "$(COMPONENT)" == "server"
52 CPPFLAGS = $(CPPFLAGS) /I "$(NETXMS_BASE)\src\server\include"
53 !endif
54
55 # Target specific settings
56 !if "$(TYPE)" == "dll"
57 CPPFLAGS = $(CPPFLAGS) /D_USRDLL
58 IMPLIB = $(BINFILE:.dll=.lib)
59 LDFLAGS = $(LDFLAGS) /DLL /IMPLIB:$(IMPLIB)
60 !endif
61 !if "$(TYPE)" == "ddr"
62 CPPFLAGS = $(CPPFLAGS) /D_USRDLL
63 LDFLAGS = $(LDFLAGS) /DLL
64 !endif
65 !if "$(TYPE)" == "hdlink"
66 CPPFLAGS = $(CPPFLAGS) /D_USRDLL
67 LDFLAGS = $(LDFLAGS) /DLL
68 !endif
69 !if "$(TYPE)" == "ndd"
70 BINDIR = $(BINDIR)\ndd
71 CPPFLAGS = $(CPPFLAGS) /D_USRDLL
72 LDFLAGS = $(LDFLAGS) /DLL
73 !endif
74 !if "$(TYPE)" == "nsm"
75 CPPFLAGS = $(CPPFLAGS) /D_USRDLL
76 LDFLAGS = $(LDFLAGS) /DLL
77 !endif
78
79 # Common C/C++ compiler flags
80 CPPFLAGS = $(CPPFLAGS) /MD /O2 /Gd /EHs- /GR- \
81 /I "$(NETXMS_BASE)\include" \
82 /I "$(NETXMS_BASE)\build" \
83 /I "$(CURL_BASE)\$(ARCH)\include" \
84 /I "$(OPENSSL_BASE)\$(ARCH)\include" \
85 /D_MT /DUNICODE
86
87 # Common linker flags
88 MANIFEST = $(TARGET).intermediate.manifest
89 LDFLAGS = $(LDFLAGS) /SUBSYSTEM:CONSOLE /MACHINE:$(ARCH) /MANIFESTFILE:$(MANIFEST) \
90 /LIBPATH:"$(NETXMS_LIBDIR)" \
91 /LIBPATH:"$(CURL_BASE)\$(ARCH)\lib" \
92 /LIBPATH:"$(OPENSSL_BASE)\$(ARCH)\lib"
93
94 # Common libraries
95 LIBS = $(LIBS) ssleay32.lib libeay32.lib uuid.lib kernel32.lib user32.lib advapi32.lib shell32.lib
96
97 # Prepare list of object files
98 __sources = $(SOURCES:.cpp=.obj)
99 OBJ = $(__sources:.c=.obj)
100
101 # Compiled resources
102 RESOBJ = $(RESOURCES:.rc=.res)
103
104 # Source directory
105 SRCDIR = $(MAKEDIR)
106
107 # Output files
108 !ifdef TARGET
109 BINFILE = $(BINDIR)\$(TARGET)
110 !endif
111
112 all: Makefile.w32 subdirs $(GENERATED) $(BINFILE)
113
114 # Build target
115 !ifdef TARGET
116
117 !if "$(TYPE)" == "jar"
118
119 $(BINFILE): pom.xml
120 mvn clean
121 mvn install
122 mv target/$(TARGET) $(BINFILE)
123
124 !else
125
126 $(BINFILE): objdir $(OBJ) $(RESOBJ)
127 @if not exist $(BINDIR) mkdir $(BINDIR)
128 @echo " LD " $(TARGET)
129 @$(LD) /NOLOGO $(LDFLAGS) /out:$(BINFILE) $(OBJ) $(RESOBJ) $(LIBS)
130 @rm -f $(MANIFEST)
131
132 $(OBJ): $(NETXMS_BASE)\build\netxms-build-tag.h
133
134 .PHONY: objdir
135
136 objdir:
137 @if not exist $(OBJDIR) mkdir $(OBJDIR)
138 @cd $(OBJDIR)
139
140 {$(SRCDIR)}.c.obj:
141 @echo " CC " $(<F)
142 @$(CC) /nologo $(CPPFLAGS) $(CFLAGS) /c $< /Fo$@ | tail -n +2
143
144 {$(SRCDIR)}.cpp.obj:
145 @echo " CXX" $(<F)
146 @$(CXX) /nologo $(CPPFLAGS) $(CXXFLAGS) /c $< /Fo$@ | tail -n +2
147
148 {$(SRCDIR)}.rc.res:
149 @echo " RC " $(<F)
150 @$(RC) /nologo /r $<
151 @mv $(SRCDIR)\$@ .
152
153 MSG00001.bin: messages.mc
154 @echo " MC messages.mc"
155 @$(MC) messages.mc
156 @rm -f messages.rc
157
158 messages.h: messages.mc
159 @echo " MC messages.mc"
160 @$(MC) messages.mc
161 @rm -f messages.rc
162
163 !endif
164 !endif
165
166 # Clean
167 .PHONY: clean
168
169 clean:
170 rm -rf $(OBJ) $(TARGET) $(OBJDIR) $(GENERATED) $(EXTRA_CLEAN)
171 @for %%s in ($(SUBDIRS)) do @( \
172 echo === Entering %%s === && \
173 cd %%s && \
174 @( \
175 $(MAKE) /NOLOGO /F Makefile.w32 clean || \
176 exit 1 \
177 ) && \
178 echo === Leaving %%s === && \
179 cd .. \
180 )
181
182 # Sub-directories building rules
183 .PHONY: subdirs
184
185 subdirs:
186 @for %%s in ($(SUBDIRS)) do @( \
187 echo === Entering %%s === && \
188 cd %%s && \
189 @( \
190 $(MAKE) /NOLOGO /F Makefile.w32 || \
191 exit 1 \
192 ) && \
193 echo === Leaving %%s === && \
194 cd .. \
195 )