More sanitizations in Makefile (needs testing):

+ Remove a bogus DOCS assignment line.
+ Cabal recreates pandoc executable by unnecessarily linking Main.o with 
  library (it skips compiling *.hs files though).  Since pandoc's time 
  stamp is modified, it is  copied from buildir to top directory, and also 
  README.html is regenerated, each time a target which has a 'build' 
  prerequisite is invoked.  As a solution, now PHONY 'build' target depends 
  on BUILDDIR/.
+ "THIS" variable has a confusing semantics and it is abusingly used in 
  various targets.  We in fact need it to specify package sub directories 
  created during installation.  Clarify this meaning by moving it to path 
  variables section.
+ Create a new variable as MAIN which holds the main executable name.  
  Sorry for my obsession to avoid simply using a magic "pandoc" name. :-)
  Modify all targets which (abusingly) refers  to THIS and replace THIS 
  with MAIN.  Note that MAIN is derived from EXECS which in turn collects  
  all executable names from Executable stanzas in cabal file.
+ As EXECS may hold more than one executable name, update EXECS target to 
  reflect this semantic.
+ Rename BINS variable as PROGS and modify it so as to hold the names of 
  all executables required to be installed.  Remove bin_all local variable 
  as PROGS can be used for the same purpose instead.
+ Modify DOCS variable so as to hold the names of all documents required to 
  be installed.  Remove doc_all local variable as DOCS can be used for the 
  same purpose instead.
+ Remove DOCS target.  README.html is already generated when needed.
+ Remove build-exec redundant prerequisite from osx_dest target.  Make can 
  find its way.
+ Set MAIN as the prerequisite of 'test' and 'test-markdown' to make things 
  more clear.


git-svn-id: https://pandoc.googlecode.com/svn/trunk@70 788f1e2b-df1e-0410-8736-df70ead52e1b
This commit is contained in:
roktas 2006-11-02 14:32:57 +00:00
parent 2d2914ff1a
commit 2066ec5d02

View file

@ -6,15 +6,15 @@ CABAL := Pandoc.cabal
# Cabal constants
#-------------------------------------------------------------------------------
NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL).in)
THIS := $(shell echo $(NAME) | tr A-Z a-z)
VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL).in)
EXECS := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
MAIN := $(word 1, $(EXECS)) # first entry in stanza is the main executable
#-------------------------------------------------------------------------------
# Build targets
# Install targets
#-------------------------------------------------------------------------------
BINS := $(EXECS)
DOCS := README.html
PROGS := $(EXECS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
DOCS := README.html README BUGS TODO
#-------------------------------------------------------------------------------
# Variables to setup through environment
@ -35,6 +35,7 @@ CONFIGURE := configure
#-------------------------------------------------------------------------------
# Installation paths
#-------------------------------------------------------------------------------
THIS := $(shell echo $(NAME) | tr A-Z a-z) # package name
DESTPATH := $(DESTDIR)$(PREFIX)
BINPATH := $(DESTPATH)/bin
DATAPATH := $(DESTPATH)/share
@ -63,13 +64,13 @@ GHC_PKG := ghc-pkg
all: build-program
# Document process rules.
%.html: % $(THIS)
./$(THIS) -s $< >$@ || rm -f $@
%.tex: % $(THIS)
./$(THIS) -s -w latex $< >$@ || rm -f $@
%.rtf: % $(THIS)
./$(THIS) -s -w rtf $< >$@ || rm -f $@
%.pdf: % $(THIS)
%.html: % $(MAIN)
./$(MAIN) -s $< >$@ || rm -f $@
%.tex: % $(MAIN)
./$(MAIN) -s -w latex $< >$@ || rm -f $@
%.rtf: % $(MAIN)
./$(MAIN) -s -w rtf $< >$@ || rm -f $@
%.pdf: % $(MAIN)
sh ./markdown2pdf $< || rm -f $@
.PHONY: templates
@ -88,20 +89,21 @@ $(BUILDCONF): $(CABAL)
$(BUILDCMD) configure --prefix=$(PREFIX)
.PHONY: build
build: templates configure
build: $(BUILDDIR)
$(BUILDDIR)/: templates configure
$(BUILDCMD) build
.PHONY: build-exec
build-exec: $(BINS)
cleanup_files+=$(BINS)
$(BINS): build
find $(BUILDDIR) -type f -name "$(BINS)" -perm +a=x -exec cp {} . \;
build-exec: $(EXECS)
cleanup_files+=$(EXECS)
$(EXECS): $(BUILDDIR)
for f in $@; do \
find $(BUILDDIR) -type f -name "$$f" -perm +a=x -exec cp {} . \; ; \
done
.PHONY: build-doc
DOCS:=README.html
cleanup_files+=$(DOCS)
cleanup_files+=README.html
build-doc: $(DOCS)
$(DOCS): build-exec
.PHONY: build-program
build-program: build-exec build-doc
@ -124,15 +126,14 @@ build-all: all build-lib-doc
# User documents installation.
.PHONY: install-doc uninstall-doc
man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
doc_all:=$(DOCS) README BUGS TODO
install-doc: build-doc
$(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(doc_all) $(DOCPATH)/
$(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(DOCS) $(DOCPATH)/
for f in $(man_all); do \
$(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
$(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
done
uninstall-doc:
-for f in $(doc_all); do rm -f $(DOCPATH)/$$f; done
-for f in $(DOCS); do rm -f $(DOCPATH)/$$f; done
-for f in $(man_all); do rm -f $(MANPATH)/$$f; done
-rmdir $(DOCPATH)
@ -146,12 +147,11 @@ uninstall-lib-doc:
# Program only installation.
.PHONY: install-exec uninstall-exec
bin_all:=$(BINS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
install-exec: build-exec
$(INSTALL) -d $(BINPATH); \
for f in $(bin_all); do $(INSTALL_PROGRAM) $$f $(BINPATH)/; done
for f in $(PROGS); do $(INSTALL_PROGRAM) $$f $(BINPATH)/; done
uninstall-exec:
-for f in $(bin_all); do rm -f $(BINPATH)/$$f; done
-for f in $(PROGS); do rm -f $(BINPATH)/$$f; done
# Program + user documents installation.
.PHONY: install-program uninstall-program
@ -187,13 +187,13 @@ doc_more:=README.rtf LICENSE.rtf $(osx_src)/Welcome.rtf
osx_pkg_name:=Pandoc_$(VERSION).pkg
cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
osx-pkg-prep: $(osx_dest)
$(osx_dest)/: build-exec $(doc_more)
$(osx_dest)/: $(doc_more)
-rm -rf $(osx_dest)
$(INSTALL) -d $(osx_dest)
DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
find $(osx_dest) -type f -regex ".*bin/$(THIS)" | xargs $(STRIP)
find $(osx_dest) -type f -regex ".*bin/$(MAIN)" | xargs $(STRIP)
$(INSTALL) -d $(osx_dest)/Resources
cp README.rtf $(osx_dest)/Resources/ReadMe.rtf
cp LICENSE.rtf $(osx_dest)/Resources/License.rtf
@ -231,10 +231,10 @@ $(osx_dmg_name): $(osx_pkg_name)
mv Pandoc.udzo.dmg $(osx_dmg_name)
.PHONY: test test-markdown
test: build-exec
@cd tests && perl runtests.pl -s $(PWD)/$(THIS)
test-markdown: build-exec
@cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(THIS) -tidy
test: $(MAIN)
@cd tests && perl runtests.pl -s $(PWD)/$(MAIN)
test-markdown: $(MAIN)
@cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(MAIN) -tidy
# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')