Commit f83ded01749f3ed6d706e3db9d35cbe5e90eb3bb

Werner Lemberg 2002-05-05T10:57:06

FreeType 2 can now be built in an external directory with the configure script also. * builds/freetype.mk (INCLUDES): Add `OBJ_DIR'. * builds/unix/detect.mk (have_mk): New variable to test for external build. (unix-def.mk): Defined according to value of `have_mk'. * builds/unix/unix.mk (have_mk): New variable to test for external build. Select include paths for unix-def.mk and unix-cc.mk according to value of `have_mk'. * builds/unix/unix-def.in (OBJ_BUILD): New variable. (DISTCLEAN): Use it. * builds/unix/unix-cc.in (LIBTOOL): Define default value only if not yet defined. * builds/unix/install.mk (install): Use `OBJ_BUILD' for installing freetype-config. * configure: Don't depend on bash features. (ft2_dir, abs_curr_dir, abs_ft2_dir): New variables (code partially taken from Autoconf). Build a dummy Makefile if not building in source tree. * docs/INSTALL: Document it.

diff --git a/ChangeLog b/ChangeLog
index 949e8f1..e8bef62 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,31 @@
+2002-05-05  Werner Lemberg  <wl@gnu.org>
+
+	FreeType 2 can now be built in an external directory with the
+	configure script also.
+
+	* builds/freetype.mk (INCLUDES): Add `OBJ_DIR'.
+
+	* builds/unix/detect.mk (have_mk): New variable to test for
+	external build.
+	(unix-def.mk): Defined according to value of `have_mk'.
+	* builds/unix/unix.mk (have_mk): New variable to test for
+	external build.
+	Select include paths for unix-def.mk and unix-cc.mk according
+	to value of `have_mk'.
+	* builds/unix/unix-def.in (OBJ_BUILD): New variable.
+	(DISTCLEAN): Use it.
+	* builds/unix/unix-cc.in (LIBTOOL): Define default value only
+	if not yet defined.
+	* builds/unix/install.mk (install): Use `OBJ_BUILD' for installing
+	freetype-config.
+
+	* configure: Don't depend on bash features.
+	(ft2_dir, abs_curr_dir, abs_ft2_dir): New variables (code
+	partially taken from Autoconf).
+	Build a dummy Makefile if not building in source tree.
+
+	* docs/INSTALL: Document it.
+
 2002-05-04  David Turner  <david@freetype.org>
 
 	* src/truetype/ttgload.c (TT_Load_Glyph): Finally fixing the last
diff --git a/builds/freetype.mk b/builds/freetype.mk
index 62e42ea..96473d8 100644
--- a/builds/freetype.mk
+++ b/builds/freetype.mk
@@ -130,7 +130,7 @@ PROJECT_LIBRARY := $(LIB_)$(LIBRARY).$A
 #                 in the `freetype/builds/<system>' directory, as these
 #                 files will override the default sources.
 #
-INCLUDES := $(BUILD) $(TOP)$(SEP)include
+INCLUDES := $(OBJ_DIR) $(BUILD) $(TOP)$(SEP)include
 
 INCLUDE_FLAGS = $(INCLUDES:%=$I%)
 
diff --git a/builds/unix/detect.mk b/builds/unix/detect.mk
index 6af635c..a6eb658 100644
--- a/builds/unix/detect.mk
+++ b/builds/unix/detect.mk
@@ -3,7 +3,7 @@
 #
 
 
-# Copyright 1996-2000 by
+# Copyright 1996-2000, 2002 by
 # David Turner, Robert Wilhelm, and Werner Lemberg.
 #
 # This file is part of the FreeType project, and may only be used, modified,
@@ -72,8 +72,15 @@ ifeq ($(PLATFORM),unix)
 
   setup: std_setup
 
-  unix-def.mk: $(TOP)/builds/unix/unix-def.in
-	  cd builds/unix; ./configure $(CFG)
+  have_mk := $(strip $(wildcard $(OBJ_DIR)/Makefile))
+  ifneq ($(have_mk),)
+    # we are building FT2 not in the src tree
+    unix-def.mk: $(TOP)/builds/unix/unix-def.in
+	    $(TOP)/builds/unix/configure $(CFG)
+  else
+    unix-def.mk: $(TOP)/builds/unix/unix-def.in
+	    cd builds/unix; ./configure $(CFG)
+  endif
 
 endif   # test PLATFORM unix
 
diff --git a/builds/unix/install.mk b/builds/unix/install.mk
index 161ce06..add09b3 100644
--- a/builds/unix/install.mk
+++ b/builds/unix/install.mk
@@ -36,7 +36,7 @@ install: $(PROJECT_LIBRARY)
           $(INSTALL_DATA) $$P $(includedir)/freetype2/freetype/cache ; \
         done
 	$(INSTALL_DATA) $(BUILD)/ft2unix.h $(includedir)/ft2build.h
-	$(INSTALL_SCRIPT) -m 755 $(BUILD)/freetype-config \
+	$(INSTALL_SCRIPT) -m 755 $(OBJ_BUILD)/freetype-config \
           $(bindir)/freetype-config
 
 
diff --git a/builds/unix/unix-cc.in b/builds/unix/unix-cc.in
index 0e53a65..7a87396 100644
--- a/builds/unix/unix-cc.in
+++ b/builds/unix/unix-cc.in
@@ -3,7 +3,9 @@
 
 CC      := @CC@
 
-LIBTOOL := $(BUILD)/libtool
+ifndef LIBTOOL
+  LIBTOOL := $(BUILD)/libtool
+endif
 
 
 # The object file extension (for standard and static libraries).  This can be
diff --git a/builds/unix/unix-def.in b/builds/unix/unix-def.in
index f7781bc..6fcf06e 100644
--- a/builds/unix/unix-def.in
+++ b/builds/unix/unix-def.in
@@ -3,7 +3,7 @@
 #
 
 
-# Copyright 1996-2000 by
+# Copyright 1996-2000, 2002 by
 # David Turner, Robert Wilhelm, and Werner Lemberg.
 #
 # This file is part of the FreeType project, and may only be used, modified,
@@ -18,12 +18,17 @@ ifndef TOP
 endif
 TOP := $(shell cd $(TOP); pwd)
 
-DELETE        := @RMF@
-DELDIR        := @RMDIR@
-SEP           := /
-HOSTSEP       := $(SEP)
-BUILD         := $(TOP)/builds/unix
-PLATFORM      := unix
+DELETE   := @RMF@
+DELDIR   := @RMDIR@
+SEP      := /
+HOSTSEP  := $(SEP)
+BUILD    := $(TOP)/builds/unix
+PLATFORM := unix
+
+# this is used for `make distclean' and `make install'
+ifndef OBJ_BUILD
+  OBJ_BUILD := $(BUILD)
+endif
 
 # don't use `:=' here since the path stuff will be included after this file
 #
@@ -35,14 +40,15 @@ INSTALL_PROGRAM := @INSTALL_PROGRAM@
 INSTALL_SCRIPT  := @INSTALL_SCRIPT@
 MKINSTALLDIRS   := $(BUILD)/mkinstalldirs
 
-DISTCLEAN += $(BUILD)/config.cache    \
-             $(BUILD)/config.log      \
-             $(BUILD)/config.status   \
-             $(BUILD)/unix-def.mk     \
-             $(BUILD)/unix-cc.mk      \
-             $(BUILD)/ftconfig.h      \
-             $(BUILD)/freetype-config \
-             $(LIBTOOL)
+DISTCLEAN += $(OBJ_BUILD)/config.cache    \
+             $(OBJ_BUILD)/config.log      \
+             $(OBJ_BUILD)/config.status   \
+             $(OBJ_BUILD)/unix-def.mk     \
+             $(OBJ_BUILD)/unix-cc.mk      \
+             $(OBJ_BUILD)/ftconfig.h      \
+             $(OBJ_BUILD)/freetype-config \
+             $(LIBTOOL)                   \
+             $(OBJ_BUILD)/Makefile
 
 
 # Standard installation variables.
diff --git a/builds/unix/unix.mk b/builds/unix/unix.mk
index 5488d7b..57d951a 100644
--- a/builds/unix/unix.mk
+++ b/builds/unix/unix.mk
@@ -3,7 +3,7 @@
 #
 
 
-# Copyright 1996-2000 by
+# Copyright 1996-2000, 2002 by
 # David Turner, Robert Wilhelm, and Werner Lemberg.
 #
 # This file is part of the FreeType project, and may only be used, modified,
@@ -12,9 +12,15 @@
 # indicate that you have read the license and understand and accept it
 # fully.
 
-
-include $(TOP)/builds/unix/unix-def.mk
-include $(TOP)/builds/unix/unix-cc.mk
+have_mk := $(strip $(wildcard $(TOP)/builds/unix/unix-def.mk))
+ifneq ($(have_mk),)
+  include $(TOP)/builds/unix/unix-def.mk
+  include $(TOP)/builds/unix/unix-cc.mk
+else
+  # we are building FT2 not in the src tree
+  include $(OBJ_DIR)/unix-def.mk
+  include $(OBJ_DIR)/unix-cc.mk
+endif
 
 ifdef BUILD_PROJECT
 
diff --git a/configure b/configure
index bd4c523..982a1df 100644
--- a/configure
+++ b/configure
@@ -9,14 +9,52 @@
 #   install
 #
 
-if [ "x$GNUMAKE" = x ]; then
+if test "x$GNUMAKE" = x; then
   GNUMAKE=make
 fi
 
-if [ `$GNUMAKE -v 2>/dev/null|grep -ic gnu` -eq 0 ]; then
+if test -z "`$GNUMAKE -v 2>/dev/null | grep GNU`"; then
   echo "Sorry, GNU make is required to build FreeType2." >&2
   echo "Please try \`GNUMAKE=<GNU make command name> $0'." >&2
   exit 1
 fi
 
+# Uh, oh.  This is taken from autoconf.  They know what they are doing...
+
+if expr a : '\(a\)' >/dev/null 2>&1; then
+  ft_expr=expr
+else
+  ft_expr=false
+fi
+
+ft2_dir=`(dirname "$0") 2>/dev/null ||
+$ft_expr X"$0" : 'X\(.*[^/]\)//*[^/][^/]*/*$' \| \
+         X"$0" : 'X\(//\)[^/]' \| \
+         X"$0" : 'X\(//\)$' \| \
+         X"$0" : 'X\(/\)' \| \
+         .     : '\(.\)' 2>/dev/null ||
+echo X"$0" |
+    sed '/^X\(.*[^/]\)\/\/*[^/][^/]*\/*$/{ s//\1/; q; }
+         /^X\(\/\/\)[^/].*/{ s//\1/; q; }
+         /^X\(\/\/\)$/{ s//\1/; q; }
+         /^X\(\/\).*/{ s//\1/; q; }
+         s/.*/./; q'`
+
+abs_curr_dir=`pwd`
+abs_ft2_dir=`cd "$ft2_dir" && pwd`
+
+# build a dummy Makefile if we are not building in the source tree
+
+if test "$abs_curr_dir" != "$abs_ft2_dir"; then
+  echo "OBJ_DIR=$abs_curr_dir"          > Makefile
+  echo "TOP=$abs_ft2_dir"              >> Makefile
+  echo "OBJ_BUILD=$abs_curr_dir"       >> Makefile
+  echo "LIBTOOL=$abs_curr_dir/libtool" >> Makefile
+  echo "include $abs_ft2_dir/Makefile" >> Makefile
+fi
+
+# call make
+
 CFG="$@" $GNUMAKE setup unix
+
+# eof
diff --git a/docs/INSTALL b/docs/INSTALL
index 70caa86..e959ed8 100644
--- a/docs/INSTALL
+++ b/docs/INSTALL
@@ -35,7 +35,6 @@ II. From the command line
   The second one is to use "GNU Make" (and NO OTHER MAKE TOOL).
 
 
-
   1. Building FT2 with "Jam"
   --------------------------
 
@@ -60,7 +59,6 @@ II. From the command line
     should become automatic on Unix systems.
 
 
-
   2. Building FT2 with "GNU Make"
   -------------------------------
 
@@ -119,8 +117,24 @@ II. From the command line
         - make setup lcc      -> Win32-LCC
 
 
-II. In your own environment (IDE)
----------------------------------
+  If you want  to build FreeType 2 in another  directory, you must set
+  two environment  variables, `OJB_DIR'  and `TOP'.  The  former gives
+  the  directory where  the object  files  and the  library should  be
+  created (this directory must exist), the latter the top directory of
+  the FreeType 2 source tree.  Example:
+
+    OBJ_DIR=~/freetype2.compiled TOP=~/freetype2 \
+      make -f$TOP/Makefile setup ansi
+    OBJ_DIR=~/freetype2.compiled TOP=~/freetype2 \
+      make -f$TOP/Makefile
+
+  On  Unix boxes,  calling  `configure' from  the  build directory  is
+  sufficient;  it  will  build  a  small   Makefile  which  calls  the
+  FreeType 2 Makefile with the necessary parameters.
+
+
+III. In your own environment (IDE)
+----------------------------------
 
   You need to add  the directories "freetype2/include" to your include
   path when compiling the library.