home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / question / 10992 < prev    next >
Encoding:
Internet Message Format  |  1992-09-12  |  4.4 KB

  1. Path: sparky!uunet!gatech!hubcap!ncrcae!ncrlnk!usglnk!usdsd1!dkowalsk
  2. From: dkowalsk@usdsd1.DaytonOH.NCR.COM (Dennis Kowalski)
  3. Newsgroups: comp.unix.questions
  4. Subject: Make -k option
  5. Message-ID: <1598@usdsd1.DaytonOH.NCR.COM>
  6. Date: 11 Sep 92 15:13:16 GMT
  7. Reply-To: dkowalsk@usdsd1.DaytonOH.NCR.COM (Dennis Kowalski)
  8. Distribution: world
  9. Organization: NCR USG Data Services Division
  10. Lines: 146
  11.  
  12.  
  13.   I posted the question a few days ago asking how to use the -k option
  14.   of make to compile all the component modules, bypasss the link if any
  15.   had errors, and still know if errors occurred.
  16.   The problem was that when the -k option is used, make ALWAYS exits
  17.   with zero.
  18.  
  19.   I also sent EMail to O'Reilly & Associates who published the
  20.   NUTSHELL book "Managing Projects with MAKE".
  21.  
  22.   I received a reply from the author!!!!
  23.  
  24.  
  25.   He suggested removing the target abd then testing to see if the make
  26.   created it.
  27.   I did not want to unconditionaly remove it, only if it was being remade.
  28.   
  29.   The key to the solution was declaring my own suffix rules which
  30.   added a remove of the target prior to each compile.
  31.  
  32.  
  33.   For anyone else interested, here is what I came up with.
  34.  
  35.   First a little explanation.
  36.   We have a shell script (shell A) that does a system wide make involving many
  37.   subdirectories.
  38.   Each subdirectory has a shell in it (B) that runs the make for that
  39.   directory.
  40.   Shell A executes shell B.
  41.  
  42.   Prior to doing the makes, Shell A backs up the libraries and our bin
  43.   directories.
  44.   As it runs each individual make shell (shell B),
  45.   it checks the exit status and sets
  46.   an error flag if a non-zero is returned from that make.
  47.  
  48.   When all the makes are done, shell A checks the error flag , and if not zero
  49.   the libraries and bin are restored.
  50.  
  51.   We wanted to see all the errors, not just the 1st one for a given target,
  52.   but using the -k option meant never doing a restore.
  53.  
  54.  
  55.   Here is the solution that warks just fine.
  56.  
  57.  
  58. -----------------------------------------------------------
  59. This is shell B wich does a single make in a subdirectory
  60. -----------------------------------------------------------
  61.  
  62. ErrorFlag=0
  63.  
  64. make -kf progx.mk     # run with -k option
  65. ErrorFlag=$?          # save status (always 0)
  66. if [ ! -f progx ]     # test for target missing
  67. then
  68.   ErrorFlag=1         # set flag
  69. fi
  70.  
  71. exit $ErrorFlag  # exit with make status for shell A to check
  72.  
  73. # End of mkprogx
  74.  
  75.  
  76.  
  77. ------------------------------------------------------------------
  78. What follows is the progx.mk file
  79. The new suffix rules will cause the target executable to
  80. be removed prior to each compile of a component.
  81. If the link is not performed due to an error,
  82. the target executable will no longer exist.
  83.  
  84. If the target is up to date or newly made, it will exist
  85.  
  86. In this example, all three .c files use aaa.h.
  87. If it changes, all three will compile.
  88. If modules 1 or 2 have errors, the remaining .c's will still 
  89. be compiled because of the -k option and we will see all errors
  90. The target will be removed prior to each compile.
  91.  
  92. NOTE
  93.   The rm -f target is associated with the component compile.
  94.   No rm will be done is no compiles are done.
  95. ------------------------------------------------------------------
  96.  
  97. TARGET = progx                 # declare the targer
  98.  
  99. OFILES= \                      # list components
  100.         progx01.o \
  101.         progx02.o \
  102.         progx03.o 
  103.  
  104. #
  105. # ---------------------------------------------------------------
  106. # here are the new suffix rules for non SCCS .c's and SCCS .c's
  107. # ---------------------------------------------------------------
  108. #
  109.  
  110. .SUFFIXES: .c .c~
  111.  
  112. #
  113. # rule for non SCCS files
  114. #
  115.  
  116. .c.o :
  117.         rm -f $(TARGET)
  118.         $(CC) $(CFLAGS) -c $<
  119.  
  120. #
  121. # rule for SCCS files
  122. #
  123.  
  124. .c~.o:
  125.         rm -f $(TARGET)
  126.         $(GET) $(GFLAGS) $<
  127.         $(CC) $(CFLAGS) -c $*.c
  128.         -rm -f $*.c
  129.  
  130. #
  131. # --------------------------------------------------
  132. # Now we specify the target and it's dependancies
  133. # --------------------------------------------------
  134.  
  135. $(TARGET):  $(OFILES) 
  136.         $(CC) -o $@ $(OFILES)
  137.  
  138. #
  139. # -----------------------------------------------------
  140. # Now we specify the components and their dependancies
  141. # -----------------------------------------------------
  142.  
  143. progx01.o:  aaa.h  bbb.h
  144.  
  145. progx02.o:  aaa.h  ccc.h
  146.  
  147. progx03.o:  aaa.h  ddd.h
  148.  
  149. #  End of makefile for progx
  150.  
  151. -- 
  152. Dennis Kowalski         NCR Corporation  PCD-3                  (513) 445-1843
  153. Systems Architecture    1700 S. Patterson Blvd              VOICEplus 622-1843
  154. USG Data Services Div   Dayton, Ohio     45479
  155. Dennis.Kowalski@DaytonOH.NCR.COM
  156.