nspr: import 3.0 RC1 cutoff from CVS
[mozilla-nspr.git] / nsprpub / config / rules.mk
blobd944a0cff76170682f568de64d74fa8b2c89ec1e
1 #! gmake
2 #
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is the Netscape Portable Runtime (NSPR).
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1998-2000
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 ################################################################################
40 # We used to have a 4 pass build process. Now we do everything in one pass.
42 # export - Create generated headers and stubs. Publish public headers to
43 # dist/<arch>/include.
44 # Create libraries. Publish libraries to dist/<arch>/lib.
45 # Create programs.
47 # libs - obsolete. Now a synonym of "export".
49 # all - the default makefile target. Now a synonym of "export".
51 # install - Install headers, libraries, and programs on the system.
53 # Parameters to this makefile (set these before including):
55 # a)
56 # TARGETS -- the target to create
57 # (defaults to $LIBRARY $PROGRAM)
58 # b)
59 # DIRS -- subdirectories for make to recurse on
60 # (the 'all' rule builds $TARGETS $DIRS)
61 # c)
62 # CSRCS -- .c files to compile
63 # (used to define $OBJS)
64 # d)
65 # PROGRAM -- the target program name to create from $OBJS
66 # ($OBJDIR automatically prepended to it)
67 # e)
68 # LIBRARY -- the target library name to create from $OBJS
69 # ($OBJDIR automatically prepended to it)
71 ################################################################################
73 ifndef topsrcdir
74 topsrcdir=$(MOD_DEPTH)
75 endif
77 ifndef srcdir
78 srcdir=.
79 endif
81 ifndef NSPR_CONFIG_MK
82 include $(topsrcdir)/config/config.mk
83 endif
85 ifdef USE_AUTOCONF
86 ifdef CROSS_COMPILE
87 ifdef INTERNAL_TOOLS
88 CC=$(HOST_CC)
89 CCC=$(HOST_CXX)
90 CFLAGS=$(HOST_CFLAGS)
91 CXXFLAGS=$(HOST_CXXFLAGS)
92 LDFLAGS=$(HOST_LDFLAGS)
93 endif
94 endif
95 endif
98 # This makefile contains rules for building the following kinds of
99 # libraries:
100 # - LIBRARY: a static (archival) library
101 # - SHARED_LIBRARY: a shared (dynamic link) library
102 # - IMPORT_LIBRARY: an import library, used only on Windows and OS/2
104 # The names of these libraries can be generated by simply specifying
105 # LIBRARY_NAME and LIBRARY_VERSION.
108 ifdef LIBRARY_NAME
109 ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
112 # Win95, Win16, and OS/2 require library names conforming to the 8.3 rule.
113 # other platforms do not.
115 ifeq (,$(filter-out WIN95 OS2,$(OS_TARGET)))
116 LIBRARY = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
117 SHARED_LIBRARY = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
118 IMPORT_LIBRARY = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
119 SHARED_LIB_PDB = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).pdb
120 else
121 LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.$(LIB_SUFFIX)
122 SHARED_LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
123 IMPORT_LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
124 SHARED_LIB_PDB = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).pdb
125 endif
127 else
129 LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
130 ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
131 SHARED_LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_shr.a
132 else
133 ifdef MKSHLIB
134 SHARED_LIBRARY = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
135 endif
136 endif
138 endif
139 endif
141 ifndef TARGETS
142 ifeq (,$(filter-out WINNT OS2,$(OS_ARCH)))
143 TARGETS = $(LIBRARY) $(SHARED_LIBRARY) $(IMPORT_LIBRARY)
144 ifndef BUILD_OPT
145 ifdef MSC_VER
146 ifneq (,$(filter-out 1100 1200,$(MSC_VER)))
147 TARGETS += $(SHARED_LIB_PDB)
148 endif
149 endif
150 endif
151 else
152 TARGETS = $(LIBRARY) $(SHARED_LIBRARY)
153 endif
154 endif
157 # OBJS is the list of object files. It can be constructed by
158 # specifying CSRCS (list of C source files) and ASFILES (list
159 # of assembly language source files).
162 ifndef OBJS
163 OBJS = $(addprefix $(OBJDIR)/,$(CSRCS:.c=.$(OBJ_SUFFIX))) \
164 $(addprefix $(OBJDIR)/,$(ASFILES:.$(ASM_SUFFIX)=.$(OBJ_SUFFIX)))
165 endif
167 ifeq ($(MOZ_OS2_TOOLS),VACPP)
168 EXTRA_LIBS := $(patsubst -l%,$(DIST)/lib/%.$(LIB_SUFFIX),$(EXTRA_LIBS))
169 endif
171 ALL_TRASH = $(TARGETS) $(OBJS) $(RES) $(filter-out . .., $(OBJDIR)) LOGS TAGS $(GARBAGE) \
172 $(NOSUCHFILE) \
173 so_locations
175 ifeq ($(OS_ARCH),OpenVMS)
176 ALL_TRASH += $(wildcard *.c*_defines)
177 ifdef SHARED_LIBRARY
178 VMS_SYMVEC_FILE = $(SHARED_LIBRARY:.$(DLL_SUFFIX)=_symvec.opt)
179 VMS_SYMVEC_FILE_MODULE = $(srcdir)/$(LIBRARY_NAME)_symvec.opt
180 ALL_TRASH += $(VMS_SYMVEC_FILE)
181 endif
182 endif
184 ifndef RELEASE_LIBS_DEST
185 RELEASE_LIBS_DEST = $(RELEASE_LIB_DIR)
186 endif
188 ifdef DIRS
189 LOOP_OVER_DIRS = \
190 @for d in $(DIRS); do \
191 if test -d $$d; then \
192 set -e; \
193 echo "cd $$d; $(MAKE) $@"; \
194 $(MAKE) -C $$d $@; \
195 set +e; \
196 else \
197 echo "Skipping non-directory $$d..."; \
198 fi; \
199 done
200 endif
202 ################################################################################
204 all:: export
206 export::
207 +$(LOOP_OVER_DIRS)
209 libs:: export
211 clean::
212 rm -rf $(OBJS) $(RES) so_locations $(NOSUCHFILE) $(GARBAGE)
213 +$(LOOP_OVER_DIRS)
215 clobber::
216 rm -rf $(OBJS) $(RES) $(TARGETS) $(filter-out . ..,$(OBJDIR)) $(GARBAGE) so_locations $(NOSUCHFILE)
217 +$(LOOP_OVER_DIRS)
219 realclean clobber_all::
220 rm -rf $(wildcard *.OBJ *.OBJD) dist $(ALL_TRASH)
221 +$(LOOP_OVER_DIRS)
223 distclean::
224 rm -rf $(wildcard *.OBJ *.OBJD) dist $(ALL_TRASH) $(DIST_GARBAGE)
225 +$(LOOP_OVER_DIRS)
227 install:: $(RELEASE_BINS) $(RELEASE_HEADERS) $(RELEASE_LIBS)
228 ifdef RELEASE_BINS
229 $(NSINSTALL) -t -m 0755 $(RELEASE_BINS) $(DESTDIR)$(bindir)
230 endif
231 ifdef RELEASE_HEADERS
232 $(NSINSTALL) -t -m 0644 $(RELEASE_HEADERS) $(DESTDIR)$(includedir)/$(include_subdir)
233 endif
234 ifdef RELEASE_LIBS
235 $(NSINSTALL) -t -m 0755 $(RELEASE_LIBS) $(DESTDIR)$(libdir)/$(lib_subdir)
236 endif
237 +$(LOOP_OVER_DIRS)
239 release:: export
240 ifdef RELEASE_BINS
241 @echo "Copying executable programs and scripts to release directory"
242 @if test -z "$(BUILD_NUMBER)"; then \
243 echo "BUILD_NUMBER must be defined"; \
244 false; \
245 else \
246 true; \
248 @if test ! -d $(RELEASE_BIN_DIR); then \
249 rm -rf $(RELEASE_BIN_DIR); \
250 $(NSINSTALL) -D $(RELEASE_BIN_DIR);\
251 else \
252 true; \
254 cp $(RELEASE_BINS) $(RELEASE_BIN_DIR)
255 endif
256 ifdef RELEASE_LIBS
257 @echo "Copying libraries to release directory"
258 @if test -z "$(BUILD_NUMBER)"; then \
259 echo "BUILD_NUMBER must be defined"; \
260 false; \
261 else \
262 true; \
264 @if test ! -d $(RELEASE_LIBS_DEST); then \
265 rm -rf $(RELEASE_LIBS_DEST); \
266 $(NSINSTALL) -D $(RELEASE_LIBS_DEST);\
267 else \
268 true; \
270 cp $(RELEASE_LIBS) $(RELEASE_LIBS_DEST)
271 endif
272 ifdef RELEASE_HEADERS
273 @echo "Copying header files to release directory"
274 @if test -z "$(BUILD_NUMBER)"; then \
275 echo "BUILD_NUMBER must be defined"; \
276 false; \
277 else \
278 true; \
280 @if test ! -d $(RELEASE_HEADERS_DEST); then \
281 rm -rf $(RELEASE_HEADERS_DEST); \
282 $(NSINSTALL) -D $(RELEASE_HEADERS_DEST);\
283 else \
284 true; \
286 cp $(RELEASE_HEADERS) $(RELEASE_HEADERS_DEST)
287 endif
288 +$(LOOP_OVER_DIRS)
290 alltags:
291 rm -f TAGS tags
292 find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs etags -a
293 find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs ctags -a
295 $(NFSPWD):
296 cd $(@D); $(MAKE) $(@F)
298 $(PROGRAM): $(OBJS)
299 @$(MAKE_OBJDIR)
300 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
301 $(CC) $(OBJS) -Fe$@ -link $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
302 ifdef MT
303 @if test -f $@.manifest; then \
304 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;1; \
305 rm -f $@.manifest; \
307 endif # MSVC with manifest tool
308 else # WINNT && !GCC
309 ifeq ($(MOZ_OS2_TOOLS),VACPP)
310 $(CC) $(OBJS) -Fe$@ $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
311 else
312 $(CC) -o $@ $(CFLAGS) $(OBJS) $(LDFLAGS)
313 endif
314 endif # WINNT && !GCC
315 ifdef ENABLE_STRIP
316 $(STRIP) $@
317 endif
319 $(LIBRARY): $(OBJS)
320 @$(MAKE_OBJDIR)
321 rm -f $@
322 ifeq ($(MOZ_OS2_TOOLS),VACPP)
323 $(AR) $(subst /,\\,$(OBJS)) $(AR_FLAGS)
324 else
325 $(AR) $(AR_FLAGS) $(OBJS) $(AR_EXTRA_ARGS)
326 endif
327 $(RANLIB) $@
329 ifeq ($(OS_TARGET), OS2)
330 $(IMPORT_LIBRARY): $(MAPFILE)
331 rm -f $@
332 $(IMPLIB) $@ $(MAPFILE)
333 endif
335 $(SHARED_LIBRARY): $(OBJS) $(RES) $(MAPFILE)
336 @$(MAKE_OBJDIR)
337 rm -f $@
338 ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
339 echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms
340 nm -B -C -g $(OBJS) \
341 | awk '/ [T,D] / {print $$3}' \
342 | sed -e 's/^\.//' \
343 | sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms
344 $(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \
345 -bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS)
346 else # AIX 4.1
347 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
348 $(LINK_DLL) -MAP $(DLLBASE) $(DLL_LIBS) $(EXTRA_LIBS) $(OBJS) $(RES)
349 ifdef MT
350 @if test -f $@.manifest; then \
351 $(MT) -NOLOGO -MANIFEST $@.manifest -OUTPUTRESOURCE:$@\;2; \
352 rm -f $@.manifest; \
354 endif # MSVC with manifest tool
355 else # WINNT && !GCC
356 ifeq ($(MOZ_OS2_TOOLS),VACPP)
357 $(LINK_DLL) $(DLLBASE) $(OBJS) $(OS_LIBS) $(EXTRA_LIBS) $(MAPFILE)
358 else # !os2 vacpp
359 ifeq ($(OS_TARGET), OpenVMS)
360 @if test ! -f $(VMS_SYMVEC_FILE); then \
361 if test -f $(VMS_SYMVEC_FILE_MODULE); then \
362 echo Creating component options file $(VMS_SYMVEC_FILE); \
363 cp $(VMS_SYMVEC_FILE_MODULE) $(VMS_SYMVEC_FILE); \
364 fi; \
366 endif # OpenVMS
367 $(MKSHLIB) $(OBJS) $(RES) $(EXTRA_LIBS)
368 endif # OS2 vacpp
369 endif # WINNT && !GCC
370 endif # AIX 4.1
371 ifdef ENABLE_STRIP
372 $(STRIP) $@
373 endif
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
393 ifeq ($(OS_ARCH),OS2)
394 echo LIBRARY $(LIBRARY_NAME)$(LIBRARY_VERSION) INITINSTANCE TERMINSTANCE > $@
395 echo PROTMODE >> $@
396 echo CODE LOADONCALL MOVEABLE DISCARDABLE >> $@
397 echo DATA PRELOAD MOVEABLE MULTIPLE NONSHARED >> $@
398 echo EXPORTS >> $@
399 ifeq ($(MOZ_OS2_TOOLS),VACPP)
400 grep -v ';+' $< | grep -v ';-' | \
401 sed -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,,' >> $@
402 else
403 grep -v ';+' $< | grep -v ';-' | \
404 sed -e 's; DATA ;;' -e 's,;;,,' -e 's,;.*,,' -e 's,\([\t ]*\),\1_,' | \
405 awk 'BEGIN {ord=1;} { print($$0 " @" ord " RESIDENTNAME"); ord++;}' >> $@
406 $(ADD_TO_DEF_FILE)
407 endif
408 endif
411 # Translate source filenames to absolute paths. This is required for
412 # debuggers under Windows and OS/2 to find source files automatically.
415 ifeq (,$(filter-out AIX OS2,$(OS_ARCH)))
416 NEED_ABSOLUTE_PATH = 1
417 endif
419 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
420 NEED_ABSOLUTE_PATH = 1
421 endif
423 ifdef NEED_ABSOLUTE_PATH
424 PWD := $(shell pwd)
425 abspath = $(if $(findstring :,$(1)),$(1),$(if $(filter /%,$(1)),$(1),$(PWD)/$(1)))
426 endif
428 $(OBJDIR)/%.$(OBJ_SUFFIX): %.cpp
429 @$(MAKE_OBJDIR)
430 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
431 $(CCC) -Fo$@ -c $(CCCFLAGS) $(call abspath,$<)
432 else
433 ifeq ($(MOZ_OS2_TOOLS),VACPP)
434 $(CCC) -Fo$@ -c $(CCCFLAGS) $(call abspath,$<)
435 else
436 ifdef NEED_ABSOLUTE_PATH
437 $(CCC) -o $@ -c $(CCCFLAGS) $(call abspath,$<)
438 else
439 $(CCC) -o $@ -c $(CCCFLAGS) $<
440 endif
441 endif
442 endif
444 WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
445 WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
446 WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
447 $(OBJDIR)/%.$(OBJ_SUFFIX): %.c
448 @$(MAKE_OBJDIR)
449 ifeq ($(NS_USE_GCC)_$(OS_ARCH),_WINNT)
450 $(CC) -Fo$@ -c $(CFLAGS) $(call abspath,$<)
451 else
452 ifeq ($(MOZ_OS2_TOOLS),VACPP)
453 $(CC) -Fo$@ -c $(CFLAGS) $(call abspath,$<)
454 else
455 ifdef NEED_ABSOLUTE_PATH
456 $(CC) -o $@ -c $(CFLAGS) $(call abspath,$<)
457 else
458 $(CC) -o $@ -c $(CFLAGS) $<
459 endif
460 endif
461 endif
464 $(OBJDIR)/%.$(OBJ_SUFFIX): %.s
465 @$(MAKE_OBJDIR)
466 $(AS) -o $@ $(ASFLAGS) -c $<
468 ifeq ($(MOZ_OS2_TOOLS),VACPP)
469 $(OBJDIR)/%.$(OBJ_SUFFIX): %.asm
470 @$(MAKE_OBJDIR)
471 $(AS) -Fdo:./$(OBJDIR) $(ASFLAGS) $<
472 endif
474 %.i: %.c
475 $(CC) -C -E $(CFLAGS) $< > $*.i
477 %: %.pl
478 rm -f $@; cp $< $@; chmod +x $@
481 # HACK ALERT
483 # The only purpose of this rule is to pass Mozilla's Tinderbox depend
484 # builds (http://tinderbox.mozilla.org/showbuilds.cgi). Mozilla's
485 # Tinderbox builds NSPR continuously as part of the Mozilla client.
486 # Because NSPR's make depend is not implemented, whenever we change
487 # an NSPR header file, the depend build does not recompile the NSPR
488 # files that depend on the header.
490 # This rule makes all the objects depend on a dummy header file.
491 # Touch this dummy header file to force the depend build to recompile
492 # everything.
494 # This rule should be removed when make depend is implemented.
497 DUMMY_DEPEND_H = $(topsrcdir)/config/prdepend.h
499 $(filter $(OBJDIR)/%.$(OBJ_SUFFIX),$(OBJS)): $(OBJDIR)/%.$(OBJ_SUFFIX): $(DUMMY_DEPEND_H)
501 # END OF HACK
503 ################################################################################
504 # Special gmake rules.
505 ################################################################################
508 # Re-define the list of default suffixes, so gmake won't have to churn through
509 # hundreds of built-in suffix rules for stuff we don't need.
511 .SUFFIXES:
512 .SUFFIXES: .a .$(OBJ_SUFFIX) .c .cpp .s .h .i .pl
515 # Fake targets. Always run these rules, even if a file/directory with that
516 # name already exists.
518 .PHONY: all alltags clean export install libs realclean release
521 # List the target pattern of an implicit rule as a dependency of the
522 # special target .PRECIOUS to preserve intermediate files made by
523 # implicit rules whose target patterns match that file's name.
524 # (See GNU Make documentation, Edition 0.51, May 1996, Sec. 10.4,
525 # p. 107.)
527 .PRECIOUS: $(OBJDIR)/%.$(OBJ_SUFFIX)