2023-03-24 15:28:42 +01:00
#!/bin/bash
2023-05-01 18:46:11 +02:00
# spmenu build script
2023-04-22 00:26:50 +02:00
PREFIX = " ${ PREFIX :- /usr } "
DESTDIR = " ${ DESTDIR :- } "
INCDIR = " ${ INCDIR :- /usr/include } "
2023-04-26 10:01:11 +02:00
makebin = " ${ makebin :- $( command -v make) } "
2023-04-22 00:26:50 +02:00
cc = " ${ cc :- ${ CC :- gcc } } "
opt = " ${ opt :- ${ OPT :- -O2 } } "
warn = " ${ warn :- true } "
2023-03-24 15:28:42 +01:00
check_dist( ) {
2023-04-22 00:26:50 +02:00
[ -f "/etc/pacman.conf" ] && [ " $warn " != "false" ] && printf "hint: detected Pacman. if you want you can run 'makepkg' with proper arguments to install it using pacman.\n" && pacman = true
[ -f "/System/Library/CoreServices/SystemVersion.plist" ] && [ " $warn " != "false" ] && printf "hint: detected a Mac. Please report any issues you find as it is untested.\n" && mac = true
2023-03-24 15:28:42 +01:00
uname -a | grep -q OpenBSD && printf "hint: detected OpenBSD. Please report any issues you find as it is untested.\n" && openbsd = true
}
check( ) {
2023-04-26 10:01:11 +02:00
if [ " $mac " != "true" ] ; then
2023-03-24 15:28:42 +01:00
[ ! -x " $( command -v ldconfig) " ] && printf "ldconfig not found in %s. Please make sure your system is set up properly." "\$PATH" && exit 1
[ ! -x " $( command -v make) " ] && printf "make not found in %s. Please make sure your system is set up properly." "\$PATH" && exit 1
2023-04-22 00:26:50 +02:00
[ ! -x " $( command -v " $cc " ) " ] && printf "%s not found in %s. Please make sure your system is set up properly." " $cc " "\$PATH"
2023-03-24 15:28:42 +01:00
[ -n " $( ldconfig -p | grep Imlib2) " ] && printf "Imlib2 found\n" && imlib2 = true || imlib2 = false
[ -n " $( ldconfig -p | grep libXft) " ] && printf "libXft found\n" && xft = true || xft = false
[ -n " $( ldconfig -p | grep libX11) " ] && printf "libX11 found\n" && x11 = true || x11 = false
[ -n " $( ldconfig -p | grep libXrender) " ] && printf "libXrender found\n" && xrender = true || xrender = false
[ -n " $( ldconfig -p | grep libpango) " ] && printf "libpango found\n" && pango = true || pango = false
[ -n " $( ldconfig -p | grep libpangoxft) " ] && printf "libpangoxft found\n" && pangoxft = true || pangoxft = false
[ -n " $( ldconfig -p | grep libxcb-xinerama) " ] && printf "libxcb-xinerama found\n" && xinerama = true || xinerama = false
[ -n " $( ldconfig -p | grep libgnutls-openssl) " ] && printf "openssl found\n" && openssl = true || openssl = false
[ -n " $( ldconfig -p | grep fribidi) " ] && printf "fribidi found\n" && fribidi = true || fribidi = false
[ -n " $( ldconfig -p | grep freetype) " ] && printf "freetype found\n" && freetype = true || freetype = false
2023-04-04 21:39:38 +02:00
[ -n " $( ldconfig -p | grep libconfig) " ] && printf "libconfig found\n" && libconfig = true || libconfig = false
2023-04-26 10:01:11 +02:00
else
makebin = "gnumake"
GEN_MANUAL = "false"
2023-04-26 21:31:33 +02:00
PREFIX = "/usr/local"
2023-04-26 10:01:11 +02:00
fi
2023-03-24 15:28:42 +01:00
}
loadconf( ) {
[ -x "buildconf" ] && source buildconf
# mandatory deps
[ " $freetype " = "false" ] && printf "Freetype not found. Install it.\n" && exit 1
2023-03-28 21:46:23 +02:00
[ " $openssl " = "false" ] && [ " $imlib2 " = "true" ] && printf "OpenSSL not found. Install it.\n" && exit 1
2023-03-24 15:28:42 +01:00
[ " $xrender " = "false" ] && printf "libXrender not found. Install it.\n" && exit 1
[ " $x11 " = "false" ] && printf "libX11 not found. Install it.\n" && exit 1
[ " $xft " = "false" ] && printf "libXft not found. Install it.\n" && exit 1
}
build( ) {
# to be overriden
FREETYPEINC = " $INCDIR /freetype2 "
X11INC = "/usr/X11R6/include"
X11LIB = "/usr/X11R6/lib"
# macOS
if [ " $mac " = "true" ] ; then
INCDIR = "/usr/local/include"
FREETYPEINC = " $INCDIR /freetype2 "
X11INC = "/opt/X11/include"
X11LIB = "/opt/X11/lib"
fi
# openbsd
if [ " $openbsd " = "true" ] ; then
INCDIR = " $X11INC "
FREETYPEINC = " $INCDIR /freetype2 "
fi
# xinerama
if [ " $xinerama " = "true" ] ; then
xineramalib = "-lXinerama"
xineramatoggle = "-DXINERAMA"
fi
# imlib2
if [ " $imlib2 " = "true" ] ; then
imlib2libs = "-lImlib2"
imlib2toggle = "-DIMAGE"
fi
2023-03-28 21:46:23 +02:00
# openssl
if [ " $openssl " = "true" ] ; then
opensslconf = "openssl"
fi
2023-03-24 15:28:42 +01:00
# pango
if [ " $pango " = "true" ] && [ " $pangoxft " = "true" ] ; then
pangoconf = "pango"
pangoxftconf = "pangoxft"
pangotoggle = "-DPANGO"
fi
2023-04-04 21:39:38 +02:00
# libconfig
if [ " $libconfig " = "true" ] ; then
libconfigtoggle = "-DCONFIG"
libconfigconf = "libconfig"
fi
2023-03-24 15:28:42 +01:00
# fribidi
if [ " $fribidi " = "true" ] ; then
bdlibs = "-lfribidi"
bdinc = " $INCDIR /fribidi "
bdtoggle = "-DRTL"
2023-03-25 15:29:51 +01:00
else
bdlibs = ""
bdinc = ""
bdtoggle = ""
2023-03-24 15:28:42 +01:00
fi
2023-04-26 10:01:11 +02:00
$makebin clean
2023-04-29 13:34:59 +02:00
[ " $GEN_MANUAL " != "false" ] && [ -x " $( command -v pandoc) " ] && $makebin man
2023-03-28 21:46:23 +02:00
2023-04-26 10:01:11 +02:00
$makebin \
2023-04-22 00:26:50 +02:00
CC = " $cc " \
2023-03-24 15:28:42 +01:00
PREFIX = " $PREFIX " \
2023-05-01 20:08:52 +02:00
DESTDIR = " $DESTDIR " \
2023-04-22 00:26:50 +02:00
OPT = " $opt " \
2023-03-24 15:28:42 +01:00
XINERAMALIBS = " $xineramalib " \
XINERAMATOGGLE = " $xineramatoggle " \
IMLIB2LIBS = " $imlib2libs " \
IMLIB2TOGGLE = " $imlib2toggle " \
PANGOCONF = " $pangoconf " \
PANGOXFTCONF = " $pangoxftconf " \
PANGOTOGGLE = " $pangotoggle " \
BDLIBS = " $bdlibs " \
BDINC = " $bdinc " \
BDTOGGLE = " $bdtoggle " \
2023-03-25 15:29:51 +01:00
FREETYPEINC = " $FREETYPEINC " \
2023-03-28 21:46:23 +02:00
OPENSSLCONF = " $opensslconf " \
2023-04-04 21:39:38 +02:00
LIBCONFIGTOGGLE = " $libconfigtoggle " \
LIBCONFIGCONF = " $libconfigconf " \
2023-03-24 15:28:42 +01:00
X11LIB = " $X11LIB " \
X11INC = " $X11INC "
}
install( ) {
2023-04-26 10:01:11 +02:00
if [ " $mac " = "true" ] ; then
RULE = "install_mac"
else
RULE = "install"
fi
$makebin $RULE \
2023-04-22 00:26:50 +02:00
CC = " $cc " \
2023-03-24 15:28:42 +01:00
PREFIX = " $PREFIX " \
2023-04-22 00:26:50 +02:00
OPT = " $opt " \
2023-03-24 15:28:42 +01:00
XINERAMALIBS = " $xineramalib " \
XINERAMATOGGLE = " $xineramatoggle " \
IMLIB2LIBS = " $imlib2libs " \
IMLIB2TOGGLE = " $imlib2toggle " \
PANGOCONF = " $pangoconf " \
PANGOXFTCONF = " $pangoxftconf " \
PANGOTOGGLE = " $pangotoggle " \
BDLIBS = " $bdlibs " \
BDINC = " $bdinc " \
BDTOGGLE = " $bdtoggle " \
2023-03-25 15:29:51 +01:00
FREETYPEINC = " $FREETYPEINC " \
2023-03-28 21:46:23 +02:00
OPENSSLCONF = " $opensslconf " \
2023-04-04 21:39:38 +02:00
LIBCONFIGTOGGLE = " $libconfigtoggle " \
LIBCONFIGCONF = " $libconfigconf " \
2023-03-24 15:28:42 +01:00
X11LIB = " $X11LIB " \
X11INC = " $X11INC "
}
2023-04-26 10:01:11 +02:00
[ " $1 " = "--no-install" ] && install = false
2023-03-29 15:33:58 +02:00
2023-03-24 15:28:42 +01:00
check_dist
check
loadconf
build
2023-03-28 22:16:30 +02:00
[ " $install " != "false" ] && install