bothner@WSL.DEC.COM (04/20/89)
[This message bounced the first time.]
It is desirable to keep sources files separate from "make"
directories (where compilations are done, and where binaries
are executed). This allows multiple simultaneous configurations
(binary versions) made from the same sources. A more immediate
reason for many is g++, where two sets of binaries are made from
a largely overlapping set of sources. One solution is to use
links (as done by the X sources, and g++), but I find that a
messy approach. An alternative is to use the power of GNU make,
including source paths.
I describe an experiment I did for doing this. It has the advantage
that it is compatible with existing Makefiles, for those who have
vanilla makes. Only a minor and compatible change to config.*
is needed, which will not affect current uses. The Makefiles need
not be changed. The set-up is a little more complicated the first
time, though shell-scripts can be written to automate the task (just
like config was written to automate choosing machine desciptions).
The big win (in addition to being able to deal with multiple versions)
is that it makes installing upgrades easier (especially for g++).
I have tested the scheme enough to compile c++.
METHOD:
First, put the master tar sources in gcc/gcc-1.34.
Make gcc/mi (for machine independent) be a symbolic link to gcc/gcc-1.34.
Create gcc/vax (say) for the binaries. Put the following Makefile in it:
SRC=../mi
MACHINE=vax
VPATH=$(SRC)
include $(SRC)/Makefile
CFLAGS = -g -I. -I- -I$(SRC)
.PHONY: config
config:
$(SRC)/config.gcc -path $(SRC) $(MACHINE)
rm -f move-if-change
ln -s $(SRC)/move-if-change .
The first two lines specify where the sources are, and what version
we are building in this (gcc/vax) directory. The actual make rules
come from the \unmodified/ distributed Makefile. The include
search path must be specified to look in the source directory.
(The latter has only been tested for the g++ version, below.)
The config target sets up machine-specific links, using a modified
config.gcc.
The change to config.gcc to accept a new "path" option.
Note that if no "path" option is given, config.gcc acts are currently.
*** config.gcc.orig Tue Apr 18 14:45:39 1989
- --- config.gcc Tue Apr 18 15:22:17 1989
***************
*** 40,45
#hard_link="echo ln"
#symbolic_link="echo ln -s"
case $# in
2)
vint=on
- --- 40,57 -----
#hard_link="echo ln"
#symbolic_link="echo ln -s"
+ # get path from where to get the configuration sources
+ case $1 in
+ -p | -path)
+ path=$2/
+ shift
+ shift
+ ;;
+ *)
+ path=
+ ;;
+ esac
+
case $# in
2)
vint=on
***************
*** 217,223
set $files; file=$1; shift; files=$*
set $links; link=$1; shift; links=$*
! if [ ! -r $file ]
then
echo "$progname: cannot create a link \`$link',"
echo "since the file \`$file' does not exist."
- --- 229,235 -----
set $files; file=$1; shift; files=$*
set $links; link=$1; shift; links=$*
! if [ ! -r $path$file ]
then
echo "$progname: cannot create a link \`$link',"
echo "since the file \`$path$file' does not exist."
***************
*** 220,226
if [ ! -r $file ]
then
echo "$progname: cannot create a link \`$link',"
! echo "since the file \`$file' does not exist."
exit 1
fi
- --- 232,238 -----
if [ ! -r $path$file ]
then
echo "$progname: cannot create a link \`$link',"
! echo "since the file \`$path$file' does not exist."
exit 1
fi
***************
*** 227,233
$remove -f $link
rm -f config.status
# Make a symlink if possible, otherwise try a hard link
! $symbolic_link $file $link 2>/dev/null || $hard_link $file $link
if [ ! -r $link ]
then
- --- 239,245 -----
$remove -f $link
rm -f config.status
# Make a symlink if possible, otherwise try a hard link
! $symbolic_link $path$file $link 2>/dev/null ||
$hard_link $path$file $link
if [ ! -r $link ]
then
Now we do the same thing for g++.
First put the sources in g++/src-g++.
Create (say) g++/vax.
Let g++/gcc contain or point to the gcc source (gcc/gcc-1.34).
The g++/vax Makefile is:
PSRC=../src-g++
CSRC=../gcc
MACHINE=vax
VPATH=$(PSRC):$(CSRC)
include $(PSRC)/Makefile
CFLAGS = -g -DSOS -DESKIT -O -I. -I- -I$(PSRC) -I$(CSRC)
.PHONY: config
config:
$(PSRC)/config.g++ -path $(CSRC) $(MACHINE)
rm -f move-if-change
ln -s $(CSRC)/move-if-change .
Here PSRC is the cPlus sources, while CSRC is the gCc sources.
Both make and cpp search both directories (after the current one).
Finally, here are the patches to config.g++:
*** config.g++.orig Thu Mar 30 02:09:25 1989
- --- config.g++ Tue Apr 18 15:43:52 1989
***************
*** 40,45
#hard_link="echo ln"
#symbolic_link="echo ln -s"
case $# in
2)
vint=on
- --- 40,57 -----
#hard_link="echo ln"
#symbolic_link="echo ln -s"
+ # get path from where to get the configuration sources
+ case $1 in
+ -p | -path)
+ path=$2/
+ shift
+ shift
+ ;;
+ *)
+ path=
+ ;;
+ esac
+
case $# in
2)
vint=on
***************
*** 208,215
cpu_type=${cpu_type=$machine}
configuration_file=${configuration_file=xm-$cpu_type.h}
machine_type=${machine_type=$machine}
! target_machine=tm-${machine_type}+.h
! sed 's/\([^A-Za-z]\)crt0.o/\1crt0+.o/g' < tm-$machine_type.h >
$target_machine
machine_description=${cpu_type}.md
aux_output=${aux_output=output-$cpu_type.c}
- --- 220,227 -----
cpu_type=${cpu_type=$machine}
configuration_file=${configuration_file=xm-$cpu_type.h}
machine_type=${machine_type=$machine}
! target_machine=tm-${machine_type}.h
! sed 's/\([^A-Za-z]\)crt0.o/\1crt0+.o/g' <
${path}tm-$machine_type.h > $target_machine
machine_description=${cpu_type}.md
aux_output=${aux_output=output-$cpu_type.c}
***************
*** 230,236
set $files; file=$1; shift; files=$*
set $links; link=$1; shift; links=$*
! if [ ! -r $file ]
then
echo "$progname: cannot create a link \`$link',"
echo "since the file \`$file' does not exist."
- --- 242,248 -----
set $files; file=$1; shift; files=$*
set $links; link=$1; shift; links=$*
! if [ ! -r $path$file ]
then
echo "$progname: cannot create a link \`$link',"
echo "since the file \`$path$file' does not exist."
***************
*** 233,239
if [ ! -r $file ]
then
echo "$progname: cannot create a link \`$link',"
! echo "since the file \`$file' does not exist."
exit 1
fi
- --- 245,251 -----
if [ ! -r $path$file ]
then
echo "$progname: cannot create a link \`$link',"
! echo "since the file \`$path$file' does not exist."
exit 1
fi
***************
*** 240,246
$remove -f $link
rm -f config.status
# Make a symlink if possible, otherwise try a hard link
! $symbolic_link $file $link 2>/dev/null || $hard_link $file $link
if [ ! -r $link ]
then
- --- 252,258 -----
$remove -f $link
rm -f config.status
# Make a symlink if possible, otherwise try a hard link
! $symbolic_link $path$file $link 2>/dev/null ||
$hard_link $path$file $link
if [ ! -r $link ]
then
***************
*** 244,250
if [ ! -r $link ]
then
! echo "$progname: unable to link \`$link' to \`$file'."
exit 1
fi
echo "Linked \`$link' to \`$file'."
- --- 256,262 -----
if [ ! -r $link ]
then
! echo "$progname: unable to link \`$link' to \`$path$file'."
exit 1
fi
echo "Linked \`$link' to \`$file$file'."
***************
*** 247,253
echo "$progname: unable to link \`$link' to \`$file'."
exit 1
fi
! echo "Linked \`$link' to \`$file'."
done
if [ xx${vint} = xx ]
- --- 259,265 -----
echo "$progname: unable to link \`$link' to \`$path$file'."
exit 1
fi
! echo "Linked \`$link' to \`$file$file'."
done
if [ xx${vint} = xx ]
Actually, I don't understand why config.g++ differs from config.gcc.
Assuming this is just for historical reasons, we could replace
the config target in the g++/vax/Makefile.
config:
$(CSRC)/config.gcc -path $(CSRC) $(MACHINE)