home *** CD-ROM | disk | FTP | other *** search
/ Tools / WinSN5.0Ver.iso / NETSCAP.50 / WIN1998.ZIP / ns / nsprpub / config / rules.mk < prev    next >
Encoding:
Text File  |  1998-04-08  |  9.8 KB  |  368 lines

  1. #! gmake
  2. #
  3. # The contents of this file are subject to the Netscape Public License
  4. # Version 1.0 (the "NPL"); you may not use this file except in
  5. # compliance with the NPL.  You may obtain a copy of the NPL at
  6. # http://www.mozilla.org/NPL/
  7. # Software distributed under the NPL is distributed on an "AS IS" basis,
  8. # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
  9. # for the specific language governing rights and limitations under the
  10. # NPL.
  11. # The Initial Developer of this code under the NPL is Netscape
  12. # Communications Corporation.  Portions created by Netscape are
  13. # Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  14. # Reserved.
  15. #
  16.  
  17. ################################################################################
  18. # We have a 4 pass build process:
  19. #
  20. # Pass 1. export - Create generated headers and stubs. Publish public headers to
  21. #        dist/<arch>/include.
  22. #
  23. # Pass 2. libs - Create libraries. Publish libraries to dist/<arch>/lib.
  24. #
  25. # Pass 3. all - Create programs. 
  26. #
  27. # Pass 4. install - Publish programs to dist/<arch>/bin.
  28. #
  29. # Parameters to this makefile (set these before including):
  30. #
  31. # a)
  32. #    TARGETS    -- the target to create 
  33. #            (defaults to $LIBRARY $PROGRAM)
  34. # b)
  35. #    DIRS    -- subdirectories for make to recurse on
  36. #            (the 'all' rule builds $TARGETS $DIRS)
  37. # c)
  38. #    CSRCS   -- .c files to compile
  39. #            (used to define $OBJS)
  40. # d)
  41. #    PROGRAM    -- the target program name to create from $OBJS
  42. #            ($OBJDIR automatically prepended to it)
  43. # e)
  44. #    LIBRARY    -- the target library name to create from $OBJS
  45. #            ($OBJDIR automatically prepended to it)
  46. #
  47. ################################################################################
  48.  
  49. ifndef NSPR_CONFIG_MK
  50. include $(MOD_DEPTH)/config/config.mk
  51. endif
  52.  
  53. #
  54. # This makefile contains rules for building the following kinds of
  55. # libraries:
  56. # - LIBRARY: a static (archival) library
  57. # - SHARED_LIBRARY: a shared (dynamic link) library
  58. # - IMPORT_LIBRARY: an import library, used only on Windows and OS/2
  59. # - PURE_LIBRARY: a library for Purify
  60. #
  61. # The names of these libraries can be generated by simply specifying
  62. # LIBRARY_NAME and LIBRARY_VERSION.
  63. #
  64.  
  65. ifdef LIBRARY_NAME
  66. ifeq ($(OS_ARCH), WINNT)
  67.  
  68. #
  69. # Win16 and OS/2 require library names conforming to the 8.3 rule.
  70. # other platforms do not.
  71. #
  72. ifeq (,$(filter-out WIN16 OS2,$(OS_TARGET)))
  73. LIBRARY        = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.lib
  74. SHARED_LIBRARY    = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).dll
  75. IMPORT_LIBRARY    = $(OBJDIR)/$(LIBRARY_NAME)$(LIBRARY_VERSION).lib
  76. else
  77. LIBRARY        = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_s.lib
  78. SHARED_LIBRARY    = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).dll
  79. IMPORT_LIBRARY    = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).lib
  80. endif
  81.  
  82. else
  83.  
  84. LIBRARY        = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
  85. ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
  86. SHARED_LIBRARY    = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION)_shr.a
  87. else
  88. SHARED_LIBRARY    = $(OBJDIR)/lib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
  89. endif
  90. ifdef HAVE_PURIFY
  91. ifdef DSO_BACKEND
  92. PURE_LIBRARY    = $(OBJDIR)/purelib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(DLL_SUFFIX)
  93. else
  94. PURE_LIBRARY    = $(OBJDIR)/purelib$(LIBRARY_NAME)$(LIBRARY_VERSION).$(LIB_SUFFIX)
  95. endif
  96. endif
  97.  
  98. endif
  99. endif
  100.  
  101. ifndef TARGETS
  102. ifeq ($(OS_ARCH), WINNT)
  103. TARGETS        = $(LIBRARY) $(SHARED_LIBRARY) $(IMPORT_LIBRARY)
  104. else
  105. TARGETS        = $(LIBRARY) $(SHARED_LIBRARY)
  106. ifdef HAVE_PURIFY
  107. TARGETS        += $(PURE_LIBRARY)
  108. endif
  109. endif
  110. endif
  111.  
  112. #
  113. # OBJS is the list of object files.  It can be constructed by
  114. # specifying CSRCS (list of C source files) and ASFILES (list
  115. # of assembly language source files).
  116. #
  117.  
  118. ifndef OBJS
  119. OBJS        = $(addprefix $(OBJDIR)/,$(CSRCS:.c=.o)) \
  120.           $(addprefix $(OBJDIR)/,$(ASFILES:.s=.o))
  121. endif
  122.  
  123. ifeq ($(OS_TARGET), WIN16)
  124.     comma := ,
  125.     empty :=
  126.     space := $(empty) $(empty)
  127.     W16OBJS = $(subst $(space),$(comma)$(space),$(strip $(OBJS)))
  128.     W16TEMP =$(OS_LIBS) $(EXTRA_LIBS)
  129.     ifeq ($(strip $(W16TEMP)),)
  130.         W16LIBS =
  131.     else
  132.         W16LIBS = library $(subst $(space),$(comma)$(space),$(strip $(W16TEMP)))
  133.     endif
  134.     W16DEF = $(notdir $(basename $(SHARED_LIBRARY))).DEF
  135. endif
  136.  
  137. ifeq ($(OS_ARCH), WINNT)
  138. ifneq ($(OS_TARGET), WIN16)
  139. ifneq ($(OS_TARGET), OS2)
  140. OBJS += $(RES)
  141. endif
  142. endif
  143. endif
  144.  
  145. ALL_TRASH        = $(TARGETS) $(OBJS) $(OBJDIR) LOGS TAGS $(GARBAGE) \
  146.               $(NOSUCHFILE) \
  147.               so_locations
  148.  
  149. ifdef DIRS
  150. LOOP_OVER_DIRS        =                    \
  151.     @for d in $(DIRS); do                    \
  152.         if test -d $$d; then                \
  153.             set -e;                    \
  154.             echo "cd $$d; $(MAKE) $@";        \
  155.             $(MAKE) -C $$d $@;            \
  156.             set +e;                    \
  157.         else                        \
  158.             echo "Skipping non-directory $$d...";    \
  159.         fi;                        \
  160.     done
  161. endif
  162.  
  163. ################################################################################
  164.  
  165. all:: export libs install
  166.  
  167. export::
  168.     +$(LOOP_OVER_DIRS)
  169.  
  170. libs::
  171.     +$(LOOP_OVER_DIRS)
  172.  
  173. install::
  174.     +$(LOOP_OVER_DIRS)
  175.  
  176. clean::
  177.     rm -rf $(OBJS) so_locations $(NOSUCHFILE)
  178.     +$(LOOP_OVER_DIRS)
  179.  
  180. clobber::
  181.     rm -f $(OBJS) $(TARGETS) $(GARBAGE) so_locations $(NOSUCHFILE)
  182.     +$(LOOP_OVER_DIRS)
  183.  
  184. realclean clobber_all::
  185.     rm -rf $(wildcard *.OBJ *.OBJD) dist $(ALL_TRASH)
  186.     +$(LOOP_OVER_DIRS)
  187.  
  188. release:: export
  189. ifdef RELEASE_LIBS
  190.     @echo "Copying libraries to release directory"
  191.     @if test -z "$(BUILD_NUMBER)"; then \
  192.         echo "BUILD_NUMBER must be defined"; \
  193.         false; \
  194.     fi
  195.     @if test ! -d $(RELEASE_LIB_DIR); then \
  196.         rm -f $(RELEASE_LIB_DIR); \
  197.         $(NSINSTALL) -D $(RELEASE_LIB_DIR);\
  198.     fi
  199.     cp $(RELEASE_LIBS) $(RELEASE_LIB_DIR)
  200. endif
  201. ifdef RELEASE_HEADERS
  202.     @echo "Copying header files to release directory"
  203.     @if test -z "$(BUILD_NUMBER)"; then \
  204.         echo "BUILD_NUMBER must be defined"; \
  205.         false; \
  206.     fi
  207.     @if test ! -d $(RELEASE_HEADERS_DEST); then \
  208.         rm -rf $(RELEASE_HEADERS_DEST); \
  209.         $(NSINSTALL) -D $(RELEASE_HEADERS_DEST);\
  210.     fi
  211.     cp $(RELEASE_HEADERS) $(RELEASE_HEADERS_DEST)
  212. endif
  213.     +$(LOOP_OVER_DIRS)
  214.  
  215. alltags:
  216.     rm -f TAGS tags
  217.     find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs etags -a
  218.     find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs ctags -a
  219.  
  220. $(NFSPWD):
  221.     cd $(@D); $(MAKE) $(@F)
  222.  
  223. $(PROGRAM): $(OBJS)
  224.     @$(MAKE_OBJDIR)
  225. ifeq ($(OS_ARCH),WINNT)
  226.     $(CC) $(OBJS) -Fe$@ -link $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
  227. else
  228.     $(CC) -o $@ $(CFLAGS) $(OBJS) $(LDFLAGS)
  229. endif
  230.  
  231. $(LIBRARY): $(OBJS)
  232.     @$(MAKE_OBJDIR)
  233.     rm -f $@
  234.     $(AR) $(OBJS) $(AR_EXTRA_ARGS)
  235.     $(RANLIB) $@
  236.  
  237. ifeq ($(OS_TARGET), WIN16)
  238. $(IMPORT_LIBRARY): $(SHARED_LIBRARY)
  239.     wlib $(OS_LIB_FLAGS) $@ +$(SHARED_LIBRARY)
  240. endif
  241.  
  242. ifeq ($(OS_TARGET), OS2)
  243. $(IMPORT_LIBRARY): $(SHARED_LIBRARY)
  244.     $(IMPLIB) $@ $(SHARED_LIBRARY).def
  245. endif
  246.     
  247. $(SHARED_LIBRARY): $(OBJS)
  248.     @$(MAKE_OBJDIR)
  249.     rm -f $@
  250. ifeq ($(OS_ARCH)$(OS_RELEASE), AIX4.1)
  251.     echo "#!" > $(OBJDIR)/lib$(LIBRARY_NAME)_syms
  252.     nm -B -C -g $(OBJS) \
  253.         | awk '/ [T,D] / {print $$3}' \
  254.         | sed -e 's/^\.//' \
  255.         | sort -u >> $(OBJDIR)/lib$(LIBRARY_NAME)_syms
  256.     $(LD) $(XCFLAGS) -o $@ $(OBJS) -bE:$(OBJDIR)/lib$(LIBRARY_NAME)_syms \
  257.         -bM:SRE -bnoentry $(OS_LIBS) $(EXTRA_LIBS)
  258.  
  259. else
  260. ifeq ($(OS_ARCH), WINNT)
  261. ifeq ($(OS_TARGET), WIN16)
  262.     echo system windows dll initinstance >w16link
  263.     echo option map >>w16link
  264.     echo option oneautodata >>w16link
  265.     echo option heapsize=32K >>w16link
  266.     echo option $(OS_DLL_OPTION) >>w16link
  267.     echo debug $(DEBUGTYPE) all >>w16link
  268.     echo name $@ >>w16link
  269.     echo file >>w16link
  270.     echo $(W16OBJS) >>w16link
  271.     echo $(W16IMPORTS) >>w16link
  272.     echo $(W16LIBS) >>w16link
  273.     echo $(W16_EXPORTS) >>w16link
  274.     echo libfile libentry >>w16link
  275.     $(LINK) @w16link.
  276.     rm w16link
  277. else
  278. ifeq ($(OS_TARGET), OS2)
  279. # append ( >> ) doesn't seem to be working under OS/2 gmake. Run through OS/2 shell instead.    
  280.     @cmd /C "echo LIBRARY $(notdir $(basename $(SHARED_LIBRARY))) INITINSTANCE TERMINSTANCE >$@.def"
  281.     @cmd /C "echo PROTMODE >>$@.def"
  282.     @cmd /C "echo CODE    LOADONCALL MOVEABLE DISCARDABLE >>$@.def"
  283.     @cmd /C "echo DATA    PRELOAD MOVEABLE MULTIPLE NONSHARED >>$@.def"    
  284.     @cmd /C "echo EXPORTS >>$@.def"
  285.     @cmd /C "$(FILTER) -B -P $(LIBRARY) >> $@.def"
  286.     $(LINK_DLL) -MAP $(DLLBASE) $(OS_LIBS) $(EXTRA_LIBS) $(OBJS) $@.def
  287. else
  288.     $(LINK_DLL) -MAP $(DLLBASE) $(OS_LIBS) $(EXTRA_LIBS) $(OBJS)
  289. endif
  290. endif
  291. else
  292.     $(MKSHLIB) -o $@ $(OBJS) $(LD_LIBS) $(EXTRA_LIBS) $(OS_LIBS)
  293. endif
  294. endif
  295.  
  296. $(PURE_LIBRARY):
  297.     rm -f $@
  298. ifneq ($(OS_ARCH), WINNT)
  299.     $(AR) $(OBJS)
  300. endif
  301.     $(RANLIB) $@
  302.  
  303. ifeq ($(OS_ARCH), WINNT)
  304. $(RES): $(RESNAME)
  305.     @$(MAKE_OBJDIR)
  306. ifeq ($(OS_TARGET),OS2)
  307.     $(RC) -DOS2 -r $(RESNAME) $(RES)
  308. else
  309.     $(RC) -Fo$(RES) $(RESNAME)
  310. endif
  311.     @echo $(RES) finished
  312. endif
  313.  
  314. $(OBJDIR)/%.o: %.cpp
  315.     @$(MAKE_OBJDIR)
  316. ifeq ($(OS_ARCH), WINNT)
  317.     $(CCC) -Fo$@ -c $(CFLAGS) $<
  318. else
  319.     $(CCC) -o $@ -c $(CFLAGS) $< 
  320. endif
  321.  
  322. WCCFLAGS1 = $(subst /,\\,$(CFLAGS))
  323. WCCFLAGS2 = $(subst -I,-i=,$(WCCFLAGS1))
  324. WCCFLAGS3 = $(subst -D,-d,$(WCCFLAGS2))
  325. $(OBJDIR)/%.o: %.c
  326.     @$(MAKE_OBJDIR)
  327. ifeq ($(OS_ARCH), WINNT)
  328. ifeq ($(OS_TARGET), WIN16)
  329. #    $(MOD_DEPTH)/config/w16opt $(WCCFLAGS3)
  330.     echo $(WCCFLAGS3) >w16wccf
  331.     $(CC) -zq -fo$(OBJDIR)\\$*.o  @w16wccf $*.c
  332.     rm w16wccf
  333. else
  334.     $(CC) -Fo$@ -c $(CFLAGS) $*.c
  335. endif
  336. else
  337.     $(CC) -o $@ -c $(CFLAGS) $*.c
  338. endif
  339.  
  340. $(OBJDIR)/%.o: %.s
  341.     @$(MAKE_OBJDIR)
  342.     $(AS) -o $@ $(ASFLAGS) -c $*.s
  343.  
  344. %.i: %.c
  345.     $(CC) -C -E $(CFLAGS) $< > $*.i
  346.  
  347. %: %.pl
  348.     rm -f $@; cp $*.pl $@; chmod +x $@
  349.  
  350. ################################################################################
  351. # Special gmake rules.
  352. ################################################################################
  353.  
  354. #
  355. # Re-define the list of default suffixes, so gmake won't have to churn through
  356. # hundreds of built-in suffix rules for stuff we don't need.
  357. #
  358. .SUFFIXES:
  359. .SUFFIXES: .a .o .c .cpp .s .h .i .pl
  360.  
  361. #
  362. # Fake targets.  Always run these rules, even if a file/directory with that
  363. # name already exists.
  364. #
  365. .PHONY: all alltags clean export install libs realclean release
  366.