no bug - Import translations from android-l10n r=release a=l10n CLOSED TREE
[gecko.git] / nsprpub / config / rules.mk
blob84dff56179417c81b00e4eb287f5b6c7d1066247
1 #! gmake
2 #
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.
13 # Create programs.
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):
23 # a)
24 # TARGETS -- the target to create
25 # (defaults to $LIBRARY $PROGRAM)
26 # b)
27 # DIRS -- subdirectories for make to recurse on
28 # (the 'all' rule builds $TARGETS $DIRS)
29 # c)
30 # CSRCS -- .c files to compile
31 # (used to define $OBJS)
32 # d)
33 # PROGRAM -- the target program name to create from $OBJS
34 # ($OBJDIR automatically prepended to it)
35 # e)
36 # LIBRARY -- the target library name to create from $OBJS
37 # ($OBJDIR automatically prepended to it)
39 ################################################################################
41 ifndef topsrcdir
42 topsrcdir=$(MOD_DEPTH)
43 endif
45 ifndef srcdir
46 srcdir=.
47 endif
49 ifndef NSPR_CONFIG_MK
50 include $(topsrcdir)/config/config.mk
51 endif
53 ifdef USE_AUTOCONF
54 ifdef CROSS_COMPILE
55 ifdef INTERNAL_TOOLS
56 CC=$(HOST_CC)
57 CCC=$(HOST_CXX)
58 CFLAGS=$(HOST_CFLAGS)
59 CXXFLAGS=$(HOST_CXXFLAGS)
60 LDFLAGS=$(HOST_LDFLAGS)
61 endif
62 endif
63 endif
66 # This makefile contains rules for building the following kinds of
67 # libraries:
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.
76 ifdef LIBRARY_NAME
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
86 ifdef MSC_VER
87 LIBRARY = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
88 IMPORT_LIBRARY = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
89 else
90 LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
91 IMPORT_LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
92 endif
93 else
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)
98 endif
100 else
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
105 else
106 ifdef MKSHLIB
107 SHARED_LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
108 endif
109 endif
111 endif
112 endif
114 ifndef TARGETS
115 ifeq (,$(filter-out WINNT WINCE OS2,$(OS_ARCH)))
116 TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(IMPORT_LIBRARY)
117 ifdef MOZ_DEBUG_SYMBOLS
118 ifdef MSC_VER
119 ifneq (,$(filter-out 1100 1200,$(MSC_VER)))
120 TARGETS += $(SHARED_LIB_PDB)
121 endif
122 endif
123 endif
124 else
125 TARGETS = $(LIBRARY) $(SHARED_LIBRARY)
126 endif
127 endif
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).
135 ifndef OBJS
136 OBJS = $(addprefix $(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX))) \
137 $(addprefix $(OBJDIR)/,$(ASFILES:.$(ASM_SUFFIX)=.$(OBJ_SUFFIX)))
138 endif
140 ALL_TRASH = $(TARGETS) $(OBJS) $(RES) $(filter-out . .., $(OBJDIR)) LOGS TAGS $(GARBAGE) \
141 $(NOSUCHFILE) \
142 $(OBJS:.$(OBJ_SUFFIX)=.i_o) \
143 so_locations
145 ifndef RELEASE_LIBS_DEST
146 RELEASE_LIBS_DEST = $(RELEASE_LIB_DIR)
147 endif
149 define MAKE_IN_DIR
150 $(MAKE) -C $(dir) $@
152 endef # do not remove the blank line!
154 ifdef DIRS
155 LOOP_OVER_DIRS = $(foreach dir,$(DIRS),$(MAKE_IN_DIR))
156 endif
158 ################################################################################
160 all:: export
162 export::
163 +$(LOOP_OVER_DIRS)
165 libs:: export
167 clean::
168 rm -rf $(OBJS) $(RES) so_locations $(NOSUCHFILE) $(GARBAGE)
169 +$(LOOP_OVER_DIRS)
171 clobber::
172 rm -rf $(OBJS) $(RES) $(TARGETS) $(filter-out . ..,$(OBJDIR)) $(GARBAGE) so_locations $(NOSUCHFILE)
173 +$(LOOP_OVER_DIRS)
175 realclean clobber_all::
176 rm -rf $(wildcard *.OBJ *.OBJD) dist $(ALL_TRASH)
177 +$(LOOP_OVER_DIRS)
179 distclean::
180 rm -rf $(wildcard *.OBJ *.OBJD) dist $(ALL_TRASH) $(DIST_GARBAGE)
181 +$(LOOP_OVER_DIRS)
183 install:: $(RELEASE_BINS) $(RELEASE_HEADERS) $(RELEASE_LIBS)
184 ifdef RELEASE_BINS
185 $(NSINSTALL) -t -m 0755 $(RELEASE_BINS) $(DESTDIR)$(bindir)
186 endif
187 ifdef RELEASE_HEADERS
188 $(NSINSTALL) -t -m 0644 $(RELEASE_HEADERS) $(DESTDIR)$(includedir)/$(include_subdir)
189 endif
190 ifdef RELEASE_LIBS
191 $(NSINSTALL) -t -m 0755 $(RELEASE_LIBS) $(DESTDIR)$(libdir)/$(lib_subdir)
192 endif
193 +$(LOOP_OVER_DIRS)
195 release:: export
196 ifdef RELEASE_BINS
197 @echo "Copying executable programs and scripts to release directory"
198 @if test -z "$(BUILD_NUMBER)"; then \
199 echo "BUILD_NUMBER must be defined"; \
200 false; \
201 else \
202 true; \
204 @if test ! -d $(RELEASE_BIN_DIR); then \
205 rm -rf $(RELEASE_BIN_DIR); \
206 $(NSINSTALL) -D $(RELEASE_BIN_DIR);\
207 else \
208 true; \
210 cp $(RELEASE_BINS) $(RELEASE_BIN_DIR)
211 endif
212 ifdef RELEASE_LIBS
213 @echo "Copying libraries to release directory"
214 @if test -z "$(BUILD_NUMBER)"; then \
215 echo "BUILD_NUMBER must be defined"; \
216 false; \
217 else \
218 true; \
220 @if test ! -d $(RELEASE_LIBS_DEST); then \
221 rm -rf $(RELEASE_LIBS_DEST); \
222 $(NSINSTALL) -D $(RELEASE_LIBS_DEST);\
223 else \
224 true; \
226 cp $(RELEASE_LIBS) $(RELEASE_LIBS_DEST)
227 endif
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"; \
232 false; \
233 else \
234 true; \
236 @if test ! -d $(RELEASE_HEADERS_DEST); then \
237 rm -rf $(RELEASE_HEADERS_DEST); \
238 $(NSINSTALL) -D $(RELEASE_HEADERS_DEST);\
239 else \
240 true; \
242 cp $(RELEASE_HEADERS) $(RELEASE_HEADERS_DEST)
243 endif
244 +$(LOOP_OVER_DIRS)
246 alltags:
247 rm -f TAGS tags
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
251 $(NFSPWD):
252 cd $(@D); $(MAKE) $(@F)
254 $(PROGRAM): $(OBJS)
255 @$(MAKE_OBJDIR)
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)
265 ifdef MT
266 @if test -f $@.manifest; then \
267 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
268 rm -f $@.manifest; \
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
276 else # WINNT && !GCC
277 $(CC) -o $@ $(CFLAGS) $(OBJS) $(LDFLAGS) $(WRAP_LDFLAGS)
278 endif # WINNT && !GCC
279 ifdef ENABLE_STRIP
280 $(STRIP) $@
281 endif
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)
287 @$(MAKE_OBJDIR)
288 rm -f $@
289 $(AR) $(AR_FLAGS) $(STATICLIB_OBJS) $(AR_EXTRA_ARGS)
290 $(RANLIB) $@
292 ifeq ($(OS_TARGET), OS2)
293 $(IMPORT_LIBRARY): $(MAPFILE)
294 rm -f $@
295 $(IMPLIB) $@ $(MAPFILE)
296 else
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)
302 endif
303 endif
305 $(SHARED_LIBRARY): $(OBJS) $(RES) $(MAPFILE)
306 @$(MAKE_OBJDIR)
307 rm -f $@
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}' \
312 | sed -e 's/^\.//' \
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)
316 else # AIX 4.1
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)
323 ifdef MT
324 @if test -f $@.manifest; then \
325 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;2; \
326 rm -f $@.manifest; \
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
332 else # WINNT && !GCC
333 $(MKSHLIB) $(OBJS) $(RES) $(LDFLAGS) $(WRAP_LDFLAGS) $(EXTRA_LIBS)
334 endif # WINNT && !GCC
335 endif # AIX 4.1
336 ifdef ENABLE_STRIP
337 $(STRIP) $@
338 endif
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))
357 ifdef NS_USE_GCC
358 # Force rebuilding libraries and programs in both passes because each
359 # pass uses different object files.
360 $(PROGRAM) $(SHARED_LIBRARY) $(LIBRARY): FORCE
361 .PHONY: FORCE
362 endif
363 endif
365 ################################################################################
367 ifdef MOZ_PROFILE_GENERATE
368 # Clean up profiling data during PROFILE_GENERATE phase
369 export::
370 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
371 $(foreach pgd,$(wildcard *.pgd),pgomgr -clear $(pgd);)
372 else
373 ifdef NS_USE_GCC
374 -$(RM) *.gcda
375 endif
376 endif
377 endif
379 ################################################################################
381 ifeq ($(OS_ARCH),WINNT)
382 $(RES): $(RESNAME)
383 @$(MAKE_OBJDIR)
384 # The resource compiler does not understand the -U option.
385 ifdef NS_USE_GCC
386 $(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES:-I%=--include-dir %) -o $@ $<
387 else
388 $(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES) -Fo$@ $<
389 endif # GCC
390 @echo $(RES) finished
391 endif
393 $(MAPFILE): $(LIBRARY_NAME).def
394 @$(MAKE_OBJDIR)
395 ifeq ($(OS_ARCH),SunOS)
396 grep -v ';-' $< | \
397 sed -e 's,;+,,' -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,;,' > $@
398 endif
399 ifeq ($(OS_ARCH),OS2)
400 echo LIBRARY $(LIBRARY_NAME)$(LIBRARY_VERSION) INITINSTANCE TERMINSTANCE > $@
401 echo PROTMODE >> $@
402 echo CODE LOADONCALL MOVEABLE DISCARDABLE >> $@
403 echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $@
404 echo EXPORTS >> $@
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++;}' >> $@
408 $(ADD_TO_DEF_FILE)
409 endif
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
418 endif
420 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
421 NEED_ABSOLUTE_PATH = 1
422 endif
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)))"
427 endif
429 $(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp
430 @$(MAKE_OBJDIR)
431 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
432 $(CCC) -Fo$@ -c $(CCCFLAGS) $(call pr_abspath,$<)
433 else
434 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINCE)
435 $(CCC) -Fo$@ -c $(CCCFLAGS) $<
436 else
437 ifdef NEED_ABSOLUTE_PATH
438 $(CCC) -o $@ -c $(CCCFLAGS) $(call pr_abspath,$<)
439 else
440 $(CCC) -o $@ -c $(CCCFLAGS) $<
441 endif
442 endif
443 endif
445 WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
446 WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
447 WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
448 $(OBJDIR)/%.$(OBJ_SUFFIX): %.c
449 @$(MAKE_OBJDIR)
450 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
451 $(CC) -Fo$@ -c $(CFLAGS) $(call pr_abspath,$<)
452 else
453 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINCE)
454 $(CC) -Fo$@ -c $(CFLAGS) $<
455 else
456 ifdef NEED_ABSOLUTE_PATH
457 $(CC) -o $@ -c $(CFLAGS) $(call pr_abspath,$<)
458 else
459 $(CC) -o $@ -c $(CFLAGS) $<
460 endif
461 endif
462 endif
465 $(OBJDIR)/%.$(OBJ_SUFFIX): %.s
466 @$(MAKE_OBJDIR)
467 $(AS) -o $@ $(ASFLAGS) -c $<
469 %.i: %.c
470 $(CC) -C -E $(CFLAGS) $< > $*.i
472 %: %.pl
473 rm -f $@; cp $< $@; chmod +x $@
476 # HACK ALERT
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
487 # everything.
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)
496 # END OF HACK
498 ################################################################################
499 # Special gmake rules.
500 ################################################################################
503 # Disallow parallel builds with MSVC < 8 since it can't open the PDB file in
504 # parallel.
506 ifeq (,$(filter-out 1200 1300 1310,$(MSC_VER)))
507 .NOTPARALLEL:
508 endif
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.
514 .SUFFIXES:
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,
528 # p. 107.)
530 .PRECIOUS: $(OBJDIR)/%.$(OBJ_SUFFIX)