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