help-gnu-utils
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to simplify this makefile?


From: Bob Stark
Subject: Re: How to simplify this makefile?
Date: 7 May 2004 18:19:58 -0700

> Anyway, happy making :).
> k

Thanks, Karl and others who responded. It took days, but I am now
pretty happy. I'll post details of my solution to date, might make a
good example for other newbies like me who have difficulty reading
Paul Smith's tightly written prose. People can make further
suggestions, but I'll start a new post with the next question.

We begin with the following files:
dir /s /a-d /b
O:\protech\TestClass\PT9998\Makefile
O:\protech\TestClass\PT9998\Materials\PT9998.pdf
O:\protech\TestClass\PT9998\Materials\PT9998Color.pdf
O:\protech\TestClass\PT9998\Materials\we_have.txt
O:\protech\TestClass\PT9998\Source\00cover.ppt
O:\protech\TestClass\PT9998\Source\01overview.ppt
O:\protech\TestClass\PT9998\Source\02WebView.ppt
O:\protech\TestClass\PT9998\Source\Makefile

Note that there are two Makefiles:
Source\Makefile is where we iteratively work on the class, doing
little builds and proofreading the material.
Makefile is when we are ready to close up work on a version of the
class and send it to the printer.

O:\protech\TestClass\PT9998>make all
cd source && make all
make[1]: Entering directory `O:/protech/TestClass/PT9998/Source'
mkdir ..\tmp\book
cd ..\tmp\book && make -f O:/protech/TestClass/PT9998/Source/Mak...
... about 100 lines not shown ...

This does several things: 
1. Create a temporary directory where we are going to run a future
make
2. Call make recursively in the Source directory w/ make all. This
creates the materials\PT9998.PDF and materials\PT9998Color.pdf file
3. Creates two zip files, one of the source directory, one with
everything else

When I'm done, the directories look like this:
dir /s /a-d /b
O:\protech\TestClass\PT9998\Makefile
O:\protech\TestClass\PT9998\PT9998.zip
O:\protech\TestClass\PT9998\PT9998SR.zip
O:\protech\TestClass\PT9998\Materials\PT9998.pdf<--------------------+
O:\protech\TestClass\PT9998\Materials\PT9998Color.pdf<-----------+   |
O:\protech\TestClass\PT9998\Materials\we_have.txt                |   |
O:\protech\TestClass\PT9998\Source\00cover.ppt--->-----------+   |   |
O:\protech\TestClass\PT9998\Source\01overview.ppt--->----+   |   |   |
O:\protech\TestClass\PT9998\Source\02WebView.ppt-->------|-+ |   |   |
O:\protech\TestClass\PT9998\Source\Makefile              | | |   |   |
O:\protech\TestClass\PT9998\tmp\book\00cover.pdf<--------|---+   |->-|
O:\protech\TestClass\PT9998\tmp\book\01overview.pdf<-----+ | |   |->-|
O:\protech\TestClass\PT9998\tmp\book\02WebView.pdf<------|-+ |   |->-+
O:\protech\TestClass\PT9998\tmp\colorbook\00cover.pdf<---|---+->-|
O:\protech\TestClass\PT9998\tmp\colorbook\01overview.pdf<+ |  ->-|
O:\protech\TestClass\PT9998\tmp\colorbook\02WebView.pdf<---+  ->-+

Once I do a make clean, the tmp\* directory & contents go away.

I read the heck out of http://make.paulandlesley.org/multi-arch.html
and decided to attempt something based on the "get make to switch to
the target directory" approach. So the following make file has two
sections; one which takes effect in the Source directory, and another
which is in effect in the \tmp\book and tmp\colorbook directories,
which I make the current directories during the build, so that I can
use VPATH to locate the sources. It's whacky, but it finally works; I
had a lot of trouble getting the
ifeq (tmp,$(findstring tmp,$(CURDIR)))
syntax coded correctly, plus understanding when things happened. It
does meet my criteria of having only a few lines which need changed
for each course.

This is Source\Makefile:
# Makefile for building a ProTech student workbook w/ gnu make
# Set PT number and source files for this class below
PTNUM=PT9998
CHAPTERS=00cover.pdf            \
         01overview.pdf         \
         02WebView.pdf          \

PRINTER=-PRINTER="Acrobat Distiller"


ifeq (Source,$(notdir $(CURDIR)))
  # Makefile rules for Source go here

  PDFFILE=..\..\Materials\${PTNUM}.pdf
  PDFCOLOR=..\..\Materials\${PTNUM}Color.pdf

  .PHONY     : all              # Keep make from whacking out if we
ever create a file named all
  all        : book colorbook   # The all target makes all the books
        @echo For help, type:    make help

  .PHONY     : help
  help       :
        @echo                 Instructions
        @echo make all        Build all books into PDF files
        @echo make book       Build monochrome version into ${PDFFILE}
        @echo make colorbook  Build color version into into ${PDFCOLOR}
        @echo make clean      Delete temporary work files and directories
        @echo make help       Display this help
        @echo PTNUM=${PTNUM}, current directory is ${CURDIR}

  .PHONY     : book
  book       : ..\tmp\book      # The book target makes the monochrome
book for printing
        cd ..\tmp\book && $(MAKE) -f $(CURDIR)/Makefile COLOR=NO
VPATH=$(CURDIR) $(PDFFILE)

  .PHONY     : colorbook
  colorbook  : ..\tmp\colorbook # The colorbook target makes the color
book for on-line viewing
        cd ..\tmp\colorbook && $(MAKE) -f $(CURDIR)/Makefile COLOR=YES
VPATH=$(CURDIR) $(PDFCOLOR)

  .PHONY     : clean
  clean      :                  # This target deletes the tmp
workfiles directory
        -@echo Deleting intermediate PDF files...
        -del ..\tmp /s /q
        -rd ..\tmp /s /q

  ..\tmp\book:                  # This target makes a tmp directory
for workfiles
        -mkdir ..\tmp\book

  ..\tmp\colorbook:             # This target makes a tmp directory
for workfiles
        -mkdir ..\tmp\colorbook

  endif



ifeq (tmp,$(findstring tmp,$(CURDIR)))
  # The following Makefile statements which are in effect only when
we've been
  # invoked recursively in the tmp\ directories

  .SUFFIXES  :                  # Clean out default suffixes
  .SUFFIXES  : .pdf .ppt        # Define suffixes that make acts on
  # Generic rule to create intermediate PDF files from PPT slides
  # Note: ${<} is the name of current prereq file, e.g. the PPT file
  # Note: ${@} is the name of current target file, e.g. the PDF file
  %.pdf : %.ppt
        printppt ${PRINTER} -OUTDIR=. -WHAT=NOTES -COLOR=${COLOR} -FILES=${<}

  #${PDFFILE} : ${CHAPTERS}
  ${MAKECMDGOALS} : ${CHAPTERS}
        -del ${@}
        mergepdf -OUTFILE="${@}"

  endif


Finally, here is the primary Makefile:

# Makefile for building the student workbook
# For Instructions, type:  make help

# Set PT number and source files for this class below
PTNUM=PT9998
MAKE=make

.SUFFIXES  :                    # Clean out default suffixes
.SUFFIXES  : .zip .ZIP          # Define suffixes that make acts on
VPATH += Source

# This is the default target
.PHONY         : help
help           :
        @echo Master make file for course ${PTNUM}; Options:
        @echo                 Instructions:
        @echo make all        Completely automated course build
        @echo make clean      Cleanup temporary intermediate files
        @echo make dist       Make the zip files (final step in a course
build)
        @echo make help       Display this help
        @cd source && $(MAKE) help

.PHONY         : all
all            : book colorbook dist

.PHONY         : book           # This target calls make in the source
directory
book           :                #  to create the monochrome book for
printing
        cd source && $(MAKE) $(MAKECMDGOALS)

.PHONY         : colorbook      # This target calls make in the source
directory
colorbook      :                #  to create the color book for
on-line viewing
        cd source && $(MAKE) $(MAKECMDGOALS)

.PHONY         : clean          # This target deletes the tmp files
clean          :
        cd source && $(MAKE) $(MAKECMDGOALS)

.PHONY         : cleandist      # This target deletes all the zip
files
cleandist      : cleansource cleanzip

.PHONY         : cleanzip       # This target deletes the course zip
file
cleanzip       :
        -del ${PTNUM}.zip

.PHONY         : cleansource    # This target deletes the source code
zip file
cleansource    :
        -del ${PTNUM}SR.zip

# The dist target creates the zip files that are used to transmit the
class
.PHONY         : dist
dist           : ${PTNUM}.zip ${PTNUM}SR.zip

${PTNUM}SR.zip : cleansource
        pkzipc -zipdate=newest -level=9 -recurse -path                       
        \
        -add ${PTNUM}SR.zip Source\\*.*

${PTNUM}.zip   : cleanzip
        pkzipc -zipdate=newest -level=9 -recurse -path -exclude=Source
-exclude=tmp    \
        -add ${PTNUM}.zip   *.*


reply via email to

[Prev in Thread] Current Thread [Next in Thread]