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