1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396
|
###############################################################################
# $Id:$
###############################################################################
#
# Rules.make :
# General make rules, supporting
# -compilation of .cpp to .o, .cpp to .s and .s to .o
# -combining of multiple .o files into one single .o file
# -creation of .a archives from multiple .o files
# -recursive subdirectories
# -recursive (dist)clean
# -creation of binary executables
# -doxygen generated docs
#
.EXPORT_ALL_VARIABLES:
#
# Depending on the definition of these variables in submakefiles different
# targets get build.
# NOTE: These should not be exported so we unexport them right here.
#
unexport SUBDIRS # specifying all subdirs from $(TOPDIR)
unexport SUB_DIRS # specifying all subdirs to make
unexport ALL_SUB_DIRS # specifying all subdirs to process (dep/clean)
unexport O_TARGET # name of combined .o file to generate
unexport O_OBJS # name of .o files to combine into $(O_TARGET)
unexport L_TARGET # name of .a archive to generate
unexport L_OBJS # name of .o files to place in $(L_TARGET)
unexport B_NAME # name of binary to generate
unexport B_OBJS # name of .o files to combine into $(B_NAME)
unexport GCJ_B_NAME # Rules for gcj (native java binaries)
unexport GCJ_B_OBJS
unexport DOXY_TARGET # name of a doxygen config file to build docs from
unexport DOXY_GENDIR # name of dir doxygen generates docs into
unexport JAR_TARGETS # jar files..
unexport JAR_DEST # jar files..
unexport G_FILES # antlr .g files
unexport G_TAG_FILES # empty file to record compiling .g files
unexport G_TARGETS # per-Makefile list of ANTLR generated files
unexport C_TARGETS # name of additional targets to "clean"
unexport DC_TARGETS # name of additional targets to "distclean"
#
# Implicit rules
#
%.s: %.cpp
$(CXX) $(CXXFLAGS) $(EXTRA_CXXFLAGS) -S $< -o $@
#
# These rules support buiding the .o files into a obj_dir different than the
# current dir. This keeps the source dirs nice and clean..
# FIXME: VPATH?
#
ifdef obj_dir
OBJDIR_DEP := $(obj_dir)objects
else
OBJDIR_DEP :=
obj_dir :=
endif
$(obj_dir)%.o: %.cpp $(OBJDIR_DEP)
$(CXX) -c -o $@ $< $(CXXFLAGS) $(SHARED_FLAGS)
$(obj_dir)%.o: %.c
$(CC) $(CFLAGS) $(SHARED_FLAGS) -c -o $@ $<
$(obj_dir)%.o: %.s
$(AS) $(ASFLAGS) -o $@ $<
#
# Automatic dependency generation rules
#
$(obj_dir)%.d: %.c $(OBJDIR_DEP)
@echo "Building dependencies for $<"
@$(CC) -MM -MG $(CFLAGS) $< | $(SED) -e 's,\($*\)\.o[ :]*,$(obj_dir)\1.o $@ : ,g' > $@
$(obj_dir)%.d: %.cpp $(OBJDIR_DEP)
@echo "Building dependencies for $<"
@$(CXX) -MM -MG $(CXXFLAGS) $< | $(SED) -e 's,\($*\)\.o[ :]*,$(obj_dir)\1.o $@ : ,g' > $@
$(obj_dir)%.d: %.g $(OBJDIR_DEP) ;
@echo "Building dependencies for $<"
@echo "$($(addsuffix _FILES,$(subst .,_,$<))): $(obj_dir).$*.g ;" > $@
#
# How to make .x.g files from .g files. (ANTLR)
# A .x.g file is an empty target to record running ANTLR on x.g
# Customize flags per file 'x.g' by setting x_FLAGS
# The chmod is dirty but it makes life a lot easier with perforce
#
$(obj_dir).%.g: %.g $(OBJDIR_DEP);
@ -$(CHMOD) -f u+w $($(addsuffix _FILES, $(subst .,_,$^))) 2> /dev/null
$(ANTLR) $(ANTLR_FLAGS) $($*_FLAGS) $^
@ $(TOUCH) $@
ifdef G_FILES
# make list of the sentinel files of the .g files
G_TARGETS := $(addprefix .,$(G_FILES))
endif
#
# How to build class files
#
# Take along existing CLASSPATH definition. Necessary for jikes.
ifdef JAVAC_CLASSPATH
ifneq ($(JAVAC_CLASSPATH),)
javac_paths= -classpath $(call fix_path,$(TOPDIR)$(PATH_SEPARATOR)$(JAVAC_CLASSPATH))
else
javac_paths = -classpath $(call fix_path,$(TOPDIR))
endif
endif
#
# For native binary java
#
%.o: %.java
ifdef VERBOSE
$(GCJ) -c -o $@ $< -classpath $(TOPDIR) $(GCJFLAGS) $(EXTRA_GCJFLAGS)
else
@ echo "Building native binary for $<"
@ $(GCJ) -c -o $@ $< -classpath $(TOPDIR) $(GCJFLAGS) $(EXTRA_GCJFLAGS)
endif
#
# For class files
#
%.class: %.java
ifdef VERBOSE
$(JAVAC) $(JAVAC_FLAGS) $(javac_paths) $(obj_dir_arg) $<
else
@ echo "Building java bytecode for $<"
@ $(JAVAC) $(JAVAC_FLAGS) $(javac_paths) $(obj_dir_arg) $<
endif
unexport obj_dir_arg javac_paths
#
# Note: this stuff is just too annoying to use.... Now do it in the
# submakefile itself
#
# How to build a Java jar file.
#
# Note: The jar contents are taken from the rule dependency
# list; thus the user must explicitly define dependencies per
# jar target. E.g.
# x.jar : $(x_jar_FILES)
# Make performs variable expansion before implicit rule search,
# hence, the desired implicit rule dependency
# $($(subst .,_,$%)_jar_FILES)
# is an undefined variable, resulting in an empty dependency
# list.
#
#%.jar:
# @ echo "==========================================="
# @ echo "Making $(JAR_DEST)/$(@)..."
# @ rm -f $@
# @ (cd $(JAR_DEST) $(JAR) cf $(JAR_DEST)/$@ $(subst $$,\$$,$^)
# @ echo "==========================================="
#
# Get things started:
# 1. Build ANTLR generated files, subdirectories.
# 2. Remaining TARGETS
#
first_rule: sub_dirs
$(MAKE) all_targets
unexport TARGETS
#
# Build default targets
#
all_targets: $(G_TARGETS) $(O_TARGET) $(L_TARGET) $(GCJ_B_NAME) $(B_NAME) $(JAR_TARGETS) $(GCJ_B_NAME)
#
# Compile a set of .o files into one .o file
#
ifdef O_TARGET
$(O_TARGET): $(O_OBJS)
-$(RM) -f $@
ifneq "$(strip $(O_OBJS))" ""
$(LD) $(EXTRA_LDFLAGS) -r -o $@ $(O_OBJS)
else
$(AR) rus $@
endif
endif
#
# Compile a set of .o files into one .a file
#
ifdef L_TARGET
$(L_TARGET): $(L_OBJS)
-$(RM) -f $@
$(AR) $(EXTRA_ARFLAGS) $(ARFLAGS) $@ $(L_OBJS)
$(RANLIB) $@
endif
#
# This takes care of creating obj_dirs's
#
ifdef obj_dir
$(OBJDIR_DEP): ;
$(MKDIR) -p $(obj_dir)
$(TOUCH) $(OBJDIR_DEP)
endif
ifeq ($(ANTLR_WIN32),"yes")
ifdef DLL_TARGET
$(DLL_TARGET): $(DLL_OBJS)
-$(RM) -f $@
$(CXX) -o $@ -Wl,-mdll $(L_OBJS)
endif
endif
ifdef DOXY_TARGET
gen_doc: $(DOXY_TARGET) ;
ifdef DOXY_GENDIR
ifneq ($(DOXY_GENDIR),)
-$(RM) -f $(DOXY_GENDIR)/*
endif
endif
ifneq ($(DOXYGEN),"")
$(DOXYGEN) -f $(DOXY_TARGET)
else
echo "Doxygen not installed skipping $(DOXY_TARGET)"
endif
endif
# Rule to make subdirs
#
.PHONY: $(SUB_DIRS) sub_dirs
sub_dirs: $(SUB_DIRS)
ifdef SUB_DIRS
ifneq ($(strip $(SUB_DIRS)),)
$(SUB_DIRS):
@echo ">>>>>>>>>>>>>>>>>>>> Entering $@ ..."
$(MAKE) -C $@
@echo "<<<<<<<<<<<<<<<<<<<< Leaving $@"
endif
endif
#
# Rule to make binaries
#
ifdef B_NAME
$(B_NAME): $(B_OBJS)
-$(RM) -f $@
$(CXX) -o $@ $(EXTRA_LDFLAGS) $(B_OBJS) $(EXTRA_LIBS)
endif
ifdef GCJ_B_NAME
$(GCJ_B_NAME): $(GCJ_B_OBJS)
@ -$(RM) -f $@
$(GCJ) $(GCJFLAGS) $(EXTRA_GCJFLAGS) -o $@ --main=antlr.Tool $(GCJ_B_OBJS)
endif
#
# Include dependency files if they exist (and we're not cleaning)
#
ifneq (clean,$(findstring clean,$(MAKECMDGOALS)))
-include .depend
ifneq ($(SOURCE),)
-include $(addprefix $(obj_dir),$(SOURCE:.cpp=.d))
endif
ifneq ($(SOURCES),)
-include $(addprefix $(obj_dir),$(SOURCES:.cpp=.d))
endif
ifneq ($(CXXSOURCE),)
-include $(addprefix $(obj_dir),$(CXXSOURCE:.cpp=.d))
endif
ifneq ($(GCJSOURCES),)
-include $(GCJSOURCES:.java=.d)
endif
ifneq ($(CSOURCE),)
-include $(addprefix $(obj_dir),$(CSOURCE:.c=.d))
endif
ifneq ($(G_FILES),)
-include $(addprefix $(obj_dir),$(G_FILES:.g=.d))
endif
endif
#
# Rule to bootstrap from external ANTLR jar.
#
.PHONY: bootstrap_g
bootstrap_g: ANTLR := $(ANTLR_BOOTSTRAP)
bootstrap_g: ANTLR_FLAGS := $(ANTLR_BOOTSTRAP_FLAGS)
bootstrap_g: $(G_TAG_FILES)
ifdef ALL_SUB_DIRS
@set -e; for i in $(ALL_SUB_DIRS); do $(MAKE) -C $$i bootstrap_g; done
endif
#
# Rule to clean ANTLR generated files (corresponding
# to bootstrap_g targets).
#
.PHONY: clean_g
clean_g:
ifdef ALL_SUB_DIRS
@set -e; for i in $(ALL_SUB_DIRS); do $(MAKE) -C $$i clean_g; done
endif
-$(RM) -f $(G_TAG_FILES) $(G_TARGETS)
#
# Rule to remove all objects, cores, etc.; leaving
# ANTLR generated and config files.
#
.PHONY: mostlyclean
mostlyclean:
ifdef obj_dir
ifneq ($(obj_dir),)
-$(RM) -f $(obj_dir)/*
endif
endif
ifdef DOXY_GENDIR
ifneq ($(DOXY_GENDIR),)
-$(RM) -f $(DOXY_GENDIR)/*
endif
endif
ifdef ALL_SUB_DIRS
set -e; for i in $(ALL_SUB_DIRS); do $(MAKE) -C $$i mostlyclean; done
endif
-$(RM) -f *.o *.class *.a *.so core *.s $(B_NAME) $(C_TARGETS) $(JAR_TARGETS)
#
# Rule to remove all objects, cores, ANTLR generated, etc.;
# leaving configure generated files.
#
.PHONY: clean
clean: mostlyclean clean_g
ifdef obj_dir
# make sure to do nothing if obj_dir empty...
ifneq ($(obj_dir),)
@-test -d $(obj_dir) && $(RM) -f $(obj_dir)/* $(obj_dir)/.*.g
@-test -d $(obj_dir) && $(RMDIR) $(obj_dir)
endif
endif
ifdef ALL_SUB_DIRS
set -e; for i in $(ALL_SUB_DIRS); do $(MAKE) -C $$i clean; done
endif
#
# Rule to remove all objects, cores, ANTLR generated,
# configure generated, etc.; leaving files requiring
# additional programs to generate (e.g., autoconf).
#
# FIXME: can not be called more than once successively because
# FIXME: it removes files unconditionally included by subdirectory
# FIXME: Makefiles (e.g., Config.make).
#
.PHONY: distclean
distclean: clean
ifdef ALL_SUB_DIRS
set -e; for i in $(ALL_SUB_DIRS); do $(MAKE) -C $$i distclean; done
endif
-$(RM) -f .depend $(DC_TARGETS)
#
# Install rule
#
ifndef OVERRULE_INSTALL
.PHONY: install
install:
ifdef B_NAME
@echo "Installing $(B_NAME) into $(bindir)"
@test -d $(DESTDIR)$(bindir) || $(MKDIR) -p $(DESTDIR)$(bindir)
@$(INSTALL) -m 755 $(B_NAME) $(DESTDIR)$(bindir)
endif
ifdef L_TARGET
@echo "Installing $(L_TARGET) into $(libdir)"
@test -d $(DESTDIR)$(libdir) || $(MKDIR) -p $(DESTDIR)$(libdir)
@$(INSTALL) -m 644 $(L_TARGET) $(DESTDIR)$(libdir)
endif
ifdef JAR_TARGETS
@test -d $(DESTDIR)$(datadir)/$(versioneddir) || $(MKDIR) -p $(DESTDIR)$(datadir)/$(versioneddir)
@for i in $(JAR_TARGETS); do \
echo "Installing $i into $(datadir)/$(versioneddir)" \
$(INSTALL) -m 644 $$i $(DESTDIR)$(datadir)/$(versioneddir) ;\
done
endif
ifdef INSTALL_TARGETS
@test -d $(DESTDIR)$(INSTALL_DIR) || $(MKDIR) -p $(DESTDIR)$(INSTALL_DIR)
@for i in $(INSTALL_TARGETS); do \
echo "Installing $$i into $(INSTALL_DIR)" ; \
$(INSTALL) -m $(INSTALL_MODE) $$i $(DESTDIR)$(INSTALL_DIR) > /dev/null ;\
done
endif
ifdef ALL_SUB_DIRS
@set -e; for i in $(ALL_SUB_DIRS); do $(MAKE) -C $$i install; done
endif
endif
|