3 # This Source Code Form is subject to the terms of the Mozilla Public
4 # License, v. 2.0. If a copy of the MPL was not distributed with this
5 # file, You can obtain one at http://mozilla.org/MPL/2.0/.
7 ################################################################################
8 # We used to have a 4 pass build process. Now we do everything in one pass.
10 # export - Create generated headers and stubs. Publish public headers to
11 # dist/<arch>/include.
12 # Create libraries. Publish libraries to dist/<arch>/lib.
15 # libs - obsolete. Now a synonym of "export".
17 # all - the default makefile target. Now a synonym of "export".
19 # install - Install headers, libraries, and programs on the system.
21 # Parameters to this makefile (set these before including):
24 # TARGETS -- the target to create
25 # (defaults to $LIBRARY $PROGRAM)
27 # DIRS -- subdirectories for make to recurse on
28 # (the 'all' rule builds $TARGETS $DIRS)
30 # CSRCS -- .c files to compile
31 # (used to define $OBJS)
33 # PROGRAM -- the target program name to create from $OBJS
34 # ($OBJDIR automatically prepended to it)
36 # LIBRARY -- the target library name to create from $OBJS
37 # ($OBJDIR automatically prepended to it)
39 ################################################################################
42 topsrcdir
=$(MOD_DEPTH
)
50 include $(topsrcdir
)/config
/config.mk
59 CXXFLAGS
=$(HOST_CXXFLAGS
)
60 LDFLAGS
=$(HOST_LDFLAGS
)
66 # This makefile contains rules for building the following kinds of
68 # - LIBRARY: a static (archival) library
69 # - SHARED_LIBRARY: a shared (dynamic link) library
70 # - IMPORT_LIBRARY: an import library, used only on Windows and OS/2
72 # The names of these libraries can be generated by simply specifying
73 # LIBRARY_NAME and LIBRARY_VERSION.
77 ifeq (,$(filter-out WINNT WINCE OS2
,$(OS_ARCH
)))
80 # Win95 and OS/2 require library names conforming to the 8.3 rule.
81 # other platforms do not.
83 ifeq (,$(filter-out WIN95 WINCE WINMO OS2
,$(OS_TARGET
)))
84 SHARED_LIBRARY
= $(OBJDIR
)/$(LIBRARY_NAME
)$(LIBRARY_VERSION
).
$(DLL_SUFFIX
)
85 SHARED_LIB_PDB
= $(OBJDIR
)/$(LIBRARY_NAME
)$(LIBRARY_VERSION
).pdb
87 LIBRARY
= $(OBJDIR
)/$(LIBRARY_NAME
)$(LIBRARY_VERSION
)_s.
$(LIB_SUFFIX
)
88 IMPORT_LIBRARY
= $(OBJDIR
)/$(LIBRARY_NAME
)$(LIBRARY_VERSION
).
$(LIB_SUFFIX
)
90 LIBRARY
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
)_s.
$(LIB_SUFFIX
)
91 IMPORT_LIBRARY
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
).
$(LIB_SUFFIX
)
94 SHARED_LIBRARY
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
).
$(DLL_SUFFIX
)
95 SHARED_LIB_PDB
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
).pdb
96 LIBRARY
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
)_s.
$(LIB_SUFFIX
)
97 IMPORT_LIBRARY
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
).
$(LIB_SUFFIX
)
102 LIBRARY
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
).
$(LIB_SUFFIX
)
103 ifeq ($(OS_ARCH
)$(OS_RELEASE
), AIX4.1
)
104 SHARED_LIBRARY
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
)_shr.a
107 SHARED_LIBRARY
= $(OBJDIR
)/lib
$(LIBRARY_NAME
)$(LIBRARY_VERSION
).
$(DLL_SUFFIX
)
115 ifeq (,$(filter-out WINNT WINCE OS2
,$(OS_ARCH
)))
116 TARGETS
= $(LIBRARY
) $(SHARED_LIBRARY
) $(IMPORT_LIBRARY
)
117 ifdef MOZ_DEBUG_SYMBOLS
119 ifneq (,$(filter-out 1100 1200,$(MSC_VER
)))
120 TARGETS
+= $(SHARED_LIB_PDB
)
125 TARGETS
= $(LIBRARY
) $(SHARED_LIBRARY
)
130 # OBJS is the list of object files. It can be constructed by
131 # specifying CSRCS (list of C source files) and ASFILES (list
132 # of assembly language source files).
136 OBJS
= $(addprefix $(OBJDIR
)/,$(CSRCS
:.c
=.
$(OBJ_SUFFIX
))) \
137 $(addprefix $(OBJDIR
)/,$(ASFILES
:.
$(ASM_SUFFIX
)=.
$(OBJ_SUFFIX
)))
140 ALL_TRASH
= $(TARGETS
) $(OBJS
) $(RES
) $(filter-out . ..
, $(OBJDIR
)) LOGS TAGS
$(GARBAGE
) \
142 $(OBJS
:.
$(OBJ_SUFFIX
)=.i_o
) \
145 ifndef RELEASE_LIBS_DEST
146 RELEASE_LIBS_DEST
= $(RELEASE_LIB_DIR
)
152 endef # do not remove the blank line!
155 LOOP_OVER_DIRS
= $(foreach dir,$(DIRS
),$(MAKE_IN_DIR
))
158 ################################################################################
168 rm -rf
$(OBJS
) $(RES
) so_locations
$(NOSUCHFILE
) $(GARBAGE
)
172 rm -rf
$(OBJS
) $(RES
) $(TARGETS
) $(filter-out . ..
,$(OBJDIR
)) $(GARBAGE
) so_locations
$(NOSUCHFILE
)
175 realclean clobber_all
::
176 rm -rf
$(wildcard *.OBJ
*.OBJD
) dist $(ALL_TRASH
)
180 rm -rf
$(wildcard *.OBJ
*.OBJD
) dist $(ALL_TRASH
) $(DIST_GARBAGE
)
183 install:: $(RELEASE_BINS
) $(RELEASE_HEADERS
) $(RELEASE_LIBS
)
185 $(NSINSTALL
) -t
-m
0755 $(RELEASE_BINS
) $(DESTDIR
)$(bindir)
187 ifdef RELEASE_HEADERS
188 $(NSINSTALL
) -t
-m
0644 $(RELEASE_HEADERS
) $(DESTDIR
)$(includedir)/$(include_subdir
)
191 $(NSINSTALL
) -t
-m
0755 $(RELEASE_LIBS
) $(DESTDIR
)$(libdir)/$(lib_subdir
)
197 @echo
"Copying executable programs and scripts to release directory"
198 @if
test -z
"$(BUILD_NUMBER)"; then \
199 echo
"BUILD_NUMBER must be defined"; \
204 @if
test ! -d
$(RELEASE_BIN_DIR
); then \
205 rm -rf
$(RELEASE_BIN_DIR
); \
206 $(NSINSTALL
) -D
$(RELEASE_BIN_DIR
);\
210 cp
$(RELEASE_BINS
) $(RELEASE_BIN_DIR
)
213 @echo
"Copying libraries to release directory"
214 @if
test -z
"$(BUILD_NUMBER)"; then \
215 echo
"BUILD_NUMBER must be defined"; \
220 @if
test ! -d
$(RELEASE_LIBS_DEST
); then \
221 rm -rf
$(RELEASE_LIBS_DEST
); \
222 $(NSINSTALL
) -D
$(RELEASE_LIBS_DEST
);\
226 cp
$(RELEASE_LIBS
) $(RELEASE_LIBS_DEST
)
228 ifdef RELEASE_HEADERS
229 @echo
"Copying header files to release directory"
230 @if
test -z
"$(BUILD_NUMBER)"; then \
231 echo
"BUILD_NUMBER must be defined"; \
236 @if
test ! -d
$(RELEASE_HEADERS_DEST
); then \
237 rm -rf
$(RELEASE_HEADERS_DEST
); \
238 $(NSINSTALL
) -D
$(RELEASE_HEADERS_DEST
);\
242 cp
$(RELEASE_HEADERS
) $(RELEASE_HEADERS_DEST
)
248 find .
-name
dist -prune
-o \
( -name
'*.[hc]' -o
-name
'*.cp' -o
-name
'*.cpp' \
) -print | xargs etags
-a
249 find .
-name
dist -prune
-o \
( -name
'*.[hc]' -o
-name
'*.cp' -o
-name
'*.cpp' \
) -print | xargs ctags
-a
252 cd
$(@D
); $(MAKE
) $(@F
)
256 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINNT
)
257 ifdef MOZ_PROFILE_USE
258 # In the second pass, we need to merge the pgc files into the pgd file.
259 # The compiler would do this for us automatically if they were in the right
260 # place, but they're in dist/bin.
261 python
$(topsrcdir
)/build
/win32
/pgomerge.py \
262 $(notdir $(PROGRAM
:.exe
=)) $(DIST
)/bin
263 endif # MOZ_PROFILE_USE
264 $(CC
) $(OBJS
) -Fe
$@
-link
$(LDFLAGS
) $(OS_LIBS
) $(EXTRA_LIBS
)
266 @if
test -f
$@.manifest
; then \
267 $(MT
) -NOLOGO
-MANIFEST
$@.manifest
-OUTPUTRESOURCE
:$@\
;1; \
270 endif # MSVC with manifest tool
271 ifdef MOZ_PROFILE_GENERATE
272 # touch it a few seconds into the future to work around FAT's
273 # 2-second granularity
274 touch
-t
`date +%Y%m%d%H%M.%S -d "now+5seconds"` pgo.relink
275 endif # MOZ_PROFILE_GENERATE
277 $(CC
) -o
$@
$(CFLAGS
) $(OBJS
) $(LDFLAGS
) $(WRAP_LDFLAGS
)
278 endif # WINNT && !GCC
283 # Same as OBJS, but without any file that matches p*vrsion.o, since these
284 # collide for static libraries, and are not useful for that case anyway.
285 STATICLIB_OBJS
= $(filter-out $(OBJDIR
)/p
%vrsion.
$(OBJ_SUFFIX
),$(OBJS
))
286 $(LIBRARY
): $(STATICLIB_OBJS
)
289 $(AR
) $(AR_FLAGS
) $(STATICLIB_OBJS
) $(AR_EXTRA_ARGS
)
292 ifeq ($(OS_TARGET
), OS2
)
293 $(IMPORT_LIBRARY
): $(MAPFILE
)
295 $(IMPLIB
) $@
$(MAPFILE
)
297 ifeq (,$(filter-out WIN95 WINCE WINMO
,$(OS_TARGET
)))
298 # PDBs and import libraries need to depend on the shared library to
299 # order dependencies properly.
300 $(IMPORT_LIBRARY
): $(SHARED_LIBRARY
)
301 $(SHARED_LIB_PDB
): $(SHARED_LIBRARY
)
305 $(SHARED_LIBRARY
): $(OBJS
) $(RES
) $(MAPFILE
)
308 ifeq ($(OS_ARCH
)$(OS_RELEASE
), AIX4.1
)
309 echo
"#!" > $(OBJDIR
)/lib
$(LIBRARY_NAME
)_syms
310 nm
-B
-C
-g
$(OBJS
) \
311 | awk
'/ [T,D] / {print $$3}' \
313 |
sort -u
>> $(OBJDIR
)/lib
$(LIBRARY_NAME
)_syms
314 $(LD
) $(XCFLAGS
) -o
$@
$(OBJS
) -bE
:$(OBJDIR
)/lib
$(LIBRARY_NAME
)_syms \
315 -bM
:SRE
-bnoentry
$(OS_LIBS
) $(EXTRA_LIBS
)
317 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINNT
)
318 ifdef MOZ_PROFILE_USE
319 python
$(topsrcdir
)/build
/win32
/pgomerge.py \
320 $(notdir $(SHARED_LIBRARY
:.
$(DLL_SUFFIX
)=)) $(DIST
)/bin
321 endif # MOZ_PROFILE_USE
322 $(LINK_DLL
) -MAP
$(DLLBASE
) $(DLL_LIBS
) $(EXTRA_LIBS
) $(OBJS
) $(RES
)
324 @if
test -f
$@.manifest
; then \
325 $(MT
) -NOLOGO
-MANIFEST
$@.manifest
-OUTPUTRESOURCE
:$@\
;2; \
328 endif # MSVC with manifest tool
329 ifdef MOZ_PROFILE_GENERATE
330 touch
-t
`date +%Y%m%d%H%M.%S -d "now+5seconds"` pgo.relink
331 endif # MOZ_PROFILE_GENERATE
333 $(MKSHLIB
) $(OBJS
) $(RES
) $(LDFLAGS
) $(WRAP_LDFLAGS
) $(EXTRA_LIBS
)
334 endif # WINNT && !GCC
340 ################################################################################
342 ifdef MOZ_PROFILE_USE
343 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINNT
)
344 # When building with PGO, we have to make sure to re-link
345 # in the MOZ_PROFILE_USE phase if we linked in the
346 # MOZ_PROFILE_GENERATE phase. We'll touch this pgo.relink
347 # file in the link rule in the GENERATE phase to indicate
348 # that we need a relink.
349 $(SHARED_LIBRARY
): pgo.relink
351 $(PROGRAM
): pgo.relink
353 endif # WINNT && !GCC
354 endif # MOZ_PROFILE_USE
356 ifneq (,$(MOZ_PROFILE_GENERATE
)$(MOZ_PROFILE_USE
))
358 # Force rebuilding libraries and programs in both passes because each
359 # pass uses different object files.
360 $(PROGRAM
) $(SHARED_LIBRARY
) $(LIBRARY
): FORCE
365 ################################################################################
367 ifdef MOZ_PROFILE_GENERATE
368 # Clean up profiling data during PROFILE_GENERATE phase
370 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINNT
)
371 $(foreach pgd
,$(wildcard *.pgd
),pgomgr
-clear
$(pgd
);)
379 ################################################################################
381 ifeq ($(OS_ARCH
),WINNT
)
384 # The resource compiler does not understand the -U option.
386 $(RC
) $(RCFLAGS
) $(filter-out -U
%,$(DEFINES
)) $(INCLUDES
:-I
%=--include-dir
%) -o
$@
$<
388 $(RC
) $(RCFLAGS
) $(filter-out -U
%,$(DEFINES
)) $(INCLUDES
) -Fo
$@
$<
390 @echo
$(RES
) finished
393 $(MAPFILE
): $(LIBRARY_NAME
).def
395 ifeq ($(OS_ARCH
),SunOS
)
397 sed
-e
's,;+,,' -e
's; DATA ;;' -e
's,;;,,' -e
's,;.*,;,' > $@
399 ifeq ($(OS_ARCH
),OS2
)
400 echo LIBRARY
$(LIBRARY_NAME
)$(LIBRARY_VERSION
) INITINSTANCE TERMINSTANCE
> $@
402 echo CODE LOADONCALL MOVEABLE DISCARDABLE
>> $@
403 echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED
>> $@
405 grep
-v
';+' $< | grep
-v
';-' | \
406 sed
-e
's; DATA ;;' -e
's,;;,,' -e
's,;.*,,' -e
's,\([\t ]*\),\1_,' | \
407 awk
'BEGIN {ord=1;} { print($$0 " @" ord " RESIDENTNAME"); ord++;}' >> $@
412 # Translate source filenames to absolute paths. This is required for
413 # debuggers under Windows and OS/2 to find source files automatically.
416 ifeq (,$(filter-out AIX OS2
,$(OS_ARCH
)))
417 NEED_ABSOLUTE_PATH
= 1
420 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINNT
)
421 NEED_ABSOLUTE_PATH
= 1
424 ifdef NEED_ABSOLUTE_PATH
425 # The quotes allow absolute paths to contain spaces.
426 pr_abspath
= "$(if $(findstring :,$(1)),$(1),$(if $(filter /%,$(1)),$(1),$(CURDIR)/$(1)))"
429 $(OBJDIR
)/%.
$(OBJ_SUFFIX
): %.
cpp
431 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINNT
)
432 $(CCC
) -Fo
$@
-c
$(CCCFLAGS
) $(call pr_abspath
,$<)
434 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINCE
)
435 $(CCC
) -Fo
$@
-c
$(CCCFLAGS
) $<
437 ifdef NEED_ABSOLUTE_PATH
438 $(CCC
) -o
$@
-c
$(CCCFLAGS
) $(call pr_abspath
,$<)
440 $(CCC
) -o
$@
-c
$(CCCFLAGS
) $<
445 WCCFLAGS1
= $(subst /,\\,$(CFLAGS
))
446 WCCFLAGS2
= $(subst -I
,-i
=,$(WCCFLAGS1
))
447 WCCFLAGS3
= $(subst -D
,-d
,$(WCCFLAGS2
))
448 $(OBJDIR
)/%.
$(OBJ_SUFFIX
): %.c
450 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINNT
)
451 $(CC
) -Fo
$@
-c
$(CFLAGS
) $(call pr_abspath
,$<)
453 ifeq ($(NS_USE_GCC
)_
$(OS_ARCH
),_WINCE
)
454 $(CC
) -Fo
$@
-c
$(CFLAGS
) $<
456 ifdef NEED_ABSOLUTE_PATH
457 $(CC
) -o
$@
-c
$(CFLAGS
) $(call pr_abspath
,$<)
459 $(CC
) -o
$@
-c
$(CFLAGS
) $<
465 $(OBJDIR
)/%.
$(OBJ_SUFFIX
): %.s
467 $(AS
) -o
$@
$(ASFLAGS
) -c
$<
470 $(CC
) -C
-E
$(CFLAGS
) $< > $*.i
473 rm -f
$@
; cp
$< $@
; chmod
+x
$@
478 # The only purpose of this rule is to pass Mozilla's Tinderbox depend
479 # builds (http://tinderbox.mozilla.org/showbuilds.cgi). Mozilla's
480 # Tinderbox builds NSPR continuously as part of the Mozilla client.
481 # Because NSPR's make depend is not implemented, whenever we change
482 # an NSPR header file, the depend build does not recompile the NSPR
483 # files that depend on the header.
485 # This rule makes all the objects depend on a dummy header file.
486 # Touch this dummy header file to force the depend build to recompile
489 # This rule should be removed when make depend is implemented.
492 DUMMY_DEPEND_H
= $(topsrcdir
)/config
/prdepend.h
494 $(filter $(OBJDIR
)/%.
$(OBJ_SUFFIX
),$(OBJS
)): $(OBJDIR
)/%.
$(OBJ_SUFFIX
): $(DUMMY_DEPEND_H
)
498 ################################################################################
499 # Special gmake rules.
500 ################################################################################
503 # Disallow parallel builds with MSVC < 8 since it can't open the PDB file in
506 ifeq (,$(filter-out 1200 1300 1310,$(MSC_VER
)))
511 # Re-define the list of default suffixes, so gmake won't have to churn through
512 # hundreds of built-in suffix rules for stuff we don't need.
515 .SUFFIXES
: .a .
$(OBJ_SUFFIX
) .c .
cpp .s .h .i .pl
518 # Fake targets. Always run these rules, even if a file/directory with that
519 # name already exists.
521 .PHONY
: all alltags
clean export install libs
realclean release
524 # List the target pattern of an implicit rule as a dependency of the
525 # special target .PRECIOUS to preserve intermediate files made by
526 # implicit rules whose target patterns match that file's name.
527 # (See GNU Make documentation, Edition 0.51, May 1996, Sec. 10.4,
530 .PRECIOUS
: $(OBJDIR
)/%.
$(OBJ_SUFFIX
)