Bug 1454816 - Remove base::SharedMemory r=ipc-reviewers,nika
[gecko.git] / nsprpub / config / rules.mk
blob8f3f926072abfd93c7fe1c6f3774f64e52c69651
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,$(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,$(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,$(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 (,$(filter-out WIN95 WINCE WINMO,$(OS_TARGET)))
293 # PDBs and import libraries need to depend on the shared library to
294 # order dependencies properly.
295 $(IMPORT_LIBRARY): $(SHARED_LIBRARY)
296 $(SHARED_LIB_PDB): $(SHARED_LIBRARY)
297 endif
299 $(SHARED_LIBRARY): $(OBJS) $(RES) $(MAPFILE)
300 @$(MAKE_OBJDIR)
301 rm -f $@
302 ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
303 echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms
304 nm -B -C -g $(OBJS) \
305 | awk '/ [T,D] / {print $$3}' \
306 | sed -e 's/^\.//' \
307 | sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms
308 $(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \
309 -bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS)
310 else # AIX 4.1
311 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
312 ifdef MOZ_PROFILE_USE
313 python $(topsrcdir)/build/win32/pgomerge.py \
314 $(notdir $(SHARED_LIBRARY:.$(DLL_SUFFIX)=)) $(DIST)/bin
315 endif # MOZ_PROFILE_USE
316 $(LINK_DLL) -MAP $(DLLBASE) $(DLL_LIBS) $(EXTRA_LIBS) $(OBJS) $(RES)
317 ifdef MT
318 @if test -f $@.manifest; then \
319 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;2; \
320 rm -f $@.manifest; \
322 endif # MSVC with manifest tool
323 ifdef MOZ_PROFILE_GENERATE
324 touch -t `date +%Y%m%d%H%M.%S -d "now+5seconds"` pgo.relink
325 endif # MOZ_PROFILE_GENERATE
326 else # WINNT && !GCC
327 $(MKSHLIB) $(OBJS) $(RES) $(LDFLAGS) $(WRAP_LDFLAGS) $(EXTRA_LIBS)
328 endif # WINNT && !GCC
329 endif # AIX 4.1
330 ifdef ENABLE_STRIP
331 $(STRIP) $@
332 endif
334 ################################################################################
336 ifdef MOZ_PROFILE_USE
337 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
338 # When building with PGO, we have to make sure to re-link
339 # in the MOZ_PROFILE_USE phase if we linked in the
340 # MOZ_PROFILE_GENERATE phase. We'll touch this pgo.relink
341 # file in the link rule in the GENERATE phase to indicate
342 # that we need a relink.
343 $(SHARED_LIBRARY): pgo.relink
345 $(PROGRAM): pgo.relink
347 endif # WINNT && !GCC
348 endif # MOZ_PROFILE_USE
350 ifneq (,$(MOZ_PROFILE_GENERATE)$(MOZ_PROFILE_USE))
351 ifdef NS_USE_GCC
352 # Force rebuilding libraries and programs in both passes because each
353 # pass uses different object files.
354 $(PROGRAM) $(SHARED_LIBRARY) $(LIBRARY): FORCE
355 .PHONY: FORCE
356 endif
357 endif
359 ################################################################################
361 ifdef MOZ_PROFILE_GENERATE
362 # Clean up profiling data during PROFILE_GENERATE phase
363 export::
364 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
365 $(foreach pgd,$(wildcard *.pgd),pgomgr -clear $(pgd);)
366 else
367 ifdef NS_USE_GCC
368 -$(RM) *.gcda
369 endif
370 endif
371 endif
373 ################################################################################
375 ifeq ($(OS_ARCH),WINNT)
376 $(RES): $(RESNAME)
377 @$(MAKE_OBJDIR)
378 # The resource compiler does not understand the -U option.
379 ifdef NS_USE_GCC
380 $(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES:-I%=--include-dir %) -o $@ $<
381 else
382 $(RC) $(RCFLAGS) $(filter-out -U%,$(DEFINES)) $(INCLUDES) -Fo$@ $<
383 endif # GCC
384 @echo $(RES) finished
385 endif
387 $(MAPFILE): $(LIBRARY_NAME).def
388 @$(MAKE_OBJDIR)
389 ifeq ($(OS_ARCH),SunOS)
390 grep -v ';-' $< | \
391 sed -e 's,;+,,' -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,;,' > $@
392 endif
395 # Translate source filenames to absolute paths. This is required for
396 # debuggers under Windows to find source files automatically.
399 ifeq (,$(filter-out AIX,$(OS_ARCH)))
400 NEED_ABSOLUTE_PATH = 1
401 endif
403 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
404 NEED_ABSOLUTE_PATH = 1
405 endif
407 ifdef NEED_ABSOLUTE_PATH
408 # The quotes allow absolute paths to contain spaces.
409 pr_abspath = "$(if $(findstring :,$(1)),$(1),$(if $(filter /%,$(1)),$(1),$(CURDIR)/$(1)))"
410 endif
412 $(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp
413 @$(MAKE_OBJDIR)
414 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
415 $(CCC) -Fo$@ -c $(CCCFLAGS) $(call pr_abspath,$<)
416 else
417 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINCE)
418 $(CCC) -Fo$@ -c $(CCCFLAGS) $<
419 else
420 ifdef NEED_ABSOLUTE_PATH
421 $(CCC) -o $@ -c $(CCCFLAGS) $(call pr_abspath,$<)
422 else
423 $(CCC) -o $@ -c $(CCCFLAGS) $<
424 endif
425 endif
426 endif
428 WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
429 WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
430 WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
431 $(OBJDIR)/%.$(OBJ_SUFFIX): %.c
432 @$(MAKE_OBJDIR)
433 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
434 $(CC) -Fo$@ -c $(CFLAGS) $(call pr_abspath,$<)
435 else
436 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINCE)
437 $(CC) -Fo$@ -c $(CFLAGS) $<
438 else
439 ifdef NEED_ABSOLUTE_PATH
440 $(CC) -o $@ -c $(CFLAGS) $(call pr_abspath,$<)
441 else
442 $(CC) -o $@ -c $(CFLAGS) $<
443 endif
444 endif
445 endif
448 $(OBJDIR)/%.$(OBJ_SUFFIX): %.s
449 @$(MAKE_OBJDIR)
450 $(AS) -o $@ $(ASFLAGS) -c $<
452 %.i: %.c
453 $(CC) -C -E $(CFLAGS) $< > $*.i
455 %: %.pl
456 rm -f $@; cp $< $@; chmod +x $@
459 # HACK ALERT
461 # The only purpose of this rule is to pass Mozilla's Tinderbox depend
462 # builds (http://tinderbox.mozilla.org/showbuilds.cgi). Mozilla's
463 # Tinderbox builds NSPR continuously as part of the Mozilla client.
464 # Because NSPR's make depend is not implemented, whenever we change
465 # an NSPR header file, the depend build does not recompile the NSPR
466 # files that depend on the header.
468 # This rule makes all the objects depend on a dummy header file.
469 # Touch this dummy header file to force the depend build to recompile
470 # everything.
472 # This rule should be removed when make depend is implemented.
475 DUMMY_DEPEND_H = $(topsrcdir)/config/prdepend.h
477 $(filter $(OBJDIR)/%.$(OBJ_SUFFIX),$(OBJS)): $(OBJDIR)/%.$(OBJ_SUFFIX): $(DUMMY_DEPEND_H)
479 # END OF HACK
481 ################################################################################
482 # Special gmake rules.
483 ################################################################################
486 # Disallow parallel builds with MSVC < 8 since it can't open the PDB file in
487 # parallel.
489 ifeq (,$(filter-out 1200 1300 1310,$(MSC_VER)))
490 .NOTPARALLEL:
491 endif
494 # Re-define the list of default suffixes, so gmake won't have to churn through
495 # hundreds of built-in suffix rules for stuff we don't need.
497 .SUFFIXES:
498 .SUFFIXES: .a .$(OBJ_SUFFIX) .c .cpp .s .h .i .pl
501 # Fake targets. Always run these rules, even if a file/directory with that
502 # name already exists.
504 .PHONY: all alltags clean export install libs realclean release
507 # List the target pattern of an implicit rule as a dependency of the
508 # special target .PRECIOUS to preserve intermediate files made by
509 # implicit rules whose target patterns match that file's name.
510 # (See GNU Make documentation, Edition 0.51, May 1996, Sec. 10.4,
511 # p. 107.)
513 .PRECIOUS: $(OBJDIR)/%.$(OBJ_SUFFIX)