------------------------------------------------------------------------------- Shell scripts in Makefile You must backslash all lines to make them a single line, also hiding the resultact command is usful. FILE_TEST: @echo "performing sheel commands" @if [ -f file ]; \ then set -x; \ command args... \ fi OR .ENV_CHECK: @if [ $(PMISSOURCE) != "/p7" ]; then exit 1; fi OR .ENV_CHECK: @[ $(PMISSOURCE) != "/p7" && exit 1 ------------------------------------------------------------------------------- Make options -k Continue other dependancies after an error (don't stop) -t touch all so that everything is actually ok ------------------------------------------------------------------------------- Full ANSI/OSI error checking with gcc CC = gcc CFLAGS = -Wall -Wpointer-arith -Wconversion \ -Wstrict-prototypes -Wmissing-prototypes \ -ansi -pedantic -g -O \ #-DDEBUG ------------------------------------------------------------------------------- Selective recompile after a header edit make -t touch module_to_recompile make ------------------------------------------------------------------------------- Adding a new make rule Convert .c into a .cgi program .c.cgi: $(CC) $(CFLAGS) -o $@ $< $(LIBS) chmod 755 $@ .SUFFIXES: .SUFFIXES: .cgi $(SUFFIXES) ------------------------------------------------------------------------------- Substitutions Rules # Sed substitions rule .sed: @echo "SED SUBSTITUTIONS \"$@.sed\" ==> \"$@\"" @sed -e 's|==BROWSERDIR==|$(BROWSERDIR)|' \ -e 's|==LIBRARY_RC==|$(LIBRARY_RC)|' \ -e 's|==USERS_RC==|$(USERS_RC)|' \ -e 's|==X_BITMAPS==|$(X_BITMAPS)|' \ -e '/==COLOR_SETTINGS_DIVIDER==/d' \ < $@.sed >$@ .SUFFIXES: .sed Some of the special character around the substition strings are as follows so take your pick. ==LABEL== @@LABEL@@ @#LABEL#@ ------------------------------------------------------------------------------- Hiding intermediate object files (for large programs) Subdirectories : bin upstairs, objects in sub-directory BIN = ../bin/ OBJ = obj/ TARGET = $(BIN)foo OBJS = $(OBJ)ack.o \ $(OBJ)bar.o \ $(OBJ)frotz.o \ $(OBJ)ozmoo.o $(TARGET): $(OBJS) @echo "Linking $@" @$(LINK.c) -o $@ $? $(OBJ)%.o: %.c @echo "Compiling $<" @$(COMPILE.c) -o $@ $< Of course, this is oversimplified. However, it should give you the idea. The LINK.c and COMPILE.c are predefined macros supplied with the version of make that comes with SunOS, and all they are is predefined 'cc' commands. 'man make' for more info about predefined macros on your system. The above example ensures that your source, executable, and objects are separate. Of course, depending on how large the project is, you could make an inc/ directory also to separate your include files. Of course you would have to define that dir in your makefile as well. ------------------------------------------------------------------------------- Auto-increment of a build version number Makefile.autoincr.gen : Integers only! VERSION = 23 NEWVERS = `expr $(VERSION) + $(UDVAL)` update: @mv Makefile Makefile.bak @sed "s/^VERSION[ \t]*=[ \t]*[0-9]*/VERSION = $(NEWVERS)/" \ Makefile.bak > Makefile Makefile.autoincr.sun : Bells & whistles! VERSION = 1.23 NEWVERS = echo "scale=2 ; $(VERSION) + $(UDVAL)" | bc update: @mv Makefile Makefile.bak @sed "s/^VERSION[ \t]*=[ \t]*[0-9.]*/VERSION = $(NEWVERS:sh)/" \ Makefile.bak > Makefile Then the following can be used to update the version number make -f Makefile.autoincr.sun update UDVAL="0.01" Another way is to have the version in a separate file and increment this. -------------------------------------------------------------------------------