Notify Shell Script from Makefile when got error ???
Hi folks,
I am writing a shell script which will call another shell scripts. And those scripts are actually calling Makefiles. I just want a notification from the makefiles that build is successful or have some error. I don't want to change the makefiles and dont want to add any export variable in the makefile's as i dont want to change the makefiles. Structure is like Shell Script (A) || || Shell Script (B) || Makefile 1 / Makefile 2 / Makefile 3 /Makefile 4 Example if any error or success comes in Makefile 1/2/3/4 then Shell Script A should get notification. We can only modify the Shell Script A. ( A big constraint :) ) Thnx in advance for the help. thnx & best regards Rocky |
Hi and welcome to LinuxQuestions!
Maybe I don't quite understand the problem, but can't you just let the make command throw its output to the terminal? Or eventually redirect it to some files and then parse them in script A, looking for some keywords that can tell you if it run successfully or not? Even more simple if the make command exits with a proper status code (0 = success, >0 = failure) so that you can simply check it using $? and act accordingly to notify the user. |
Thnx for ur prompt reply first.
I did that i used $? for getting the last error. But as i m calling a makefile from the shell script so the last error is coming as 0 always i don't know why it is not capturing the last error of makefile inside the shell script. And regarding the problem i m explaining it again hope that you can get it. I am calling a makefile from a shell script to build it. I just need the makefile build status back in the shell script. |
Quote:
Quote:
Code:
make -f whatever_makefile Usually in the script you would catch $? just after running that command. Code:
make -f whatever_makefile Code:
function die() { In your case, I'd start checking that you are not using -q, as you see, when you use it a non-zero value is not necessarily an error, which can cause confusion. |
Hi,
U r absolutlly correct that code can say thousands of words so here is the piece of code. This is my bash script #!/bin/bash # Shell Script for automating the build .... SAMBA_PATH=$STACK_PATH/Build function compile() { echo "Starting Building ........................" cd $STACK_PATH/Build/ make all echo "Build Sucessfull !!!!!" VAR=$? echo $VAR -------> Value of VAR is always "0" means no error has been detected ------------------> If make file gives error also it always give "0" ------------------> If make file produces some error then i should get notified } In the directory lets say i am having a makefile which is just doing # Sample Makefile CC = g++ TARGET = test CXXFLAGS = -g -c -Wall -Werror -O2 DXXFLAGS = -D_LINUX INCLUDE = -I../inc/ SRC = $(shell find . -name '*.cc') OBJ = $(SRC:.cc=.o) $(TARGET) : $(OBJ) $(CC) -o ../exe/$(TARGET) $(OBJ) .cc.o : $(CC) $(CXXFLAGS) $(DXXFLAGS) $(INCLUDE) $< -o $@ So if lets say that there is an error i got while compiling the source code with this file then i should get a notification in the Bash Script file which is above So when ever there is an error come in the compilation there should be a notification to the BASH Script file. |
Code:
make all |
colucix told it so: when we say "the last command" we really mean so. In this case, it would be the exit status of echo, which will be "success" (0).
A quick look at echo.c from current coreutils seems to suggest that it's really impossible to get any other exit status than EXIT_SUCCESS, which I assume is zero. |
Thnx i92guboj...
I am able to solve the problem. I put the $? at correct location and after that it is working |
All times are GMT -5. The time now is 01:45 AM. |