Fixed order of TARGET_LFLAGS in the command lines of rules for kernel-mode targets
[reactos.git] / reactos / tools / helper.mk
index 3da55ec..453f49e 100644 (file)
@@ -1,4 +1,4 @@
-# $Id: helper.mk,v 1.9 2001/12/11 06:00:07 phreak Exp $
+# $Id: helper.mk,v 1.12 2002/04/29 23:02:12 hyperion Exp $
 #
 # Helper makefile for ReactOS modules
 # Variables this makefile accepts:
@@ -6,7 +6,7 @@
 #                        program = User mode program
 #                        proglib = Executable program that have exported functions
 #                        dynlink = Dynamic Link Library (DLL)
-#                        library = Import library that will be linked with other code
+#                        library = Library that will be linked with other code
 #                        driver_library = Import library for a driver
 #                        driver = Kernel mode driver
 #                        export_driver = Kernel mode driver that have exported functions
@@ -125,8 +125,8 @@ endif
 endif
 
 ifeq ($(TARGET_TYPE),library)
-  MK_MODE := user
-  MK_EXETYPE := dll
+  MK_MODE := static
+  MK_EXETYPE :=
   MK_DEFEXT := .a
   MK_DEFENTRY :=
   MK_DDKLIBS :=
@@ -135,12 +135,12 @@ ifeq ($(TARGET_TYPE),library)
   MK_CPPFLAGS := -I./ -I$(SDK_PATH_INC)
   MK_RCFLAGS := --include-dir $(SDK_PATH_INC)
   MK_IMPLIB := no
-  MK_IMPLIBONLY := yes
-  MK_IMPLIBDEFPATH := $(SDK_PATH_LIB)
-  MK_IMPLIB_EXT := .a
+  MK_IMPLIBONLY := no
+  MK_IMPLIBDEFPATH :=
+  MK_IMPLIB_EXT :=
   MK_INSTALLDIR := $(SDK_PATH_INC)
   MK_DISTDIR := # FIXME
-  MK_RES_BASE := 
+  MK_RES_BASE :=
 endif
 
 ifeq ($(TARGET_TYPE),driver_library)
@@ -398,6 +398,7 @@ MK_NOSTRIPNAME := $(MK_BASENAME).nostrip$(MK_EXT)
 
 # We don't want to link header files
 MK_OBJECTS := $(filter-out %.h,$(TARGET_OBJECTS)) 
+MK_STRIPPED_OBJECT := $(MK_BASENAME).stripped.o
 
 ifeq ($(MK_IMPLIBONLY),yes)
 
@@ -415,7 +416,7 @@ $(MK_IMPLIBPATH)/$(MK_IMPLIB_FULLNAME): $(TARGET_OBJECTS)
 else # MK_IMPLIBONLY
 
 
-all: $(MK_FULLNAME)
+all: $(MK_FULLNAME) $(MK_NOSTRIPNAME)
        
 
 ifeq ($(MK_IMPLIB),yes)
@@ -453,6 +454,11 @@ endif
          $(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS)
        - $(RM) temp.exp
        - $(NM) --numeric-sort $(MK_NOSTRIPNAME) > $(MK_BASENAME).sym
+
+$(MK_FULLNAME): $(MK_NOSTRIPNAME)
+        $(CP) $(MK_NOSTRIPNAME) $(MK_FULLNAME)
+#       $(STRIP) --strip-debug $(MK_FULLNAME)
+
 endif # KM_MODE
 
 # Kernel mode targets 
@@ -476,24 +482,60 @@ $(MK_NOSTRIPNAME): $(MK_FULLRES) $(TARGET_OBJECTS) $(MK_LIBS)
                --base-file base.tmp \
                --output-exp temp.exp $(MK_EXTRACMD)
        - $(RM) base.tmp
-       $(CC) $(TARGET_LFLAGS) \
+       $(CC) \
                -Wl,--subsystem,native \
                -Wl,--image-base,$(TARGET_BASE) \
                -Wl,--file-alignment,0x1000 \
                -Wl,--section-alignment,0x1000 \
                -Wl,--entry,$(TARGET_ENTRY) \
                -Wl,temp.exp \
+               $(TARGET_LFLAGS) \
                -mdll -nostartfiles -nostdlib \
                -o $(MK_NOSTRIPNAME) \
          $(MK_FULLRES) $(MK_OBJECTS) $(MK_LIBS) $(MK_GCCLIBS)
        - $(RM) temp.exp
        - $(NM) --numeric-sort $(MK_NOSTRIPNAME) > $(MK_BASENAME).sym
 
+$(MK_FULLNAME): $(MK_FULLRES) $(TARGET_OBJECTS) $(MK_LIBS)
+       $(LD) -r -o $(MK_STRIPPED_OBJECT) $(MK_OBJECTS)
+       $(STRIP) --strip-debug $(MK_STRIPPED_OBJECT)
+       $(CC) -Wl,--base-file,base.tmp \
+               -Wl,--entry,$(TARGET_ENTRY) \
+               $(TARGET_LFLAGS) \
+               -nostartfiles -nostdlib \
+               -o junk.tmp \
+               $(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
+       - $(RM) junk.tmp
+       $(DLLTOOL) --dllname $(MK_FULLNAME) \
+               --base-file base.tmp \
+               --output-exp temp.exp $(MK_EXTRACMD)
+       - $(RM) base.tmp
+       $(CC) \
+               -Wl,--subsystem,native \
+               -Wl,--image-base,$(TARGET_BASE) \
+               -Wl,--file-alignment,0x1000 \
+               -Wl,--section-alignment,0x1000 \
+               -Wl,--entry,$(TARGET_ENTRY) \
+               -Wl,temp.exp \
+               $(TARGET_LFLAGS) \
+               -mdll -nostartfiles -nostdlib \
+               -o $(MK_FULLNAME) \
+         $(MK_FULLRES) $(MK_STRIPPED_OBJECT) $(MK_LIBS) $(MK_GCCLIBS)
+       - $(RM) temp.exp
+
 endif # MK_MODE
 
+# Static library target
+ifeq ($(MK_MODE),static)
+
+$(MK_NOSTRIPNAME): $(TARGET_OBJECTS)
+       $(AR) -r $(MK_NOSTRIPNAME) $(TARGET_OBJECTS)
+
+# FIXME: dummy rule
 $(MK_FULLNAME): $(MK_NOSTRIPNAME)
         $(CP) $(MK_NOSTRIPNAME) $(MK_FULLNAME)
-#       $(STRIP) --strip-debug $(MK_FULLNAME)
+
+endif # MK_MODE
 
 endif # MK_IMPLIBONLY