2
+ − 1
#
+ − 2
# Copyright 1995-2007 Sun Microsystems, Inc. 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. Sun designates this
+ − 8
# particular file as subject to the "Classpath" exception as provided
+ − 9
# by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
+ − 22
# CA 95054 USA or visit www.sun.com if you need additional information or
+ − 23
# have any questions.
+ − 24
#
+ − 25
+ − 26
#
+ − 27
# Native C/C++ Compile Rules
+ − 28
#
+ − 29
+ − 30
#
+ − 31
# INCREMENTAL_BUILD: Record the #include file dependencies.
+ − 32
#
+ − 33
# NOTE: We build make include files with the suffix
+ − 34
# $(DEPEND_SUFFIX) on every compilation. These are initially
+ − 35
# created as temp files just in case a ^C kills it in the middle.
+ − 36
# Compiler is smart enough to handle ^C and not create the .o file, or
+ − 37
# is supposed to be that smart, but the .$(DEPEND_SUFFIX) file
+ − 38
# creation here isn't.
+ − 39
# These .$(DEPEND_SUFFIX) files are included by Library.gmk and
+ − 40
# Program.gmk, when they exist (Search for 'make dependencies').
+ − 41
#
+ − 42
+ − 43
ifeq ($(INCREMENTAL_BUILD),true)
+ − 44
+ − 45
$(OBJDIR)/%.$(DEPEND_SUFFIX): %.c
+ − 46
@$(prep-target)
+ − 47
@$(ECHO) "Creating $@"
+ − 48
@$(RM) $@.temp
+ − 49
@$(CC) $(CC_DEPEND) $(CPPFLAGS) $< 2> $(DEV_NULL) | \
+ − 50
$(CC_DEPEND_FILTER) > $@.temp
+ − 51
@$(MV) $@.temp $@
+ − 52
+ − 53
$(OBJDIR)/%.$(DEPEND_SUFFIX): %.cpp
+ − 54
@$(prep-target)
+ − 55
@$(ECHO) "Creating $@"
+ − 56
@$(RM) $@.temp
+ − 57
@$(CXX) $(CC_DEPEND) $(CPPFLAGS) $(CXXFLAGS) $< 2> $(DEV_NULL) | \
+ − 58
$(CC_DEPEND_FILTER) > $@.temp
+ − 59
@$(MV) $@.temp $@
+ − 60
+ − 61
endif # INCREMENTAL_BUILD
+ − 62
+ − 63
#
+ − 64
# C, C++, asm files.
+ − 65
#
+ − 66
# Normal or parallel compile rule is the same, but batch compiles require
+ − 67
# we save up the sources files that use the same compile line so that we
+ − 68
# can do one compile line.
+ − 69
#
+ − 70
+ − 71
ifneq ($(COMPILE_APPROACH), batch)
+ − 72
+ − 73
$(OBJDIR)/%.$(OBJECT_SUFFIX): %.c
+ − 74
@$(prep-target)
+ − 75
$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
+ − 76
@$(check-conventions)
+ − 77
+ − 78
$(OBJDIR)/%.$(OBJECT_SUFFIX): %.cpp
+ − 79
@$(prep-target)
+ − 80
$(COMPILE.cc) $(CC_OBJECT_OUTPUT_FLAG)$@ $(CFLAGS_GPROF) $<
+ − 81
@$(check-conventions)
+ − 82
+ − 83
else
+ − 84
+ − 85
#
+ − 86
# Batch compiling might be faster if the compiler was smart about recognizing
+ − 87
# optimization opportunities available when all files are being compiled
+ − 88
# the same way. Unfortunately this is rare.
+ − 89
# Automatic pre-compiled headers (pch) might be a possibility so we
+ − 90
# add any auto pch options here.
+ − 91
# So we save all the source files that have the same compile line as the
+ − 92
# first file. A normal compile pass is made after the batch compile
+ − 93
# to catch anything missed.
+ − 94
# If the compilers had a -o option that allowed us to direct where to
+ − 95
# write the object files to, then we would not need to save the object
+ − 96
# file list or move them from the make directory to the build directory.
+ − 97
#
+ − 98
+ − 99
# Source names
+ − 100
COMPILE_LIST.c = $(OBJDIR)/.source_names_c
+ − 101
COMPILE_LIST.cpp = $(OBJDIR)/.source_names_cpp
+ − 102
+ − 103
# Object file list
+ − 104
COMPILE_OBJ_LIST.c = $(OBJDIR)/.obj_names_c
+ − 105
COMPILE_OBJ_LIST.cpp = $(OBJDIR)/.obj_names_cpp
+ − 106
+ − 107
# The compile line
+ − 108
COMPILE_BATCH.c = $(OBJDIR)/.compile_c
+ − 109
COMPILE_BATCH.cpp = $(OBJDIR)/.compile_cpp
+ − 110
+ − 111
# The compile line for the current target
+ − 112
THIS_COMPILE_BATCH.c = $(COMPILE_BATCH.c)-$(@F)
+ − 113
THIS_COMPILE_BATCH.cpp = $(COMPILE_BATCH.cpp)-$(@F)
+ − 114
+ − 115
$(OBJDIR)/%.$(OBJECT_SUFFIX): %.c
+ − 116
@$(prep-target)
+ − 117
@$(ECHO) "$(COMPILE.c) $(CFLAGS_GPROF)" > $(THIS_COMPILE_BATCH.c)
+ − 118
@if [ ! -s $(COMPILE_BATCH.c) ] ; then \
+ − 119
$(CP) $(THIS_COMPILE_BATCH.c) $(COMPILE_BATCH.c) ; \
+ − 120
$(ECHO) $< > $(COMPILE_LIST.c); \
+ − 121
$(ECHO) $(@F) > $(COMPILE_OBJ_LIST.c); \
+ − 122
elif [ "`$(DIFF) -w -b $(THIS_COMPILE_BATCH.c) $(COMPILE_BATCH.c)`" \
+ − 123
= "" ] ; then \
+ − 124
$(ECHO) $< >> $(COMPILE_LIST.c); \
+ − 125
$(ECHO) $(@F) >> $(COMPILE_OBJ_LIST.c); \
+ − 126
fi
+ − 127
@$(RM) $(THIS_COMPILE_BATCH.c)
+ − 128
@$(check-conventions)
+ − 129
+ − 130
$(OBJDIR)/%.$(OBJECT_SUFFIX): %.cpp
+ − 131
@$(prep-target)
+ − 132
@$(ECHO) "$(COMPILE.cpp) $(CFLAGS_GPROF)" > $(THIS_COMPILE_BATCH.cpp)
+ − 133
@if [ ! -s $(COMPILE_BATCH.cpp) ] ; then \
+ − 134
$(CP) $(THIS_COMPILE_BATCH.cpp) $(COMPILE_BATCH.cpp) ; \
+ − 135
$(ECHO) $< > $(COMPILE_LIST.cpp); \
+ − 136
$(ECHO) $(@F) > $(COMPILE_OBJ_LIST.cpp); \
+ − 137
elif [ "`$(DIFF) -w -b $(THIS_COMPILE_BATCH.cpp) $(COMPILE_BATCH.cpp)`"\
+ − 138
= "" ] ; then \
+ − 139
$(ECHO) $< >> $(COMPILE_LIST.cpp); \
+ − 140
$(ECHO) $(@F) >> $(COMPILE_OBJ_LIST.cpp); \
+ − 141
fi
+ − 142
@$(RM) $(THIS_COMPILE_BATCH.cpp)
+ − 143
@$(check-conventions)
+ − 144
+ − 145
batch_compile: $(FILES_o)
+ − 146
@$(ECHO) "Doing batch compilations"
+ − 147
@if [ -s $(COMPILE_LIST.c) ] ; then \
+ − 148
$(ECHO) "$(COMPILE.c) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \
+ − 149
`$(CAT) $(COMPILE_LIST.c)`" ; \
+ − 150
( $(COMPILE.c) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \
+ − 151
`$(CAT) $(COMPILE_LIST.c)` && \
+ − 152
$(ECHO) "$(MV) `$(CAT) $(COMPILE_OBJ_LIST.c)` $(OBJDIR)" && \
+ − 153
$(MV) `$(CAT) $(COMPILE_OBJ_LIST.c)` $(OBJDIR) ) || exit 1 ; \
+ − 154
fi
+ − 155
@if [ -s $(COMPILE_LIST.cpp) ] ; then \
+ − 156
$(ECHO) "$(COMPILE.cpp) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \
+ − 157
`$(CAT) $(COMPILE_LIST.cpp)`" ; \
+ − 158
( $(COMPILE.cpp) $(CFLAGS_GPROF) $(AUTOMATIC_PCH_OPTION) \
+ − 159
`$(CAT) $(COMPILE_LIST.cpp)` && \
+ − 160
$(ECHO) "$(MV) `$(CAT) $(COMPILE_OBJ_LIST.cpp)` $(OBJDIR)" && \
+ − 161
$(MV) `$(CAT) $(COMPILE_OBJ_LIST.cpp)` $(OBJDIR) ) || exit 1 ; \
+ − 162
fi
+ − 163
@$(RM) $(COMPILE_BATCH.c) $(COMPILE_LIST.c) $(COMPILE_OBJ_LIST.c)
+ − 164
@$(RM) $(COMPILE_BATCH.cpp) $(COMPILE_LIST.cpp) $(COMPILE_OBJ_LIST.cpp)
+ − 165
+ − 166
endif
+ − 167
+ − 168
# newer as does not handle c++ style comments
+ − 169
$(OBJDIR)/%.$(OBJECT_SUFFIX): %.s
+ − 170
ifneq ($(CC_VERSION), gcc)
+ − 171
@$(prep-target)
+ − 172
$(COMPILE.s) $(CC_OBJECT_OUTPUT_FLAG)$@ $<
+ − 173
else
+ − 174
@$(prep-target)
+ − 175
$(CPP) -x assembler-with-cpp $< | $(COMPILE.s) -o $@
+ − 176
endif
+ − 177
@$(check-conventions)
+ − 178
+ − 179
#
+ − 180
# Quick hack for making the compiler generate just the assembly file.
+ − 181
# $ gnumake obj/sparc/myfile.s
+ − 182
#
+ − 183
$(OBJDIR)/%.s: %.c
+ − 184
@$(prep-target)
+ − 185
$(COMPILE.c) $(CC_OBJECT_OUTPUT_FLAG)$@ -S $<
+ − 186
@$(check-conventions)
+ − 187
+ − 188
# remove the intermediate files from the directories.
+ − 189
# (If VARIANT=OPT, this removes all debug and fastdebug files too)
+ − 190
clobber clean::
+ − 191
$(RM) -r $(OBJDIR)
+ − 192
$(RM) -r $(OBJDIR)_*
+ − 193
+ − 194
#
+ − 195
# Lint support
+ − 196
# (The 'lint' rule below is an older rule not using the .$(LINT_SUFFIX) files)
+ − 197
#
+ − 198
+ − 199
ifeq ($(PLATFORM), solaris)
+ − 200
$(OBJDIR)/%.$(LINT_SUFFIX): %.c
+ − 201
@$(prep-target)
+ − 202
$(LINT.c) -dirout=$(OBJDIR) -c $<
+ − 203
lint.clean:
+ − 204
$(RM) $(OBJDIR)/*.$(LINT_SUFFIX)
+ − 205
# Old rule
+ − 206
lint: $(FILES_c)
+ − 207
ifneq ($(FILES_c),)
+ − 208
$(LINT.c) -Ncheck -Nlevel=3 $? $(LDLIBS) > lint.$(ARCH) 2>&1
+ − 209
endif
+ − 210
endif
+ − 211
+ − 212
.PHONY: batch_compile
+ − 213
+ − 214