duke@1: # duke@1: # Copyright 1995-2007 Sun Microsystems, Inc. All Rights Reserved. duke@1: # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. duke@1: # duke@1: # This code is free software; you can redistribute it and/or modify it duke@1: # under the terms of the GNU General Public License version 2 only, as duke@1: # published by the Free Software Foundation. Sun designates this duke@1: # particular file as subject to the "Classpath" exception as provided duke@1: # by Sun in the LICENSE file that accompanied this code. duke@1: # duke@1: # This code is distributed in the hope that it will be useful, but WITHOUT duke@1: # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or duke@1: # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License duke@1: # version 2 for more details (a copy is included in the LICENSE file that duke@1: # accompanied this code). duke@1: # duke@1: # You should have received a copy of the GNU General Public License version duke@1: # 2 along with this work; if not, write to the Free Software Foundation, duke@1: # Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. duke@1: # duke@1: # Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, duke@1: # CA 95054 USA or visit www.sun.com if you need additional information or duke@1: # have any questions. duke@1: # duke@1: duke@1: # duke@1: # Native C/C++ Compile Rules duke@1: # duke@1: duke@1: # duke@1: # INCREMENTAL_BUILD: Record the #include file dependencies. duke@1: # duke@1: # NOTE: We build make include files with the suffix duke@1: # $(DEPEND_SUFFIX) on every compilation. These are initially duke@1: # created as temp files just in case a ^C kills it in the middle. duke@1: # Compiler is smart enough to handle ^C and not create the .o file, or duke@1: # is supposed to be that smart, but the .$(DEPEND_SUFFIX) file duke@1: # creation here isn't. duke@1: # These .$(DEPEND_SUFFIX) files are included by Library.gmk and duke@1: # Program.gmk, when they exist (Search for 'make dependencies'). duke@1: # duke@1: duke@1: ifeq ($(INCREMENTAL_BUILD),true) duke@1: duke@1: $(OBJDIR)/%.$(DEPEND_SUFFIX): %.c duke@1: @$(prep-target) duke@1: @$(ECHO) "Creating $@" duke@1: @$(RM) $@.temp duke@1: @$(CC) $(CC_DEPEND) $(CPPFLAGS) $< 2> $(DEV_NULL) | \ duke@1: $(CC_DEPEND_FILTER) > $@.temp duke@1: @$(MV) $@.temp $@ duke@1: duke@1: $(OBJDIR)/%.$(DEPEND_SUFFIX): %.cpp duke@1: @$(prep-target) duke@1: @$(ECHO) "Creating $@" duke@1: @$(RM) $@.temp duke@1: @$(CXX) $(CC_DEPEND) $(CPPFLAGS) $(CXXFLAGS) $< 2> $(DEV_NULL) | \ duke@1: $(CC_DEPEND_FILTER) > $@.temp duke@1: @$(MV) $@.temp $@ duke@1: duke@1: endif # INCREMENTAL_BUILD duke@1: duke@1: # duke@1: # C, C++, asm files. duke@1: # duke@1: # Normal or parallel compile rule is the same, but batch compiles require duke@1: # we save up the sources files that use the same compile line so that we duke@1: # can do one compile line. duke@1: # duke@1: duke@1: ifneq ($(COMPILE_APPROACH), batch) duke@1: duke@1: $(OBJDIR)/%.$(OBJECT_SUFFIX): %.c duke@1: @$(prep-target) duke@1: $(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $< duke@1: @$(check-conventions) duke@1: duke@1: $(OBJDIR)/%.$(OBJECT_SUFFIX): %.cpp duke@1: @$(prep-target) duke@1: $(COMPILE.cc) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $< duke@1: @$(check-conventions) duke@1: duke@1: else duke@1: duke@1: # duke@1: # Batch compiling might be faster if the compiler was smart about recognizing duke@1: # optimization opportunities available when all files are being compiled duke@1: # the same way. Unfortunately this is rare. duke@1: # Automatic pre-compiled headers (pch) might be a possibility so we duke@1: # add any auto pch options here. duke@1: # So we save all the source files that have the same compile line as the duke@1: # first file. A normal compile pass is made after the batch compile duke@1: # to catch anything missed. duke@1: # If the compilers had a -o option that allowed us to direct where to duke@1: # write the object files to, then we would not need to save the object duke@1: # file list or move them from the make directory to the build directory. duke@1: # duke@1: duke@1: # Source names duke@1: COMPILE_LIST.c = $(OBJDIR)/.source_names_c duke@1: COMPILE_LIST.cpp = $(OBJDIR)/.source_names_cpp duke@1: duke@1: # Object file list duke@1: COMPILE_OBJ_LIST.c = $(OBJDIR)/.obj_names_c duke@1: COMPILE_OBJ_LIST.cpp = $(OBJDIR)/.obj_names_cpp duke@1: duke@1: # The compile line duke@1: COMPILE_BATCH.c = $(OBJDIR)/.compile_c duke@1: COMPILE_BATCH.cpp = $(OBJDIR)/.compile_cpp duke@1: duke@1: # The compile line for the current target duke@1: THIS_COMPILE_BATCH.c = $(COMPILE_BATCH.c)-$(@F) duke@1: THIS_COMPILE_BATCH.cpp = $(COMPILE_BATCH.cpp)-$(@F) duke@1: duke@1: $(OBJDIR)/%.$(OBJECT_SUFFIX): %.c duke@1: @$(prep-target) duke@1: @$(ECHO) "$(COMPILE.c) $(CFLAGS_GPROF)" > $(THIS_COMPILE_BATCH.c) duke@1: @if [ ! -s $(COMPILE_BATCH.c) ] ; then \ duke@1: $(CP) $(THIS_COMPILE_BATCH.c) $(COMPILE_BATCH.c) ; \ duke@1: $(ECHO) $< > $(COMPILE_LIST.c); \ duke@1: $(ECHO) $(@F) > $(COMPILE_OBJ_LIST.c); \ duke@1: elif [ "`$(DIFF) -w -b $(THIS_COMPILE_BATCH.c) $(COMPILE_BATCH.c)`" \ duke@1: = "" ] ; then \ duke@1: $(ECHO) $< >> $(COMPILE_LIST.c); \ duke@1: $(ECHO) $(@F) >> $(COMPILE_OBJ_LIST.c); \ duke@1: fi duke@1: @$(RM) $(THIS_COMPILE_BATCH.c) duke@1: @$(check-conventions) duke@1: duke@1: $(OBJDIR)/%.$(OBJECT_SUFFIX): %.cpp duke@1: @$(prep-target) duke@1: @$(ECHO) "$(COMPILE.cpp) $(CFLAGS_GPROF)" > $(THIS_COMPILE_BATCH.cpp) duke@1: @if [ ! -s $(COMPILE_BATCH.cpp) ] ; then \ duke@1: $(CP) $(THIS_COMPILE_BATCH.cpp) $(COMPILE_BATCH.cpp) ; \ duke@1: $(ECHO) $< > $(COMPILE_LIST.cpp); \ duke@1: $(ECHO) $(@F) > $(COMPILE_OBJ_LIST.cpp); \ duke@1: elif [ "`$(DIFF) -w -b $(THIS_COMPILE_BATCH.cpp) $(COMPILE_BATCH.cpp)`"\ duke@1: = "" ] ; then \ duke@1: $(ECHO) $< >> $(COMPILE_LIST.cpp); \ duke@1: $(ECHO) $(@F) >> $(COMPILE_OBJ_LIST.cpp); \ duke@1: fi duke@1: @$(RM) $(THIS_COMPILE_BATCH.cpp) duke@1: @$(check-conventions) duke@1: duke@1: batch_compile: $(FILES_o) duke@1: @$(ECHO) "Doing batch compilations" duke@1: @if [ -s $(COMPILE_LIST.c) ] ; then \ duke@1: $(ECHO) "$(COMPILE.c) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \ duke@1: `$(CAT) $(COMPILE_LIST.c)`" ; \ duke@1: ( $(COMPILE.c) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \ duke@1: `$(CAT) $(COMPILE_LIST.c)` && \ duke@1: $(ECHO) "$(MV) `$(CAT) $(COMPILE_OBJ_LIST.c)` $(OBJDIR)" && \ duke@1: $(MV) `$(CAT) $(COMPILE_OBJ_LIST.c)` $(OBJDIR) ) || exit 1 ; \ duke@1: fi duke@1: @if [ -s $(COMPILE_LIST.cpp) ] ; then \ duke@1: $(ECHO) "$(COMPILE.cpp) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \ duke@1: `$(CAT) $(COMPILE_LIST.cpp)`" ; \ duke@1: ( $(COMPILE.cpp) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \ duke@1: `$(CAT) $(COMPILE_LIST.cpp)` && \ duke@1: $(ECHO) "$(MV) `$(CAT) $(COMPILE_OBJ_LIST.cpp)` $(OBJDIR)" && \ duke@1: $(MV) `$(CAT) $(COMPILE_OBJ_LIST.cpp)` $(OBJDIR) ) || exit 1 ; \ duke@1: fi duke@1: @$(RM) $(COMPILE_BATCH.c) $(COMPILE_LIST.c) $(COMPILE_OBJ_LIST.c) duke@1: @$(RM) $(COMPILE_BATCH.cpp) $(COMPILE_LIST.cpp) $(COMPILE_OBJ_LIST.cpp) duke@1: duke@1: endif duke@1: duke@1: # newer as does not handle c++ style comments duke@1: $(OBJDIR)/%.$(OBJECT_SUFFIX): %.s duke@1: ifneq ($(CC_VERSION), gcc) duke@1: @$(prep-target) duke@1: $(COMPILE.s) $(CC_OBJECT_OUTPUT_FLAG)$@ $< duke@1: else duke@1: @$(prep-target) duke@1: $(CPP) -x assembler-with-cpp $< | $(COMPILE.s) -o $@ duke@1: endif duke@1: @$(check-conventions) duke@1: duke@1: # duke@1: # Quick hack for making the compiler generate just the assembly file. duke@1: # $ gnumake obj/sparc/myfile.s duke@1: # duke@1: $(OBJDIR)/%.s: %.c duke@1: @$(prep-target) duke@1: $(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ -S $< duke@1: @$(check-conventions) duke@1: duke@1: # remove the intermediate files from the directories. duke@1: # (If VARIANT=OPT, this removes all debug and fastdebug files too) duke@1: clobber clean:: duke@1: $(RM) -r $(OBJDIR) duke@1: $(RM) -r $(OBJDIR)_* duke@1: duke@1: # duke@1: # Lint support duke@1: # (The 'lint' rule below is an older rule not using the .$(LINT_SUFFIX) files) duke@1: # duke@1: duke@1: ifeq ($(PLATFORM), solaris) duke@1: $(OBJDIR)/%.$(LINT_SUFFIX): %.c duke@1: @$(prep-target) duke@1: $(LINT.c) -dirout=$(OBJDIR) -c $< duke@1: lint.clean: duke@1: $(RM) $(OBJDIR)/*.$(LINT_SUFFIX) duke@1: # Old rule duke@1: lint: $(FILES_c) duke@1: ifneq ($(FILES_c),) duke@1: $(LINT.c) -Ncheck -Nlevel=3 $? $(LDLIBS) > lint.$(ARCH) 2>&1 duke@1: endif duke@1: endif duke@1: duke@1: .PHONY: batch_compile duke@1: duke@1: