Add support out-of-tree builds. jv
authorJan Vrany <jan.vrany@fit.cvut.cz>
Tue, 14 Jan 2020 22:47:55 +0000
branchjv
changeset 1625 2425cb5d073e
parent 1608 efa48d08c563
child 1626 62ac134d4f7f
Add support out-of-tree builds. This commit adds a support for out-of-tree builds, i.e, object files, executables and so on are writen to `$(OUTDIR)` (which defaults to `build/<BUILD_TARGET>` directory. This allows building Smalltalk/X from single source tree for multiple targets.
Make.proto
smalltalk
--- a/Make.proto	Fri Jul 19 11:09:39 2019 +0100
+++ b/Make.proto	Tue Jan 14 22:47:55 2020 +0000
@@ -357,12 +357,12 @@
 	    @-rm -f modulList.stc modulList.c modulList.o
 	    @-rm -rf resources source bitmaps include examples lib
 	    @-rm -f stx st.img st.img.sav st.sav
-	    @-rm -f main.o
+	    @-rm -f $(OUTDIR)main.o
 	    @-rm -rf modules
 	    @-rm -rf package
 	    @-rm -rf stxtmp_*
 
-main.o::    $(INCLUDE)/stc.h $(INCLUDE)/stcIntern.h Make.proto
+$(OUTDIR)main.o::    $(INCLUDE)/stc.h $(INCLUDE)/stcIntern.h Make.proto
 
 installProgsIf:: $(INSTALLBIN_DIR)
 	@-echo "installing smalltalk..."
--- a/smalltalk	Fri Jul 19 11:09:39 2019 +0100
+++ b/smalltalk	Tue Jan 14 22:47:55 2020 +0000
@@ -48,6 +48,26 @@
 else
     # Running from build tree
     STX_LIBDIR="$STX_BIN_DIR"
+    if [ -x "$STX_BIN_DIR/../../../../config.guess" ]; then
+	native_target=$($STX_BIN_DIR/../../../../config.guess)
+        STX_EXE="$STX_BIN_DIR/build/${native_target}/stx"
+        if [ ! -x "$STX_EXE" ]; then
+	    # Sigh, special hack for i386. I know, I know, this is kind of 
+	    # dated, but still, I'd like to keep it alive as this is
+            # - as of today - the only working 32bit architecture. 
+	    if [ "${native_target}" == "x86_64-pc-linux-gnu" ]; then
+		# Try i386...
+		STX_EXE="$STX_BIN_DIR/build/i686-pc-linux-gnu/stx"
+		if [ ! -x "$STX_EXE" ]; then
+                    STX_EXE=stx
+                    export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(dirname $STX_EXE)"
+                fi
+	    else
+                STX_EXE=stx
+                export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:$(dirname $STX_EXE)"
+            fi
+        fi
+    fi
 fi
 
 if [ "$STX_LIBDIR" != "" ]
@@ -65,15 +85,15 @@
 then
     bindir=`dirname $0`
     case "$bindir" in
-        /* )
-        ;;
-        .* )
-        bindir=`( cd $bindir; pwd ) 2> /dev/null`
-        ;;
+    /* )
+    ;;
+    .* )
+    bindir=`( cd $bindir; pwd ) 2> /dev/null`
+    ;;
     esac
     if [ -d ${bindir}/../lib ]
     then
-        STX_LIBDIR=`cd ${bindir}/../lib ; pwd`
+    STX_LIBDIR=`cd ${bindir}/../lib ; pwd`
     fi
 fi
 
@@ -81,14 +101,14 @@
 then
     if [ -d ../lib ]
     then
-        STX_LIBDIR=`cd ../lib ; pwd`
+    STX_LIBDIR=`cd ../lib ; pwd`
     fi
 fi
 if [ ! -d "$STX_LIBDIR" ]
 then
     if [ -d ../lib ]
     then
-        STX_LIBDIR=`cd ../lib ; pwd`
+    STX_LIBDIR=`cd ../lib ; pwd`
     fi
 fi
 
@@ -96,16 +116,16 @@
 then
     if [ -f ../lib/smalltalk.rc ]
     then
-        STX_TOPDIR=`cd .. ; pwd`
+    STX_TOPDIR=`cd .. ; pwd`
     else
        if [ -f $STX_LIBDIR/../lib/smalltalk.rc ]
        then
-           STX_TOPDIR=`cd $STX_LIBDIR/.. ; pwd`
+       STX_TOPDIR=`cd $STX_LIBDIR/.. ; pwd`
        else
-           if [ -f $STX_BIN_DIR/smalltalk.rc ]
-           then
-              STX_TOPDIR=`cd $STX_BIN_DIR/../.. ; pwd`
-           fi
+       if [ -f $STX_BIN_DIR/smalltalk.rc ]
+       then
+          STX_TOPDIR=`cd $STX_BIN_DIR/../.. ; pwd`
+       fi
        fi
     fi
 fi
@@ -118,8 +138,8 @@
 # echo STX is $STX_EXE
 
 function error() {
-	echo "$0: $1"	
-	exit 1
+    echo "$0: $1"   
+    exit 1
 }
 
 function usage() {
@@ -134,14 +154,14 @@
    --gdb .................. run with gdb (type r in debugger to start)   
    --cgdb ................. run with cgdb (type r in debugger to start)                            
    --callgrind ............ run under callgrind profiler tool with profiling 
-                            off. Use this to profile some benchmark.
+                off. Use this to profile some benchmark.
    --callgrind-startup .... run under callgrind profiler tool with profiling 
-                            on. Use this to profile VM startup.
+                on. Use this to profile VM startup.
    --stap SCRIPT .......... run given systemtap script, passing stx command as
-                            stap -c 'stx ...' Systemtap may not be compiled in.
+                stap -c 'stx ...' Systemtap may not be compiled in.
    --record ............... record execution using rr. 
    --replay ............... replay last recorded execution using rr. Must be used
-                            in combination with --vdb.
+                in combination with --vdb.
 USAGE_END
   $STX_BIN_DIR/$STX_EXE --help
   exit 0
@@ -151,71 +171,71 @@
 while [ $# -gt 0 ]
 do
     case $1 in
-        --help)
-            usage
-            ;;
-        -x)
-            STX_EXE=$2
-            shift 2
-            ;;
-        -X)            
-            STX_EXE=$2/stx
-            shift 2
-            ;; 
-        --ldd)            
-            DEBUGLIB=yes
-            shift
-            ;;
-        --gdb|--cgdb|--vdb|--callgrind|--callgrind-startup|--stap)
-			if [ ! -z "$SUPERVISOR" ]; then
-				error "$1 cannot be used together with $SUPERVISOR."
-			fi			
-			if [ "x$RECORD" == "xyes" ]; then
-				error "$1 cannot be used together with --record"
-			fi
-			if [ "x$REPLAY" == "xyes" ]; then
-				if [ "$1" != "--vdb" ]; then
-					error "$1 cannot be used together with --replay"
-				fi
-			fi
-            SUPERVISOR=$1            
-            if [ $SUPERVISOR == "--stap" ]; then
-            	if [ -z "$2" ]; then
-                	error "--stap requires systemtap script to run"
+    --help)
+        usage
+        ;;
+    -x)
+        STX_EXE=$2
+        shift 2
+        ;;
+    -X)            
+        STX_EXE=$2/stx
+        shift 2
+        ;; 
+    --ldd)            
+        DEBUGLIB=yes
+        shift
+        ;;
+    --gdb|--cgdb|--vdb|--callgrind|--callgrind-startup|--stap)
+            if [ ! -z "$SUPERVISOR" ]; then
+                error "$1 cannot be used together with $SUPERVISOR."
+            fi          
+            if [ "x$RECORD" == "xyes" ]; then
+                error "$1 cannot be used together with --record"
+            fi
+            if [ "x$REPLAY" == "xyes" ]; then
+                if [ "$1" != "--vdb" ]; then
+                    error "$1 cannot be used together with --replay"
                 fi
-                if [ ! -r "$2" ]; then
-                	error "$2: no such file or not readable"
-                fi
-                STAPSCRIPT=$2
-                shift
             fi
+        SUPERVISOR=$1            
+        if [ $SUPERVISOR == "--stap" ]; then
+        if [ -z "$2" ]; then
+            error "--stap requires systemtap script to run"
+        fi
+        if [ ! -r "$2" ]; then
+            error "$2: no such file or not readable"
+        fi
+        STAPSCRIPT=$2
+        shift
+        fi
+        shift
+        ;;     
+    --record)
+            if [ ! -z "$SUPERVISOR" ]; then
+                error "$1 cannot be used together with $SUPERVISOR."                
+            fi
+            if [ "x$REPLAY" == "xyes" ]; then
+                error "$1 cannot be used together with --replay"
+            fi
+            RECORD=yes
             shift
-            ;;     
-        --record)
-			if [ ! -z "$SUPERVISOR" ]; then
-				error "$1 cannot be used together with $SUPERVISOR."				
-			fi
-			if [ "x$REPLAY" == "xyes" ]; then
-				error "$1 cannot be used together with --replay"
-			fi
-			RECORD=yes
-			shift
-        	;;        
-        --replay)
-			if [ ! -z "$SUPERVISOR" ]; then
-				if [ "$SUPERVISOR" != "--vgb" ]; then
-					error "$1 cannot be used together with $SUPERVISOR."
-				fi
-			fi
-			if [ "x$RECORD" == "xyes" ]; then
-				error "$1 cannot be used together with --record"
-			fi
-        	REPLAY=yes
-        	shift
-        	;;   
-        *)
-            break
-            ;;
+        ;;        
+    --replay)
+            if [ ! -z "$SUPERVISOR" ]; then
+                if [ "$SUPERVISOR" != "--vgb" ]; then
+                    error "$1 cannot be used together with $SUPERVISOR."
+                fi
+            fi
+            if [ "x$RECORD" == "xyes" ]; then
+                error "$1 cannot be used together with --record"
+            fi
+        REPLAY=yes
+        shift
+        ;;   
+    *)
+        break
+        ;;
     esac
 done 
 
@@ -321,22 +341,22 @@
 
 
 #
-# When running on modern DE (such as GNOME or KDE), install 
-# .desktop and .svg so to get nice(r) icon and - more importantly - 
-# proper window grouping in task list. 
+# When running on modern DE (such as GNOME or KDE), install
+# .desktop and .svg so to get nice(r) icon and - more importantly -
+# proper window grouping in task list.
 #
 # See issue #66: https://swing.fit.cvut.cz/projects/stx-jv/ticket/66
-#           
+#
 if [ ! -z "$XDG_CURRENT_DESKTOP" ]; then
     icon_dir=~/.local/share/icons/hicolor/scalable/apps
     dskp_dir=~/.local/share/applications
     if [ ! -f "$icon_dir/smalltalkx.svg" ]; then
-        mkdir -p "$icon_dir" || true
-        cp "$STX_LIBDIR/smalltalkx.svg" "$icon_dir" || true
+    mkdir -p "$icon_dir" || true
+    cp "$STX_LIBDIR/smalltalkx.svg" "$icon_dir" || true
     fi
     if [ ! -f "$dskp_dir/smalltalkx.desktop" ]; then
-        mkdir -p "$dskp_dir" || true
-        cp "$STX_LIBDIR/smalltalkx.desktop" "$dskp_dir" || true
+    mkdir -p "$dskp_dir" || true
+    cp "$STX_LIBDIR/smalltalkx.desktop" "$dskp_dir" || true
     fi
 fi
 
@@ -349,44 +369,48 @@
 fi
 
 if [ "x$RECORD" == "xyes" ]; then
-	exec rr $STX_EXE ${1+"$@"}
+    exec rr $STX_EXE ${1+"$@"}
+elif [ "x$REPLAY" == "xyes" ]; then
+    if [ -z "$SUPERVISOR" ]; then
+        error "--replay can only be used together with --vdb"
+    elif [ "$SUPERVISOR" != "--vdb" ]; then
+        error "--replay can only be used together with --vdb"
+    else
+        exec vdb --replay $STX_EXE ${1+"$@"}
+    fi
 elif [ ! -z "$SUPERVISOR" ]; then
-	case "$SUPERVISOR" in
-		--gdb)
-			exec gdb --tui --args $STX_EXE ${1+"$@"}
-			;;
-		--cgdb)
-			exec cgdb --args $STX_EXE ${1+"$@"}
-			;;
-		--vdb)
-			if which "vdb"; then
-                vdb=vdb
-            elif [ -x "$STX_BIN_DIR/../../../jv/vdb/application/vdb" ]; then
-                vdb="$STX_BIN_DIR/../../../jv/vdb/application/vdb"
-            else
-                error "could not find Visual / VM Debugger (vdb)"                
-            fi   
-            if [ "x$REPLAY" == "xyes" ]; then
-            	exec vdb --replay $STX_EXE ${1+"$@"}
-            else
-            	exec vdb $STX_EXE ${1+"$@"}
-            fi
-            ;;
-		--callgrind)
-    		exec valgrind --tool=callgrind --instr-atstart=no $STX_EXE ${1+"$@"}
-    		;;
-    	--callgrind-startup)
-			exec valgrind --tool=callgrind $STX_EXE ${1+"$@"}
-    		;;
-    	--stap)			
-    		exec stap --unprivileged $STAPSCRIPT -I "$STX_TOPDIR/librun" -c "$STX_EXE $@"
-    		;;
-    	*)
-			error "Unknown supervisor option: $SUPERVISOR"
-			;;
-	esac
+    case "$SUPERVISOR" in
+    --gdb)
+        exec gdb --tui --args $STX_EXE ${1+"$@"}
+        ;;
+    --cgdb)
+        exec cgdb --args $STX_EXE ${1+"$@"}
+        ;;
+    --vdb)
+        if which "vdb"; then
+            vdb=vdb
+        elif [ -x "$STX_BIN_DIR/../../../jv/vdb/application/vdb" ]; then
+            vdb="$STX_BIN_DIR/../../../jv/vdb/application/vdb"
+        else
+            error "could not find Visual / VM Debugger (vdb)"
+        fi
+        exec vdb $STX_EXE ${1+"$@"}
+        ;;
+    --callgrind)
+        exec valgrind --tool=callgrind --instr-atstart=no $STX_EXE ${1+"$@"}
+        ;;
+    --callgrind-startup)
+        exec valgrind --tool=callgrind $STX_EXE ${1+"$@"}
+        ;;
+    --stap)
+        exec stap --unprivileged $STAPSCRIPT -I "$STX_TOPDIR/librun" -c "$STX_EXE $@"
+        ;;
+    *)
+        error "Unknown supervisor option: $SUPERVISOR"
+        ;;
+    esac
 else
-	exec $STX_EXE ${1+"$@"}
+    exec $STX_EXE ${1+"$@"}
 fi