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