#!/bin/sh #======== #=============================================================================# # Snog is Not Overwhelmingly GNUlike (!) # # ordinary bash script to eliminate useless debugging of # # xmkmf, imake, cpp, makedepend, make, & other buildtime gnonsense # # sources bashsyntax control files to acquire project-specific parms # # executes various preprocessors, compilers, assemblers, linkers & # # other routines in a controllable, transparent, & maintainable fashion. # #============================================================================== snoghead() { date +%G%b%d%a.%P%H:%M:%S uname -srm } echo ooo echo Snog ... snoghead SNOG=$0 if [ -d /libexec ] then DYNLINK=/libexec/ld-elf.so.1 DYNLOAD=${HOME}/lib else # UCI=/opt/gnudev # if [ ! -d ${UCI} ] # then # iwmenu gnudev --norun # $(zkp)/sh/gnudev # fi DYNLINK=/lib/ld-linux.so.2 DYNLOAD=/usr/local/lib SYS_LIBS="-ldl" LOC_LIBS="-lX11 -lXext -lXt -lXaw -lXmu -lXpm -lXdmcp -lSM -lICE" fi MAPDEST=MAPsnog snoginit() { case $1 in help ) runhelp $2 ; exit 0 ;; info ) runinfo ; exit 0 ;; esac LNKD=ELFlinked SF=./Snogfile [ ! -f ${SF} ] && echo "No Snogfile found. proceeding anyway." || source ${SF} DEFS="-Dtrcm "${DEFS} INCLUDES="-I. -I/tmp/include" for i in $(ls) do [ -d ${i} ] && INCLUDES="${INCLUDES} "-I${i} done for i in c cc cxx do [ ":${SRCS}:" == "::" ] && SRCS="$(ls *.${i} 2>/dev/null)" done if [ ":${OBJS}:" == "::" ] then for i in ${SRCS} do OBJS="${OBJS} "${i%%.c*}.o done fi [ -z $1 ] && TARG=${SNOGACT:=gcc} || TARG=$1 echo =[${TARG}]= #/**/# =============== #/**/# #/**/# welcome to SNOG #/**/# #/**/# =============== #/**/# # GNUDIR=/KNOPPIX/usr/lib/gcc-lib/i486-linux/3.3.4 # GNUDIR=/usr/lib/gcc/i486-slitaz-linux/4.5.2 GNUDIR=/usr/lib/gcc/i486-slackware-linux/4.7.1 SNOGDIRS=" -L${GNUDIR} -L/usr/lib -L/usr/X11R6/lib -L/usr/local/lib -L/opt/cobol-it/lib -L${HOME}/lib" } # -L/lib # -L/opt/gnudev/usr/lib # -L/ramdisk/tmp/libc.a snogmain() { snoginit $@ shift case ${TARG} in tccr ) runtcc $@ -run ;; tccc ) runtcc $@ -c; ls -al ${OBJS} ;; tcc ) runtcc $@ -o ${LNKD}; runq ;; cpp ) runcpp $@ ;; gcc ) rungcc $@ -c; ls -al ${OBJS}; ldbell; runq ;; gccr ) rungcc $@ -c; ls -al ${OBJS}; ldbell; runq; ${LNKD} ;; gccc ) rungcc $@ -c; ls -al ${OBJS} ;; stat ) rungcc $@ -c; ls -al ${OBJS}; runlds; runq ;; tool ) rungcc $@ ${SNOGDIRS} ${PROJDIRS} ${PROJLIBS} -o ${LNKD}; runq ;; cxx ) runcxx $@ -c; ls -al ${OBJS}; runldx; runq ;; cxxt ) runcxx $@ ${SNOGDIRS} ${PROJDIRS} ${PROJLIBS} -o ${LNKD}; runq ;; cobc ) runcob $@; runq ;; cobx ) runcob $@ -x; runq ;; link ) ldbell $@; runq ;; links ) runlds $@; runq ;; linkx ) runldx $@; runq ;; shar ) runsrt $@; runout ${SOFL} ;; shag ) runsrg $@; runq ;; map ) runq; exec ue -v ${MAPDEST};; mapc ) runq; cat ${MAPDEST} ;; clean ) runclean ;; * ) echo "snog: no target ${TARG}. stop." ;; esac } # SNOG has a very robust & serviceable default behaviour. # when invoked without parms in a given project directory it: # * prepares a complete list of C sources & corresponding objects # * passes all subdirs to the compiler as -I parameters # * runs the gcc toolchain thru the assembly of all sources # * runs the linker explicitly with an accurate list of -L dirs # * is prepared to conditionally link common libs without specification. # although debugging autoconf & Imakefile scripts is a laudable exercise # SNOG can in many cases immediately produce smaller, properly linked # executables from a wide range of projects with a single command. runcpp() { for i in $(ls -1 *.h) do EX="cpp -C -dID \ $@ ${i}" echo ${EX}; ${EX} >${i%.h}.i done } rungcc() { for i in ${SRCS} do EX="gcc -O2 ${DEFS} ${INCLUDES} \ $@ ${i}" echo ${EX}; ${EX} done } runtcc() { for i in ${SRCS} do EX="tcc -Wall ${DEFS} ${INCLUDES} \ ${SNOGDIRS} ${PROJDIRS} ${PROJLIBS} \ $@ ${i}" echo ${EX}; ${EX} done } runcxx() { for i in ${SRCS} do EX="g++ -Wall -save-temps -O2 ${INCLUDES} \ $@ ${i}" echo ${EX}; ${EX} done } runcob() { source /opt/cobol-it/bin/cobol-it-setup.sh EX="cobc ${SRCC} -Wall -v -save-temps ${INCLUDES} -Wl -Map=${MAPDEST}.lnk -lc -ldl $@" ${EX} } runldx() { CTORB=${GNUDIR}/crtbegin.o CTORE=${GNUDIR}/crtend.o ldbell } ldbell() { # SNOGLINK="${GNUDIR}/collect2 --eh-frame-hdr -m elf_i386" SNOGLINK="ld" EX="${SNOGLINK} -dynamic-linker ${DYNLINK} $@ ${LDFLAGS} -Map=${MAPDEST}.lnk \ ${SNOGDIRS} ${PROJDIRS} \ /usr/lib/crt1.o /usr/lib/crti.o ${CTORB} \ ${OBJS} \ ${PROJLIBS} \ -lc -lgcc --as-needed ${SYS_LIBS} -lgcc_s -lm -lncurses -lstdc++ ${LOC_LIBS} --no-as-needed \ ${CTORE} /usr/lib/crtn.o -o ${LNKD}" echo '/**/#' echo ${EX}; ${EX} } runlds() { # SNOGLINK="${GNUDIR}/collect2 --eh-frame-hdr -m elf_i386" SNOGLINK="ld -s -t --no-whole-archive" EX="${SNOGLINK} $@ ${LDFLAGS} \ ${SNOGDIRS} ${PROJDIRS} \ /usr/lib/crt1.o /usr/lib/crti.o \ ${OBJS} \ ${PROJLIBS} \ -Bstatic -lc -Bdynamic -lgcc \ /usr/lib/crtn.o -o ${LNKD}" echo '/**/#' echo ${EX}; ${EX} } runsrt() { EX="tcc -Wall -c -fPIC ${INCLUDES} $@ ${SRCS}" echo ${EX} ${EX} EX="ld -shared -soname ${SONM} -o ${SOFL} ${OBJS} -lc" echo ${EX}; ${EX} } runsrg() { PRIM=null if [ ! -f null.c ] then if [ -z $1 ] then echo please specify one program linked outside of the so exit 0 fi PRIM=$1 fi echo generating position-independent code ... for i in ${SRCS} do EX="gcc -c -O2 -fpic ${DEFS} ${INCLUDES} \ ${i}" echo ${EX}; ${EX} done echo linking shared object ... rm -rf ${PRIM}.o EX="gcc -shared -Wl,-s,-soname,${SONM} -o ${SOFL} $(ls -1 *.o) -lc" echo ${EX}; ${EX} runout ${SOFL} echo installing shared object ... rm -rf ${DYNLOAD}/${SOFL} cp -p ${SOFL} ${DYNLOAD} [ -f /usr/bin/sudo ] && sudo ldconfig ln -sf ${DYNLOAD}/${SOFL} ${DYNLOAD}/${SONM} ln -sf ${DYNLOAD}/${SOFL} ${DYNLOAD}/${SOFL%%.*}.so echo LD_LIBRARY_PATH is: ${LD_LIBRARY_PATH} echo compiling ${PRIM}.c ... SRCS=${PRIM}.c OBJS=${PRIM}.o # rungcc -o ${LNKD} rungcc -c; ls -al ${PRIM}.o; ldbell } runq() { echo ooo >${MAPDEST} runinfo >>${MAPDEST} echo >>${MAPDEST} snoghead >>${MAPDEST} if [ -f ${MAPDEST}.lnk ] then echo >>${MAPDEST} cat ${MAPDEST}.lnk >>${MAPDEST} rm -f ${MAPDEST}.lnk fi echo >>${MAPDEST} echo ooo >>${MAPDEST} readelf -a ${LNKD} >>${MAPDEST} runout ${LNKD} echo >>${MAPDEST} # echo -n ooo >>${MAPDEST} # objdump -S ${LNKD} >>${MAPDEST} } runout() { ldd $1 # file $1 ls -al $1 } runclean() { rm -f *.i *.ii *.s *.so *.o *.c.* *~ *.*~ ${LNKD} ${SOFL} ls -al "${MAPDEST}"* } runhelp() { if [ -z $1 ] then tcc -v echo -n "GNU gcc " ; gcc -dumpversion strip -V | grep "strip" readelf -v | grep "readelf" objdump -v | grep "objdump" ld -v ldd --version | grep "ldd" type cobc &>/dev/null && cobc -V | grep "cobc" echo : runinfo echo 'type "snog help [ pgmname ]" for further help' else case $1 in tcc ) tcc ;; gcc ) gcc --help ;; strip ) strip ;; readelf ) readelf ;; objdump ) objdump ;; ld ) ld --help ;; ldd ) ldd --help ;; cobc ) cobc --help ;; snog ) cat ${SNOG} ;; * ) echo "snog: you are helpless. stop." ;; esac fi } runinfo() { echo 'Snog v1.02.024: Snog is Not Overwhelmingly GNUlike' echo '(c) 2012 Screaming CuckooBroad Associates' } snogmain $@ exit 0