home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!gatech!hubcap!ncrcae!ncrlnk!usglnk!usdsd1!dkowalsk
- From: dkowalsk@usdsd1.DaytonOH.NCR.COM (Dennis Kowalski)
- Newsgroups: comp.unix.questions
- Subject: Make -k option
- Message-ID: <1598@usdsd1.DaytonOH.NCR.COM>
- Date: 11 Sep 92 15:13:16 GMT
- Reply-To: dkowalsk@usdsd1.DaytonOH.NCR.COM (Dennis Kowalski)
- Distribution: world
- Organization: NCR USG Data Services Division
- Lines: 146
-
-
- I posted the question a few days ago asking how to use the -k option
- of make to compile all the component modules, bypasss the link if any
- had errors, and still know if errors occurred.
- The problem was that when the -k option is used, make ALWAYS exits
- with zero.
-
- I also sent EMail to O'Reilly & Associates who published the
- NUTSHELL book "Managing Projects with MAKE".
-
- I received a reply from the author!!!!
-
-
- He suggested removing the target abd then testing to see if the make
- created it.
- I did not want to unconditionaly remove it, only if it was being remade.
-
- The key to the solution was declaring my own suffix rules which
- added a remove of the target prior to each compile.
-
-
- For anyone else interested, here is what I came up with.
-
- First a little explanation.
- We have a shell script (shell A) that does a system wide make involving many
- subdirectories.
- Each subdirectory has a shell in it (B) that runs the make for that
- directory.
- Shell A executes shell B.
-
- Prior to doing the makes, Shell A backs up the libraries and our bin
- directories.
- As it runs each individual make shell (shell B),
- it checks the exit status and sets
- an error flag if a non-zero is returned from that make.
-
- When all the makes are done, shell A checks the error flag , and if not zero
- the libraries and bin are restored.
-
- We wanted to see all the errors, not just the 1st one for a given target,
- but using the -k option meant never doing a restore.
-
-
- Here is the solution that warks just fine.
-
-
- -----------------------------------------------------------
- This is shell B wich does a single make in a subdirectory
- -----------------------------------------------------------
-
- ErrorFlag=0
-
- make -kf progx.mk # run with -k option
- ErrorFlag=$? # save status (always 0)
- if [ ! -f progx ] # test for target missing
- then
- ErrorFlag=1 # set flag
- fi
-
- exit $ErrorFlag # exit with make status for shell A to check
-
- # End of mkprogx
-
-
-
- ------------------------------------------------------------------
- What follows is the progx.mk file
- The new suffix rules will cause the target executable to
- be removed prior to each compile of a component.
- If the link is not performed due to an error,
- the target executable will no longer exist.
-
- If the target is up to date or newly made, it will exist
-
- In this example, all three .c files use aaa.h.
- If it changes, all three will compile.
- If modules 1 or 2 have errors, the remaining .c's will still
- be compiled because of the -k option and we will see all errors
- The target will be removed prior to each compile.
-
- NOTE
- The rm -f target is associated with the component compile.
- No rm will be done is no compiles are done.
- ------------------------------------------------------------------
-
- TARGET = progx # declare the targer
-
- OFILES= \ # list components
- progx01.o \
- progx02.o \
- progx03.o
-
- #
- # ---------------------------------------------------------------
- # here are the new suffix rules for non SCCS .c's and SCCS .c's
- # ---------------------------------------------------------------
- #
-
- .SUFFIXES: .c .c~
-
- #
- # rule for non SCCS files
- #
-
- .c.o :
- rm -f $(TARGET)
- $(CC) $(CFLAGS) -c $<
-
- #
- # rule for SCCS files
- #
-
- .c~.o:
- rm -f $(TARGET)
- $(GET) $(GFLAGS) $<
- $(CC) $(CFLAGS) -c $*.c
- -rm -f $*.c
-
- #
- # --------------------------------------------------
- # Now we specify the target and it's dependancies
- # --------------------------------------------------
- #
-
- $(TARGET): $(OFILES)
- $(CC) -o $@ $(OFILES)
-
- #
- # -----------------------------------------------------
- # Now we specify the components and their dependancies
- # -----------------------------------------------------
- #
-
- progx01.o: aaa.h bbb.h
-
- progx02.o: aaa.h ccc.h
-
- progx03.o: aaa.h ddd.h
-
- # End of makefile for progx
-
- --
- Dennis Kowalski NCR Corporation PCD-3 (513) 445-1843
- Systems Architecture 1700 S. Patterson Blvd VOICEplus 622-1843
- USG Data Services Div Dayton, Ohio 45479
- Dennis.Kowalski@DaytonOH.NCR.COM
-