I have a smelly bash script that I need to cross-compile:
Full contents of the script
:
src='../lp_MDO.c ../shared/commonlib.c ../colamd/colamd.c ../shared/mmio.c ../shared/myblas.c ../ini.c ../fortify.c ../lp_rlp.c ../lp_crash.c ../bfp/bfp_LUSOL/lp_LUSOL.c ../bfp/bfp_LUSOL/LUSOL/lusol.c ../lp_Hash.c ../lp_lib.c ../lp_wlp.c ../lp_matrix.c ../lp_mipbb.c ../lp_MPS.c ../lp_params.c ../lp_presolve.c ../lp_price.c ../lp_pricePSE.c ../lp_report.c ../lp_scale.c ../lp_simplex.c lp_solve.c ../lp_SOS.c ../lp_utils.c ../yacc_read.c'
c=cc
MYTMP=`mktemp -d "${TMPDIR:-/tmp}"/lp_solve_XXXXXX`
#determine platform (32/64 bit)
>"$MYTMP"/platform.c
echo '#include <stdlib.h>'>>"$MYTMP"/platform.c
echo '#include <stdio.h>'>>"$MYTMP"/platform.c
echo 'main(){printf("ux%d", (int) (sizeof(void *)*8));}'>>"$MYTMP"/platform.c
$c "$MYTMP"/platform.c -o "$MYTMP"/platform
PLATFORM=`"$MYTMP"/platform`
rm "$MYTMP"/platform "$MYTMP"/platform.c >/dev/null 2>&1
mkdir bin bin/$PLATFORM >/dev/null 2>&1
math=-lm
#check if this system has the isnan function
>"$MYTMP"/isnan.c
echo '#include <stdio.h>'>>"$MYTMP"/isnan.c
echo '#include <stdlib.h>'>>"$MYTMP"/isnan.c
echo '#include <math.h>'>>"$MYTMP"/isnan.c
echo 'main(){isnan(0.0);return 0;}'>>"$MYTMP"/isnan.c
$c "$MYTMP"/isnan.c -o "$MYTMP"/isnan $math >/dev/null 2>&1
if [ $? = 0 ]
then NOISNAN=
else NOISNAN=-DNOISNAN
fi
rm "$MYTMP"/isnan.c "$MYTMP"/isnan >/dev/null 2>&1
opts='-O3'
rmdir "$MYTMP"
def=
if [ "$PLATFORM" = "SCO_UNIX" ]
then opts='-O0'
def='-dy -K PIC -DLLONG=long'
dl=-ldl
else dl=-ldl
fi
$c -I.. -I../bfp -I../bfp/bfp_LUSOL -I../bfp/bfp_LUSOL/LUSOL -I../colamd -I../shared $opts $def $NOISNAN -DYY_NEVER_INTERACTIVE -DPARSER_LP -DINVERSE_ACTIVE=INVERSE_LUSOL -DRoleIsExternalInvEngine $src -o bin/$PLATFORM/lp_solve $math $dl
Initially it needs buildPlatform
compiler (gcc
).
#determine platform (32/64 bit)
>"$MYTMP"/platform.c
echo '#include <stdlib.h>'>>"$MYTMP"/platform.c
echo '#include <stdio.h>'>>"$MYTMP"/platform.c
echo 'main(){printf("ux%d", (int) (sizeof(void *)*8));}'>>"$MYTMP"/platform.c
$c "$MYTMP"/platform.c -o "$MYTMP"/platform
PLATFORM=`"$MYTMP"/platform`
rm "$MYTMP"/platform "$MYTMP"/platform.c >/dev/null 2>&1
But that the end I assume it needs a hostPlatform
cross-compiler (aarch64-unknown-linux-gnu-gcc
).
$c -I.. -I../bfp -I../bfp/bfp_LUSOL -I../bfp/bfp_LUSOL/LUSOL -I../colamd -I../shared $opts $def $NOISNAN -DYY_NEVER_INTERACTIVE -DPARSER_LP -DINVERSE_ACTIVE=INVERSE_LUSOL -DRoleIsExternalInvEngine $src -o bin/$PLATFORM/lp_solve $math $dl
Initialy I tried using substituteInPlace
, but you can’t really substitute some parts of the file but not others.
I then thought about writing a patch, but that would make it hard to access ${pkgs.gcc}
.