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