do ifopt --help
echo "Available options:
--enable-debug - Enable debug builds of the library and programs
--disable-debug - Disables building debug builds of the library and
programs
--enable-exclopts=x - Compile exclusively for the proccessor 'x'
--enable-platform=x - Compile assuming platform 'x'. Allowed platforms are
Win32, Unix, MacOSX, and DOS
--disable-platform - Do not assume a platform, eg. autodetect
--disable-xvoverlay - Disables Xv support in explay for YUV overlays
--enable-xvoverlay - Re-enables Xv support
--disable-ogg - Disables Ogg Vorbis/Theora support
--enable-ogg - Re-enables Ogg Vorbis/Theora support
--disable-mpa - Disables MPEG audio support
--enable-mpa - Re-enables MPEG audio support
--verbose - Show raw commands being given to the system in place
of the human-readable messages
--disable-gui - Disable use of KDE's GUI while building
--write-config - Writes the settings to a config file (default is
'settings.cbd'), which will be automatically loaded
on later runs
--use-config=x - Use config file 'x' instead of 'settings.cbd'
--install - Automatically install, without prompting
Available targets:
showconfig - Shows some of the settings that will be used for compiling
clean - Delete the lib, temp files, and programs of the current build
srcpkg - For development use, uses the 'rm' command to clean backup
files and 'tar' to package up an archive
Note: You do not need to specify --disable-ogg or -disable-xvoverlay if you do
not have them. The script will automatically disable them if they aren't
detected.
"
exit 0
done
ifopt --verbose verbose 1
# Check if we're building a src package
do ifopt srcpkg
APEG_PKG ?= 'apeg-src.tar.bz2'
@Call rm -rf *.bak~ */*.bak~ */*/*.bak~ ${APEG_PKG}
echo Packaging up APEG into ${APEG_PKG}...
@chdir ..
@Call tar -chjf "${APEG_PKG}" apeg --exclude=apeg/settings.cbd --exclude=apeg/cbuild
@chdir apeg
Exit 0
done
define dialog noop
define dcop noop
define error echo '${*}'
do ifnopt --disable-gui
# Locate dcop and make sure it's running. Also, look for kdialog.
DCOP = $(*which dcop)
do ifnot ${'DCOP'}=''
setoutput /dev/null
@!call ${'DCOP'}
do ifret 0
DIALOG = $(*which kdialog)
if ${'DIALOG'}='' DCOP = ''
else
DCOP = ''
done
setoutput
done
# If KDE's not available, bail out and go console-only
if ${'DCOP'}='' goto skip_gui
define dialog @!readexec '"${1}"' \'${'DIALOG'}\' '${@2}'
define dcop @!call \'${'DCOP'}\' '${\'DCOP_REF\'} ${@}'
define error @!call \'${'DIALOG'}\' '--title "APEG Error" --error ${@}'
else
DCOP = ''
done
:skip_gui
# Set/load config file
CFG_FILE ?= $(*getoptval --use-config)
CFG_FILE ?= settings.cbd
!invoke ${'CFG_FILE'}
# Get platform
PLATCHECK = $(*getoptval --enable-platform)
do ifnot ${'PLATCHECK'}=''
PLAT = ${'PLATCHECK'}
else
ifopt --disable-platform PLAT = ''
done
put 'Checking platform... '
do if ${'PLAT'}=''
ifplat win32 PLAT = Win32
ifplat msdos PLAT = DOS
ifplat unix PLAT = Unix
ifplat macosx PLAT = MacOSX
else
# Fix up capitalization..
do if $(*tolower ${'PLAT'})='win32'
PLAT = Win32
else if $(*tolower ${'PLAT'})='dos'
PLAT = DOS
else if $(*tolower ${'PLAT'})='unix'
PLAT = Unix
else if $(*tolower ${'PLAT'})='macosx'
PLAT = MacOSX
else
error 'Unknown platform "'${'PLAT'}'" specified!'
exit 1
done
done
echo ${'PLAT'}
# Set object and dependacy file directories
OBJ_DIR = obj/${'PLAT'}
DEP_DIR = dep/${'PLAT'}
# Check for debugging
do ifopt --enable-debug
DEBUGMODE = 1
else
ifopt --disable-debug DEBUGMODE = 0
DEBUGMODE ?= 0
done
do if ${'DEBUGMODE'}='1'
CPPFLAGS = '-DDEBUGMODE '
CFLAGS = '-MMD -W -Wall -Werror -g3'
OBJ_EXT = 'd.o'
DEP_EXT = 'd.d'
EXE_EXT = -dbg${'EXE_EXT'}
LIB_NAME = apgd
else
# Optimized settings
do ifopt --enable-exclopts
ARCH_TYPE = $(*getoptval --enable-exclopts)
else if ${'PLAT'}='Win32'
ARCH_TYPE ?= pentium
done
CFLAGS ?= "-W -Wall -O3 -ffast-math -funroll-loops -fomit-frame-pointer"
ifopt --enable-strictwarn CFLAGS = "-Werror "${'CFLAGS'}
LIB_NAME = apeg
done
CPPFLAGS += '-Iinclude'
# Check for MPEG audio support
do ifopt --enable-mpa
NO_MPA = 0
else
ifopt --disable-mpa NO_MPA = 1
NO_MPA ?= 0
done
if ${'NO_MPA'}='1' CPPFLAGS = '-DDISABLE_MPEG_AUDIO '${'CPPFLAGS'}
# Set the Allegro(GL) libraries we'll be needing
if ${'PLAT'}='MacOSX' goto set_unix
do if ${'PLAT'}='Unix'
:set_unix
do ifnot ${'DEBUGMODE'}='1'
AL_LIBS = ' `allegro-config --libs`'
AGL_LIBS = '-lagl -lGL -lGLU '
else
AL_LIBS = ' `allegro-config --libs debug`'
AGL_LIBS = '-lagld -lGL -lGLU '
done
else if ${'PLAT'}='Win32'
do ifopt --enable-static
STATICLINK=1
else
ifopt --disable-static STATICLINK = 0
if ${'STATICLINK'}='' STATICLINK = 0
done
do ifnot ${'STATICLINK'}='1'
do ifnot ${'DEBUGMODE'}='1'
AL_LIBS = ' -lalleg'
AGL_LIBS = '-lagl '
else
AL_LIBS = ' -lalld'
AGL_LIBS = '-lagld '
done
AGL_LIBS += '-luser32 -lgdi32 -lopengl32 -lglu32 '
else
do ifnot ${'DEBUGMODE'}='1'
AL_LIBS = ' -lalleg_s'
AGL_LIBS = '-lagl_s '
else
AL_LIBS = ' -lalld_s'
AGL_LIBS = '-lagld_s '
done
AL_LIBS += ' -lkernel32 -luser32 -lgdi32 -lcomdlg32 -lole32 -ldinput -lddraw -ldxguid -lwinmm -ldsound'
AGL_LIBS += '-lopengl32 -lglu32 '
CPPFLAGS = '-DALLEGRO_STATICLINK '${'CPPFLAGS'}
LIB_NAME += _s
done
else if ${'PLAT'}='DOS'
do ifnot ${'DEBUGMODE'}='1'
AL_LIBS = ' -lalleg'
AGL_LIBS = '-lagl '
else
AL_LIBS = ' -lalld'
AGL_LIBS = '-lagld '
done
AGL_LIBS += '-lGL -lGLU '
else
error "* Unknown platform '"${'PLAT'}"'! *"
exit 1
done
# Set installation path
ifopt --install-path INSTALL_PATH = $(*getoptval --install-path)
do if ${'INSTALL_PATH'}=''
do if ${'PLAT'}='Win32'
do if ${'MINGDIR'}=''
error "Your MINGDIR environment variable is not set!"
exit 1
done
INSTALL_PATH = ${'MINGDIR'}
else if ${'PLAT'}='DOS'
do if ${'DJDIR'}=''
echo "Your DJDIR environment variable is not set!"
exit 1
done
INSTALL_PATH = ${'DJDIR'}
else
INSTALL_PATH = '/usr/local'
done
done
fixpath INSTALL_PATH
# Uninstall from the set installation path
do ifopt uninstall
echo * Uninstalling APEG *
do ifnot ${'DCOP'}=''
NEED_PERM = ''
ifexist ${'INSTALL_PATH'}/include/apeg.h \
ifnwrite ${'INSTALL_PATH'}/include/apeg.h NEED_PERM = 1
ifexist $(*libname ${'INSTALL_PATH'}/lib/${'LIB_NAME'}) \
ifnwrite $(*libname ${'INSTALL_PATH'}/lib/${'LIB_NAME'}) NEED_PERM = 1
do ifnot ${'NEED_PERM'}=''
!call kdesu -t -c "rm ${'INSTALL_PATH'}/include/apeg.h \&\& rm $(*libname ${'INSTALL_PATH'}/lib/${'LIB_NAME'})"
do ifnret 0
error "Error uninstalling APEG from "${'INSTALL_PATH'}"!"
exit 1
done
exit 0
done
done
-rmlib ${'INSTALL_PATH'}/lib/${'LIB_NAME'}
-rm ${'INSTALL_PATH'}/include/apeg.h
exit 0
done
# Check if we should be cleaning up
ifopt clean goto clean
AR_OPT=rcs
do ifnot ${'DCOP'}=''
seterror /dev/null
dialog DCOP_REF --title "Building APEG" --progressbar "Step 1 of 4
Checking for Ogg support..." 3
ifret 0 define atexit_dcop dcop close
seterror
done
# Check Ogg, and set the appropriate CPPFLAGS or libs
FORCE_OGG = 0
do ifopt --disable-ogg
NO_OGG = 1
else
do ifopt --enable-ogg
FORCE_OGG = 1
goto check_ogg
done
done
do if ${'NO_OGG'}=''
:check_ogg
!writefile tmp.c '/* testfile for Ogg. safe to delete */
#include
#include
#include
int main() { return 0; }'
do ifret 0
put 'Testing for Ogg support... '
seterror ogg-err.log
@!Call ${CC} ${OUT_OPT}tmp${EXE_EXT} tmp.c -ltheora -lvorbis -lvorbisenc -logg
do ifret 0
seterror
@!rm ogg-err.log
NO_OGG = 0
echo ok
else
seterror
NO_OGG = 1
echo failed, error logged (ogg-err.log)
done
@!rm tmp${EXE_EXT}
@!rm tmp.c
else
echo * Could not test Ogg, support disabled *
NO_OGG = 1
done
done
dcop setProgress 1
do ifnot "${NO_OGG}"="1"
OGG_LIBS = ' -ltheora -lvorbis -lvorbisenc -logg'
else
do ifnot "${FORCE_OGG}"="0"
error "Ogg support requested but is not available!
Aborting"
exit 1
done
OGG_LIBS = ''
CPPFLAGS += ' -DNO_OGG'
done
FORCE_OGG =
# Check/test for Xv support
dcop setLabel "Step 1 of 4
Checking for Xv support..."
FORCE_XV = 0
do ifopt --disable-xvoverlay
USE_XV = 0
else
do ifopt --enable-xvoverlay
FORCE_XV = 1
goto check_xv
done
done
do if ${'USE_XV'}=''
:check_xv
!writefile tmp.c '/* testfile for Xv. safe to delete */
#include
#include
#include
#include
#include
#include
int main() { return 0; }'
do ifret 0
put 'Testing for Xv support... '
seterror xv-err.log
@!Call ${CC} ${OUT_OPT}tmp${EXE_EXT} tmp.c -lXv
do ifret 0
seterror
@!rm xv-err.log
USE_XV = 1
echo ok
else
seterror
USE_XV = 0
echo failed, error logged (xv-err.log)
done
@!rm tmp${EXE_EXT}
@!rm tmp.c
else
echo * Could not test Xv, support disabled *
USE_XV = 0
done
done
dcop setProgress 2
do if ${'USE_XV'}='1'
XV_LIBS = '-lXv '
else
do ifnot "${FORCE_XV}"="0"
error "Xv overlay support requested but is not available!
Aborting"
exit 1
done
XV_LIBS = ''
done
FORCE_XV = ''
# Check Ogg, and set the appropriate CPPFLAGS or libs
dcop setLabel "Step 1 of 4
Checking for AGUP support..."
FORCE_AGUP = 0
do ifopt --disable-agup
NO_AGUP = 1
else
do ifopt --enable-agup
FORCE_AGUP = 1
goto check_agup
done
done
do if ${'NO_AGUP'}=''
:check_agup
!writefile tmp.c '/* testfile for AGUP. safe to delete */
#include
#include "agup.h"
int main() { return 0; }'
do ifret 0
put 'Testing for AGUP support... '
seterror agup-err.log
@!Call ${CC} ${OUT_OPT}tmp${EXE_EXT} tmp.c -lagup ${AL_LIBS}
do ifret 0
seterror
@!rm agup-err.log
NO_AGUP = 0
AGUP_LOCAL = 0
echo ok
else
seterror
echo failed, attempting to build local copy...
echo ''
!call make -C .agup CBUILD=1 DEBUGMODE= $(ifeq $(*which sh.exe)$(*which sh),'','','UNIXTOOLS=1')
do ifret 0
!call make -C .agup CBUILD=1 DEBUGMODE=1 $(ifeq $(*which sh.exe)$(*which sh),'','','UNIXTOOLS=1')
AGUP_LOCAL = 1
NO_AGUP = 0
else
NO_AGUP = 1
AGUP_LOCAL = 0
echo ''
echo AGUP build failed! Not using AGUP.
done
echo ''
# NO_AGUP = 1
# echo failed, error logged (agup-err.log)
done
@!rm tmp${EXE_EXT}
@!rm tmp.c
else
echo * Could not test AGUP, support disabled *
NO_AGUP = 1
done
done
dcop setProgress 2
do ifnot "${NO_AGUP}"="1"
do ifnot "${AGUP_LOCAL}"="1"
AGUP_LIBS = '-lagup '
AGUP_FLAGS = ''
else
AGUP_LIBS = $(*ifeq ${'DEBUGMODE'},'1','.agup/lib/debug/libagupd.a ','.agup/lib/release/libagup.a ')
AGUP_FLAGS = ' -I.agup'
done
else
do ifnot "${FORCE_AGUP}"="0"
error "AGUP support requested but is not available!
Aborting"
exit 1
done
AGUP_LIBS = ''
done
FORCE_AGUP =
# Write out settings file
ifnexist ${'CFG_FILE'} goto write_cfg
do ifopt --write-config
:write_cfg
echo Writing settings to ${'CFG_FILE'}...
writefile ${'CFG_FILE'} \# File generated by cbuild. Be *very* careful if hand-editing!
appendfile ${'CFG_FILE'} PLAT ?= \"${'PLAT'}\"
appendfile ${'CFG_FILE'} NO_OGG ?= \"${'NO_OGG'}\"
appendfile ${'CFG_FILE'} NO_MPA ?= \"${'NO_MPA'}\"
appendfile ${'CFG_FILE'} NO_AGUP ?= \"${'NO_AGUP'}\"
appendfile ${'CFG_FILE'} AGUP_LOCAL ?= \"${'AGUP_LOCAL'}\"
appendfile ${'CFG_FILE'} USE_XV ?= \"${'USE_XV'}\"
appendfile ${'CFG_FILE'} CFLAGS ?= \"${'CFLAGS'}\"
appendfile ${'CFG_FILE'} ARCH_TYPE ?= \"${'ARCH_TYPE'}\"
appendfile ${'CFG_FILE'} INSTALL_PATH ?= \"${'INSTALL_PATH'}\"
appendfile ${'CFG_FILE'} DEBUGMODE ?= \"${'DEBUGMODE'}\"
appendfile ${'CFG_FILE'} STATICLINK ?= \"${'STATICLINK'}\"
echo ''
done
ifnot ${'ARCH_TYPE'}='' CFLAGS += " -march="${'ARCH_TYPE'}
LDFLAGS = $(*libname lib/${'PLAT'}/${LIB_NAME})"${OGG_LIBS}${AL_LIBS} -lm -s"
# Should we show the configuration?
do ifopt showconfig
echo ""
echo "Target platform is "${'PLAT'}
echo "CC = "${'CC'}
echo "AR = "${'AR'}
echo "CPPFLAGS = "${'CPPFLAGS'}
echo "CFLAGS = "${'CFLAGS'}
echo "LDFLAGS = "${'LDFLAGS'}
echo "INSTALL_PATH = "${'INSTALL_PATH'}
echo ""
echo "Ogg support $(ifeq ${'NO_OGG'},'1',disabled,enabled)"
echo "MPEG audio support $(ifeq ${'NO_MPA'},'1',disabled,enabled)"
echo "Xv support for examples $(ifeq ${'USE_XV'},'1',enabled,disabled)"
echo "AGUP support for Ogg encoder $(ifeq ${'NO_AGUP'},'1',disabled,enabled$(ifeq ${'AGUP_LOCAL'},'1',' (local)',''))"
echo "Building $(ifeq ${'DEBUGMODE'},'1',debugging,optimized) library"
echo "$(ifeq ${'STATICLINK'},'1',Building for static-linked Allegro
,)"
exit 0
done
# Create the object and dependancy directories for the target platform
ifnexist obj/. mkdir obj
ifnexist ${'OBJ_DIR'}/. mkdir ${'OBJ_DIR'}
ifnexist dep/. mkdir dep
ifnexist ${'DEP_DIR'}/. mkdir ${'DEP_DIR'}
ifnexist lib/. mkdir lib
ifnexist lib/${'PLAT'}/. mkdir lib/${'PLAT'}
# Compile the main lib
echo ''
echo '* Checking Library *'
src_paths src src/audio
FILES = display.c getbits.c gethdr.c idct.c mpeg1dec.c recon.c getblk.c getpic.c motion.c ogg.c audio.c common.c dct64.c decode_1to1.c decode_2to1.c decode_4to1.c layer1.c layer2.c layer3.c mpg123.c readers.c tabinit.c vbrhead.c
dcop setProgress 0
dcop setTotalSteps 24
compile
FNUM = 0
:loop_start
FILE = $(*word 1,${FILES})
dcop setLabel "Step 2 of 4
Compiling "${'FILE'}...
compileadd ${'FILE'}
FNUM = $(add ${FNUM},1)
dcop setProgress ${FNUM}
popfront FILES
ifnot ${'FILES'}='' goto loop_start
#loop_end
dcop setProgress ${FNUM}
dcop setLabel "Step 2 of 4
Creating "$(*libname ${'LIB_NAME'})...
Linklib lib/${'PLAT'}/${'LIB_NAME'}
dcop setProgress $(add ${FNUM},1)
# We want to relink the tools and examples if the lib changed
EXTRA_LD_DEPS = $(*libname lib/${'PLAT'}/${'LIB_NAME'})
# Compile the tools
echo ''
echo '* Checking Tools *'
src_paths tools
dcop setProgress 0
dcop setTotalSteps $(ifeq ${'NO_OGG'},1,4,6)
dcop setLabel "Step 3 of 4
Building demux"${'EXE_EXT'}...
Compile demux.c
dcop setProgress 1
Linkexec tools/demux
dcop setProgress 2
dcop setLabel "Step 3 of 4
Building dump_stream"${'EXE_EXT'}...
Compile dump_stream.c
dcop setProgress 3
Linkexec tools/dump_stream
dcop setProgress 4
do ifnot ${'NO_OGG'}='1'
do ifnot "${NO_AGUP}"="1"
dcop setLabel "Step 3 of 4
Building ogg_encoder"${'EXE_EXT'}...
LDFLAGS = ${'AGUP_LIBS'}${'LDFLAGS'}
CPPFLAGS += ${'AGUP_FLAGS'}
Compile ogg_encoder.c
dcop setProgress 5
Linkexec tools/ogg_encoder
LDFLAGS -= ${'AGUP_LIBS'}
ifnot ${'AGUP_FLAGS'}='' CPPFLAGS -= ${'AGUP_FLAGS'}
dcop setProgress 6
done
done
# Compile the examples
echo ''
echo '* Checking Examples *'
src_paths examples
do if ${'USE_XV'}='1'
CPPFLAGS = '-DUSE_XV '${'CPPFLAGS'}
LDFLAGS = ${'XV_LIBS'}${'LDFLAGS'}
done
dcop setProgress 0
dcop setTotalSteps 6
dcop setLabel "Step 4 of 4
Building exsimple"${'EXE_EXT'}...
Compile exsimple.c
dcop setProgress 1
Linkexec examples/exsimple
dcop setProgress 2
dcop setLabel "Step 4 of 4
Building explay"${'EXE_EXT'}...
Compile explay.c
dcop setProgress 3
Linkexec examples/explay
dcop setProgress 4
dcop setLabel "Step 4 of 4
Building exagl"${'EXE_EXT'}...
-Compile exagl.c
do ifret 0
dcop setProgress 5
LDFLAGS = ${'AGL_LIBS'}${'LDFLAGS'}
Linkexec examples/exagl
LDFLAGS -= ${'AGL_LIBS'}
dcop setProgress 6
done
dcop close
define atexit_dcop
# Install the lib
echo ''
echo '* Checking Install *'
ifnot ${'DCOP'}='' goto kde_install
do ifopt --install
INPUT = ${'INSTALL_PATH'}
goto check_dir
done
put 'Do you wish to install APEG? [y/N] '
read INPUT
ifnret 0 exit 1
if ${'INPUT'}='' goto skip_install
if $(*tolower ${'INPUT'})='n' goto skip_install
if $(*tolower ${'INPUT'})='no' goto skip_install
if $(*tolower ${'INPUT'})='y' goto input_ok
if $(*tolower ${'INPUT'})='yes' goto input_ok
echo "Invalid response '"${'INPUT'}"'"
echo "Aborting installation..."
goto end_install
:skip_install
echo "Skipping install..."
goto end_install
:input_ok
echo ""
echo "APEG will install to '"${'INSTALL_PATH'}"'."
echo "If you wish to use a different location, please specify it below (press enter"
echo "for the default, type 'abort' to abort installation)"
put "-> "
:get_path
read INPUT
ifnret 0 exit 1
fixpath INPUT
do ifnot ${'INPUT'}=''
if $(*tolower ${'INPUT'})='abort' goto skip_install
:check_dir
do ifnexist ${'INPUT'}/.
echo ""
echo "The directory '"${'INPUT'}"/' doesn't appear to be valid."
echo "Please specify a valid path, or 'abort' to abort installation."
put "-> "
goto get_path
done
INSTALL_PATH = ${'INPUT'}
INPUT =
done
copylib lib/${'PLAT'}/${'LIB_NAME'} ${'INSTALL_PATH'}/lib/
copy include/apeg.h ${'INSTALL_PATH'}/include/
goto end_install
:kde_install
seterror /dev/null
# Ask if the user wants to install, if they didn't previously specify to
do ifnopt --install
dialog '' --title "Install APEG?" --yesno "Do you wish to install APEG?"
ifnret 0 goto end_install
:kde_get_path
# Get the install path from the user
dialog INSTALL_PATH --title "Install APEG in..." --getexistingdirectory ${'INSTALL_PATH'}
ifnret 0 goto end_install
do ifnexist ${'INSTALL_PATH'}
error "Could not read install directory from kdialog!
Installation aborted!"
goto end_install
done
done
# If we don't have write permissions, we'll need to use kdesu to try and get
# them.
do ifwrite ${'INSTALL_PATH'}/.
@!call cp include/apeg.h ${'INSTALL_PATH'}/lib/ \&\& cp $(*libname lib/${'PLAT'}/${'LIB_NAME'}) ${'INSTALL_PATH'}/lib/
else
@!call kdesu -t -c "cp 'include/apeg.h' '"${'INSTALL_PATH'}"/include/' \&\& cp '"$(*libname lib/${'PLAT'}/${'LIB_NAME'})"' '"${'INSTALL_PATH'}"/lib/'"
done
# Make sure the copy succeeded
do ifnret 0
dialog '' --title "Error installing APEG" --warningyesno "Could not install APEG in "${'INSTALL_PATH'}"!
This may be due to invalid permissions. Please check with your system administrator.
Select a different location?"
ifret 0 goto kde_get_path
goto end_install
done
dialog '' --title "Install succeeded" --msgbox "Installation was successful!
APEG has been installed in "${'INSTALL_PATH'}"!"
:end_install
seterror
echo ''
echo '* Done! *'
echo ''
exit 0
:clean
# Clean up our mess...
-rmobj audio common dct64 decode_1to1 decode_2to1 decode_4to1 display getbits \
getblk gethdr getpic idct layer1 layer2 layer3 motion mpeg1dec mpg123 ogg \
readers recon tabinit vbrhead demux dump_stream ogg_encoder exsimple \
explay exagl
-rm obj/${'PLAT'} dep/${'PLAT'} obj dep
-rmexec tools/demux tools/dump_stream tools/ogg_encoder examples/exsimple \
examples/explay examples/exagl
-rmlib lib/${'PLAT'}/${'LIB_NAME'}
-rm lib/${'PLAT'} lib
exit 0