#!/bin/sh
#
# makeParameters - determine locations of various files/directories 
#    on this machine and setup the makeConfig file which is included by
#    all Makefiles
#
# Uses environmental variables APP_INSTALL_ROOT and APP_PREFIX_PATH if defined

if [ -f "makeConfig" ]
then
	echo "Using existing makeConfig file"
	exit 0
fi

echo "Creating makeConfig"
echo ""

F=makeConfig

>$F

echo "# File: makeConfig" >> $F
echo "#" >> $F
echo "# Description: This file is created automatically when make is" >> $F
echo "#              invoked for the first time in the top level directory." >> $F
echo "#              It is included in all makefiles and is used to define" >> $F
echo "#              os/version/architecture/package/... dependent variables." >> $F
echo "#              If you need to modify any of these settings you can" >> $F
echo "#              either edit them here, or if you have the time figure out" >> $F
echo "#              which script generated the entry and change it. If you do" >> $F
echo "#              the latter then I would appreciate an email" >> $F
echo "#              letting me know what changes you made. The ultimate" >> $F
echo "#              goal is that this process be completely automatic." >> $F
echo "#" >> $F
echo "#              The main script used to generate this file is " >> $F
echo "#              ./scripts/localize/makeParameters. It calls other" >> $F
echo "#              scripts to perform the localization. Read" >> $F
echo "#              ./doc/Configure for more details." >> $F
echo "#" >> $F
echo "# Note: This file is *REMOVED* with a make clobber.  " >> $F


# If we find gcc then use it as cc is sometimes non-functional

CC_DEFN=`getCCDefn`

if [ ! -z "$CC_DEFN" ]
then
    echo "" >> $F
    echo "# Note: the following overrides the CC macro, most likely" >> $F
    echo "#       with gcc. You may have cc and if you want to use it," >> $F
    echo "#       then change the definition here or modify getCCDefn">>$F
    echo "" >> $F

    echo "$CC_DEFN" >> $F
fi

echo "" >> $F


echo "" >> $F
echo "# The following removes all symbols from the executable to reduce" >> $F
echo "# space. If your debugging the program, then comment out the" >> $F
echo "# second line." >> $F
echo "" >> $F
echo "STRIP=echo" >> $F
echo "STRIP=strip" >> $F

echo "" >> $F
echo "# If you want to compile a debug version of the program then " >> $F
echo "# uncomment one or more of the following lines." >> $F
echo "" >> $F

echo "#DEBUG=-g" >> $F
echo "#PROFILE_PROCESS=-p" >> $F
echo "#TRACE=-DPROC_TRACE" >> $F
echo "" >> $F



echo "# Use the following to add any additional CFLAGS arguments" >> $F
echo "" >> $F
echo 'EXTRA_CFLAGS= ' >> $F
echo "" >> $F
echo "# The following can be used to add additional LDFLAGS" >> $F
echo "" >> $F
echo 'EXTRA_LDFLAGS= $(DEBUG) $(PROFILE_PROCESS) ' >> $F

echo "" >> $F

getMotifTearOffDefn >> $F
echo "" >> $F

# Output LESSTIF Flags (Should remove this at earliest opportunity)
#			and when ifdef is removed from code.

getLessTifDefn >> $F

echo "" >> $F


PLATFORM_DEFINES=`getPlatformDefines`

echo "PLATFORM_FLAGS= $PLATFORM_DEFINES" >> $F
echo "" >> $F

X11_INCLUDE_LOCATION=`getXIncludePath`
MOTIF_INCLUDE_LOCATION=`getMotifIncludePath`

X11_LIB_LOCATION=`getXLibPath`
MOTIF_LIB_LOCATION=`getMotifLibPath`

# Determine what extra libs are needed for X to compile

MOTIF_LIBS=`getMotifLibs`
X11_LIBS=`getX11Libs`
EXTRA_LIBS=`getMotifX11SupportLibs`    # This one varies a lot

X11_MOTIF_AND_SUPPORT_LIBS="$MOTIF_LIBS $X11_LIBS $EXTRA_LIBS"

INCLUDE_LIST=
LIB_LIST=

# Now output the entries

echo "# The following are for X11 ">>$F
echo "" >> $F

if  inStdHdrPath $X11_INCLUDE_LOCATION
then
     echo "# X11 include files appear to be in the default include dirs!" >> $F
     echo "" >> $F
     echo "#X11_INCLUDE_PATH=-I " >> $F
else
     echo "X11_INCLUDE_PATH=-I$X11_INCLUDE_LOCATION" >> $F

     INCLUDE_LIST="$X11_INCLUDE_LOCATION"
fi

echo "" >> $F

# Only output another path for motif includes if we need to

if  inStdHdrPath $MOTIF_INCLUDE_LOCATION
then
     echo "# Motif include files appear to be in the default include dirs!" >>$F
     echo "" >> $F
     echo "#MOTIF_INCLUDE_PATH=-I" >> $F
else
     if [ "$X11_INCLUDE_LOCATION" != "$MOTIF_INCLUDE_LOCATION" ]
     then
         echo "MOTIF_INCLUDE_PATH=-I$MOTIF_INCLUDE_LOCATION" >> $F

         INCLUDE_LIST="$INCLUDE_LIST $MOTIF_INCLUDE_LOCATION"
     else
         echo "# Motif includes are in the same place as X11 includes" >>$F
	 echo "" >> $F
         echo "#MOTIF_INCLUDE_PATH=-I" >> $F
     fi
fi

echo "" >> $F


echo "# The following are for X11 and Motif libraries">>$F
echo "" >> $F

if  inStdLibPath $X11_LIB_LOCATION
then
     echo "# X11 lib files appear to be in the default lib dirs!" >>$F
     echo "" >> $F
     echo "#X11_LIB_PATH=-L " >> $F
else
    echo "X11_LIB_PATH=-L $X11_LIB_LOCATION" >> $F
    LIB_LIST="$X11_LIB_LOCATION"
fi

echo "" >> $F

# Only output another path for motif libs if we need to

if  inStdLibPath $MOTIF_LIB_LOCATION
then
     echo "# Motif lib files appear to be in the default lib dirs!" >>$F
     echo "" >> $F
     echo "#MOTIF_LIB_PATH=-L " >> $F
else
     if [ "$X11_LIB_LOCATION" != "$MOTIF_LIB_LOCATION" ]
     then
         echo "MOTIF_LIB_PATH=-L $MOTIF_LIB_LOCATION" >> $F
         LIB_LIST="$LIB_LIST $MOTIF_LIB_LOCATION"
     else
         echo "# Motif libs are in the same location as the X11 libs" >>$F
         echo "" >> $F
         echo "#MOTIF_LIB_PATH=-L " >> $F
     fi
fi
echo "" >> $F


echo "" >> $F
echo "# The following define the Motif, X11 and support libraries." >> $F
echo "" >> $F

echo "MOTIF_X11_AND_SUPPORT_LIBS=$X11_MOTIF_AND_SUPPORT_LIBS" >> $F
echo "" >> $F



# Output entried for constucting statically linked motif binary

echo "" >> $F
echo "# The following are used to create an executable with statically" >> $F
echo "# linked motif libs. See Linux/treeps.mkf MAKE_STATIC_BIN target.">>$F
echo "" >> $F

STATIC_MOTIF_LIB_PATHS="$MOTIF_LIB_LOCATION/libXm.a"
STATIC_MOTIF_LIB_PATHS="$STATIC_MOTIF_LIB_PATHS $MOTIF_LIB_LOCATION/libMrm.a"

echo "STATIC_MOTIF_LIBS=$STATIC_MOTIF_LIB_PATHS" >> $F
echo "" >> $F
echo "X11_AND_SUPPORT_LIBS=$X11_LIBS $EXTRA_LIBS" >> $F
echo "" >> $F


# Output Pixmap related entries

XPM_LIB_PATH=`libLocation libXpm.a`
XPM_INCLUDE_LOC=`hdrLocation xpm.h`
XPM_INCLUDE_PATH=`dirname $XPM_INCLUDE_LOC`
XPM_INCLUDE_PATH=`deReference $XPM_INCLUDE_PATH`

# If we have both the pixmap lib and hdr then we can compile to use xpm

if [ ! -z "$XPM_LIB_PATH" -a ! -z "$XPM_INCLUDE_PATH" ]
then
    echo "" >> $F
    echo "# The following are for the pixmap library, the include statement" >>$F
    echo "# for the file is <xpm.h> as it sometimes resides in" >>$F
    echo "# /usr/local/include. " >>$F
    echo "" >> $F

    echo "PIXMAP_LIB = -lXpm" >> $F
    echo "" >> $F

    # If the pixmap lib is in the X11 dir then we don't really need to 
    # output the include statement, but it causes no harm.

    if  inStdHdrPath $XPM_INCLUDE_PATH
    then
        echo "# Xpm include files appear to be in the default include dirs!" >>$F
        echo "" >> $F
        echo "#PIXMAP_INCLUDE_DIR= -I " >> $F
    else
        if [ -z "$INCLUDE_LIST" ]
	then
            echo "PIXMAP_INCLUDE_DIR= -I $XPM_INCLUDE_PATH" >> $F
	else
	    if inList $XPM_INCLUDE_PATH $INCLUDE_LIST
	    then
                 echo "The Pixmap include dir is already in other includes" >> $F
    		 echo "" >> $F
                 echo "#PIXMAP_INCLUDE_DIR= -I " >> $F
	    else
                 echo "PIXMAP_INCLUDE_DIR= -I $XPM_INCLUDE_PATH" >> $F
	    fi
	fi
    fi
    echo "" >> $F
        

    # Output pixmap lib path

    if  inStdLibPath $XPM_LIB_PATH
    then
        echo "# Xpm lib files appear to be in the default lib dirs!" >>$F
    	echo "" >> $F
        echo "#PIXMAP_LIB_PATH= -L " >> $F
    else
    	if [ -z "$LIB_LIST" ]
	then
            echo "PIXMAP_LIB_PATH= -L$XPM_LIB_PATH" >> $F
	else
	    if inList $XPM_LIB_PATH $LIB_LIST
	    then
	        echo "#The Pixmap lib appears to already be in your path" >> $F
    		echo "" >> $F
                echo "#PIXMAP_LIB_PATH= -L " >> $F
	    else
                echo "PIXMAP_LIB_PATH= -L$XPM_LIB_PATH" >> $F
	    fi
	fi
    fi
    echo "" >> $F

    echo "PIXMAP_OPTIONS=-DUSE_PIXMAPS" >> $F
    echo "" >> $F
else
    echo "# Could not find the Pixmap lib - bummer no color icons " >> $F
fi


echo "AR=ar" >> $F
echo "AR_FLAGS=ruv" >> $F



# Ouput command to strip binary of symbols

