I am trying to automate my linux build setup from a Bash script.
Most all of this works when I execute it manually, but I cannot figure out how to get a bash script to execute it automatically.
In this particular case, I am trying to build the xorg utilities. If I manually step through the process, prepending the commands with CFLAGS, LDFLAGS, etc, all of the packages build.
So I created a bash script, test.sh:
Code:
#!/bin/bash
export INITFS=/initfs
export SOURCES=/sources
export CFLAGS="-O2 -march=i586 -s -I${INITFS}/usr/include"
export CONFIG_OPTS="--disable-nls"
export XORG_PREFIX="/usr/X11"
export XORG_CONFIG="--prefix=$XORG_PREFIX --sysconfdir=/etc \
--mandir=$XORG_PREFIX/share/man --localstatedir=/var"
export XORG_DEST="DESTDIR=${INITFS}"
export PKG_CONFIG_LIBDIR="${INITFS}/usr/lib/pkgconfig"
export PKG_CONFIG_PATH="${INITFS}/usr/lib/pkgconfig"
export PKG_CONFIG_SYSROOT_DIR="${INITFS}"
export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1
export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1
export S_PREPEND="CFLAGS=\"${CFLAGS}\" \
XORG_PREFIX=\"${XORG_PREFIX}\" \
XORG_CONFIG=\"${XORG_CONFIG}\" \
XORG_DEST=\"${XORG_DEST}\" \
PKG_CONFIG_LIBDIR=\"${PKG_CONFIG_LIBDIR}\" \
PKG_CONFIG_PATH=\"${PKG_CONFIG_PATH}\" \
PKG_CONFIG_SYSROOT_DIR=\"${PKG_CONFIG_SYSROOT_DIR}\" \
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=\"${PKG_CONFIG_ALLOW_SYSTEM_CFLAGS}\" \
PKG_CONFIG_ALLOW_SYSTEM_LIBS=\"${PKG_CONFIG_ALLOW_SYSTEM_LIBS}\" \
"
...abbreviated - for loop through packages ...
"${S_PREPEND}" ./configure ${CONFIG_OPTS} $XORG_CONFIG
"${S_PREPEND}" make ${XORG_DEST}
"${S_PREPEND}" make ${XORG_DEST} install
If I set these variables manually, then echo $S_PREPEND, "$S_PREPEND", ${S_PREPEND}, or "${S_PREPEND}", I get (I manually line-wrapped these):
Code:
CFLAGS="-O2 -march=i586 -s -I/initfs/usr/include"
XORG_PREFIX="/usr/X11"
XORG_CONFIG="--prefix=/usr/X11 --sysconfdir=/etc --mandir=/usr/X11/share/man --localstatedir=/var"
XORG_DEST="DESTDIR=/initfs"
PKG_CONFIG_LIBDIR="/initfs/usr/lib/pkgconfig"
PKG_CONFIG_PATH=/initfs/usr/lib/pkgconfig"
PKG_CONFIG_PATH="/usr/X11/lib/pkgconfig" PKG_CONFIG_SYSROOT_DIR="/initfs"
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1" PKG_CONFIG_ALLOW_SYSTEM_LIBS="1"
which is exactly as expected.
But when the configure or make commands execute, I get various errors, in the latest configuration I get (I manually line-wrapped these):
Code:
... bash is echo'ing commands ...
+ 'CFLAGS="-O2 -march=i586 -s -I/initfs/usr/include"
XORG_PREFIX="/usr/X11" XORG_CONFIG="--prefix=/usr/X11 --sysconfdir=/etc --mandir=/usr/X11/share/man --localstatedir=/var"
XORG_DEST="DESTDIR=/initfs"
PKG_CONFIG_LIBDIR="/initfs/usr/lib/pkgconfig"
PKG_CONFIG_PATH="/initfs/usr/lib/pkgconfig"
PKG_CONFIG_SYSROOT_DIR="/initfs"
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1"
PKG_CONFIG_ALLOW_SYSTEM_LIBS="1" ' ./configure
--disable-nls --prefix=/usr/X11 --sysconfdir=/etc --mandir=/usr/X11/share/man --localstatedir=/var
... and here is the error
./test.sh: line 167: CFLAGS="-O2 -march=i586 -s -I/initfs
/usr/include" XORG_PREFIX="/usr/X11"
XORG_CONFIG="--prefix=/usr/X11 --sysconfdir=/etc --mandir=/usr
/X11/share/man --localstatedir=/var"
XORG_DEST="DESTDIR=/initfs" PKG_CONFIG_LIBDIR="/initfs/usr/lib
/pkgconfig" PKG_CONFIG_PATH="/initfs/usr/lib/pkgconfig"
PKG_CONFIG_SYSROOT_DIR="/initfs"
PKG_CONFIG_ALLOW_SYSTEM_CFLAGS="1"
PKG_CONFIG_ALLOW_SYSTEM_LIBS="1" : No such file or directory
Is this possible in a script file? I assume it's syntax that I haven't been able to find or stumble upon. Wrapping the commands in $(...) doesn't work, a single quote ' doesn't expand the $S_PREPEND and other variables, and a back tick ` seems to requote the strings in a fashion that causes errors.
Should I be creating a makefile to do all of this? I started with the bash script because I am more familiar with it, and it's creating the entire system, un-tar'ing packages, building directories, etc. I am sure a makefile can do all of this, but I don't know how.
Thanks for any help or suggestions.