Update kleopatra
[gpg4win.git] / src / gpg4win.mk.in
index f3dc9a0..9e20bf9 100644 (file)
@@ -1,3 +1,23 @@
+# gpg4win.m4.in - Installer for GnuPG 4 Windows Makefile.   -*- makefile -*-
+# Copyright (C) 2005, 2009 g10 Code GmbH
+# 
+# This file is part of GPG4Win.
+# 
+# GPG4Win is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+# 
+# GPG4Win is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+# 
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
+
+
 # No servicable parts below this line :)
 
 
@@ -6,8 +26,11 @@ root := $(shell pwd)/playground
 bdir := $(root)/build
 idir := $(root)/install
 ipdir := $(root)/install/pkgs
+tsdir := $(shell pwd)/${top_srcdir}
 pdir := $(shell pwd)/${top_srcdir}/patches
 
+# We collect the names of all pkg files used.
+pkg_files =
 
 # The playground area is our scratch area, where we unpack, build and
 # install the packages.
@@ -17,6 +40,7 @@ stamps/stamp-directories:
        $(MKDIR) $(bdir)
        $(MKDIR) $(idir)
        $(MKDIR) $(ipdir)
+       touch $(bdir)/versioninfo.txt
        touch stamps/stamp-directories
 
 
@@ -27,7 +51,7 @@ endef
 
 # Get the variable $(1) (which may contain '-' and '+' characters).
 define GETVAR
-$$($(call FROB_macro,$(1)))
+$($(call FROB_macro,$(1)))
 endef
 
 # Set a couple of common variables.
@@ -37,34 +61,58 @@ define SETVARS
        pkgsdir="$(bdir)/$$$${pkg_version}";                            \
        pkgbdir="$(bdir)/$$$${pkg_version}-build";                      \
        pkgpdir="$(pdir)/$$$${pkg_version}";                            \
+       pkgpbdir="$(pdir)/$(1)";                                        \
        pkgidir="$(ipdir)/$$$${pkg_version}";                           \
        pkg_dev="$(call GETVAR,gpg4win_pkg_$(1)_dev)";                  \
        pkg_version_dev="$(1)-dev-$(call GETVAR,gpg4win_pkg_$(1)_version)"; \
        pkgidir_dev="$(ipdir)/$$$${pkg_version_dev}";                   \
        pkgcfg="$(call GETVAR,gpg4win_pkg_$(1)_configure)";             \
-       export PKG_CONFIG="$(shell pwd)/$(top_srcdir)/src/pkg-config";  \
-       export PKG_CONFIG_PATH="${idir}/lib/pkgconfig";                 \
-       export SYSROOT="${idir}"
+       pkgmkargs="$(call GETVAR,gpg4win_pkg_$(1)_make_args)";          \
+       pkgmkargs_inst="$(call GETVAR,gpg4win_pkg_$(1)_make_args_inst)";\
+       export PKG_CONFIG="$(tsdir)/src/pkg-config";                    \
+       export PKG_CONFIG_PATH="$(idir)/lib/pkgconfig";                 \
+       export PKG_CONFIG_LIBDIR="";                                    \
+       export PATH="$(idir)/bin:$${PATH}";                             \
+       export SYSROOT="$(idir)";                                       \
+       export CONFIG_SITE="$(tsdir)/src/config.site"
 endef
 
 # Support macro.  Unpack the archive $(1).
 define DEFLATE_macro
        case "$(1)" in                  \
+          */gnupg2-2.*.tar.bz2)          \
+            $(TAR) -xj --transform='s,^gnupg-,gnupg2-,' -f "$(1)" ;; \
          *.tar.gz | *.tgz)             \
            $(TAR) xzf "$(1)" ;;        \
          *.tar.bz2 | *.tbz2 | *.tbz)   \
            $(TAR) xjf "$(1)" ;;        \
          *.zip)                        \
-           $(UNZIP) "$(1)" ;;  \
+           $(UNZIP) -o "$(1)" ;;               \
        esac
 endef
 
+# Support macro.  Strip all exe files below $(1).
+define STRIP_macro
+       if test -z '$(DEBUG)'; then                     \
+         (cd $(1);                                     \
+          for f in `find . -name \*.exe -o -name \*.dll`; do           \
+          echo Calling $(STRIP) "$$$${pkg_version}/$$$${f}"; \
+          $(STRIP) "$$$${f}"; done);                   \
+       fi
+endef
+
+define GETDEPS
+  $(addprefix stamps/stamp-final-, $(call GETVAR,gpg4win_pkg_$(1)_deps))
+endef
+
 
 # Template for source packages.
 
-define SPKG_template
+define SPKG_template_
 
-stamps/stamp-$(1)-00-unpack: stamps/stamp-directories 
+pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
+
+stamps/stamp-$(1)-00-unpack: stamps/stamp-directories $(call GETDEPS,$(1))
        (cd $(bdir);                                    \
         $(call SETVARS,$(1));                          \
         $(call DEFLATE_macro,$$$${pkg}))
@@ -73,7 +121,7 @@ stamps/stamp-$(1)-00-unpack: stamps/stamp-directories
 stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
        (shopt -s nullglob;                             \
         $(call SETVARS,$(1));                          \
-        for pfile in "$$$${pkgpdir}"/*.patch ; do      \
+        for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do  \
           (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
         done)
        touch stamps/stamp-$(1)-01-patch
@@ -82,22 +130,30 @@ stamps/stamp-$(1)-02-configure: stamps/stamp-$(1)-01-patch
        ($(call SETVARS,$(1));                          \
         mkdir "$$$${pkgbdir}";                         \
          cd "$$$${pkgbdir}";                           \
-        "$$$${pkgsdir}/configure"                      \
+        eval "../$$$${pkg_version}/configure"          \
                --prefix="$$$${pkgidir}"                \
                --host=$(host_cpu)-$(host_os)           \
-               --build=$(build_cpu)-$(build_os) $$$${pkgcfg})
+               --build=$(build_cpu)-$(build_os)        \
+               $$$${pkgcfg} CFLAGS=-mms-bitfields)
        touch stamps/stamp-$(1)-02-configure
 
 stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-02-configure
        ($(call SETVARS,$(1));                          \
          cd "$$$${pkgbdir}";                           \
-         $(MAKE) $(AM_MAKEFLAGS))
+         $(MAKE) $(AM_MAKEFLAGS) $(GPG4WIN_PARALLEL) $$$${pkgmkargs} || \
+         $(MAKE) $(AM_MAKEFLAGS) $(GPG4WIN_PARALLEL) $$$${pkgmkargs} || \
+         $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
        touch stamps/stamp-$(1)-03-make
 
+# Note that post_install must come last because it may be empty and
+# "; ;" is a syntax error.
 stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
        ($(call SETVARS,$(1));                          \
          cd "$$$${pkgbdir}";                           \
-         $(MAKE) $(AM_MAKEFLAGS) install)
+         $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
+         $(call STRIP_macro,"$$$${pkgidir}");          \
+         rm -f "$$$${pkgidir}/share/info/dir";         \
+         $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
        touch stamps/stamp-$(1)-04-install
 
 stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
@@ -108,25 +164,106 @@ stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
 
 stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
        touch stamps/stamp-final-$(1)
+
+.PHONY : clean-$(1)
+clean-$(1):
+       ($(call SETVARS,$(1));                          \
+        (cd $(ipdir) &&                                \
+         ($(STOW) -D "$$$${pkg_version}";              \
+          rm -fR "$$$${pkg_version}"));                \
+        rm -fR "$$$${pkgsdir}" "$$$${pkgbdir}")
+       rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
+
+endef
+
+define SPKG_template
+$(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
+  $(call SPKG_template_,$1))
 endef
 
 
+# Template for source packages using only make and no build
+# directory.
+
+define MPKG_template_
+
+pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
+
+stamps/stamp-$(1)-00-unpack: stamps/stamp-directories $(call GETDEPS,$(1))
+       (cd $(bdir);                                    \
+        $(call SETVARS,$(1));                          \
+        $(call DEFLATE_macro,$$$${pkg}))
+       touch stamps/stamp-$(1)-00-unpack
+
+stamps/stamp-$(1)-01-patch: stamps/stamp-$(1)-00-unpack
+       (shopt -s nullglob;                             \
+        $(call SETVARS,$(1));                          \
+        for pfile in "$$$${pkgpbdir}"/*.patch "$$$${pkgpdir}"/*.patch ; do \
+          (cd "$$$${pkgsdir}"; "$$$${pfile}")          \
+        done)
+       touch stamps/stamp-$(1)-01-patch
+
+stamps/stamp-$(1)-03-make: stamps/stamp-$(1)-01-patch
+       ($(call SETVARS,$(1));                          \
+         cd "$$$${pkgsdir}";                           \
+         $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs})
+       touch stamps/stamp-$(1)-03-make
+
+stamps/stamp-$(1)-04-install: stamps/stamp-$(1)-03-make
+       ($(call SETVARS,$(1));                          \
+         cd "$$$${pkgsdir}";                           \
+         $(MAKE) $(AM_MAKEFLAGS) $$$${pkgmkargs_inst} install; \
+         $(call STRIP_macro,"$$$${pkgidir}"))
+       touch stamps/stamp-$(1)-04-install
+
+stamps/stamp-$(1)-05-stow: stamps/stamp-$(1)-04-install
+       ($(call SETVARS,$(1));                          \
+        cd $(ipdir);                                   \
+        $(STOW) "$$$${pkg_version}")
+       touch stamps/stamp-$(1)-05-stow
+
+stamps/stamp-final-$(1): stamps/stamp-$(1)-05-stow
+       touch stamps/stamp-final-$(1)
+
+.PHONY : clean-$(1)
+clean-$(1):
+       ($(call SETVARS,$(1));                          \
+        (cd $(ipdir) &&                                \
+         ($(STOW) -D "$$$${pkg_version}";              \
+          rm -fR "$$$${pkg_version}"));                \
+        rm -fR "$$$${pkgsdir}"
+       rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
+
+endef
+
+define MPKG_template
+$(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
+  $(call MPKG_template_,$1))
+endef
+
+
+
 # Template for binary packages.
 
-define BPKG_template
+define BPKG_template_
 
-stamps/stamp-$(1)-00-install: stamps/stamp-directories 
+pkg_files += $(call GETVAR,gpg4win_pkg_$(1))
+pkg_files += $(call GETVAR,gpg4win_pkg_$(1)_dev)
+
+stamps/stamp-$(1)-00-install: stamps/stamp-directories $(call GETDEPS,$(1))
        ($(call SETVARS,$(1));                          \
         $(MKDIR) "$$$${pkgidir}";                      \
         cd $$$${pkgidir};                              \
         $(call DEFLATE_macro,$$$${pkg}))
        touch stamps/stamp-$(1)-00-install
 
+# Note that post_install must come last because it may be empty and
+# "; ;" is a syntax error.
 stamps/stamp-$(1)-01-install-dev: stamps/stamp-$(1)-00-install
        ($(call SETVARS,$(1));                          \
         $(MKDIR) "$$$${pkgidir_dev}";                  \
-        cd $$$${pkgidir_dev};                          \
-        $(call DEFLATE_macro,$$$${pkg_dev});           \
+        (cd $$$${pkgidir_dev};                         \
+         $(call DEFLATE_macro,$$$${pkg_dev}));         \
         $(call gpg4win_pkg_$(call FROB_macro,$(1))_post_install))
        touch stamps/stamp-$(1)-01-install-dev
 
@@ -144,26 +281,79 @@ stamps/stamp-$(1)-03-stow-dev: stamps/stamp-$(1)-02-stow
 
 stamps/stamp-final-$(1): stamps/stamp-$(1)-03-stow-dev
        touch stamps/stamp-final-$(1)
+
+.PHONY : clean-$(1)
+clean-$(1):
+       ($(call SETVARS,$(1));                          \
+        cd $(ipdir) &&                                 \
+        ($(STOW) -D "$$$${pkg_version}";               \
+         $(STOW) -D "$$$${pkg_version_dev}";           \
+         rm -fR "$$$${pkg_version}" "$$$${pkg_version_dev}"))
+       rm -f stamps/stamp-final-$(1) stamps/stamp-$(1)-*
+
 endef
 
+define BPKG_template
+$(if $(filter-out no, $(call GETVAR,gpg4win_pkg_$(1))),
+  $(call BPKG_template_,$1))
+endef
+
+
+# Template for internal packages.
+
+define IPKG_template
+
+stamps/stamp-final-$(1): stamps/stamp-directories $(call GETDEPS,$(1))
+       touch stamps/stamp-final-$(1)
+endef
+
+# Template for README files
+
+define README_template
+README.$(1).txt : versioninfo.txt NEWS.tmp $(top_srcdir)/doc/README.$(1).txt \
+                  $(top_srcdir)/doc/beta-warning.txt
+       sed -e '/^;.*/d;/!VERSIONINFO!/{r versioninfo.txt' -e 'd;}' \
+       -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
+       -e '/!NEWSFILE!/{r NEWS.tmp' -e 'd;}' \
+        -e '/!PKG-COPYRIGHT!/{r $(top_srcdir)/doc/pkg-copyright.txt' -e 'd;}' \
+        -e 's,!VERSION!,$(VERSION),g' \
+          < $(top_srcdir)/doc/README.$(1).txt \
+          | (if echo "$(VERSION)" | egrep 'svn|rc|beta' >/dev/null; then \
+              sed -e '/!BETA-WARNING!/{r $(top_srcdir)/doc/beta-warning.txt' \
+               -e 'd;}'; else sed -e 's,!BETA-WARNING!,,g'; fi) \
+           | awk '{printf "%s\r\n", $$$$0}' >README.$(1).txt
+endef
 
 # Insert the template for each source package.
 $(foreach spkg, $(gpg4win_spkgs), $(eval $(call SPKG_template,$(spkg))))
 
+# Insert the template for each make only source package.
+$(foreach mpkg, $(gpg4win_mpkgs), $(eval $(call MPKG_template,$(mpkg))))
+
 # Insert the template for each binary package.
 $(foreach bpkg, $(gpg4win_bpkgs), $(eval $(call BPKG_template,$(bpkg))))
 
+# Insert the template for each internal package.
+$(foreach ipkg, $(gpg4win_ipkgs), $(eval $(call IPKG_template,$(ipkg))))
 
-.PHONY : final
+# Insert the template for each README file.
+$(foreach rll, $(gpg4win_readme_ll), $(eval $(call README_template,$(rll))))
 
-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
+stamps/stamp-final: stamps/stamp-directories
+stamps/stamp-final: $(addprefix stamps/stamp-final-,$(gpg4win_build_list))
+       touch stamps/stamp-final
 
-all-gpg4win: final
+$(bdir)/versioninfo.txt: stamps/stamp-final
+       touch $(bdir)/versioninfo.txt
 
 
+all-gpg4win: stamps/stamp-final
+
 # Just to check if we catched all stamps.
 clean-stamps:
        $(RM) -fR $(stamps)
 
 clean-gpg4win:
-       $(RM) -fR playground stamps
\ No newline at end of file
+       $(RM) -fR playground stamps
+
+.PHONY : all-gpg4win clean-stamps clean-gpg4win