f376b40edcfc02f15a0f3b013c107fb412dc20a7
[reactos.git] / reactos / tools / helper.mk
1 # $Id: helper.mk,v 1.52 2004/02/20 08:33:37 gvg Exp $
2 #
3 # Helper makefile for ReactOS modules
4 # Variables this makefile accepts:
5 # $TARGET_TYPE = Type of target:
6 # program = User mode program
7 # proglib = Executable program that have exported functions
8 # dynlink = Dynamic Link Library (DLL)
9 # library = Library that will be linked with other code
10 # driver = Kernel mode driver
11 # export_driver = Kernel mode driver that have exported functions
12 # driver_library = Import library for a driver
13 # kmlibrary = Static kernel-mode library
14 # hal = Hardware Abstraction Layer
15 # bootpgm = Boot program
16 # miniport = Kernel mode driver that does not link with ntoskrnl.exe or hal.dll
17 # gdi_driver = Kernel mode graphics driver that link with win32k.sys
18 # subsystem = Kernel subsystem
19 # kmdll = Kernel mode DLL
20 # winedll = DLL imported from wine
21 # $TARGET_APPTYPE = Application type (windows,native,console)
22 # $TARGET_NAME = Base name of output file and .rc, .def, and .edf files
23 # $TARGET_OBJECTS = Object files that compose the module
24 # $TARGET_CPPAPP = C++ application (no,yes) (optional)
25 # $TARGET_HEADERS = Header files that the object files depend on (optional)
26 # $TARGET_DEFNAME = Base name of .def and .edf files (optional)
27 # $TARGET_BASENAME = Base name of output file (overrides $TARGET_NAME if it exists) (optional)
28 # $TARGET_EXTENSION = Extension of the output file (optional)
29 # $TARGET_DDKLIBS = DDK libraries that are to be imported by the module (optional)
30 # $TARGET_SDKLIBS = SDK libraries that are to be imported by the module (optional)
31 # $TARGET_LIBS = Other libraries that are to be imported by the module (optional)
32 # $TARGET_GCCLIBS = GCC libraries imported with -l (optional)
33 # $TARGET_LFLAGS = GCC flags when linking (optional)
34 # $TARGET_CFLAGS = GCC flags (optional)
35 # $TARGET_CPPFLAGS = G++ flags (optional)
36 # $TARGET_ASFLAGS = GCC assembler flags (optional)
37 # $TARGET_NFLAGS = NASM flags (optional)
38 # $TARGET_RCFLAGS = Windres flags (optional)
39 # $TARGET_CLEAN = Files that are part of the clean rule (optional)
40 # $TARGET_PATH = Relative path for *.def, *.edf, and *.rc (optional)
41 # $TARGET_BASE = Default base address (optional)
42 # $TARGET_ENTRY = Entry point (optional)
43 # $TARGET_DEFONLY = Use .def instead of .edf extension (no,yes) (optional)
44 # $TARGET_NORC = Do not include standard resource file (no,yes) (optional)
45 # $TARGET_LIBPATH = Destination path for import libraries (optional)
46 # $TARGET_INSTALLDIR = Destination path when installed (optional)
47 # $TARGET_PCH = Filename of header to use to generate a PCH if supported by the compiler (optional)
48 # $TARGET_BOOTSTRAP = Whether this file is needed to bootstrap the installation (no,yes) (optional)
49 # $TARGET_BOOTSTRAP_NAME = Name on the installation medium (optional)
50 # $WINE_MODE = Compile using WINE headers (no,yes) (optional)
51 # $WINE_RC = Name of .rc file for WINE modules (optional)
52 # $SUBDIRS = Subdirs in which to run make (optional)
53
54 include $(PATH_TO_TOP)/config
55
56
57 ifeq ($(TARGET_PATH),)
58 TARGET_PATH := .
59 endif
60
61 ifeq ($(ARCH),i386)
62 MK_ARCH_ID := _M_IX86
63 endif
64
65 ifeq ($(ARCH),alpha)
66 MK_ARCH_ID := _M_ALPHA
67 endif
68
69 ifeq ($(ARCH),mips)
70 MK_ARCH_ID := _M_MIPS
71 endif
72
73 ifeq ($(ARCH),powerpc)
74 MK_ARCH_ID := _M_PPC
75 endif
76
77 # unknown architecture
78 ifeq ($(MK_ARCH_ID),)
79 MK_ARCH_ID := _M_UNKNOWN
80 endif
81
82 #
83 # VARIABLES IN USE BY VARIOUS TARGETS
84 #
85 # MK_BOOTCDDIR = Directory on the ReactOS ISO CD in which to place the file (subdir of reactos/)
86 # MK_CFLAGS = C compiler command-line flags for this target
87 # MK_CPPFLAGS = C++ compiler command-line flags for this target
88 # MK_DDKLIBS = Import libraries from the ReactOS DDK to link with
89 # MK_DEFENTRY = Module entry point:
90 # _WinMain@16 for windows EXE files that are export libraries
91 # _DriverEntry@8 for .SYS files
92 # _DllMain@12 for .DLL files
93 # _DrvEnableDriver@12 for GDI drivers
94 # _WinMainCRTStartup for Win32 EXE files
95 # _NtProcessStartup@4 for Native EXE files
96 # _mainCRTStartup for Console EXE files
97 # MK_DEFEXT = Extension to give compiled modules (.EXE, .DLL, .SYS, .a)
98 # MK_DISTDIR = (unused?)
99 # MK_EXETYPE = Compiler option packages based on type of PE file (exe, dll)
100 # MK_IMPLIB = Whether or not to generate a DLL import stub library (yes, no)
101 # MK_IMPLIB_EXT = Extension to give import libraries (.a always)
102 # MK_IMPLIBDEFPATH = Default place to put the import stub library when built
103 # MK_IMPLIBONLY = Whether the target is only an import library (yes, no; used only by generic hal)
104 # MK_INSTALLDIR = Where "make install" should put the target, relative to reactos/
105 # MK_MODE = Mode the target's code is intended to run in
106 # user - User-mode compiler settings
107 # kernel - Kernel-mode compiler settings
108 # static - Static library compiler settings
109 # MK_RCFLAGS = Flags to add to resource compiler command line
110 # MK_RES_BASE = Base name of resource files
111 # MK_SDKLIBS = Default SDK libriaries to link with
112 #
113
114 ifeq ($(TARGET_TYPE),program)
115 MK_MODE := user
116 MK_EXETYPE := exe
117 MK_DEFEXT := .exe
118 MK_DEFENTRY := _DEFINE_TARGET_APPTYPE
119 MK_DDKLIBS :=
120 MK_SDKLIBS :=
121 ifneq ($(WINE_MODE),yes)
122 MK_CFLAGS := -I./ -I$(SDK_PATH_INC)
123 MK_CPPFLAGS := -I./ -I$(SDK_PATH_INC)
124 else
125 MK_CFLAGS := -I$(PATH_TO_TOP)/include/wine -I./ -I$(WINE_INCLUDE)
126 MK_CPPFLAGS := -I$(PATH_TO_TOP)/include/wine -I./ -I$(WINE_INCLUDE)
127 MK_RCFLAGS := --include-dir $(PATH_TO_TOP)/include/wine --include-dir $(WINE_INCLUDE)
128 endif
129 MK_IMPLIB := no
130 MK_IMPLIBONLY := no
131 MK_IMPLIBDEFPATH :=
132 MK_IMPLIB_EXT := .a
133 MK_INSTALLDIR := bin
134 MK_BOOTCDDIR := system32
135 MK_DISTDIR := apps
136 ifeq ($(WINE_RC),)
137 MK_RES_BASE := $(TARGET_NAME)
138 else
139 MK_RES_BASE := $(WINE_RC)
140 endif
141 endif
142
143 ifeq ($(TARGET_TYPE),proglib)
144 MK_MODE := user
145 MK_EXETYPE := dll
146 MK_DEFEXT := .exe
147 MK_DEFENTRY := _WinMain@16
148 MK_DDKLIBS :=
149 MK_SDKLIBS :=
150 MK_CFLAGS := -I./ -I$(SDK_PATH_INC)
151 MK_CPPFLAGS := -I./ -I$(SDK_PATH_INC)
152 MK_IMPLIB := yes
153 MK_IMPLIBONLY := no
154 MK_IMPLIBDEFPATH := $(SDK_PATH_LIB)
155 MK_IMPLIB_EXT := .a
156 MK_INSTALLDIR := bin
157 MK_BOOTCDDIR := system32
158 MK_DISTDIR := apps
159 MK_RES_BASE := $(TARGET_NAME)
160 endif
161
162 ifeq ($(TARGET_TYPE),dynlink)
163 MK_MODE := user
164 MK_EXETYPE := dll
165 MK_DEFEXT := .dll
166 MK_DEFENTRY := _DllMain@12
167 MK_DDKLIBS :=
168 MK_SDKLIBS :=
169 ifneq ($(WINE_MODE),yes)
170 MK_CFLAGS := -I./ -I$(SDK_PATH_INC)
171 MK_CPPFLAGS := -I./ -I$(SDK_PATH_INC)
172 else
173 MK_CFLAGS := -I$(PATH_TO_TOP)/include/wine -I./ -I$(WINE_INCLUDE)
174 MK_CPPFLAGS := -I$(PATH_TO_TOP)/include/wine -I./ -I$(WINE_INCLUDE)
175 MK_RCFLAGS := --include-dir $(PATH_TO_TOP)/include/wine --include-dir $(WINE_INCLUDE)
176 endif
177 MK_IMPLIB := yes
178 MK_IMPLIBONLY := no
179 MK_IMPLIBDEFPATH := $(SDK_PATH_LIB)
180 MK_IMPLIB_EXT := .a
181 MK_INSTALLDIR := system32
182 MK_BOOTCDDIR := system32
183 MK_DISTDIR := dlls
184 ifeq ($(WINE_RC),)
185 MK_RES_BASE := $(TARGET_NAME)
186 else
187 MK_RES_BASE := $(WINE_RC)
188 endif
189 endif
190
191 ifeq ($(TARGET_TYPE),library)
192 TARGET_NORC := yes
193 MK_MODE := static
194 MK_EXETYPE :=
195 MK_DEFEXT := .a
196 MK_DEFENTRY :=
197 MK_DDKLIBS :=
198 MK_SDKLIBS :=
199 MK_CFLAGS := -I./ -I$(SDK_PATH_INC)
200 MK_CPPFLAGS := -I./ -I$(SDK_PATH_INC)
201 MK_IMPLIB := no
202 MK_IMPLIBONLY := no
203 MK_IMPLIBDEFPATH :=
204 MK_IMPLIB_EXT :=
205 MK_INSTALLDIR := # none
206 MK_BOOTCDDIR := system32
207 MK_DISTDIR := # none
208 MK_RES_BASE :=
209 endif
210
211 ifeq ($(TARGET_TYPE),kmlibrary)
212 TARGET_NORC := yes
213 MK_MODE := static
214 MK_DEFEXT := .a
215 MK_CFLAGS := -I./ -I$(DDK_PATH_INC)
216 MK_CPPFLAGS := -I./ -I$(DDK_PATH_INC)
217 MK_IMPLIB := no
218 MK_IMPLIBONLY := no
219 MK_IMPLIBDEFPATH := $(DDK_PATH_LIB)
220 #MK_IMPLIB_EXT :=
221 endif
222 ifeq ($(TARGET_TYPE),driver_library)
223 MK_MODE := kernel
224 MK_EXETYPE := dll
225 MK_DEFEXT := .dll
226 MK_DEFENTRY :=
227 MK_DDKLIBS :=
228 MK_SDKLIBS :=
229 MK_CFLAGS := -I./ -I$(DDK_PATH_INC)
230 MK_CPPFLAGS := -I./ -I$(DDK_PATH_INC)
231 MK_IMPLIB := no
232 MK_IMPLIBONLY := yes
233 MK_IMPLIBDEFPATH := $(DDK_PATH_LIB)
234 MK_IMPLIB_EXT := .a
235 MK_INSTALLDIR := $(DDK_PATH_INC)
236 MK_BOOTCDDIR := .
237 MK_DISTDIR := # FIXME
238 MK_RES_BASE :=
239 endif
240
241 ifeq ($(TARGET_TYPE),driver)
242 MK_MODE := kernel
243 MK_EXETYPE := dll
244 MK_DEFEXT := .sys
245 MK_DEFENTRY := _DriverEntry@8
246 MK_DDKLIBS := ntoskrnl.a hal.a
247 MK_SDKLIBS :=
248 MK_CFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
249 MK_CPPFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
250 MK_IMPLIB := no
251 MK_IMPLIBONLY := no
252 MK_IMPLIBDEFPATH :=
253 MK_IMPLIB_EXT := .a
254 MK_INSTALLDIR := system32/drivers
255 MK_BOOTCDDIR := .
256 MK_DISTDIR := drivers
257 MK_RES_BASE := $(TARGET_NAME)
258 endif
259
260 ifeq ($(TARGET_TYPE),export_driver)
261 MK_MODE := kernel
262 MK_EXETYPE := dll
263 MK_DEFEXT := .sys
264 MK_DEFENTRY := _DriverEntry@8
265 MK_DDKLIBS := ntoskrnl.a hal.a
266 MK_SDKLIBS :=
267 MK_CFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
268 MK_CPPFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
269 MK_IMPLIB := yes
270 MK_IMPLIBONLY := no
271 MK_IMPLIBDEFPATH := $(DDK_PATH_LIB)
272 MK_IMPLIB_EXT := .a
273 MK_INSTALLDIR := system32/drivers
274 MK_BOOTCDDIR := .
275 MK_DISTDIR := drivers
276 MK_RES_BASE := $(TARGET_NAME)
277 endif
278
279 ifeq ($(TARGET_TYPE),hal)
280 MK_MODE := kernel
281 MK_EXETYPE := dll
282 MK_DEFEXT := .dll
283 MK_DEFENTRY := _DriverEntry@8
284 MK_DDKLIBS := ntoskrnl.a
285 MK_SDKLIBS :=
286 MK_CFLAGS := -D__NTHAL__ -I./ -I$(DDK_PATH_INC)
287 MK_CPPFLAGS := -D__NTHAL__ -I./ -I$(DDK_PATH_INC)
288 MK_IMPLIB := yes
289 MK_IMPLIBONLY := no
290 MK_IMPLIBDEFPATH :=
291 MK_IMPLIB_EXT := .a
292 MK_INSTALLDIR := system32
293 MK_BOOTCDDIR := .
294 MK_DISTDIR := dlls
295 MK_RES_BASE := $(TARGET_NAME)
296 endif
297
298 ifeq ($(TARGET_TYPE),bootpgm)
299 MK_MODE := kernel
300 MK_EXETYPE := exe
301 MK_DEFEXT := .exe
302 MK_DEFENTRY := _DriverEntry@8
303 MK_DDKLIBS :=
304 MK_SDKLIBS :=
305 MK_CFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
306 MK_CPPFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
307 MK_IMPLIB := no
308 MK_IMPLIBONLY := no
309 MK_IMPLIBDEFPATH :=
310 MK_IMPLIB_EXT := .a
311 MK_INSTALLDIR := system32
312 MK_BOOTCDDIR := system32
313 MK_DISTDIR := # FIXME
314 MK_RES_BASE := $(TARGET_NAME)
315 endif
316
317 ifeq ($(TARGET_TYPE),miniport)
318 MK_MODE := kernel
319 MK_EXETYPE := dll
320 MK_DEFEXT := .sys
321 MK_DEFENTRY := _DriverEntry@8
322 MK_DDKLIBS :=
323 MK_SDKLIBS :=
324 MK_CFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
325 MK_CPPFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
326 MK_IMPLIB := no
327 MK_IMPLIBONLY := no
328 MK_IMPLIBDEFPATH :=
329 MK_IMPLIB_EXT := .a
330 MK_INSTALLDIR := system32/drivers
331 MK_BOOTCDDIR := .
332 MK_DISTDIR := drivers
333 MK_RES_BASE := $(TARGET_NAME)
334 endif
335
336 ifeq ($(TARGET_TYPE),gdi_driver)
337 MK_MODE := kernel
338 MK_EXETYPE := dll
339 MK_DEFEXT := .dll
340 MK_DEFENTRY := _DrvEnableDriver@12
341 MK_DDKLIBS := ntoskrnl.a hal.a win32k.a
342 MK_SDKLIBS :=
343 MK_CFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
344 MK_CPPFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
345 MK_IMPLIB := yes
346 MK_IMPLIBONLY := no
347 MK_IMPLIBDEFPATH := $(DDK_PATH_LIB)
348 MK_IMPLIB_EXT := .a
349 MK_INSTALLDIR := system32
350 MK_BOOTCDDIR := .
351 MK_DISTDIR := dlls
352 MK_RES_BASE := $(TARGET_NAME)
353 endif
354
355
356 # can be overidden with $(CXX) for linkage of c++ executables
357 LD_CC = $(CC)
358
359
360 ifeq ($(TARGET_TYPE),program)
361 ifeq ($(TARGET_APPTYPE),windows)
362 MK_DEFENTRY := _WinMainCRTStartup
363 MK_SDKLIBS := ntdll.a kernel32.a gdi32.a user32.a
364 TARGET_LFLAGS += -Wl,--subsystem,windows
365 endif
366
367 ifeq ($(TARGET_APPTYPE),native)
368 MK_DEFENTRY := _NtProcessStartup@4
369 MK_SDKLIBS := ntdll.a
370 TARGET_LFLAGS += -Wl,--subsystem,native -nostartfiles
371 endif
372
373 ifeq ($(TARGET_APPTYPE),console)
374 MK_DEFENTRY := _mainCRTStartup
375 MK_SDKLIBS :=
376 TARGET_LFLAGS += -Wl,--subsystem,console
377 endif
378 endif
379
380 ifeq ($(TARGET_TYPE),proglib)
381 ifeq ($(TARGET_APPTYPE),windows)
382 MK_DEFENTRY := _WinMainCRTStartup
383 MK_SDKLIBS := ntdll.a kernel32.a gdi32.a user32.a
384 TARGET_LFLAGS += -Wl,--subsystem,windows
385 endif
386
387 ifeq ($(TARGET_APPTYPE),native)
388 MK_DEFENTRY := _NtProcessStartup@4
389 MK_SDKLIBS := ntdll.a
390 TARGET_LFLAGS += -Wl,--subsystem,native -nostartfiles
391 endif
392
393 ifeq ($(TARGET_APPTYPE),console)
394 MK_DEFENTRY := _mainCRTStartup
395 MK_SDKLIBS :=
396 TARGET_LFLAGS += -Wl,--subsystem,console
397 endif
398 endif
399
400 ifeq ($(TARGET_TYPE),subsystem)
401 MK_MODE := kernel
402 MK_EXETYPE := dll
403 MK_DEFEXT := .sys
404 MK_DEFENTRY := _DriverEntry@8
405 MK_DDKLIBS := ntoskrnl.a hal.a
406 MK_SDKLIBS :=
407 MK_CFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
408 MK_CPPFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
409 MK_IMPLIB := yes
410 MK_IMPLIBONLY := no
411 MK_IMPLIBDEFPATH := $(DDK_PATH_LIB)
412 MK_IMPLIB_EXT := .a
413 MK_INSTALLDIR := system32
414 MK_DISTDIR := drivers
415 MK_RES_BASE := $(TARGET_NAME)
416 endif
417
418 ifeq ($(TARGET_TYPE),kmdll)
419 MK_MODE := kernel
420 MK_EXETYPE := dll
421 MK_DEFEXT := .dll
422 MK_DEFENTRY := 0x0
423 MK_DDKLIBS := ntoskrnl.a hal.a
424 MK_SDKLIBS :=
425 MK_CFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
426 MK_CPPFLAGS := -D__NTDRIVER__ -I./ -I$(DDK_PATH_INC)
427 MK_IMPLIB := yes
428 MK_IMPLIBONLY := no
429 MK_IMPLIBDEFPATH := $(DDK_PATH_LIB)
430 MK_IMPLIB_EXT := .a
431 MK_INSTALLDIR := system32
432 MK_DISTDIR := drivers
433 MK_RES_BASE := $(TARGET_NAME)
434 endif
435
436 ifeq ($(TARGET_TYPE),winedll)
437 -include Makefile.ros
438 MK_GENERATED_MAKEFILE = Makefile.ros
439 MK_MODE := user
440 MK_EXETYPE := dll
441 MK_DEFEXT := .dll
442 MK_DEFENTRY := _DllMain@12
443 MK_DDKLIBS :=
444 MK_SDKLIBS :=
445 MK_CFLAGS := -D__USE_W32API -D_WIN32_IE=0x600 -D_WIN32_WINNT=0x501 -DWINVER=0x501 -D__need_offsetof -DCOBJMACROS -I$(PATH_TO_TOP)/include -I$(PATH_TO_TOP)/include/wine
446 MK_CPPFLAGS := -D__USE_W32API -D_WIN32_IE=0x600 -D_WIN32_WINNT=0x501 -DWINVER=0x501 -D__need_offsetof -DCOBJMACROS -I$(PATH_TO_TOP)/include -I$(PATH_TO_TOP)/include/wine
447 MK_RCFLAGS := --define __USE_W32API --include-dir $(PATH_TO_TOP)/include/wine
448 MK_IMPLIB := yes
449 MK_IMPLIBONLY := no
450 MK_IMPLIBDEFPATH := $(SDK_PATH_LIB)
451 MK_IMPLIB_EXT := .a
452 MK_INSTALLDIR := system32
453 MK_BOOTCDDIR := system32
454 MK_DISTDIR := dlls
455 MK_RES_BASE := $(TARGET_NAME)
456 ifeq ($(TARGET_DEFNAME),)
457 MK_DEFBASENAME := $(TARGET_NAME).spec
458 MK_SPECDEF := $(MK_DEFBASENAME).def
459 else
460 MK_DEFBASENAME := $(TARGET_DEFNAME)
461 endif
462 MK_KILLAT := --kill-at
463 TARGET_DEFONLY := yes
464 MK_RC_BINARIES = $(TARGET_RC_BINARIES)
465 endif
466
467 ifeq ($(TARGET_RC_SRCS),)
468 MK_RES_SRC := $(TARGET_PATH)/$(MK_RES_BASE).rc
469 MK_RESOURCE := $(MK_RES_BASE).coff
470 else
471 MK_RES_SRC := $(TARGET_RC_SRCS)
472 MK_RESOURCE := $(TARGET_RC_SRCS:.rc=.coff)
473 endif
474
475 ifneq ($(TARGET_INSTALLDIR),)
476 MK_INSTALLDIR := $(TARGET_INSTALLDIR)
477 endif
478
479
480 ifneq ($(BOOTCD_INSTALL),)
481 MK_INSTALLDIR := .
482 endif
483
484
485 ifeq ($(TARGET_LIBPATH),)
486 MK_IMPLIBPATH := $(MK_IMPLIBDEFPATH)
487 else
488 MK_IMPLIBPATH := $(TARGET_LIBPATH)
489 endif
490
491
492 ifeq ($(TARGET_BASENAME),)
493 MK_BASENAME := $(TARGET_NAME)
494 else
495 MK_BASENAME := $(TARGET_BASENAME)
496 endif
497
498
499 ifeq ($(TARGET_EXTENSION),)
500 MK_EXT := $(MK_DEFEXT)
501 else
502 MK_EXT := $(TARGET_EXTENSION)
503 endif
504
505
506 ifeq ($(TARGET_NORC),yes)
507 MK_FULLRES :=
508 else
509 MK_FULLRES := $(TARGET_PATH)/$(MK_RESOURCE)
510 endif
511
512 ifneq ($(TARGET_TYPE),winedll)
513 ifeq ($(TARGET_DEFNAME),)
514 MK_DEFBASENAME := $(TARGET_NAME)
515 else
516 MK_DEFBASENAME := $(TARGET_DEFNAME)
517 endif
518 endif
519
520 MK_DEFNAME := $(TARGET_PATH)/$(MK_DEFBASENAME).def
521 ifeq ($(TARGET_DEFONLY),yes)
522 MK_EDFNAME := $(MK_DEFNAME)
523 else
524 MK_EDFNAME := $(TARGET_PATH)/$(MK_DEFBASENAME).edf
525 endif
526
527
528 ifeq ($(MK_MODE),user)
529 ifeq ($(MK_EXETYPE),dll)
530 MK_DEFBASE := 0x10000000
531 else
532 MK_DEFBASE := 0x400000
533 endif
534 ifneq ($(TARGET_SDKLIBS),)
535 MK_LIBS := $(addprefix $(SDK_PATH_LIB)/, $(TARGET_SDKLIBS))
536 else
537 MK_LIBS := $(addprefix $(SDK_PATH_LIB)/, $(MK_SDKLIBS))
538 endif
539 endif
540
541
542 ifeq ($(MK_MODE),kernel)
543 MK_DEFBASE := 0x10000
544 MK_LIBS := $(addprefix $(DDK_PATH_LIB)/, $(TARGET_DDKLIBS) $(MK_DDKLIBS))
545 endif
546
547
548 ifneq ($(TARGET_LIBS),)
549 MK_LIBS := $(TARGET_LIBS) $(MK_LIBS)
550 endif
551
552
553 ifeq ($(TARGET_BASE),)
554 TARGET_BASE := $(MK_DEFBASE)
555 endif
556
557
558 ifeq ($(TARGET_ENTRY),)
559 TARGET_ENTRY := $(MK_DEFENTRY)
560 endif
561
562 #
563 # Include details of the OS configuration
564 #
565 include $(PATH_TO_TOP)/config
566
567
568 TARGET_ASFLAGS += -march=$(ARCH) -D$(MK_ARCH_ID)
569 TARGET_CFLAGS += $(MK_CFLAGS)
570 TARGET_CFLAGS += -pipe -march=$(ARCH) -D$(MK_ARCH_ID)
571 ifeq ($(DBG),1)
572 TARGET_ASFLAGS += -g
573 TARGET_CFLAGS += -g
574 TARGET_LFLAGS += -g
575 endif
576
577 TARGET_CPPFLAGS += $(MK_CPPFLAGS)
578 TARGET_CPPFLAGS += -pipe -march=$(ARCH) -D$(MK_ARCH_ID)
579
580 TARGET_RCFLAGS += $(MK_RCFLAGS)
581
582 TARGET_ASFLAGS += $(MK_ASFLAGS)
583 TARGET_ASFLAGS += -pipe -march=$(ARCH)
584
585 TARGET_NFLAGS += $(MK_NFLAGS)
586
587
588 MK_GCCLIBS := $(addprefix -l, $(TARGET_GCCLIBS))
589
590 ifeq ($(TARGET_TYPE), library)
591 MK_FULLNAME := $(SDK_PATH_LIB)/$(MK_BASENAME)$(MK_EXT)
592 else
593 MK_FULLNAME := $(MK_BASENAME)$(MK_EXT)
594 endif
595
596 ifeq ($(TARGET_TYPE), kmlibrary)
597 MK_FULLNAME := $(DDK_PATH_LIB)/$(MK_BASENAME)$(MK_EXT)
598 endif
599
600 MK_IMPLIB_FULLNAME := $(MK_BASENAME)$(MK_IMPLIB_EXT)
601
602 MK_NOSTRIPNAME := $(MK_BASENAME).nostrip$(MK_EXT)
603
604 # We don't want to link header files
605 MK_OBJECTS := $(filter-out %.h,$(TARGET_OBJECTS))
606
607 # There is problems with C++ applications and ld -r. Ld can cause errors like:
608 # reloc refers to symbol `.text$_ZN9CCABCodecC2Ev' which is not being output
609 ifeq ($(TARGET_CPPAPP),yes)
610 MK_STRIPPED_OBJECT := $(MK_OBJECTS)
611 else
612 MK_STRIPPED_OBJECT := $(MK_BASENAME).stripped.o
613 endif
614
615 ifeq ($(MK_IMPLIBONLY),yes)
616
617 TARGET_CLEAN += $(MK_IMPLIBPATH)/$(MK_IMPLIB_FULLNAME)
618
619 all: $(MK_IMPLIBPATH)/$(MK_IMPLIB_FULLNAME)
620
621 $(MK_IMPLIBPATH)/$(MK_IMPLIB_FULLNAME): $(TARGET_OBJECTS) $(MK_DEFNAME)
622 $(DLLTOOL) \
623 --dllname $(MK_FULLNAME) \
624 --def $(MK_DEFNAME) \
625 --output-lib $(MK_IMPLIBPATH)/$(MK_BASENAME).a \
626 --kill-at
627
628 else # MK_IMPLIBONLY
629
630 all: $(MK_FULLNAME) $(MK_NOSTRIPNAME) $(SUBDIRS:%=%_all)
631
632
633 ifeq ($(MK_IMPLIB),yes)
634 MK_EXTRACMD := --def $(MK_EDFNAME)
635 else
636 MK_EXTRACMD :=
637 endif
638
639 # User mode targets
640 ifeq ($(MK_MODE),user)
641
642 ifeq ($(MK_EXETYPE),dll)
643 TARGET_LFLAGS += -mdll -Wl,--image-base,$(TARGET_BASE)
644 MK_EXTRADEP := $(MK_EDFNAME)
645 MK_EXTRACMD2 := -Wl,temp.exp
646 else
647 MK_EXTRADEP :=
648 MK_EXTRACMD2 :=
649 endif
650
651 $(MK_NOSTRIPNAME): $(MK_FULLRES) $(TARGET_OBJECTS) $(MK_EXTRADEP) $(MK_LIBS)
652 ifeq ($(MK_EXETYPE),dll)
653 $(LD_CC) -Wl,--base-file,base.tmp \
654 -Wl,--entry,$(TARGET_ENTRY) \
655 $(TARGET_LFLAGS) \
656 -o junk.tmp \
657 $(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS)
658 - $(RM) junk.tmp
659 $(DLLTOOL) --dllname $(MK_FULLNAME) \
660 --base-file base.tmp \
661 --output-exp temp.exp $(MK_EXTRACMD)
662 - $(RM) base.tmp
663 $(LD_CC) -Wl,--base-file,base.tmp \
664 -Wl,--entry,$(TARGET_ENTRY) \
665 $(TARGET_LFLAGS) \
666 temp.exp \
667 -o junk.tmp \
668 $(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS)
669 - $(RM) junk.tmp
670 $(DLLTOOL) --dllname $(MK_FULLNAME) \
671 --base-file base.tmp \
672 --output-exp temp.exp $(MK_KILLAT) $(MK_EXTRACMD)
673 - $(RM) base.tmp
674 endif
675 $(LD_CC) $(TARGET_LFLAGS) \
676 -Wl,--entry,$(TARGET_ENTRY) $(MK_EXTRACMD2) \
677 -o $(MK_NOSTRIPNAME) \
678 $(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS)
679 - $(RM) temp.exp
680 - $(RSYM) $(MK_NOSTRIPNAME) $(MK_BASENAME).sym
681 ifeq ($(FULL_MAP),yes)
682 $(OBJDUMP) -d -S $(MK_NOSTRIPNAME) > $(MK_BASENAME).map
683 else
684 $(NM) --numeric-sort $(MK_NOSTRIPNAME) > $(MK_BASENAME).map
685 endif
686
687 $(MK_FULLNAME): $(MK_NOSTRIPNAME) $(MK_EXTRADEP)
688 -
689 ifneq ($(TARGET_CPPAPP),yes)
690 $(LD) -r -o $(MK_STRIPPED_OBJECT) $(MK_OBJECTS)
691 $(STRIP) --strip-debug $(MK_STRIPPED_OBJECT)
692 endif
693 ifeq ($(MK_EXETYPE),dll)
694 $(LD_CC) -Wl,--base-file,base.tmp \
695 -Wl,--entry,$(TARGET_ENTRY) \
696 -Wl,--strip-debug \
697 $(TARGET_LFLAGS) \
698 -o junk.tmp \
699 $(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
700 - $(RM) junk.tmp
701 $(DLLTOOL) --dllname $(MK_FULLNAME) \
702 --base-file base.tmp \
703 --output-exp temp.exp $(MK_EXTRACMD)
704 - $(RM) base.tmp
705 $(LD_CC) -Wl,--base-file,base.tmp \
706 -Wl,--entry,$(TARGET_ENTRY) \
707 -Wl,--strip-debug \
708 $(TARGET_LFLAGS) \
709 temp.exp \
710 -o junk.tmp \
711 $(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
712 - $(RM) junk.tmp
713 $(DLLTOOL) --dllname $(MK_FULLNAME) \
714 --base-file base.tmp \
715 --output-exp temp.exp $(MK_KILLAT) $(MK_EXTRACMD)
716 - $(RM) base.tmp
717 endif
718 $(LD_CC) $(TARGET_LFLAGS) \
719 -Wl,--entry,$(TARGET_ENTRY) \
720 -Wl,--strip-debug \
721 $(MK_EXTRACMD2) \
722 -o $(MK_FULLNAME) \
723 $(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
724 ifneq ($(TARGET_CPPAPP),yes)
725 - $(RM) temp.exp $(MK_STRIPPED_OBJECT)
726 else
727 - $(RM) temp.exp
728 endif
729
730 endif # KM_MODE
731
732 # Kernel mode targets
733 ifeq ($(MK_MODE),kernel)
734
735 ifeq ($(MK_IMPLIB),yes)
736 MK_EXTRACMD := --def $(MK_EDFNAME)
737 MK_EXTRADEP := $(MK_EDFNAME)
738 else
739 MK_EXTRACMD :=
740 MK_EXTRADEP :=
741 endif
742
743 $(MK_NOSTRIPNAME): $(MK_FULLRES) $(TARGET_OBJECTS) $(MK_EXTRADEP) $(MK_LIBS)
744 $(LD_CC) -Wl,--base-file,base.tmp \
745 -Wl,--entry,$(TARGET_ENTRY) \
746 $(TARGET_LFLAGS) \
747 -nostartfiles -nostdlib \
748 -o junk.tmp \
749 $(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS)
750 - $(RM) junk.tmp
751 $(DLLTOOL) --dllname $(MK_FULLNAME) \
752 --base-file base.tmp \
753 --output-exp temp.exp $(MK_EXTRACMD)
754 - $(RM) base.tmp
755 $(LD_CC) $(TARGET_LFLAGS) \
756 -Wl,--subsystem,native \
757 -Wl,--image-base,$(TARGET_BASE) \
758 -Wl,--file-alignment,0x1000 \
759 -Wl,--section-alignment,0x1000 \
760 -Wl,--entry,$(TARGET_ENTRY) \
761 -Wl,temp.exp \
762 -mdll -nostartfiles -nostdlib \
763 -o $(MK_NOSTRIPNAME) \
764 $(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS)
765 - $(RM) temp.exp
766 $(RSYM) $(MK_NOSTRIPNAME) $(MK_BASENAME).sym
767 ifeq ($(FULL_MAP),yes)
768 $(OBJDUMP) -d -S $(MK_NOSTRIPNAME) > $(MK_BASENAME).map
769 else
770 $(NM) --numeric-sort $(MK_NOSTRIPNAME) > $(MK_BASENAME).map
771 endif
772
773 $(MK_FULLNAME): $(MK_FULLRES) $(TARGET_OBJECTS) $(MK_EXTRADEP) $(MK_LIBS) $(MK_NOSTRIPNAME)
774 -
775 ifneq ($(TARGET_CPPAPP),yes)
776 $(LD) -r -o $(MK_STRIPPED_OBJECT) $(MK_OBJECTS)
777 $(STRIP) --strip-debug $(MK_STRIPPED_OBJECT)
778 endif
779 $(LD_CC) -Wl,--base-file,base.tmp \
780 -Wl,--entry,$(TARGET_ENTRY) \
781 $(TARGET_LFLAGS) \
782 -nostartfiles -nostdlib \
783 -o junk.tmp \
784 $(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
785 - $(RM) junk.tmp
786 $(DLLTOOL) --dllname $(MK_FULLNAME) \
787 --base-file base.tmp \
788 --output-exp temp.exp $(MK_EXTRACMD)
789 - $(RM) base.tmp
790 $(LD_CC) $(TARGET_LFLAGS) \
791 -Wl,--subsystem,native \
792 -Wl,--image-base,$(TARGET_BASE) \
793 -Wl,--file-alignment,0x1000 \
794 -Wl,--section-alignment,0x1000 \
795 -Wl,--entry,$(TARGET_ENTRY) \
796 -Wl,temp.exp \
797 -mdll -nostartfiles -nostdlib \
798 -o $(MK_FULLNAME) \
799 $(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
800 ifneq ($(TARGET_CPPAPP),yes)
801 - $(RM) temp.exp $(MK_STRIPPED_OBJECT)
802 else
803 - $(RM) temp.exp
804 endif
805
806 endif # MK_MODE
807
808 # Static library target
809 ifeq ($(MK_MODE),static)
810
811 $(MK_FULLNAME): $(TARGET_OBJECTS)
812 $(AR) -r $(MK_FULLNAME) $(TARGET_OBJECTS)
813
814 # Static libraries dont have a nostrip version
815 $(MK_NOSTRIPNAME):
816 -
817
818 .PHONY: $(MK_NOSTRIPNAME)
819
820 endif # MK_MODE
821
822 endif # MK_IMPLIBONLY
823
824
825 $(MK_FULLRES): $(PATH_TO_TOP)/include/reactos/buildno.h $(MK_RES_SRC)
826
827 ifeq ($(MK_DEPENDS),yes)
828 depends:
829 else
830 depends:
831 endif
832
833 ifeq ($(MK_IMPLIB),yes)
834 $(MK_IMPLIBPATH)/$(MK_BASENAME).a: $(MK_DEFNAME)
835 $(DLLTOOL) --dllname $(MK_FULLNAME) \
836 --def $(MK_DEFNAME) \
837 --output-lib $(MK_IMPLIBPATH)/$(MK_BASENAME).a \
838 --kill-at
839
840 implib: $(MK_IMPLIBPATH)/$(MK_BASENAME).a
841 else
842 implib: $(SUBDIRS:%=%_implib)
843 endif
844
845 # Be carefull not to clean non-object files
846 MK_CLEANFILES := $(filter %.o,$(MK_OBJECTS))
847 MK_CLEANFILTERED := $(MK_OBJECTS:.o=.d)
848 MK_CLEANDEPS := $(join $(dir $(MK_CLEANFILTERED)), $(addprefix ., $(notdir $(MK_CLEANFILTERED))))
849
850 clean: $(SUBDIRS:%=%_clean)
851 - $(RM) *.o depend.d *.pch $(MK_BASENAME).sym $(MK_BASENAME).a $(MK_RESOURCE) \
852 $(MK_FULLNAME) $(MK_NOSTRIPNAME) $(MK_CLEANFILES) $(MK_CLEANDEPS) $(MK_BASENAME).map \
853 junk.tmp base.tmp temp.exp $(MK_RC_BINARIES) $(MK_SPECDEF) $(MK_GENERATED_MAKEFILE) \
854 $(TARGET_CLEAN)
855
856 ifneq ($(TARGET_HEADERS),)
857 $(TARGET_OBJECTS): $(TARGET_HEADERS)
858 endif
859
860 # install and bootcd rules
861
862 ifeq ($(MK_IMPLIBONLY),yes)
863
864 # Don't install import libraries
865
866 install:
867
868 bootcd:
869
870 else # MK_IMPLIBONLY
871
872
873 # Don't install static libraries
874 ifeq ($(MK_MODE),static)
875
876 install:
877
878 bootcd:
879
880 else # MK_MODE
881
882 ifeq ($(INSTALL_SYMBOLS),yes)
883
884 install: $(SUBDIRS:%=%_install)
885 -$(CP) $(MK_FULLNAME) $(INSTALL_DIR)/$(MK_INSTALLDIR)/$(MK_FULLNAME)
886 -$(CP) $(MK_BASENAME).sym $(INSTALL_DIR)/symbols/$(MK_BASENAME).sym
887
888 else # INSTALL_SYMBOLS
889
890 install: $(SUBDIRS:%=%_install)
891 -$(CP) $(MK_FULLNAME) $(INSTALL_DIR)/$(MK_INSTALLDIR)/$(MK_FULLNAME)
892
893 endif # INSTALL_SYMBOLS
894
895
896 # Bootstrap files for the bootable CD
897 ifeq ($(TARGET_BOOTSTRAP),yes)
898
899 ifneq ($(TARGET_BOOTSTRAP_NAME),)
900 MK_BOOTSTRAP_NAME := $(TARGET_BOOTSTRAP_NAME)
901 else # TARGET_BOOTSTRAP_NAME
902 MK_BOOTSTRAP_NAME := $(MK_FULLNAME)
903 endif # TARGET_BOOTSTRAP_NAME
904
905 bootcd: $(SUBDIRS:%=%_bootcd)
906 - $(CP) $(MK_FULLNAME) $(BOOTCD_DIR)/reactos/$(MK_BOOTCDDIR)/$(MK_BOOTSTRAP_NAME)
907
908 else # TARGET_BOOTSTRAP
909
910 bootcd:
911
912 endif # TARGET_BOOTSTRAP
913
914 endif # MK_MODE
915
916 endif # MK_IMPLIBONLY
917
918 ifeq ($(TARGET_TYPE),winedll)
919 Makefile.ros: Makefile.in Makefile.ros-template
920 $(TOOLS_PATH)/wine2ros/wine2ros Makefile.in Makefile.ros-template Makefile.ros
921
922 $(MK_RC_BINARIES): $(TARGET_RC_BINSRC)
923 $(TOOLS_PATH)/bin2res/bin2res -f -o $@ $(TARGET_RC_BINSRC)
924
925 $(MK_RESOURCE): $(MK_RC_BINARIES)
926 endif
927
928 .PHONY: all depends implib clean install dist bootcd depends
929
930 ifneq ($(SUBDIRS),)
931 $(SUBDIRS:%=%_all): %_all:
932 $(MAKE) -C $* SUBDIRS= all
933
934 $(SUBDIRS:%=%_implib): %_implib:
935 $(MAKE) -C $* SUBDIRS= implib
936
937 $(SUBDIRS:%=%_clean): %_clean:
938 $(MAKE) -C $* SUBDIRS= clean
939
940 $(SUBDIRS:%=%_install): %_install:
941 $(MAKE) -C $* SUBDIRS= install
942
943 $(SUBDIRS:%=%_dist): %_dist:
944 $(MAKE) -C $* SUBDIRS= dist
945
946 $(SUBDIRS:%=%_bootcd): %_bootcd:
947 $(MAKE) -C $* SUBDIRS= bootcd
948
949 .PHONY: $(SUBDIRS:%=%_all) $(SUBDIRS:%=%_implib) $(SUBDIRS:%=%_clean) \
950 $(SUBDIRS:%=%_install) $(SUBDIRS:%=%_dist) $(SUBDIRS:%=%_bootcd)
951 endif
952
953 # Precompiled header support
954 # When using PCHs, use dependency tracking to keep the .pch files up-to-date.
955
956 MK_PCHNAME =
957 ifeq ($(ROS_USE_PCH),yes)
958 ifneq ($(TARGET_PCH),)
959 MK_PCHNAME = $(TARGET_PCH).pch
960
961 # GCC generates wrong dependencies for header files.
962 MK_PCHFAKE = $(TARGET_PCH:.h=.o)
963 $(MK_PCHFAKE):
964 - $(RTOUCH) $(MK_PCHFAKE)
965
966 $(MK_PCHNAME): depend.d
967 - $(RTOUCH) $(MK_PCHNAME)
968 - $(CC) $(TARGET_CFLAGS) $(TARGET_PCH)
969
970 depend.d: $(MK_PCHFAKE)
971 - $(RTOUCH) depend.d
972 - $(CC) $(TARGET_CFLAGS) $(TARGET_PCH) -M -MF depend.d
973
974 include depend.d
975
976 endif # TARGET_PCH
977 endif # ROS_USE_PCH
978
979
980 %.o: %.c $(MK_PCHNAME)
981 $(CC) $(TARGET_CFLAGS) -c $< -o $@
982 %.o: %.cc
983 $(CXX) $(TARGET_CPPFLAGS) -c $< -o $@
984 %.o: %.cxx
985 $(CXX) $(TARGET_CPPFLAGS) -c $< -o $@
986 %.o: %.cpp
987 $(CXX) $(TARGET_CPPFLAGS) -c $< -o $@
988 %.o: %.S
989 $(AS) $(TARGET_ASFLAGS) -c $< -o $@
990 %.o: %.s
991 $(AS) $(TARGET_ASFLAGS) -c $< -o $@
992 %.o: %.asm
993 $(NASM_CMD) $(NFLAGS) $(TARGET_NFLAGS) $< -o $@
994 %.coff: %.rc
995 $(RC) $(TARGET_RCFLAGS) $(RCINC) $< -o $@
996 %.spec.def: %.spec
997 $(WINEBUILD) $(DEFS) -o $@ --def $<
998 # Kill implicit rule
999 .o:;
1000
1001 # Compatibility
1002 CFLAGS := $(TARGET_CFLAGS)
1003
1004 # EOF