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

  1. #
  2. # The contents of this file are subject to the Netscape Public License
  3. # Version 1.0 (the "NPL"); you may not use this file except in
  4. # compliance with the NPL.  You may obtain a copy of the NPL at
  5. # http://www.mozilla.org/NPL/
  6. #
  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. #
  12. # The Initial Developer of this code under the NPL is Netscape
  13. # Communications Corporation.  Portions created by Netscape are
  14. # Copyright (C) 1998 Netscape Communications Corporation.  All Rights
  15. # Reserved.
  16. #
  17.  
  18. ################################################################################
  19. #
  20. # We now use a 3-pass build system.  This needs to be re-thought....
  21. #
  22. # Pass 1. export  - Create generated headers and stubs.  Publish public headers
  23. #                   to dist/<arch>/include.
  24. #
  25. # Pass 2. libs    - Create libraries.  Publish libraries to dist/<arch>/lib.
  26. #
  27. # Pass 3. install - Create programs.  Publish them to dist/<arch>/bin.
  28. #
  29. # 'gmake' will build each of these properly, but 'gmake -jN' will break (need
  30. # to do each pass explicitly when using -j).
  31. #
  32. # Parameters to this makefile (set these before including):
  33. #
  34. # a)
  35. #    TARGETS    -- the target to create
  36. #            (defaults to $LIBRARY $PROGRAM)
  37. # b)
  38. #    DIRS    -- subdirectories for make to recurse on
  39. #            (the 'all' rule builds $TARGETS $DIRS)
  40. # c)
  41. #    CSRCS, CPPSRCS -- .c and .cpp files to compile
  42. #            (used to define $OBJS)
  43. # d)
  44. #    PROGRAM    -- the target program name to create from $OBJS
  45. #            ($OBJDIR automatically prepended to it)
  46. # e)
  47. #    LIBRARY_NAME    -- the target library name to create from $OBJS
  48. #            ($OBJDIR automatically prepended to it)
  49. # f)
  50. #    JSRCS    -- java source files to compile into class files
  51. #            (if you don't specify this it will default to *.java)
  52. # g)
  53. #    PACKAGE    -- the package to put the .class files into
  54. #            (e.g. netscape/applet)
  55. # h)
  56. #    JMC_EXPORT -- java files to be exported for use by JMC_GEN
  57. #            (this is a list of Class names)
  58. # i)
  59. #    JRI_GEN    -- files to run through javah to generate headers and stubs
  60. #            (output goes into the _jri sub-dir)
  61. # j)
  62. #    JMC_GEN    -- files to run through jmc to generate headers and stubs
  63. #            (output goes into the _jmc sub-dir)
  64. #
  65. ################################################################################
  66.  
  67. #
  68. # Common rules used by lots of makefiles...
  69. #
  70. ifndef NS_CONFIG_MK
  71. include $(DEPTH)/config/config.mk
  72. endif
  73.  
  74. ifdef PROGRAM
  75. PROGRAM            := $(addprefix $(OBJDIR)/, $(PROGRAM))
  76. endif
  77.  
  78. ifndef LIBRARY
  79. ifdef LIBRARY_NAME
  80. LIBRARY            := lib$(LIBRARY_NAME).$(LIB_SUFFIX)
  81. endif
  82. endif
  83.  
  84. ifdef LIBRARY
  85. ifeq ($(OS_ARCH),OS2)
  86. ifndef DEF_FILE
  87. DEF_FILE        := $(LIBRARY:.lib=.def)
  88. endif
  89. endif
  90. LIBRARY            := $(addprefix $(OBJDIR)/, $(LIBRARY))
  91. ifdef MKSHLIB
  92. ifeq ($(OS_ARCH),OS2)
  93. SHARED_LIBRARY        := $(LIBRARY:.lib=.dll)
  94. MAPS            := $(LIBRARY:.lib=.map)
  95. else
  96. ifeq ($(OS_ARCH),WINNT)
  97. SHARED_LIBRARY        := $(LIBRARY:.lib=.dll)
  98. else
  99. ifeq ($(OS_ARCH),HP-UX)
  100. SHARED_LIBRARY        := $(LIBRARY:.a=.sl)
  101. else
  102. ifeq ($(OS_ARCH),FreeBSD)
  103. SHARED_LIBRARY        := $(LIBRARY:.a=.so.1.0)
  104. else
  105. ifeq ($(OS_ARCH)$(OS_RELEASE),SunOS4.1)
  106. SHARED_LIBRARY        := $(LIBRARY:.a=.so.1.0)
  107. else
  108. ifeq ($(OS_ARCH)$(OS_RELEASE),AIX4.1)
  109. SHARED_LIBRARY        := $(LIBRARY:.a=)_shr.a
  110. else
  111. SHARED_LIBRARY        := $(LIBRARY:.a=.so)
  112. endif
  113. endif
  114. endif
  115. endif
  116. endif
  117. endif
  118. endif
  119. endif
  120.  
  121. ifndef TARGETS
  122. TARGETS            = $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM)
  123. endif
  124.  
  125. ifndef OBJS
  126. OBJS            = $(JRI_STUB_CFILES) $(addsuffix .o, $(JMC_GEN)) $(CSRCS:.c=.o) $(CPPSRCS:.cpp=.o) $(ASFILES:.s=.o)
  127. endif
  128.  
  129. OBJS            := $(addprefix $(OBJDIR)/, $(OBJS))
  130.  
  131. ifdef REQUIRES
  132. MODULE_PREINCLUDES    = $(addprefix -I$(XPDIST)/public/, $(REQUIRES))
  133. endif
  134.  
  135. ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
  136. ifdef DLL
  137. DLL            := $(addprefix $(OBJDIR)/, $(DLL))
  138. ifeq ($(OS_ARCH),WINNT)
  139. LIB            := $(addprefix $(OBJDIR)/, $(LIB))
  140. endif
  141. endif
  142. MAKE_OBJDIR        = mkdir $(OBJDIR)
  143. else
  144. define MAKE_OBJDIR
  145. if test ! -d $(@D); then rm -rf $(@D); $(NSINSTALL) -D $(@D); fi
  146. endef
  147. endif
  148.  
  149. ifndef OS2_IMPLIB
  150. LIBOBJS            := $(addprefix \", $(OBJS))
  151. LIBOBJS            := $(addsuffix \", $(LIBOBJS))
  152. endif
  153.  
  154. ifndef PACKAGE
  155. PACKAGE            = .
  156. endif
  157.  
  158. ifdef MOZ_JAVA
  159. ALL_TRASH        = $(TARGETS) $(OBJS) $(OBJDIR) LOGS TAGS $(GARBAGE) \
  160.               $(NOSUCHFILE) $(JDK_HEADER_CFILES) $(JDK_STUB_CFILES) \
  161.               $(JRI_HEADER_CFILES) $(JRI_STUB_CFILES) $(JMC_STUBS) \
  162.               $(JMC_HEADERS) $(JMC_EXPORT_FILES) so_locations \
  163.               _gen _jmc _jri _stubs $(wildcard gts_tmp_*) \
  164.               $(wildcard $(JAVA_DESTPATH)/$(PACKAGE)/*.class)
  165. else
  166. ALL_TRASH        = $(TARGETS) $(OBJS) $(OBJDIR) LOGS TAGS $(GARBAGE) \
  167.               $(NOSUCHFILE) \
  168.               $(JMC_STUBS) \
  169.               so_locations \
  170.               _gen _stubs $(wildcard gts_tmp_*)
  171. endif
  172.  
  173. ifdef MOZ_JAVA
  174. ifdef JDIRS
  175. ALL_TRASH        += $(addprefix $(JAVA_DESTPATH)/,$(JDIRS))
  176. endif
  177. endif
  178.  
  179. ifdef MOZ_JAVA
  180. JMC_SUBDIR              = _jmc
  181. else
  182. JMC_SUBDIR              = $(LOCAL_JMC_SUBDIR)
  183. endif
  184.  
  185. ifdef NSBUILDROOT
  186. JDK_GEN_DIR        = $(XPDIST)/_gen
  187. JMC_GEN_DIR        = $(XPDIST)/$(JMC_SUBDIR)
  188. JRI_GEN_DIR        = $(XPDIST)/_jri
  189. JDK_STUB_DIR        = $(XPDIST)/_stubs
  190. else
  191. JDK_GEN_DIR        = _gen
  192. JMC_GEN_DIR        = $(JMC_SUBDIR)
  193. JRI_GEN_DIR        = _jri
  194. JDK_STUB_DIR        = _stubs
  195. endif
  196.  
  197. #
  198. # If this is an "official" build, try to build everything.
  199. # I.e., don't exit on errors.
  200. #
  201. ifdef BUILD_OFFICIAL
  202. EXIT_ON_ERROR        = +e
  203. CLICK_STOPWATCH        = date
  204. else
  205. EXIT_ON_ERROR        = -e
  206. CLICK_STOPWATCH        = true
  207. endif
  208.  
  209. ifdef DIRS
  210. LOOP_OVER_DIRS        =                    \
  211.     @for d in $(DIRS); do                    \
  212.         if test -d $$d; then                \
  213.             set $(EXIT_ON_ERROR);            \
  214.             echo "cd $$d; $(MAKE) $@";        \
  215.             oldDir=`pwd`;                \
  216.             cd $$d; $(MAKE) $@; cd $$oldDir;    \
  217.             set +e;                    \
  218.         else                        \
  219.             echo "Skipping non-directory $$d...";    \
  220.         fi;                        \
  221.         $(CLICK_STOPWATCH);                \
  222.     done
  223. endif
  224.  
  225. ################################################################################
  226.  
  227. all:: export libs install
  228.  
  229. #
  230. # Maybe this should be done in config/Makefile so it only happens once...?
  231. #
  232. TARGETS            += tweak_nspr
  233.  
  234. #
  235. # Since the NSPR folks won't help, we'll fix things the sneaky way.
  236. #
  237. tweak_nspr:
  238.     @(cd $(DEPTH)/nsprpub/config; \
  239.         if test -f UNIX.mk.orig; then rm -f UNIX.mk; mv UNIX.mk.orig UNIX.mk; fi; \
  240.         mv UNIX.mk UNIX.mk.orig; \
  241.         awk '/^OBJDIR_NAME[     ]*=/ { \
  242.             printf("OBJDIR_NAME\t= %s%s%s%s%s%s.OBJ\n","$(OS_CONFIG)","$(OS_VERSION)","$(PROCESSOR_ARCHITECTURE)","$(COMPILER)","$(IMPL_STRATEGY)","$(OBJDIR_TAG)"); next} {print}' UNIX.mk.orig > UNIX.mk)
  243.  
  244. ifdef ALL_PLATFORMS
  245. all_platforms:: $(NFSPWD)
  246.     @d=`$(NFSPWD)`;                            \
  247.     if test ! -d LOGS; then rm -rf LOGS; mkdir LOGS; fi;        \
  248.     for h in $(PLATFORM_HOSTS); do                    \
  249.         echo "On $$h: $(MAKE) $(ALL_PLATFORMS) >& LOGS/$$h.log";\
  250.         rsh $$h -n "(chdir $$d;                    \
  251.                  $(MAKE) $(ALL_PLATFORMS) >& LOGS/$$h.log;    \
  252.                  echo DONE) &" 2>&1 > LOGS/$$h.pid &    \
  253.         sleep 1;                        \
  254.     done
  255.  
  256. $(NFSPWD):
  257.     cd $(@D); $(MAKE) $(@F)
  258. endif
  259.  
  260. export::
  261.     +$(LOOP_OVER_DIRS)
  262.  
  263. libs install:: $(LIBRARY) $(SHARED_LIBRARY) $(PROGRAM) $(MAPS)
  264. ifdef LIBRARY
  265.     $(INSTALL) -m 444 $(LIBRARY) $(DIST)/lib
  266. endif
  267. ifdef MAPS
  268.     $(INSTALL) -m 444 $(MAPS) $(DIST)/bin
  269. endif
  270. ifdef SHARED_LIBRARY
  271.     $(INSTALL) -m 555 $(SHARED_LIBRARY) $(DIST)/bin
  272. endif
  273. ifdef PROGRAM
  274.     $(INSTALL) -m 444 $(PROGRAM) $(DIST)/bin
  275. endif
  276.     +$(LOOP_OVER_DIRS)
  277.  
  278. clean clobber::
  279.     rm -rf $(ALL_TRASH)
  280.     +$(LOOP_OVER_DIRS)
  281.  
  282. realclean clobber_all::
  283.     rm -rf $(wildcard *.OBJ) dist $(ALL_TRASH)
  284.     +$(LOOP_OVER_DIRS)
  285.  
  286. alltags:
  287.     rm -f TAGS
  288.     find . -name dist -prune -o \( -name '*.[hc]' -o -name '*.cp' -o -name '*.cpp' \) -print | xargs etags -a
  289.  
  290. $(PROGRAM): $(OBJS)
  291.     @$(MAKE_OBJDIR)
  292. ifeq ($(OS_ARCH),OS2)
  293.     $(LINK) -FREE -OUT:$@ $(LDFLAGS) $(OS_LFLAGS) $(OBJS)  $(EXTRA_LIBS) -MAP:$(@:.exe=.map) $(OS_LIBS) $(DEF_FILE)
  294. else
  295. ifeq ($(OS_ARCH),WINNT)
  296.     $(CC) $(OBJS) -Fe$@ -link $(LDFLAGS) $(OS_LIBS) $(EXTRA_LIBS)
  297. else
  298.     $(CCF) -o $@ $(OBJS) $(LDFLAGS)
  299. endif
  300. endif
  301.  
  302. ifneq ($(OS_ARCH),OS2)
  303. $(LIBRARY): $(OBJS) $(LOBJS)
  304.     @$(MAKE_OBJDIR)
  305.     rm -f $@
  306.     $(AR) $(OBJS) $(LOBJS)
  307.     $(RANLIB) $@
  308. else
  309. ifdef OS2_IMPLIB
  310. $(LIBRARY): $(OBJS) $(DEF_FILE) 
  311.     @$(MAKE_OBJDIR)
  312.     rm -f $@
  313.     $(IMPLIB) $@ $(DEF_FILE)
  314.     $(RANLIB) $@
  315. else
  316. $(LIBRARY): $(OBJS)
  317.     @$(MAKE_OBJDIR)
  318.     rm -f $@
  319.     $(AR) $(LIBOBJS),,
  320.     $(RANLIB) $@
  321. endif
  322. endif
  323.  
  324. ifneq ($(OS_ARCH),OS2)
  325. $(SHARED_LIBRARY): $(OBJS) $(LOBJS)
  326.     @$(MAKE_OBJDIR)
  327.     rm -f $@
  328.     $(MKSHLIB) -o $@ $(OBJS) $(LOBJS) $(EXTRA_DSO_LDOPTS)
  329.     chmod +x $@
  330. else
  331. $(SHARED_LIBRARY): $(OBJS) $(DEF_FILE)
  332.     @$(MAKE_OBJDIR)
  333.     rm -f $@
  334.     $(LINK_DLL) $(OBJS) $(OS_LIBS) $(EXTRA_LIBS) $(DEF_FILE)
  335.     chmod +x $@
  336. endif
  337.  
  338. ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
  339. $(DLL): $(OBJS) $(EXTRA_LIBS)
  340.     @$(MAKE_OBJDIR)
  341.     rm -f $@
  342. ifeq ($(OS_ARCH),OS2)
  343.     $(LINK_DLL) $(OBJS) $(EXTRA_LIBS) $(OS_LIBS)
  344. else
  345.     $(LINK_DLL) $(OBJS) $(OS_LIBS) $(EXTRA_LIBS)
  346. endif
  347. endif
  348.  
  349. $(OBJDIR)/%: %.c
  350.     @$(MAKE_OBJDIR)
  351. ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
  352.     $(CC) -Fo$@ -c $(CFLAGS) $*.c
  353. else
  354.     $(CCF) $(LDFLAGS) -o $@ $*.c
  355. endif
  356.  
  357. $(OBJDIR)/%.o: %.c
  358.     @$(MAKE_OBJDIR)
  359. ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
  360.     $(CC) -Fo$@ -c $(CFLAGS) $*.c
  361. else
  362.     $(CC) -o $@ -c $(CFLAGS) $*.c
  363. endif
  364.  
  365. $(OBJDIR)/%.o: %.s
  366.     @$(MAKE_OBJDIR)
  367.     $(AS) -o $@ $(ASFLAGS) -c $*.s
  368.  
  369. $(OBJDIR)/%.o: %.S
  370.     @$(MAKE_OBJDIR)
  371.     $(AS) -o $@ $(ASFLAGS) -c $*.S
  372.  
  373. $(OBJDIR)/%: %.cpp
  374.     @$(MAKE_OBJDIR)
  375.     $(CCC) -o $@ $(CFLAGS) $*.c $(LDFLAGS)
  376.  
  377. #
  378. # Please keep the next two rules in sync.
  379. #
  380. $(OBJDIR)/%.o: %.cc
  381.     @$(MAKE_OBJDIR)
  382.     $(CCC) -o $@ -c $(CFLAGS) $*.cc
  383.  
  384. $(OBJDIR)/%.o: %.cpp
  385.     @$(MAKE_OBJDIR)
  386. ifdef STRICT_CPLUSPLUS_SUFFIX
  387.     echo "#line 1 \"$*.cpp\"" | cat - $*.cpp > $(OBJDIR)/t_$*.cc
  388.     $(CCC) -o $@ -c $(CFLAGS) $(OBJDIR)/t_$*.cc
  389.     rm -f $(OBJDIR)/t_$*.cc
  390. else
  391. ifneq (,$(filter OS2 WINNT,$(OS_ARCH)))
  392.     $(CCC) -Fo$@ -c $(CFLAGS) $*.cpp
  393. else
  394.     $(CCC) -o $@ -c $(CFLAGS) $*.cpp
  395. endif
  396. endif #STRICT_CPLUSPLUS_SUFFIX
  397.  
  398. %.i: %.cpp
  399.     $(CCC) -C -E $(CFLAGS) $< > $*.i
  400.  
  401. %.i: %.c
  402.     $(CC) -C -E $(CFLAGS) $< > $*.i
  403.  
  404. %: %.pl
  405.     rm -f $@; cp $*.pl $@; chmod +x $@
  406.  
  407. %: %.sh
  408.     rm -f $@; cp $*.sh $@; chmod +x $@
  409.  
  410. ifdef DIRS
  411. $(DIRS)::
  412.     @if test -d $@; then                \
  413.         set $(EXIT_ON_ERROR);            \
  414.         echo "cd $@; $(MAKE)";            \
  415.         cd $@; $(MAKE);                \
  416.         set +e;                    \
  417.     else                        \
  418.         echo "Skipping non-directory $@...";    \
  419.     fi;                        \
  420.     $(CLICK_STOPWATCH)
  421. endif
  422.  
  423. ################################################################################
  424. # Bunch of things that extend the 'export' rule (in order):
  425. ################################################################################
  426.  
  427. $(JAVA_DESTPATH) $(JAVA_DESTPATH)/$(PACKAGE) $(JMCSRCDIR)::
  428.     @if test ! -d $@; then        \
  429.         echo Creating $@;    \
  430.         rm -rf $@;        \
  431.         $(NSINSTALL) -D $@;    \
  432.     fi
  433.  
  434. ################################################################################
  435. ### JSRCS -- for compiling java files
  436.  
  437. ifneq ($(JSRCS),)
  438. ifdef MOZ_JAVA
  439. export:: $(JAVA_DESTPATH) $(JAVA_DESTPATH)/$(PACKAGE)
  440.     list=`$(PERL) $(DEPTH)/config/outofdate.pl $(PERLARG)    \
  441.             -d $(JAVA_DESTPATH)/$(PACKAGE) $(JSRCS)`;    \
  442.     if test "$$list"x != "x"; then                \
  443.         echo $(JAVAC) $$list;                \
  444.         $(JAVAC) $$list;                    \
  445.     fi
  446.  
  447. all:: export
  448.  
  449. clobber::
  450.     rm -f $(XPDIST)/classes/$(PACKAGE)/*.class
  451.  
  452. endif
  453. endif
  454.  
  455. #
  456. # JDIRS -- like JSRCS, except you can give a list of directories and it will
  457. # compile all the out-of-date java files in those directories.
  458. #
  459. # NOTE: recursing through these can speed things up, but they also cause
  460. # some builds to run out of memory
  461. #
  462. ifdef JDIRS
  463. ifdef MOZ_JAVA
  464. export:: $(JAVA_DESTPATH) $(JAVA_DESTPATH)/$(PACKAGE)
  465.     @for d in $(JDIRS); do                            \
  466.         if test -d $$d; then                        \
  467.             set $(EXIT_ON_ERROR);                    \
  468.             files=`echo $$d/*.java`;                \
  469.             list=`$(PERL) $(DEPTH)/config/outofdate.pl $(PERLARG)    \
  470.                     -d $(JAVA_DESTPATH)/$(PACKAGE) $$files`;    \
  471.             if test "$${list}x" != "x"; then            \
  472.                 echo Building all java files in $$d;        \
  473.                 echo $(JAVAC) $$list;                \
  474.                 $(JAVAC) $$list;                    \
  475.             fi;                            \
  476.             set +e;                            \
  477.         else                                \
  478.             echo "Skipping non-directory $$d...";            \
  479.         fi;                                \
  480.         $(CLICK_STOPWATCH);                        \
  481.     done
  482. endif
  483. endif
  484.  
  485. #
  486. # JDK_GEN -- for generating "old style" native methods
  487. #
  488. # Generate JDK Headers and Stubs into the '_gen' and '_stubs' directory
  489. #
  490. ifneq ($(JDK_GEN),)
  491. ifdef MOZ_JAVA
  492. ifdef NSBUILDROOT
  493. INCLUDES        += -I$(JDK_GEN_DIR) -I$(XPDIST)
  494. else
  495. INCLUDES        += -I$(JDK_GEN_DIR)
  496. endif
  497. JDK_PACKAGE_CLASSES    = $(JDK_GEN)
  498. JDK_PATH_CLASSES    = $(subst .,/,$(JDK_PACKAGE_CLASSES))
  499. JDK_HEADER_CLASSFILES    = $(patsubst %,$(JAVA_DESTPATH)/%.class,$(JDK_PATH_CLASSES))
  500. JDK_STUB_CLASSFILES    = $(patsubst %,$(JAVA_DESTPATH)/%.class,$(JDK_PATH_CLASSES))
  501. JDK_HEADER_CFILES    = $(patsubst %,$(JDK_GEN_DIR)/%.h,$(JDK_GEN))
  502. JDK_STUB_CFILES        = $(patsubst %,$(JDK_STUB_DIR)/%.c,$(JDK_GEN))
  503.  
  504. $(JDK_HEADER_CFILES): $(JDK_HEADER_CLASSFILES)
  505. $(JDK_STUB_CFILES): $(JDK_STUB_CLASSFILES)
  506.  
  507. export::
  508.     @echo Generating/Updating JDK headers
  509.     $(JAVAH) -d $(JDK_GEN_DIR) $(JDK_PACKAGE_CLASSES)
  510.     @echo Generating/Updating JDK stubs
  511.     $(JAVAH) -stubs -d $(JDK_STUB_DIR) $(JDK_PACKAGE_CLASSES)
  512. ifdef MOZ_GENMAC
  513.     @if test ! -d $(DEPTH)/lib/mac/Java/; then                        \
  514.         echo "!!! You need to have a ns/lib/mac/Java directory checked out.";        \
  515.         echo "!!! This allows us to automatically update generated files for the mac.";    \
  516.         echo "!!! If you see any modified files there, please check them in.";        \
  517.     fi
  518.     @echo Generating/Updating JDK headers for the Mac
  519.     $(JAVAH) -mac -d $(DEPTH)/lib/mac/Java/_gen $(JDK_PACKAGE_CLASSES)
  520.     @echo Generating/Updating JDK stubs for the Mac
  521.     $(JAVAH) -mac -stubs -d $(DEPTH)/lib/mac/Java/_stubs $(JDK_PACKAGE_CLASSES)
  522. endif
  523. endif # MOZ_JAVA
  524. endif
  525.  
  526. #
  527. # JRI_GEN -- for generating JRI native methods
  528. #
  529. # Generate JRI Headers and Stubs into the 'jri' directory
  530. #
  531. ifneq ($(JRI_GEN),)
  532. ifdef MOZ_JAVA
  533. ifdef NSBUILDROOT
  534. INCLUDES        += -I$(JRI_GEN_DIR) -I$(XPDIST)
  535. else
  536. INCLUDES        += -I$(JRI_GEN_DIR)
  537. endif
  538. JRI_PACKAGE_CLASSES    = $(JRI_GEN)
  539. JRI_PATH_CLASSES    = $(subst .,/,$(JRI_PACKAGE_CLASSES))
  540. JRI_HEADER_CLASSFILES    = $(patsubst %,$(JAVA_DESTPATH)/%.class,$(JRI_PATH_CLASSES))
  541. JRI_STUB_CLASSFILES    = $(patsubst %,$(JAVA_DESTPATH)/%.class,$(JRI_PATH_CLASSES))
  542. JRI_HEADER_CFILES    = $(patsubst %,$(JRI_GEN_DIR)/%.h,$(JRI_GEN))
  543. JRI_STUB_CFILES        = $(patsubst %,$(JRI_GEN_DIR)/%.c,$(JRI_GEN))
  544.  
  545. $(JRI_HEADER_CFILES): $(JRI_HEADER_CLASSFILES)
  546. $(JRI_STUB_CFILES): $(JRI_STUB_CLASSFILES)
  547.  
  548. export::
  549.     @echo Generating/Updating JRI headers
  550.     $(JAVAH) -jri -d $(JRI_GEN_DIR) $(JRI_PACKAGE_CLASSES)
  551.     @echo Generating/Updating JRI stubs
  552.     $(JAVAH) -jri -stubs -d $(JRI_GEN_DIR) $(JRI_PACKAGE_CLASSES)
  553. ifdef MOZ_GENMAC
  554.     @if test ! -d $(DEPTH)/lib/mac/Java/; then                        \
  555.         echo "!!! You need to have a ns/lib/mac/Java directory checked out.";        \
  556.         echo "!!! This allows us to automatically update generated files for the mac.";    \
  557.         echo "!!! If you see any modified files there, please check them in.";        \
  558.     fi
  559.     @echo Generating/Updating JRI headers for the Mac
  560.     $(JAVAH) -jri -mac -d $(DEPTH)/lib/mac/Java/_jri $(JRI_PACKAGE_CLASSES)
  561.     @echo Generating/Updating JRI stubs for the Mac
  562.     $(JAVAH) -jri -mac -stubs -d $(DEPTH)/lib/mac/Java/_jri $(JRI_PACKAGE_CLASSES)
  563. endif
  564. endif # MOZ_JAVA
  565. endif
  566.  
  567. #
  568. # JMC_EXPORT -- for declaring which java classes are to be exported for jmc
  569. #
  570. ifneq ($(JMC_EXPORT),)
  571. ifdef MOZ_JAVA
  572. JMC_EXPORT_PATHS    = $(subst .,/,$(JMC_EXPORT))
  573. JMC_EXPORT_FILES    = $(patsubst %,$(JAVA_DESTPATH)/$(PACKAGE)/%.class,$(JMC_EXPORT_PATHS))
  574.  
  575. #
  576. # We're doing NSINSTALL -t here (copy mode) because calling INSTALL will pick up
  577. # your NSDISTMODE and make links relative to the current directory. This is a
  578. # problem because the source isn't in the current directory:
  579. #
  580. export:: $(JMC_EXPORT_FILES) $(JMCSRCDIR)
  581.     $(NSINSTALL) -t -m 444 $(JMC_EXPORT_FILES) $(JMCSRCDIR)
  582. endif # MOZ_JAVA
  583. endif
  584.  
  585. #
  586. # JMC_GEN -- for generating java modules
  587. #
  588. # Provide default export & install rules when using JMC_GEN
  589. #
  590. ifneq ($(JMC_GEN),)
  591. INCLUDES        += -I$(JMC_GEN_DIR) -I.
  592. ifdef MOZ_JAVA
  593. JMC_HEADERS        = $(patsubst %,$(JMC_GEN_DIR)/%.h,$(JMC_GEN))
  594. JMC_STUBS        = $(patsubst %,$(JMC_GEN_DIR)/%.c,$(JMC_GEN))
  595. JMC_OBJS        = $(patsubst %,$(OBJDIR)/%.o,$(JMC_GEN))
  596.  
  597. $(JMC_GEN_DIR)/M%.h: $(JMCSRCDIR)/%.class
  598.     $(JMC) -d $(JMC_GEN_DIR) -interface $(JMC_GEN_FLAGS) $(?F:.class=)
  599.  
  600. $(JMC_GEN_DIR)/M%.c: $(JMCSRCDIR)/%.class
  601.     $(JMC) -d $(JMC_GEN_DIR) -module $(JMC_GEN_FLAGS) $(?F:.class=)
  602.  
  603. $(OBJDIR)/M%.o: $(JMC_GEN_DIR)/M%.h $(JMC_GEN_DIR)/M%.c
  604.     @$(MAKE_OBJDIR)
  605. ifeq ($(OS_ARCH),OS2)
  606.     $(CC) -Fo$@ -c $(CFLAGS) $(JMC_GEN_DIR)/M$*.c
  607. else
  608.     $(CC) -o $@ -c $(CFLAGS) $(JMC_GEN_DIR)/M$*.c
  609. endif
  610.  
  611. export:: $(JMC_HEADERS) $(JMC_STUBS)
  612. endif # MOZ_JAVA
  613. endif
  614.  
  615. #
  616. # Copy each element of EXPORTS to $(XPDIST)/public/$(MODULE)/
  617. #
  618. ifneq ($(EXPORTS),)
  619. $(XPDIST)/public/$(MODULE)::
  620.     @if test ! -d $@; then        \
  621.         echo Creating $@;   \
  622.         rm -rf $@;        \
  623.         $(NSINSTALL) -D $@; \
  624.     fi
  625.  
  626. export:: $(EXPORTS) $(XPDIST)/public/$(MODULE)
  627.     $(INSTALL) -m 444 $(EXPORTS) $(XPDIST)/public/$(MODULE)
  628. endif
  629.  
  630. ################################################################################
  631.  
  632. -include $(DEPENDENCIES)
  633.  
  634. ifneq (,$(filter-out OS2 WINNT,$(OS_ARCH)))
  635. # Can't use sed because of its 4000-char line length limit, so resort to perl
  636. .DEFAULT:
  637.     @$(PERL) -e '                                                         \
  638.         open(MD, "< $(DEPENDENCIES)");                                    \
  639.         while (<MD>) {                                                    \
  640.         if (m@ \.*/*$< @) {                                           \
  641.             $$found = 1;                                              \
  642.             last;                                                     \
  643.         }                                                             \
  644.         }                                                                 \
  645.         if ($$found) {                                                    \
  646.         print "Removing stale dependency $< from $(DEPENDENCIES)\n";  \
  647.         seek(MD, 0, 0);                                               \
  648.         $$tmpname = "$(OBJDIR)/fix.md" . $$$$;                        \
  649.         open(TMD, "> " . $$tmpname);                                  \
  650.         while (<MD>) {                                                \
  651.             s@ \.*/*$< @ @;                                           \
  652.             if (!print TMD "$$_") {                                   \
  653.             unlink(($$tmpname));                                  \
  654.             exit(1);                                              \
  655.             }                                                         \
  656.         }                                                             \
  657.         close(TMD);                                                   \
  658.         if (!rename($$tmpname, "$(DEPENDENCIES)")) {                  \
  659.             unlink(($$tmpname));                                      \
  660.         }                                                             \
  661.         } elsif ("$<" ne "$(DEPENDENCIES)") {                             \
  662.         print "$(MAKE): *** No rule to make target $<.  Stop.\n";     \
  663.         exit(1);                                                      \
  664.         }'
  665. endif
  666.  
  667. #############################################################################
  668. # X dependency system
  669. #############################################################################
  670.  
  671. ifneq (,$(filter-out OS2 WINNT,$(OS_ARCH)))
  672.  
  673. $(MKDEPENDENCIES)::
  674.     @$(MAKE_OBJDIR)
  675.     touch $(MKDEPENDENCIES)
  676.     $(MKDEPEND) -p$(OBJDIR_NAME)/ -o'.o' -f$(MKDEPENDENCIES) $(INCLUDES) $(CSRCS) $(CPPSRCS)
  677.  
  678. $(MKDEPEND)::
  679.     cd $(MKDEPEND_DIR); $(MAKE)
  680.  
  681. ifdef OBJS
  682. depend:: $(MKDEPEND) $(MKDEPENDENCIES)
  683. else
  684. depend::
  685. endif
  686.     +$(LOOP_OVER_DIRS)
  687.  
  688. dependclean::
  689.     rm -f $(MKDEPENDENCIES)
  690.     +$(LOOP_OVER_DIRS)
  691.  
  692. -include $(OBJDIR)/depend.mk
  693.  
  694. endif
  695.  
  696. #############################################################################
  697.  
  698. -include $(MY_RULES)
  699.  
  700. #
  701. # This speeds up gmake's processing if these files don't exist.
  702. #
  703. $(MY_CONFIG) $(MY_RULES):
  704.     @touch $@
  705.  
  706. #
  707. # Generate Emacs tags in a file named TAGS if ETAGS was set in $(MY_CONFIG)
  708. # or in $(MY_RULES)
  709. #
  710. ifdef ETAGS
  711. ifneq ($(CSRCS)$(HEADERS),)
  712. all:: TAGS
  713. TAGS:: $(CSRCS) $(CPPSRCS) $(HEADERS)
  714.     $(ETAGS) $(CSRCS) $(CPPSRCS) $(HEADERS)
  715. endif
  716. endif
  717.  
  718. ################################################################################
  719. # Special gmake rules.
  720. ################################################################################
  721.  
  722. #
  723. # Re-define the list of default suffixes, so gmake won't have to churn through
  724. # hundreds of built-in suffix rules for stuff we don't need.
  725. #
  726. .SUFFIXES:
  727. .SUFFIXES: .out .a .ln .o .c .cc .C .cpp .y .l .s .S .h .sh .i .pl .class .java .html
  728.  
  729. #
  730. # Don't delete these files if we get killed.
  731. #
  732. .PRECIOUS: .java $(JDK_HEADERS) $(JDK_STUBS) $(JRI_HEADERS) $(JRI_STUBS) $(JMC_HEADERS) $(JMC_STUBS)
  733.  
  734. #
  735. # Fake targets.  Always run these rules, even if a file/directory with that
  736. # name already exists.
  737. #
  738. .PHONY: all all_platforms alltags boot clean clobber clobber_all export install libs realclean $(OBJDIR) $(DIRS)
  739.  
  740.