#!/bin/sh

# Copyright (C) 2000-2023 The Xastir Group
# <http://www.graphicsmagick.org/>

# Compile GraphicsMagick-1.1.7 under Linux Standard Base 3.0.
# Install into /opt/lsb-tmp/ directory structure.

# NOTE:
# "Free Standards Group, FSG, Linux Standard Base, LSB, Free
# Standards Certified, LSB Certified and the Free Standards
# Certified logo are trademarks, service marks and certification
# marks, as appropriate, of Free Standards Group in the United
# States and in other countries."
#
# We are in no way representing that Xastir has been certified by
# the FSG.  To do so costs real money.  We do intend some Xastir
# binaries to install and run properly on LSB-3.0 compliant x86
# Linux systems though...
#

#
# We need these additional libraries before compiling
# GraphicsMagick:
#
# ftp://ftp.uu.net/graphics/jpeg/jpegsrc.v6b.tar.gz
# http://www.libpng.org/pub/png/pngcode.html
# ftp://ftp.remotesensing.org/libtiff/
# http://www.gzip.org/zlib/
# http://www.ece.uvic.ca/~mdadams/jasper/

export PATH=${PATH}:/opt/lsb/bin
export LSBCC_WARN=1

# A colon-separated list of "extra" shared libraries to link with
# the application.  Each shared lib must be LSB-compliant and must
# be distributed along with the application.
#export LSBCC_SHAREDLIBS=

# Change freetype2 to LSB include directory in configure.
sed -i -e 's@{freetype_prefix}/include/freetype2@/opt/lsb/include@g' configure

# Remove "-std=gnu99 -c99" from configure else we'll get a some
# libraries compiled in that we don't wish 'cuz the lsbcc compiler
# won't get used.
sed -i -e 's/-std=gnu99 -c99//g' configure

CC=lsbcc CXX=lsbc++ ./configure \
    --prefix=/opt/lsb-tmp \
    --exec_prefix=/opt/lsb-tmp \
    --enable-static \
    --disable-shared \
    --without-magick-plus-plus \
    --without-perl \
    --x-libraries=/opt/lsb/lib \
    --without-x \
    --enable-libtool-verbose \
    --enable-maintainer-mode \
    --without-freetype \
    --without-freetype2 \
    --without-gslib \
    --with-quantum-depth=16
# --disable-installed

make clean

(CPPFLAGS="-I/opt/lsb/include" LDFLAGS="/opt/lsb/lib" make 2>&1) | tee make.log

#CPPFLAGS="-I/opt/lsb/include" LDFLAGS="/opt/lsb/lib" make -n install
CPPFLAGS="-I/opt/lsb/include" LDFLAGS="/opt/lsb/lib" sudo make install

# The Make has bombed out at this point, so finish the compile of
# "gm" in the utilities directory
(cd utilities; \
    /opt/lsb/bin/lsbcc -g -O2 -Wall -o gm gm.o \
        ../magick/.libs/libGraphicsMagick.a \
        -L/opt/lsb/lib -ltiff -ljasper -lpng -lz -lm -lpthread -ljpeg; \
   strip gm; \
   sudo make install)


