jdk/makefiles/common/internal/NativeCompileRules.gmk
changeset 13164 72c5d01a857d
parent 13082 9b19b2302c28
child 13167 efec101d7d87
equal deleted inserted replaced
13082:9b19b2302c28 13164:72c5d01a857d
     1 #
       
     2 # Copyright (c) 1995, 2007, Oracle and/or its affiliates. All rights reserved.
       
     3 # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
       
     4 #
       
     5 # This code is free software; you can redistribute it and/or modify it
       
     6 # under the terms of the GNU General Public License version 2 only, as
       
     7 # published by the Free Software Foundation.  Oracle designates this
       
     8 # particular file as subject to the "Classpath" exception as provided
       
     9 # by Oracle in the LICENSE file that accompanied this code.
       
    10 #
       
    11 # This code is distributed in the hope that it will be useful, but WITHOUT
       
    12 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
       
    13 # FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
       
    14 # version 2 for more details (a copy is included in the LICENSE file that
       
    15 # accompanied this code).
       
    16 #
       
    17 # You should have received a copy of the GNU General Public License version
       
    18 # 2 along with this work; if not, write to the Free Software Foundation,
       
    19 # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
       
    20 #
       
    21 # Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
       
    22 # or visit www.oracle.com if you need additional information or have any
       
    23 # questions.
       
    24 #
       
    25 
       
    26 #
       
    27 # Native C/C++ Compile Rules
       
    28 #
       
    29 
       
    30 -include $(SPEC)
       
    31 -include $(VARS)
       
    32 
       
    33 COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) -c
       
    34 COMPILE.cc = $(CXX) $(CXXFLAGS) $(CPPFLAGS) -c
       
    35 
       
    36 #
       
    37 # INCREMENTAL_BUILD: Record the #include file dependencies.
       
    38 #
       
    39 # NOTE: We build make include files with the suffix
       
    40 #       $(DEPEND_SUFFIX) on every compilation. These are initially 
       
    41 #       created as temp files just in case a ^C kills it in the middle.
       
    42 #	Compiler is smart enough to handle ^C and not create the .o file, or
       
    43 #	is supposed to be that smart, but the .$(DEPEND_SUFFIX) file 
       
    44 #       creation here isn't.
       
    45 #	These .$(DEPEND_SUFFIX) files are included by Library.gmk and 
       
    46 #       Program.gmk, when they exist (Search for 'make dependencies').
       
    47 #
       
    48 
       
    49 ifeq ($(INCREMENTAL_BUILD),true)
       
    50 
       
    51 $(OBJDIR)/%.$(DEPEND_SUFFIX): %.c
       
    52 	@$(prep-target)
       
    53 	@$(ECHO) "Creating $@"
       
    54 	@$(RM) $@.temp
       
    55 	@$(CC) $(CC_DEPEND) $(CPPFLAGS) $< 2> $(DEV_NULL) | \
       
    56 	    $(CC_DEPEND_FILTER) > $@.temp
       
    57 	@$(MV) $@.temp $@
       
    58 
       
    59 $(OBJDIR)/%.$(DEPEND_SUFFIX): %.cpp
       
    60 	@$(prep-target)
       
    61 	@$(ECHO) "Creating $@"
       
    62 	@$(RM) $@.temp
       
    63 	@$(CXX) $(CC_DEPEND) $(CPPFLAGS) $(CXXFLAGS) $< 2> $(DEV_NULL) | \
       
    64 	    $(CC_DEPEND_FILTER) > $@.temp
       
    65 	@$(MV) $@.temp $@
       
    66 
       
    67 endif # INCREMENTAL_BUILD
       
    68 
       
    69 #
       
    70 # C, C++, asm files.
       
    71 #
       
    72 # Normal or parallel compile rule is the same, but batch compiles require
       
    73 #  we save up the sources files that use the same compile line so that we
       
    74 #  can do one compile line.
       
    75 #
       
    76 
       
    77 ifneq ($(COMPILE_APPROACH), batch)
       
    78 
       
    79 $(OBJDIR)/%.$(OBJECT_SUFFIX): %.c
       
    80 	@$(prep-target)
       
    81 	$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
       
    82 	@$(check-conventions)
       
    83 
       
    84 $(OBJDIR)/%.$(OBJECT_SUFFIX): %.cpp
       
    85 	@$(prep-target)
       
    86 	$(COMPILE.cc) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
       
    87 	@$(check-conventions)
       
    88 
       
    89 else
       
    90   
       
    91   #
       
    92   # Batch compiling might be faster if the compiler was smart about recognizing
       
    93   #   optimization opportunities available when all files are being compiled
       
    94   #   the same way. Unfortunately this is rare.
       
    95   #   Automatic pre-compiled headers (pch) might be a possibility so we
       
    96   #   add any auto pch options here.
       
    97   # So we save all the source files that have the same compile line as the
       
    98   #   first file. A normal compile pass is made after the batch compile
       
    99   #   to catch anything missed.
       
   100   # If the compilers had a -o option that allowed us to direct where to
       
   101   #   write the object files to, then we would not need to save the object
       
   102   #   file list or move them from the make directory to the build directory.
       
   103   #
       
   104 
       
   105   # Source names
       
   106   COMPILE_LIST.c         = $(OBJDIR)/.source_names_c
       
   107   COMPILE_LIST.cpp       = $(OBJDIR)/.source_names_cpp
       
   108 
       
   109   # Object file list
       
   110   COMPILE_OBJ_LIST.c     = $(OBJDIR)/.obj_names_c
       
   111   COMPILE_OBJ_LIST.cpp   = $(OBJDIR)/.obj_names_cpp
       
   112   
       
   113   # The compile line
       
   114   COMPILE_BATCH.c        = $(OBJDIR)/.compile_c
       
   115   COMPILE_BATCH.cpp      = $(OBJDIR)/.compile_cpp
       
   116 
       
   117   # The compile line for the current target
       
   118   THIS_COMPILE_BATCH.c   = $(COMPILE_BATCH.c)-$(@F)
       
   119   THIS_COMPILE_BATCH.cpp = $(COMPILE_BATCH.cpp)-$(@F)
       
   120 
       
   121 $(OBJDIR)/%.$(OBJECT_SUFFIX): %.c
       
   122 	@$(prep-target)
       
   123 	@$(ECHO) "$(COMPILE.c) $(CFLAGS_GPROF)" > $(THIS_COMPILE_BATCH.c)
       
   124 	@if [ ! -s $(COMPILE_BATCH.c) ] ; then \
       
   125 	  $(CP) $(THIS_COMPILE_BATCH.c) $(COMPILE_BATCH.c) ; \
       
   126 	  $(ECHO) $< > $(COMPILE_LIST.c); \
       
   127 	  $(ECHO) $(@F) > $(COMPILE_OBJ_LIST.c); \
       
   128 	elif [ "`$(DIFF) -w -b $(THIS_COMPILE_BATCH.c) $(COMPILE_BATCH.c)`" \
       
   129 	       = "" ] ; then \
       
   130 	  $(ECHO) $< >> $(COMPILE_LIST.c); \
       
   131 	  $(ECHO) $(@F) >> $(COMPILE_OBJ_LIST.c); \
       
   132 	fi
       
   133 	@$(RM) $(THIS_COMPILE_BATCH.c)
       
   134 	@$(check-conventions)
       
   135 
       
   136 $(OBJDIR)/%.$(OBJECT_SUFFIX): %.cpp
       
   137 	@$(prep-target)
       
   138 	@$(ECHO) "$(COMPILE.cc) $(CFLAGS_GPROF)" > $(THIS_COMPILE_BATCH.cpp)
       
   139 	@if [ ! -s $(COMPILE_BATCH.cpp) ] ; then \
       
   140 	  $(CP) $(THIS_COMPILE_BATCH.cpp) $(COMPILE_BATCH.cpp) ; \
       
   141 	  $(ECHO) $< > $(COMPILE_LIST.cpp); \
       
   142 	  $(ECHO) $(@F) > $(COMPILE_OBJ_LIST.cpp); \
       
   143 	elif [ "`$(DIFF) -w -b $(THIS_COMPILE_BATCH.cpp) $(COMPILE_BATCH.cpp)`"\
       
   144 	       = "" ] ; then \
       
   145 	  $(ECHO) $< >> $(COMPILE_LIST.cpp); \
       
   146 	  $(ECHO) $(@F) >> $(COMPILE_OBJ_LIST.cpp); \
       
   147 	fi
       
   148 	@$(RM) $(THIS_COMPILE_BATCH.cpp)
       
   149 	@$(check-conventions)
       
   150 
       
   151 batch_compile: $(FILES_o)
       
   152 	@$(ECHO) "Doing batch compilations"
       
   153 	@if [ -s $(COMPILE_LIST.c) ] ; then \
       
   154 	  $(ECHO) "$(COMPILE.c) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \
       
   155 	   `$(CAT) $(COMPILE_LIST.c)`" ; \
       
   156 	  ( $(COMPILE.c) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \
       
   157 	    `$(CAT) $(COMPILE_LIST.c)` && \
       
   158 	    $(ECHO) "$(MV) `$(CAT) $(COMPILE_OBJ_LIST.c)` $(OBJDIR)" && \
       
   159 	    $(MV) `$(CAT) $(COMPILE_OBJ_LIST.c)` $(OBJDIR) ) || exit 1 ; \
       
   160 	fi
       
   161 	@if [ -s $(COMPILE_LIST.cpp) ] ; then \
       
   162 	  $(ECHO) "$(COMPILE.cc) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \
       
   163 	   `$(CAT) $(COMPILE_LIST.cpp)`" ; \
       
   164 	  ( $(COMPILE.cc) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \
       
   165 	    `$(CAT) $(COMPILE_LIST.cpp)` && \
       
   166 	    $(ECHO) "$(MV) `$(CAT) $(COMPILE_OBJ_LIST.cpp)` $(OBJDIR)" && \
       
   167 	    $(MV) `$(CAT) $(COMPILE_OBJ_LIST.cpp)` $(OBJDIR) ) || exit 1 ; \
       
   168 	fi
       
   169 	@$(RM) $(COMPILE_BATCH.c)   $(COMPILE_LIST.c)   $(COMPILE_OBJ_LIST.c)
       
   170 	@$(RM) $(COMPILE_BATCH.cpp) $(COMPILE_LIST.cpp) $(COMPILE_OBJ_LIST.cpp)
       
   171 
       
   172 endif
       
   173 
       
   174 # newer as does not handle c++ style comments
       
   175 $(OBJDIR)/%.$(OBJECT_SUFFIX): %.s
       
   176     ifneq ($(CC_VERSION), gcc)
       
   177 	@$(prep-target)
       
   178 	$(COMPILE.s) $(CC_OBJECT_OUTPUT_FLAG)$@ $<
       
   179     else
       
   180 	@$(prep-target)
       
   181 	$(CPP) -x assembler-with-cpp $< | $(COMPILE.s) -o $@
       
   182     endif
       
   183 	@$(check-conventions)
       
   184 
       
   185 # Obj-C files (Mac OS X only).
       
   186 ifeq ($(PLATFORM), macosx)
       
   187 $(OBJDIR)/%.$(OBJECT_SUFFIX): %.m
       
   188 	@$(prep-target)
       
   189 	$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
       
   190 	@$(check-conventions)
       
   191 
       
   192 $(OBJDIR)/%.$(OBJECT_SUFFIX): %.mm
       
   193 	@$(prep-target)
       
   194 	$(COMPILE.cc) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
       
   195 	@$(check-conventions)
       
   196 
       
   197 $(OBJDIR)/%.$(OBJECT_SUFFIX): %.c
       
   198 	@$(prep-target)
       
   199 	$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
       
   200 	@$(check-conventions)
       
   201 endif # PLATFORM
       
   202 
       
   203 #
       
   204 # Quick hack for making the compiler generate just the assembly file.
       
   205 #	$ gnumake obj/sparc/myfile.s
       
   206 #
       
   207 $(OBJDIR)/%.s: %.c
       
   208 	@$(prep-target)
       
   209 	$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ -S $<
       
   210 	@$(check-conventions)
       
   211 
       
   212 # remove the intermediate files from the directories.
       
   213 #    (If VARIANT=OPT, this removes all debug and fastdebug files too)
       
   214 clobber clean::
       
   215 	$(RM) -r $(OBJDIR)
       
   216 	$(RM) -r $(OBJDIR)_*
       
   217 
       
   218 #
       
   219 # Lint support
       
   220 # (The 'lint' rule below is an older rule not using the .$(LINT_SUFFIX) files)
       
   221 #
       
   222 
       
   223 ifeq ($(PLATFORM), solaris)
       
   224 $(OBJDIR)/%.$(LINT_SUFFIX): %.c
       
   225 	@$(prep-target)
       
   226 	$(LINT.c) -dirout=$(OBJDIR) -c $<
       
   227 lint.clean:
       
   228 	$(RM) $(OBJDIR)/*.$(LINT_SUFFIX)
       
   229 # Old rule
       
   230 lint: $(FILES_c)
       
   231         ifneq ($(FILES_c),)
       
   232 	  $(LINT.c) -Ncheck -Nlevel=3 $? $(LDLIBS) > lint.$(ARCH) 2>&1
       
   233         endif
       
   234 endif
       
   235 
       
   236 .PHONY: batch_compile
       
   237 
       
   238