From e23cfdea60f087b39f8cb0bf31d87f7510638f85 Mon Sep 17 00:00:00 2001
From: Sam Hocevar <sam@hocevar.net>
Date: Thu, 20 Nov 2003 16:54:04 +0000
Subject: [PATCH]   * debian/control:     + Changed section to libs/libdevel
 instead of games/games.     + Changed package name to libcaca-dev.   *
 debian/rules:     + Use debian/compat instead of DH_COMPAT.     + Install
 README, BUGS and TODO into /usr/share/doc.   * caca-config.in:     + First
 version of the config script.   * configure.ac src/Makefile.am:     + Build a
 static PIC library as well.   * README TODO:     + Various updates.

---
 Makefile.am          |   4 +-
 README               |  22 ++++++++
 TODO                 |  12 +++++
 caca-config.in       | 123 +++++++++++++++++++++++++++++++++++++++++++
 configure.ac         |  15 ++++++
 debian/compat        |   1 +
 debian/control       |  13 ++---
 debian/rules         |   5 +-
 examples/Makefile.am |  17 +++---
 examples/demo.c      |   4 +-
 src/Makefile.am      |  10 +++-
 11 files changed, 206 insertions(+), 20 deletions(-)
 create mode 100644 caca-config.in
 create mode 100644 debian/compat

diff --git a/Makefile.am b/Makefile.am
index 6735677..3c420b1 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -5,6 +5,8 @@
 SUBDIRS = src examples
 DIST_SUBDIRS = $(SUBDIRS) autotools debian
 
-EXTRA_DIST = BUGS bootstrap
+EXTRA_DIST = BUGS bootstrap caca-config.in
 AUTOMAKE_OPTIONS = foreign dist-bzip2
 
+bin_SCRIPTS = caca-config
+
diff --git a/README b/README
index 9459ac7..61d293c 100644
--- a/README
+++ b/README
@@ -12,3 +12,25 @@ Building libcaca
  
      ./configure --enable-conio --host=i386-pc-msdosdjgpp
 
+
+Using libcaca
+
+   o  Compiling a libcaca program is fairly simple:
+
+      gcc -c foobar.c -o foobar.o `caca-config --cflags`
+      gcc foobar.o -o foobar `caca-config --libs`
+
+   o  If you are writing a shared object that uses libcaca, either a
+      dynamically loadable plug-in or a shared library, you should use
+      the `--plugin-libs' flag for libcaca:
+
+      gcc -fPIC -c libfoo.c -o libfoo.o `caca-config --cflags`
+      gcc -shared libfoo.o -o libfoo.so `caca-config --plugin-libs`
+
+
+Binary packages
+
+   o  As the API is not stable yet, everyone should statically link libcaca
+      with their programs or libraries. DO NOT DISTRIBUTE SHARED VERSIONS
+      OF LIBCACA.
+
diff --git a/TODO b/TODO
index e770772..07ea6b8 100644
--- a/TODO
+++ b/TODO
@@ -8,6 +8,8 @@ Low level stuff
    o  Better keyboard driver in an X terminal, see
       http://groups.yahoo.com/group/zepp/message/381
 
+   o  Write a window resize handler.
+
    o  DONE 12 Nov 2003: Port to conio.h
 
 
@@ -19,3 +21,13 @@ High level stuff
 
    o  Fix the thin ellipse rendering
 
+
+Misc
+
+   o  Draw a nicer logo sprite
+
+
+Documentation
+
+   o  Everything is still to do.
+
diff --git a/caca-config.in b/caca-config.in
new file mode 100644
index 0000000..d181122
--- /dev/null
+++ b/caca-config.in
@@ -0,0 +1,123 @@
+#! /bin/sh
+
+##  config script for libcaca -- Sam Hocevar <sam@zoy.org>
+##  $Id$
+
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+
+lib_dir=@libdir@
+include_dir=@includedir@
+
+@USE_SLANG_TRUE@libs_slang="-lslang"
+@USE_NCURSES_TRUE@libs_ncurses="-lncurses"
+libs="$libs_slang $libs_ncurses"
+
+usage()
+{
+  cat <<EOF
+Usage: caca-config [OPTIONS] [LIBRARIES]
+Options:
+   [--prefix[=DIR]]
+   [--exec-prefix[=DIR]]
+   [--version]
+   [--libs]
+   [--plugin-libs]
+   [--ldflags]
+   [--cflags]
+EOF
+  exit $1
+}
+
+if test $# -eq 0
+then
+  usage 1 1>&2
+fi
+
+while test $# -gt 0
+do
+  case "$1" in
+    -*=*) optarg=`echo "$1" | sed 's/[-_a-zA-Z0-9]*=//'` ;;
+    *) optarg= ;;
+  esac
+
+  case $1 in
+    --prefix=*)
+      prefix=$optarg
+      local_prefix=yes
+      ;;
+    --prefix)
+      echo_prefix=yes
+      ;;
+    --exec-prefix=*)
+      exec_prefix=$optarg
+      exec_prefix_set=yes
+      local_prefix=yes
+      ;;
+    --exec-prefix)
+      echo_exec_prefix=yes
+      ;;
+    --version)
+      echo @VERSION@
+      exit 0
+      ;;
+    --cflags)
+      echo_cflags=yes
+      ;;
+    --ldflags)
+      echo_ldflags=yes
+      ;;
+@NEED_PIC_TRUE@    --libs)
+@NEED_PIC_FALSE@    --libs | --plugin-libs)
+      echo_libs=yes
+      ;;
+@NEED_PIC_TRUE@    --plugin-libs)
+@NEED_PIC_TRUE@      echo_plugin_libs=yes
+@NEED_PIC_TRUE@      ;;
+    *)
+      usage 1 1>&2
+      ;;
+  esac
+  shift
+done
+
+if test "$local_prefix" = "yes"
+then
+  if test "$exec_prefix_set" != "yes"
+  then
+    exec_prefix=$prefix
+  fi
+fi
+
+if test "$echo_prefix" = "yes"
+then
+  echo $prefix
+fi
+
+if test "$echo_exec_prefix" = "yes"
+then
+  echo $exec_prefix
+fi
+
+if test "$echo_cflags" = "yes"
+then
+  cflags="-I$include_dir/"
+  echo $cflags
+fi
+
+if test "$echo_ldflags" = "yes"
+then
+  ldflags="-L$lib_dir"
+  echo $ldflags
+fi
+
+if test "$echo_libs" = "yes"
+then
+  echo -L@libdir@ -lcaca $libs
+fi
+
+@NEED_PIC_TRUE@if test "$echo_plugin_libs" = "yes"
+@NEED_PIC_TRUE@then
+@NEED_PIC_TRUE@  echo -L@libdir@ -lcaca_pic $libs
+@NEED_PIC_TRUE@fi
+
diff --git a/configure.ac b/configure.ac
index fd61d46..5b6dabb 100644
--- a/configure.ac
+++ b/configure.ac
@@ -58,11 +58,26 @@ CFLAGS="${CFLAGS} -g -O2 -fno-strength-reduce -fomit-frame-pointer"
 # Code qui fait des warnings == code de porc == deux baffes dans ta gueule
 CFLAGS="${CFLAGS} -Wall -Wpointer-arith -Wcast-align -Wcast-qual -Wstrict-prototypes -Wshadow -Waggregate-return -Wmissing-prototypes -Wnested-externs -Wsign-compare"
 
+# Build the PIC library?
+case "${target_os}" in
+  *mingw32* | *cygwin*)
+    NEED_PIC=false
+    ;;
+  *)
+    NEED_PIC=:
+    ;;
+esac
+
+AM_CONDITIONAL(NEED_PIC, ${NEED_PIC})
+
 AC_OUTPUT([
   Makefile
   src/Makefile
   examples/Makefile
   autotools/Makefile
   debian/Makefile
+  caca-config
+],[
+  chmod 0755 caca-config
 ])
 
diff --git a/debian/compat b/debian/compat
new file mode 100644
index 0000000..b8626c4
--- /dev/null
+++ b/debian/compat
@@ -0,0 +1 @@
+4
diff --git a/debian/control b/debian/control
index 3c73333..14baf3c 100644
--- a/debian/control
+++ b/debian/control
@@ -1,15 +1,16 @@
 Source: libcaca
-Section: games
+Section: libs
 Priority: optional
 Maintainer: Sam Hocevar (Debian packages) <sam+deb@zoy.org>
-Build-Depends: debhelper (>= 2.2.0), slang1-dev
+Build-Depends: debhelper (>= 4.0), slang1-dev
 Standards-Version: 3.6.1.0
 
-Package: libcaca
-Section: games
+Package: libcaca-dev
+Section: libdevel
 Architecture: any
 Depends: ${shlibs:Depends}
 Description: text mode graphics library
- libcaca is the Color ANSI Console Art library.
+ libcaca is the Colour AsCii Art library.
  .
- It rules.
+ This package contains the header files and static libraries needed to
+ compile applications or shared objects that use libcaca.
diff --git a/debian/rules b/debian/rules
index 6834e41..621bd9b 100755
--- a/debian/rules
+++ b/debian/rules
@@ -1,7 +1,6 @@
 #!/usr/bin/make -f
 
 #export DH_VERBOSE=1
-export DH_COMPAT=3
 export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
 export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
 
@@ -38,7 +37,7 @@ install: build
 	dh_testroot
 	dh_clean -k
 	dh_installdirs
-	DESTDIR=`pwd`/debian/libcaca/ $(MAKE) install prefix=/usr
+	DESTDIR=`pwd`/debian/libcaca-dev/ $(MAKE) install prefix=/usr
 
 # Build architecture-independent files here.
 binary-indep: build install
@@ -50,7 +49,7 @@ binary-arch: build install
 	dh_testdir
 	dh_testroot
 #	dh_installdebconf	
-	dh_installdocs
+	dh_installdocs README BUGS TODO
 #	dh_installexamples
 	dh_installmenu
 #	dh_installemacsen
diff --git a/examples/Makefile.am b/examples/Makefile.am
index 98cde77..47cef73 100644
--- a/examples/Makefile.am
+++ b/examples/Makefile.am
@@ -4,6 +4,8 @@
 
 AM_CPPFLAGS = -I$(top_srcdir)/src
 
+pkgdata_DATA = caca.txt
+
 EXTRA_DIST = caca.txt
 
 if USE_SLANG
@@ -13,13 +15,14 @@ if USE_NCURSES
 LDFLAGS_ncurses = -lncurses
 endif
 
-noinst_PROGRAMS = demo spritedit
+bin_PROGRAMS = caca-demo caca-spritedit
 
-demo_SOURCES = demo.c
-demo_LDADD = ../src/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
-demo_CFLAGS = `pkg-config --cflags gtk+-2.0`
-demo_LDFLAGS = `pkg-config --libs gtk+-2.0`
+caca_demo_SOURCES = demo.c
+caca_demo_LDADD = ../src/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
+caca_demo_CPPFLAGS = -DDATADIR=\"$(pkgdatadir)\"
+caca_demo_CFLAGS = `pkg-config --cflags gtk+-2.0`
+caca_demo_LDFLAGS = `pkg-config --libs gtk+-2.0`
 
-spritedit_SOURCES = spritedit.c
-spritedit_LDADD = ../src/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
+caca_spritedit_SOURCES = spritedit.c
+caca_spritedit_LDADD = ../src/libcaca.a $(LDFLAGS_slang) $(LDFLAGS_ncurses) -lm
 
diff --git a/examples/demo.c b/examples/demo.c
index 756d2d2..d78c0be 100644
--- a/examples/demo.c
+++ b/examples/demo.c
@@ -67,7 +67,9 @@ int main(int argc, char **argv)
     caca_set_delay(40000);
 
     /* Initialize data */
-    sprite = caca_load_sprite("caca.txt");
+    sprite = caca_load_sprite(DATADIR "/caca.txt");
+    if(!sprite)
+        sprite = caca_load_sprite("caca.txt");
     if(!sprite)
         sprite = caca_load_sprite("examples/caca.txt");
 
diff --git a/src/Makefile.am b/src/Makefile.am
index 8e11eb7..cc24729 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -2,7 +2,9 @@
 # Automake targets and declarations for libcaca
 ###############################################################################
 
-lib_LIBRARIES = libcaca.a
+include_HEADERS = caca.h
+
+lib_LIBRARIES = libcaca.a $(libcaca_pic_a)
 libcaca_a_SOURCES = \
 	caca.c \
 	caca.h \
@@ -18,5 +20,9 @@ libcaca_a_SOURCES = \
 	blit.c \
 	$(NULL)
 
-include_HEADERS = caca.h
+if NEED_PIC
+libcaca_pic_a = libcaca_pic.a
+endif
+libcaca_pic_a_SOURCES = $(libcaca_a_SOURCES)
+libcaca_pic_a_CPPFLAGS = -fPIC