1# 2# This Source Code Form is subject to the terms of the Mozilla Public 3# License, v. 2.0. If a copy of the MPL was not distributed with this 4# file, You can obtain one at http://mozilla.org/MPL/2.0/. 5 6####################################################################### 7### ### 8### R U L E S O F E N G A G E M E N T ### 9### ### 10####################################################################### 11 12####################################################################### 13# Dont't use double-colon rules! # 14####################################################################### 15 16ifndef HAVE_ALL_TARGET 17all: libs 18endif 19 20autobuild: 21ifeq ($(AUTOCLEAN),1) 22 $(MAKE) clean 23endif 24 $(MAKE) all 25 $(MAKE) install 26 27platform: 28 @echo $(OBJDIR_NAME) 29 30ifeq (,$(filter-out _WIN%,$(NS_USE_GCC)_$(OS_TARGET))) 31USE_NT_C_SYNTAX=1 32endif 33 34# For whatever reason, "." can't be handled using make conditionals. 35# Based on automake's SUBDIRS "." handling. 36ifdef DIRS 37ifndef IGNORE_DIRS 38ifneq (,$(filter .,$(DIRS))) 39TARGETS = $(NULL) 40ALL_TRASH = $(NULL) 41endif 42 43$(DIRS): 44 $(IGNORE_ERROR)@if [ "$@" != "." ]; then \ 45 $(MAKE) -C $@ $(MAKECMDGOALS) ; \ 46 else \ 47 IGNORE_DIRS=1 $(MAKE) -C $@ $(MAKECMDGOALS) ; \ 48 fi 49 @$(CLICK_STOPWATCH) 50endif 51endif 52 53export: $(DIRS) private_export 54 55release_export: $(DIRS) 56 57libs program install: $(DIRS) $(TARGETS) 58ifneq ($(LIBRARY),) 59 $(INSTALL) -m 664 $(LIBRARY) $(SOURCE_LIB_DIR) 60endif 61ifneq ($(SHARED_LIBRARY),) 62 $(INSTALL) -m 775 $(SHARED_LIBRARY) $(SOURCE_LIB_DIR) 63ifdef MOZ_DEBUG_SYMBOLS 64ifeq (,$(filter-out _WIN%,$(NS_USE_GCC)_$(OS_TARGET))) 65 $(INSTALL) -m 644 $(SHARED_LIBRARY:$(DLL_SUFFIX)=pdb) $(SOURCE_LIB_DIR) 66endif 67endif 68endif 69ifneq ($(IMPORT_LIBRARY),) 70 $(INSTALL) -m 775 $(IMPORT_LIBRARY) $(SOURCE_LIB_DIR) 71endif 72ifneq ($(PROGRAM),) 73 $(INSTALL) -m 775 $(PROGRAM) $(SOURCE_BIN_DIR) 74ifdef MOZ_DEBUG_SYMBOLS 75ifeq (,$(filter-out _WIN%,$(NS_USE_GCC)_$(OS_TARGET))) 76 $(INSTALL) -m 644 $(PROGRAM:$(PROG_SUFFIX)=.pdb) $(SOURCE_BIN_DIR) 77endif 78endif 79endif 80ifneq ($(PROGRAMS),) 81 $(INSTALL) -m 775 $(PROGRAMS) $(SOURCE_BIN_DIR) 82endif 83 84check: $(DIRS) 85 86clean clobber: $(DIRS) 87ifneq (,$(ALL_TRASH)) 88 rm -rf $(ALL_TRASH) 89endif 90 91realclean clobber_all: $(DIRS) 92 rm -rf $(wildcard *.OBJ) dist $(ALL_TRASH) 93 94release_clean: 95 rm -rf $(SOURCE_XP_DIR)/release/$(RELEASE_MD_DIR) 96 97release: release_clean release_export release_md 98 99ifndef NO_MD_RELEASE 100 ifdef LIBRARY 101 MD_LIB_RELEASE_FILES += $(LIBRARY) 102 endif 103 ifdef SHARED_LIBRARY 104 MD_LIB_RELEASE_FILES += $(SHARED_LIBRARY) 105 endif 106 ifdef IMPORT_LIBRARY 107 MD_LIB_RELEASE_FILES += $(IMPORT_LIBRARY) 108 endif 109 ifdef PROGRAM 110 MD_BIN_RELEASE_FILES += $(PROGRAM) 111 endif 112 ifdef PROGRAMS 113 MD_BIN_RELEASE_FILES += $(PROGRAMS) 114 endif 115endif 116 117release_md:: $(DIRS) 118ifneq ($(MD_LIB_RELEASE_FILES),) 119 $(INSTALL) -m 444 $(MD_LIB_RELEASE_FILES) $(SOURCE_RELEASE_PREFIX)/$(SOURCE_RELEASE_LIB_DIR) 120endif 121ifneq ($(MD_BIN_RELEASE_FILES),) 122 $(INSTALL) -m 555 $(MD_BIN_RELEASE_FILES) $(SOURCE_RELEASE_PREFIX)/$(SOURCE_RELEASE_BIN_DIR) 123endif 124 125alltags: 126 rm -f TAGS 127 find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs etags -a 128 find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs ctags -a 129 130.SECONDEXPANSION: 131%/d: 132 @$(MAKE_OBJDIR) 133 134define PROGRAM_template 135 136ifndef $(1)_OBJS 137ifdef LIBRARY_NAME 138 $(1)_OBJS := $$(patsubst $$(PROG_PREFIX)%,%,$$(patsubst %$$(PROG_SUFFIX),%,$(1)))$$(OBJ_SUFFIX) 139endif 140ifdef PROGRAMS 141 $(1)_OBJS := $$(patsubst $$(PROG_PREFIX)%,%,$$(patsubst %$$(PROG_SUFFIX),%,$(1)))$$(OBJ_SUFFIX) 142endif 143ifndef $(1)_OBJS 144 $(1)_OBJS := $$(OBJS) 145endif 146endif 147 148$(1): $$($(1)_OBJS) $$(EXTRA_LIBS) | $$$$(@D)/d 149 rm -f $$@ 150ifeq (,$$(filter-out _WIN%,$$(NS_USE_GCC)_$$(OS_TARGET))) 151 $$(MKPROG) $$($(1)_OBJS) -Fe$$@ -link $$(LDFLAGS) $$(XLDFLAGS) $$(EXTRA_LIBS) $$(EXTRA_SHARED_LIBS) $$(OS_LIBS) 152ifdef MT 153 if test -f $$@.manifest; then \ 154 $$(MT) -NOLOGO -MANIFEST $$@.manifest -OUTPUTRESOURCE:$$@\;1; \ 155 rm -f $$@.manifest; \ 156 fi 157endif # MSVC with manifest tool 158else 159 $$(MKPROG) -o $$@ $$(CFLAGS) $$($(1)_OBJS) $$(LDFLAGS) $$(EXTRA_LIBS) $$(EXTRA_SHARED_LIBS) $$(OS_LIBS) 160endif 161endef # PROGRAM_template 162 163ifdef PROGRAM 164$(eval $(call PROGRAM_template,$(PROGRAM))) 165else 166ifdef PROGRAMS 167$(foreach prog,$(PROGRAMS),$(eval $(call PROGRAM_template,$(prog)))) 168endif 169endif 170 171get_objs: 172 @echo $(OBJS) 173 174$(LIBRARY): $(OBJS) | $$(@D)/d 175 rm -f $@ 176ifeq (,$(filter-out _WIN%,$(NS_USE_GCC)_$(OS_TARGET))) 177 $(AR) $(subst /,\\,$(OBJS)) 178else 179 $(AR) $(OBJS) 180endif 181 $(RANLIB) $@ 182 183 184ifeq ($(OS_TARGET),OS2) 185$(IMPORT_LIBRARY): $(MAPFILE) 186 rm -f $@ 187 $(IMPLIB) $@ $< 188 $(RANLIB) $@ 189endif 190ifeq ($(OS_ARCH),WINNT) 191$(IMPORT_LIBRARY): $(SHARED_LIBRARY) 192endif 193 194ifdef SHARED_LIBRARY_LIBS 195ifdef BUILD_TREE 196SUB_SHLOBJS = $(foreach dir,$(SHARED_LIBRARY_DIRS),$(shell $(MAKE) -C $(dir) --no-print-directory get_objs)) 197else 198SUB_SHLOBJS = $(foreach dir,$(SHARED_LIBRARY_DIRS),$(addprefix $(dir)/,$(shell $(MAKE) -C $(dir) --no-print-directory get_objs))) 199endif 200endif 201 202$(SHARED_LIBRARY): $(OBJS) $(RES) $(MAPFILE) $(SUB_SHLOBJS) | $$(@D)/d 203 rm -f $@ 204ifeq ($(OS_TARGET)$(OS_RELEASE), AIX4.1) 205 echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms 206 nm -B -C -g $(OBJS) \ 207 | awk '/ [T,D] / {print $$3}' \ 208 | sed -e 's/^\.//' \ 209 | sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms 210 $(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \ 211 -bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS) $(EXTRA_SHARED_LIBS) 212else 213ifeq (,$(filter-out WIN%,$(OS_TARGET))) 214ifdef NS_USE_GCC 215 $(LINK_DLL) $(OBJS) $(SUB_SHLOBJS) $(EXTRA_LIBS) $(EXTRA_SHARED_LIBS) $(OS_LIBS) $(LD_LIBS) $(RES) 216else 217 $(LINK_DLL) -MAP $(DLLBASE) $(subst /,\\,$(OBJS) $(SUB_SHLOBJS) $(EXTRA_LIBS) $(EXTRA_SHARED_LIBS) $(OS_LIBS) $(LD_LIBS) $(RES)) 218ifdef MT 219 if test -f $@.manifest; then \ 220 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;2; \ 221 rm -f $@.manifest; \ 222 fi 223endif # MSVC with manifest tool 224endif 225else 226 $(MKSHLIB) -o $@ $(OBJS) $(SUB_SHLOBJS) $(LD_LIBS) $(EXTRA_LIBS) $(EXTRA_SHARED_LIBS) $(OS_LIBS) 227 chmod +x $@ 228endif 229endif 230 231ifeq (,$(filter-out WIN%,$(OS_TARGET))) 232$(RES): $(RESNAME) | $$(@D)/d 233# The resource compiler does not understand the -U option. 234ifdef NS_USE_GCC 235 $(RC) $(filter-out -U%,$(DEFINES)) $(INCLUDES:-I%=--include-dir %) -o $@ $< 236else 237 $(RC) $(filter-out -U%,$(DEFINES)) $(INCLUDES) -Fo$@ $< 238endif 239 @echo $(RES) finished 240endif 241 242$(MAPFILE): $(MAPFILE_SOURCE) | $$(@D)/d 243 $(PROCESS_MAP_FILE) 244 245WCCFLAGS1 := $(subst /,\\,$(CFLAGS)) 246WCCFLAGS2 := $(subst -I,-i=,$(WCCFLAGS1)) 247WCCFLAGS3 := $(subst -D,-d,$(WCCFLAGS2)) 248 249# Translate source filenames to absolute paths. This is required for 250# debuggers under Windows & OS/2 to find source files automatically 251 252ifeq (,$(filter-out OS2 AIX,$(OS_TARGET))) 253# OS/2 and AIX 254NEED_ABSOLUTE_PATH := 1 255PWD := $(shell pwd) 256 257else 258# Windows 259ifeq (,$(filter-out _WIN%,$(NS_USE_GCC)_$(OS_TARGET))) 260NEED_ABSOLUTE_PATH := 1 261# CURDIR is always an absolute path. If it doesn't start with a /, it's a 262# Windows path meaning we're running under MINGW make (as opposed to MSYS 263# make), or pymake. In both cases, it's preferable to use a Windows path, 264# so use $(CURDIR) as is. 265ifeq (,$(filter /%,$(CURDIR))) 266PWD := $(CURDIR) 267else 268PWD := $(shell pwd) 269ifeq (,$(findstring ;,$(PATH))) 270ifndef USE_MSYS 271PWD := $(subst \,/,$(shell cygpath -w $(PWD))) 272endif 273endif 274endif 275 276else 277# everything else 278PWD := $(shell pwd) 279endif 280endif 281 282# The quotes allow absolute paths to contain spaces. 283core_abspath = '$(if $(findstring :,$(1)),$(1),$(if $(filter /%,$(1)),$(1),$(PWD)/$(1)))' 284 285$(OBJDIR)/$(PROG_PREFIX)%$(OBJ_SUFFIX): %.c | $$(@D)/d 286ifdef USE_NT_C_SYNTAX 287 $(CC) -Fo$@ -c $(CSTD) $(CFLAGS) $(call core_abspath,$<) 288else 289ifdef NEED_ABSOLUTE_PATH 290 $(CC) -o $@ -c $(CSTD) $(CFLAGS) $(call core_abspath,$<) 291else 292 $(CC) -o $@ -c $(CSTD) $(CFLAGS) $< 293endif 294endif 295 296$(PROG_PREFIX)%$(OBJ_SUFFIX): %.c | $$(@D)/d 297ifdef USE_NT_C_SYNTAX 298 $(CC) -Fo$@ -c $(CSTD) $(CFLAGS) $(call core_abspath,$<) 299else 300ifdef NEED_ABSOLUTE_PATH 301 $(CC) -o $@ -c $(CSTD) $(CFLAGS) $(call core_abspath,$<) 302else 303 $(CC) -o $@ -c $(CSTD) $(CFLAGS) $< 304endif 305endif 306 307ifneq (,$(filter-out _WIN%,$(NS_USE_GCC)_$(OS_TARGET))) 308$(OBJDIR)/$(PROG_PREFIX)%$(OBJ_SUFFIX): %.s | $$(@D)/d 309 $(AS) -o $@ $(ASFLAGS) -c $< 310endif 311 312$(OBJDIR)/$(PROG_PREFIX)%$(OBJ_SUFFIX): %.asm | $$(@D)/d 313 $(AS) -Fo$@ $(ASFLAGS) -c $< 314 315$(OBJDIR)/$(PROG_PREFIX)%$(OBJ_SUFFIX): %.S | $$(@D)/d 316 $(AS) -o $@ $(ASFLAGS) -c $< 317 318$(OBJDIR)/$(PROG_PREFIX)%: %.cpp | $$(@D)/d 319ifdef USE_NT_C_SYNTAX 320 $(CCC) -Fo$@ -c $(CXXSTD) $(CFLAGS) $(CXXFLAGS) $(call core_abspath,$<) 321else 322ifdef NEED_ABSOLUTE_PATH 323 $(CCC) -o $@ -c $(CXXSTD) $(CFLAGS) $(CXXFLAGS) $(call core_abspath,$<) 324else 325 $(CCC) -o $@ -c $(CXXSTD) $(CFLAGS) $(CXXFLAGS) $< 326endif 327endif 328 329define compile_ccc_pattern_RULE 330 331$$(OBJDIR)/$$(PROG_PREFIX)%$$(OBJ_SUFFIX): %.$(1) | $$$$(@D)/d 332ifdef STRICT_CPLUSPLUS_SUFFIX 333 echo "#line 1 \"$$<\"" | cat - $$< > $$(OBJDIR)/t_$$*.cc 334 $$(CCC) -o $$@ -c $$(CXXSTD) $$(CFLAGS) $$(CXXFLAGS) $$(OBJDIR)/t_$$*.cc 335 rm -f $$(OBJDIR)/t_$$*.cc 336else 337ifdef USE_NT_C_SYNTAX 338 $$(CCC) -Fo$$@ -c $$(CXXSTD) $$(CFLAGS) $$(CXXFLAGS) $$(call core_abspath,$$<) 339else 340ifdef NEED_ABSOLUTE_PATH 341 $$(CCC) -o $$@ -c $$(CXXSTD) $$(CFLAGS) $$(CXXFLAGS) $$(call core_abspath,$$<) 342else 343 $$(CCC) -o $$@ -c $$(CXXSTD) $$(CFLAGS) $$(CXXFLAGS) $$< 344endif 345endif 346endif #STRICT_CPLUSPLUS_SUFFIX 347endef # compile_ccc_pattern_RULE 348 349$(eval $(call compile_ccc_pattern_RULE,cc)) 350$(eval $(call compile_ccc_pattern_RULE,cpp)) 351 352%.i: %.cpp 353 $(CCC) -C -E $(CFLAGS) $(CXXFLAGS) $< > $@ 354 355%.i: %.c 356ifeq (,$(filter-out WIN%,$(OS_TARGET))) 357 $(CC) -C /P $(CFLAGS) $< 358else 359 $(CC) -C -E $(CFLAGS) $< > $@ 360endif 361 362ifneq (,$(filter-out WIN%,$(OS_TARGET))) 363%.i: %.s 364 $(CC) -C -E $(CFLAGS) $< > $@ 365endif 366 367%: %.pl 368 rm -f $@; cp $< $@; chmod +x $@ 369 370%: %.sh 371 rm -f $@; cp $< $@; chmod +x $@ 372 373define copy_varlist_into_dir_RULE 374ifdef $(2) 375ifneq (,$$(strip $$($(2)))) 376$(3)/%: % 377 $$(INSTALL) -m 444 $$^ $(3) 378 379$(1): $$(addprefix $(3)/,$$($(2))) | $(3)/d 380endif 381else 382$(1): 383endif 384endef # copy_varlist_into_dir_RULE 385 386# export rule 387$(eval $(call copy_varlist_into_dir_RULE,export,EXPORTS,$(SOURCE_XPHEADERS_DIR))) 388 389# private_export rule 390$(eval $(call copy_varlist_into_dir_RULE,private_export,PRIVATE_EXPORTS,$(SOURCE_XPPRIVATE_DIR))) 391 392########################################################################## 393### RULES FOR RUNNING REGRESSION SUITE TESTS 394### REQUIRES 'REGRESSION_SPEC' TO BE SET TO THE NAME OF A REGRESSION SPECFILE 395### AND RESULTS_SUBDIR TO BE SET TO SOMETHING LIKE SECURITY/PKCS5 396########################################################################## 397 398TESTS_DIR = $(RESULTS_DIR)/$(RESULTS_SUBDIR)/$(OS_TARGET)$(OS_RELEASE)$(CPU_TAG)$(COMPILER_TAG)$(IMPL_STRATEGY) 399 400ifneq ($(REGRESSION_SPEC),) 401 402ifneq ($(BUILD_OPT),) 403REGDATE = $(subst \ ,, $(shell $(PERL) $(CORE_DEPTH)/$(MODULE)/scripts/now)) 404endif 405 406check: $(REGRESSION_SPEC) | $(TESTS_DIR)/d 407 cd $(PLATFORM); \ 408 ../$(SOURCE_MD_DIR)/bin/regress$(PROG_SUFFIX) specfile=../$(REGRESSION_SPEC) progress $(EXTRA_REGRESS_OPTIONS) 409ifneq ($(BUILD_OPT),) 410 $(NSINSTALL) -m 664 $(PLATFORM)/$(REGDATE).sum $(TESTS_DIR); \ 411 $(NSINSTALL) -m 664 $(PLATFORM)/$(REGDATE).htm $(TESTS_DIR); \ 412 echo "Please now make sure your results files are copied to $(TESTS_DIR), "; \ 413 echo "then run 'reporter specfile=$(RESULTS_DIR)/rptspec'" 414endif 415else 416check: 417 @echo "Error: you didn't specify REGRESSION_SPEC in your manifest.mn file!" 418endif 419 420# release_export rule 421$(eval $(call copy_varlist_into_dir_RULE,release_export,EXPORTS,$(SOURCE_RELEASE_XP_DIR)/include)) 422 423# 424# HACK ALERT 425# 426# The only purpose of this rule is to pass Mozilla's Tinderbox depend 427# builds (http://tinderbox.mozilla.org/showbuilds.cgi). Mozilla's 428# Tinderbox builds NSS continuously as part of the Mozilla client. 429# Because NSS's make depend is not implemented, whenever we change 430# an NSS header file, the depend build does not recompile the NSS 431# files that depend on the header. 432# 433# This rule makes all the objects depend on a dummy header file. 434# Check in a change to this dummy header file to force the depend 435# build to recompile everything. 436# 437# This rule should be removed when make depend is implemented. 438# 439 440DUMMY_DEPEND = $(CORE_DEPTH)/coreconf/coreconf.dep 441 442$(filter $(OBJDIR)/%$(OBJ_SUFFIX),$(OBJS)): $(OBJDIR)/%$(OBJ_SUFFIX): $(DUMMY_DEPEND) 443 444# END OF HACK 445 446################################################################################ 447# Special gmake rules. 448################################################################################ 449 450# 451# Re-define the list of default suffixes, so gmake won't have to churn through 452# hundreds of built-in suffix rules for stuff we don't need. 453# 454.SUFFIXES: 455.SUFFIXES: .out .a .ln .o .obj .c .cc .C .cpp .y .l .s .S .h .sh .i .pl .html .asm .dep 456 457# 458# Fake targets. Always run these rules, even if a file/directory with that 459# name already exists. 460# 461.PHONY: all all_platforms alltags boot clean clobber clobber_all export install libs program realclean release $(DIRS) 462 463