aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitignore1
-rwxr-xr-xconfigure17
-rw-r--r--thumbnail/Makefile36
-rwxr-xr-xthumbnail/configure144
-rw-r--r--thumbnail/main.c2
5 files changed, 160 insertions, 40 deletions
diff --git a/.gitignore b/.gitignore
index 759af02..c72486a 100644
--- a/.gitignore
+++ b/.gitignore
@@ -2,6 +2,7 @@ build/
/slcl
/usergen
thumbnail/thumbnail
+/thumbnail/Makefile
*.a
*.o
*.d
diff --git a/configure b/configure
index 4f42953..35a0743 100755
--- a/configure
+++ b/configure
@@ -177,7 +177,7 @@ EOF
if [ $build_thumbnail -ne 0 ]
then
cat <<"EOF" >> $F
- +cd thumbnail && $(MAKE) PREFIX=$(PREFIX) install
+ +test -f $(THUMBNAIL_MK) && cd thumbnail && $(MAKE) install || :
EOF
fi
@@ -218,9 +218,13 @@ if [ $build_thumbnail -ne 0 ]
then
cat <<"EOF" >> $F
THUMBNAIL = thumbnail/thumbnail
+THUMBNAIL_MK = thumbnail/Makefile
thumbnail $(PROJECT): $(THUMBNAIL)
-$(THUMBNAIL): FORCE
+$(THUMBNAIL_MK):
+ cd thumbnail && CFLAGS="$(CFLAGS)" ./configure --prefix=$(PREFIX)
+$(THUMBNAIL): $(THUMBNAIL_MK) FORCE
+cd thumbnail && $(MAKE) CC=$(CC)
+all: $(THUMBNAIL)
EOF
fi
@@ -250,6 +254,13 @@ cat <<"EOF" >> $F
EOF
fi
+if [ $build_thumbnail -ne 0 ]
+then
+cat <<"EOF" >> $F
+ +test -f $(THUMBNAIL_MK) && cd thumbnail && $(MAKE) clean || :
+EOF
+fi
+
cat <<"EOF" >> $F
distclean: clean
rm -f slcl usergen
@@ -275,7 +286,7 @@ fi
if [ $build_thumbnail -ne 0 ]
then
cat <<"EOF" >> $F
- +cd thumbnail && $(MAKE) distclean
+ +test -f $(THUMBNAIL_MK) && cd thumbnail && $(MAKE) distclean || :
EOF
fi
diff --git a/thumbnail/Makefile b/thumbnail/Makefile
deleted file mode 100644
index 4ed1944..0000000
--- a/thumbnail/Makefile
+++ /dev/null
@@ -1,36 +0,0 @@
-.POSIX:
-
-PROJECT = thumbnail
-PREFIX = /usr/local
-O = -Og
-CDEFS = -D_FILE_OFFSET_BITS=64 # Required for large file support on 32-bit.
-CFLAGS = $(O) $(CDEFS) -g -Wall -I../libweb/dynstr/include -I. \
- $$(pkg-config --cflags ImageMagick) -MD -MF $(@:.o=.d)
-LDFLAGS = $(LIBS)
-DEPS = $(OBJECTS:.o=.d)
-DYNSTR = ../libweb/dynstr/libdynstr.a
-DYNSTR_LIBS = -L../libweb/dynstr -ldynstr
-LIBS = $$(pkg-config --libs ImageMagick) $(DYNSTR_LIBS)
-OBJECTS = \
- crealpath.o \
- main.o \
- cftw.o
-
-all: $(PROJECT)
-
-install: all
- cp thumbnail $(PREFIX)/bin/
-
-clean:
- rm -f $(OBJECTS) $(DEPS)
-
-distclean: clean
- rm -f $(PROJECT)
-
-$(PROJECT): $(OBJECTS) $(DYNSTR)
- $(CC) $(OBJECTS) $(LDFLAGS) $(LIBS) -o $@
-
-$(DYNSTR):
- +cd ../dynstr && $(MAKE)
-
--include $(DEPS)
diff --git a/thumbnail/configure b/thumbnail/configure
new file mode 100755
index 0000000..3ca488b
--- /dev/null
+++ b/thumbnail/configure
@@ -0,0 +1,144 @@
+#! /bin/sh
+
+set -e
+
+default_prefix=/usr/local
+prefix=$default_prefix
+default_CC='c99'
+# FILE_OFFSET_BITS=64 is required for large file support on 32-bit platforms.
+default_CFLAGS='-O1 -D_FILE_OFFSET_BITS=64 -MD'
+
+CC=${CC:-$default_CC}
+
+help()
+{
+ cat <<-EOF
+$0 [OPTION ...]
+
+--prefix Set installation directory [$default_prefix]
+
+Some influential environment variables:
+ CC C compiler [$default_CC]
+ CFLAGS C compiler flags [$default_CFLAGS]
+ LDFLAGS Link-time flags [$default_LDFLAGS]
+EOF
+}
+
+while true; do
+ split_arg=0
+
+ if printf "%s" "$1" | grep -e '=' > /dev/null
+ then
+ key="$(printf "%s" "$1" | cut -d '=' -f1)"
+ value="$(printf "%s" "$1" | cut -d '=' -f2)"
+ split_arg=1
+ else
+ key="$1"
+ value="$2"
+ fi
+
+ case "$key" in
+ --prefix ) prefix="$value"; shift; test $split_arg -eq 0 && shift ;;
+ -h | --help ) help; exit 0 ;;
+ * ) test "$1" != "" && help && exit 1 || break ;;
+ esac
+done
+
+if pkg-config ImageMagick-im6
+then
+ CFLAGS="$(pkg-config --cflags ImageMagick-im6) $CFLAGS"
+ LDFLAGS="$(pkg-config --libs ImageMagick-im6) $LDFLAGS"
+else
+ echo "Error: ImageMagick-im6 not found." >&2
+ exit 1
+fi
+
+if pkg-config dynstr
+then
+ in_tree_dynstr=0
+ CFLAGS="$(pkg-config --cflags dynstr) $CFLAGS"
+ LDFLAGS="$(pkg-config --libs dynstr) $LDFLAGS"
+else
+ echo "Info: dynstr not found. Using in-tree copy" >&2
+ in_tree_dynstr=1
+ CFLAGS="-I../libweb/dynstr/include $CFLAGS"
+ LDFLAGS="-L../libweb/dynstr -ldynstr $LDFLAGS"
+fi
+
+CFLAGS="$default_CFLAGS $CFLAGS"
+LDFLAGS="$default_LDFLAGS $LDFLAGS"
+
+cleanup()
+{
+ rm -f $F
+}
+
+F=/tmp/Makefile.thumbnail
+trap cleanup EXIT
+
+cat <<EOF > $F
+.POSIX:
+
+CC = $CC
+PREFIX = $prefix
+DST = $prefix/bin
+CFLAGS = $CFLAGS
+LDFLAGS = $LDFLAGS
+EOF
+
+cat <<"EOF" >> $F
+.POSIX:
+
+PROJECT = thumbnail
+DEPS = $(OBJECTS:.o=.d)
+OBJECTS = \
+ crealpath.o \
+ main.o \
+ cftw.o
+
+all: $(PROJECT)
+
+FORCE:
+
+install: all
+ install $(PROJECT) $(PREFIX)/bin/
+
+$(PROJECT): $(OBJECTS) $(DYNSTR)
+ $(CC) $(OBJECTS) $(LDFLAGS) -o $@
+EOF
+
+if [ $in_tree_dynstr -ne 0 ]
+then
+cat <<"EOF" >> $F
+DYNSTR = ../libweb/dynstr/libdynstr.a
+$(PROJECT): $(DYNSTR)
+$(DYNSTR): FORCE
+ +cd ../libweb/dynstr && $(MAKE) CC=$(CC)
+EOF
+fi
+
+cat <<"EOF" >> $F
+clean:
+ rm -f $(OBJECTS) $(DEPS)
+EOF
+
+if [ $in_tree_dynstr -ne 0 ]
+then
+cat <<"EOF" >> $F
+ +cd ../libweb/dynstr && $(MAKE) clean
+EOF
+fi
+
+cat <<"EOF" >> $F
+distclean: clean
+ rm -f $(PROJECT)
+ rm Makefile
+EOF
+
+# dynstr has no distclean target as of the time of this writing.
+
+cat <<"EOF" >> $F
+-include $(DEPS)
+EOF
+
+mv $F Makefile
diff --git a/thumbnail/main.c b/thumbnail/main.c
index 7163043..c2bf27a 100644
--- a/thumbnail/main.c
+++ b/thumbnail/main.c
@@ -1,7 +1,7 @@
#define _POSIX_C_SOURCE 200809L
#include "crealpath.h"
-#include <cftw.h>
+#include "cftw.h"
#include <dynstr.h>
#include <magick/api.h>
#include <fcntl.h>