Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Makefile and what a.out

0 views
Skip to first unread message

Alex Vinokur

unread,
Aug 8, 1999, 3:00:00 AM8/8/99
to

Hi,

Inserting in Makefile some commands and variables,
using some macros and
and using the what command,
we can extract useful information from executable file.

Here arw such makefile, macros and an example.
Any improving will be appreciated.

Thanks in advance,
Alex

//#########################################################
//------------------- Makefile : BEGIN --------------------

MAKEFILE = Makefile

SHELL = /bin/sh

DEPEND = makedepend

RM = rm -f

CC = g++
LD = g++

#################
# These lines are compiler-dependent
ABOUT_CC = $(CC) -v
ABOUT_LD = $(LD) -v
#################


EFFECTIVE_USER = `whoami`

LOGIN_USER = `logname`

MAIL = /usr/ucb/mail MAIL_WITH_SBJ = $(MAIL) -s MSG_BODY =
"==========================================================================\n
"\ "The source file <See this message's subject field> has no
what-indicators.\n"\

"==========================================================================\n"\
"COMPILATION DIRECTORY : "`pwd`"\n"\
"MAKEFILE : "$(MAKEFILE)"\n"\
"COMPILATION SYSTEM : "`uname -a`"\n"\
"COMPILER : "`$(ABOUT_CC) 2>&1 | tail
-1`"\n"\
"LINKER : "`$(ABOUT_LD) 2>&1 | tail
-1`"\n"\
"EFFECTIVE USER : "$(EFFECTIVE_USER)"\n"\
"LOGIN USER : "$(LOGIN_USER)"\n"\

"==========================================================================\n"

#################
COMPFLAGS_INFO = -DCOMPILE_HOST='"'`hostname`'"' \
-DCOMPILE_UNAME='"'"'`uname -a`'"'"' \
-DCOMPILE_USERID='"'"'`id`'"'"' \
-DCOMPILE_WHOAMI='"'`whoami`'"' \
-DCOMPILE_WHO_AM_I='"'"'`who am i`'"'"' \
-DCOMPILE_LOGNAME='"'`logname`'"' \
-DCOMPILE_USER_WHO_AM_I='"'"'`who am i | awk
'{print $$1}'`'"'"' \
-DCOMPILER='"'"'`$(ABOUT_CC) 2>&1 | tail
-1`'"'"' \
-DLINKER='"'"'`$(ABOUT_LD) 2>&1 | tail
-1`'"'"'

COMPFLAGS = $(COMPFLAGS_INFO)

DBFLAGS =

INCDIR1 = .


ALL_INCLUDES = -I$(INCINC1) -I/tools/GNU/lib/g++-include

CFLAGS = $(DBFLAGS) $(COMPFLAGS) $(ALL_INCLUDES)
FFLAGS = $(DBFLAGS) $(COMPFLAGS) $(ALL_INCLUDES)
CCFLAGS = $(DBFLAGS) $(ALL_INCLUDES)

################# $(COMPFLAGS)
CXXFLAGS = $(DBFLAGS) $(COMPFLAGS) $(ALL_INCLUDES)
C++FLAGS = $(DBFLAGS) $(COMPFLAGS) $(ALL_INCLUDES)

#################
SUFFIX =

#################
EXTHDRS =

HDRS = AAA.H \
BBB.H \
CCC.H \
GenDefinitions.H

#################
LDFLAGS = $(DBFLAGS)

#################
LIBS =

#################
PROGRAM = ./a.out

SRCS = AAA.C \
BBB.C \
CCC.C \
main_for_make.C

OBJS = AAA.o \
BBB.o \
CCC.o \
main_for_make.o


#################
# Target Rules
#################
.SUFFIXES :
.SUFFIXES : .i .I .h .H .C .c .o
.C.o .c.o:
@echo ""
@echo " #######################"
@echo "\t\c"
$(RM) $*.o
@echo "\t\c"
$(CC) $(C++FLAGS) -c $< \
-DLAST_MOD='"'"'`ls -l $< | awk '{print $$(NF-3) FS
$$(NF-2) FS $$(NF-1)}'`'"'"' \
-DWCSIZE_LINES='"'`wc -l $< | awk '{print $$1}'`'"' \
-DWCSIZE_WORDS='"'`wc -w $< | awk '{print $$1}'`'"' \
-DWCSIZE_BYTES='"'`wc -c $< | awk '{print $$1}'`'"'
@echo "\t=====> Number of what-indicators = \c"
@COUNTER=`what $*.o | grep -v "\.H" | grep -v "\.h" | grep -v
$*.o | wc -l 2>/dev/null`; \
echo "$$COUNTER\c"; \
if [ $$COUNTER = 0 ]; \
then \
echo " (WARNING!)"; \
MSG_SBJ="[$<] Compilation WARNING about what-command"; \
MSG_EFFECTIVE_USER_SBJ="$$MSG_SBJ"" (message to
effective user)"; \
MSG_LOGIN_USER_SBJ="$$MSG_SBJ"" (message to login
user)"; \
if [ "$(EFFECTIVE_USER)" = "$(LOGIN_USER)" ]; \
then \
echo $(MSG_BODY) | $(MAIL_WITH_SBJ) "$$MSG_SBJ"
"$(EFFECTIVE_USER)"; \
else \
echo $(MSG_BODY) | $(MAIL_WITH_SBJ)
"$$MSG_EFFECTIVE_USER_SBJ" "$(EFFECTIVE_USER)"; \
echo $(MSG_BODY) | $(MAIL_WITH_SBJ)
"$$MSG_LOGIN_USER_SBJ" "$(LOGIN_USER)"; \
fi \
else \
echo ""; \
fi

all: $(PROGRAM)


$(PROGRAM): $(OBJS) $(LIBS) $(MAKEFILE)
@echo ""
@echo ""
@echo " ##########################################"
@echo " ####==##==##==##==##==##==##==##==##==####"
@echo " ##########################################"
@echo " Linking $(PROGRAM) (executable file)..."
@echo "\t\c"
$(RM) $(PROGRAM)
@echo "\t\c"
$(LD) -o $(PROGRAM) $(LDFLAGS) $(OBJS) $(LIBS)
@echo ""
@echo ""
@echo "\t\c"
@echo "===== Done $(PROGRAM) (executable file) ====="
@echo ""
@echo ""
@echo "\t\c"
@echo "===== What-checking $(PROGRAM) - BEGINNING =="
@echo ""
@what $(PROGRAM) | grep -v "\.H" | grep -v "\.h" | grep
Source | grep DF
@echo ""
@echo "\t\c"
@echo "===== What-checking $(PROGRAM) - END ========="
@echo ""
@echo " ##########################################"
@echo " ####==##==##==##==##==##==##==##==##==####"
@echo " ##########################################"


clean:; @rm -rf $(OBJS) *.I $(PROGRAM) core

dep:; $(DEPEND) $(ALL_INCLUDES) $(SRCS)

echo:; @echo '\t<HDRS = $(HDRS)>\n\t<SRCS = $(SRCS)>\n\t<LIBS =
$(LIBS)>\n\t<SQLLIBS = $(SQLLIBS)>\n\t<SYSLIBS = $(SYSLIBS)>'

index:; @ctags -wx $(HDRS) $(SRCS)

update: $(DEST)/$(PROGRAM)

touch:; @touch $(SRCS) $(HDRS)

pre:; $(CC) -E $(SRCS) $(ALL_INCLUDES)

dl:; $(RM) $(OBJS) *.o


# DO NOT DELETE

AAA.o: AAA.H GenDefinitions.H
BBB.o: BBB.H GenDefinitions.H
CCC.o: CCC.H GenDefinitions.H
main_for_make.o: AAA.H GenDefinitions.H BBB.H CCC.H

//------------------- Makefile : END ----------------------

//#########################################################
=== File #1 of 8 : GenDefinitions.H ==========
//------------------- C++ code : BEGIN -------------------

//######################
#ifndef GenDefinitions_H
#define GenDefinitions_H
//######################


#include <iostream.h>
static char id_GenDefinitions[] = "@(#)Header ## "__FILE__"
("__DATE__" "__TIME__"); Author : Somebody#3";

//################################################################################
//######################### SOURCE_STAMP
#########################################
//################################################################################

#define AUTHOR_STAMP \
static char id_AUTHOR[] = "@(#)Author ## "__FILE__" :::
Somebody#4";


#define SOURCE_STAMP \
AUTHOR_STAMP \
static char id_010[] = "@(#)Source (FD) ## "__FILE__"
("__DATE__" "__TIME__")"; \
static char id_020[] = "@(#)Source (DF) ## ("__DATE__"
"__TIME__") " __FILE__; \
static char id_030[] = "@(#)--- Compiler ## "COMPILER;
\
static char id_040[] = "@(#)--- Linker ## "LINKER; \
static char id_050[] = "@(#)--- Size (lines) ##
"WCSIZE_LINES; \
static char id_060[] = "@(#)--- Size (words) ##
"WCSIZE_WORDS; \
static char id_070[] = "@(#)--- Size (bytes) ##
"WCSIZE_BYTES; \
static char id_080[] = "@(#)--- Last modification ## "LAST_MOD;
\
static char id_090[] = "@(#)--- Environment ##
"COMPILE_UNAME; \
static char id_100[] = "@(#)--- UserId compiled ##
"COMPILE_USERID; \
static char id_110[] = "@(#)--- Who_am_i compiled ##
"COMPILE_WHO_AM_I; \
static char id_120[] = "@(#)--- Whoami compiled ##
"COMPILE_WHOAMI; \
static char id_130[] = "@(#)--- Logname compiled ##
"COMPILE_LOGNAME; \
static char id_999[] = "@(#)";


#endif

//------------------- C++ code : END ----------------------
=== File #1 of 8 : GenDefinitions.H ==========
//#########################################################

//#########################################################
=== File #2 of 8 : AAA.H ==========
//------------------- C++ code : BEGIN -------------------

//######################
#ifndef AAA_H
#define AAA_H
//######################


#include "GenDefinitions.H"
static char id_AAA[] = "@(#)Header ## "__FILE__" ("__DATE__"
"__TIME__"); Author : Somebody#1";

#endif

//------------------- C++ code : END ----------------------
=== File #2 of 8 : AAA.H ==========
//#########################################################


//#########################################################
=== File #3 of 8 : BBB.H ==========
//------------------- C++ code : BEGIN -------------------

//######################
#ifndef BBB_H
#define BBB_H
//######################


#include "GenDefinitions.H"
static char id_BBB[] = "@(#)Header ## "__FILE__" ("__DATE__"
"__TIME__"); Author : Somebody#2";

#endif


//------------------- C++ code : END ----------------------
=== File #3 of 8 : BBB.H ==========
//#########################################################

//#########################################################
=== File #4 of 8 : CCC.H ==========
//------------------- C++ code : BEGIN -------------------

//######################
#ifndef CCC_H
#define CCC_H
//######################


#include "GenDefinitions.H"
static char id_CCC[] = "@(#)Header ## "__FILE__" ("__DATE__"
"__TIME__"); Author : Somebody#1";


#endif


//------------------- C++ code : END ----------------------
=== File #4 of 8 : CCC.H ==========
//#########################################################

//#########################################################
=== File #5 of 8 : AAA.C ==========
//------------------- C++ code : BEGIN -------------------

#include "AAA.H"

SOURCE_STAMP;

// Stuff

//------------------- C++ code : END ----------------------
=== File #5 of 8 : AAA.C ==========
//#########################################################

//#########################################################
=== File #6 of 8 : BBB.C ==========
//------------------- C++ code : BEGIN -------------------

#include "BBB.H"

SOURCE_STAMP;

// Stuff

//------------------- C++ code : END ----------------------
=== File #6 of 8 : BBB.C ==========
//#########################################################


//#########################################################
=== File #7 of 8 : CCC.C ==========
//------------------- C++ code : BEGIN -------------------

#include "CCC.H"

SOURCE_STAMP;

// Stuff

//------------------- C++ code : END ----------------------
=== File #7 of 8 : CCC.C ==========
//#########################################################

//#########################################################
=== File #8 of 8 : main_for_make.C ==========
//------------------- C++ code : BEGIN -------------------


#include "AAA.H"
#include "BBB.H"
#include "CCC.H"

SOURCE_STAMP

int main ()
{
// Stuff
return 0;
}


//------------------- C++ code : END ----------------------
=== File #8 of 8 : main_for_make.C ==========
//#########################################################

//#########################################################
//------------------- Extracting information : BEGIN ------
// For some files GenDefinitions.H,
// AAA.H, BBB.H, CCC.H,
// AAA.C, BBB.C, CCC.C,
// main_for_make.C

%make

[snip]

%what a.out


a.out:
Header ## GenDefinitions.H (Aug 2 1999 13:53:52); Author :
Somebody#3
Header ## AAA.H (Aug 2 1999 13:53:52); Author : Somebody#1
Author ## AAA.C ::: Somebody#4
Source (FD) ## AAA.C (Aug 2 1999 13:53:52)
Source (DF) ## (Aug 2 1999 13:53:52) AAA.C
--- Compiler ## 'gcc version 2.7.2.2'
--- Linker ## 'gcc version 2.7.2.2'
--- Size (lines) ## 3
--- Size (words) ## 3
--- Size (bytes) ## 32
--- Last modification ## 'Aug 1 02:09'
--- Environment ## 'SunOS tibamsun8 5.6 Generic_105181-09
sun4m sparc SUNW,SPARCstation-5'
--- UserId compiled ## 'uid=248(alexv) gid=6690(pshwsim)'
--- Who_am_i compiled ## 'alexv pts/34 Aug 2 13:52'
--- Whoami compiled ## alexv
--- Logname compiled ## alexv

Header ## GenDefinitions.H (Aug 2 1999 08:11:53); Author :
Somebody#3
Header ## BBB.H (Aug 2 1999 08:11:53); Author : Somebody#2
Author ## BBB.C ::: Somebody#4
Source (FD) ## BBB.C (Aug 2 1999 08:11:53)
Source (DF) ## (Aug 2 1999 08:11:53) BBB.C
--- Compiler ## 'gcc version egcs-2.91.57 19980901
(egcs-1.1 release)'
--- Linker ## 'gcc version egcs-2.91.57 19980901
(egcs-1.1 release)'
--- Size (lines) ## 4
--- Size (words) ## 3
--- Size (bytes) ## 32
--- Last modification ## 'Jul 1 09:17'
--- Environment ## 'SunOS tibamsun2 4.1.3_U1 1 sun4m'
--- UserId compiled ## 'uid=248(alexv) gid=6690(pshwsim)
groups=6690(pshwsim),4020(pshwsim1)'
--- Who_am_i compiled ## 'tibamsun2!alexv ttyp0 Aug 2
03:50 (tibamsun8)'
--- Whoami compiled ## alexv
--- Logname compiled ## alexv

Header ## GenDefinitions.H (Aug 2 1999 13:56:03); Author :
Somebody#3
Header ## CCC.H (Aug 2 1999 13:56:03); Author : Somebody#1
Author ## CCC.C ::: Somebody#4
Source (FD) ## CCC.C (Aug 2 1999 13:56:03)
Source (DF) ## (Aug 2 1999 13:56:03) CCC.C
--- Compiler ## 'gcc version egcs-2.91.57 19980901
(egcs-1.1 release)'
--- Linker ## 'gcc version egcs-2.91.57 19980901
(egcs-1.1 release)'
--- Size (lines) ## 5
--- Size (words) ## 3
--- Size (bytes) ## 33
--- Last modification ## 'Feb 27 1998'
--- Environment ## 'SunOS tibamsun8 5.6 Generic_105181-09
sun4m sparc SUNW,SPARCstation-5'
--- UserId compiled ## 'uid=250(alexvp) gid=47(project)'
--- Who_am_i compiled ## 'alexv pts/25 Jul 27 11:32'
--- Whoami compiled ## alexvp
--- Logname compiled ## alexv

Header ## GenDefinitions.H (Aug 2 1999 13:56:32); Author :
Somebody#3
Header ## AAA.H (Aug 2 1999 13:56:32); Author : Somebody#1
Header ## BBB.H (Aug 2 1999 13:56:32); Author : Somebody#2
Header ## CCC.H (Aug 2 1999 13:56:32); Author : Somebody#1
Author ## main_for_make.C ::: Somebody#4
Source (FD) ## main_for_make.C (Aug 2 1999 13:56:32)
Source (DF) ## (Aug 2 1999 13:56:32) main_for_make.C
--- Compiler ## 'gcc version egcs-2.91.57 19980901
(egcs-1.1 release)'
--- Linker ## 'gcc version egcs-2.91.57 19980901
(egcs-1.1 release)'
--- Size (lines) ## 12
--- Size (words) ## 14
--- Size (bytes) ## 95
--- Last modification ## 'Jul 21 15:31'
--- Environment ## 'SunOS tibamsun8 5.6 Generic_105181-09
sun4m sparc SUNW,SPARCstation-5'
--- UserId compiled ## 'uid=248(alexv) gid=6690(pshwsim)'
--- Who_am_i compiled ## 'alexv pts/25 Jul 27 11:32'
--- Whoami compiled ## alexv
--- Logname compiled ## alexv

SunOS 5.6 Generic August 1997

//------------------- Extracting information : END --------


//#########################################################
ATTENTION!
If you forget to insert the SOURCE_STAMP macros
in source file (for instance, in BBB.C),
you will get e-mail as following :

----------------

Subject: [BBB.C] Compilation WARNING about what-command

==========================================================================
The source file <See this message's subject field> has no
what-indicators.

==========================================================================
COMPILATION DIRECTORY : /homesun8.2/users/alexv/junk1
MAKEFILE : Makefile
COMPILATION SYSTEM : SunOS tibamsun8 5.6 Generic_105181-09 sun4m
sparc SUNW,SPARCstation-5
COMPILER : gcc version egcs-2.91.57 19980901 (egcs-1.1
release)
LINKER : gcc version egcs-2.91.57 19980901 (egcs-1.1
release)
EFFECTIVE USER : alexv
LOGIN USER : alexv

==========================================================================


//#########################################################

Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

0 new messages