#! /bin/bash # mopac7_darwin.sh # # This script makes the necessary accomodations to the peculiarities # of Apple's linker. In particular, it does not accept multiple # definitions of the same identifier. This hits the way common block # structs are used. To work around, we declare each one once in the # ordinary way, and all others as 'extern' # # Before running this script, run `f2c -ec *.f` to translate the # FORTRAN source to C. The -ec flag generates external common # block declarations that we will manipulate. # # Run this script in the directory where the generated C code is. # # After running the script, move *.c to the src/ directory, replacing # all the original versions. # # Mark Tracy 23-Dec-2007 if [ "${1}_x" = "_x" ] then ofile=commons.c else ofile=$1 fi # For some reason, the `f2c -ec` translation of block.f exports the # initialized common block variables which causes the program to # quietly fail. So let's delete the exported files rm -f alpha3_com.c am1blo_com.c atomi3_com.c atomic_com.c beta3_com.c \ core_com.c elemts_com.c expon3_com.c field_com.c ideaa_com.c \ ideap_com.c istope_com.c mndo_com.c natorb_com.c onele3_com.c \ pm3_com.c refs_com.c twoel3_com.c twoele_com.c vsips_com.c # Same problem with libmopac7.c rm -f numcal_com.c okmany_com.c # Concatenate all the common block files generated by `f2c -ec *.f` # into one file. Default output is commons.c rm -f $ofile echo -e "/* Collected common block declarations" > $ofile echo -e " generated by \`f2c -ec *.f\`" >> $ofile echo -e "*/ \n\n" >> $ofile echo '#include "f2c.h"' >> $ofile for com_c in `ls *_com.c` do echo -e "" >> $ofile sed '1d' $com_c >> $ofile done # For no obvious reason, gcc-4.2.2 can't deal with a file that is all # declarations without an initialization. It just forgest all the declarations. # Hence this hack. sed -i .bk -e s/atheat_/atheat_\ =\ {0.0}/ $ofile # Renames these four functions because they have the same names as # functions in BLAS. This only creates a collision if one attempts # to link both libmopac7.a and libmpqc.dylib into libghemical.dylib sed -i .bk -e s/second_/secondm7_/g \ -e s/sdot_/sdotm7_/g \ -e s/scopy_/scopym7_/g \ -e s/saxpy_/saxpym7_/g \ *.c # Renames this function because it is defined differently in # mopac7lib.c and mopac7app.c sed -i .bk -e s/getdat_/getdaa_/g mopac7app.c # delete the backup files leftover from the sed operations rm -f *.bk # we have collected all the common blocks together so we don't need these rm -f *_com.c