summaryrefslogtreecommitdiffstats
path: root/doc/distcc
blob: 1afdfbe039f16c123afd31c611a88d974f5ca7d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
Online documentation:

Using distcc and crosstool-ng for distributed cross-compilations:
- http://archlinuxarm.org/developers/distcc-cross-compiling

Setting up a distcc environment:
- http://archlinuxarm.org/developers/distributed-compiling

# ===========================================================================

Setting up distcc on the host (the ARM computer):

Add the following to /etc/profile.d/distcc.sh :

#-----8<------------------------------------------
# Explicitly set the ARCH since we are not natively compiling:
export ARCH=armv7hl

# Automatically determine the ARCH we are running distcc on:
MARCH=$( uname -m )
if [ -z "$ARCH" ]; then
  case "$MARCH" in
    i?86)    export ARCH=i486 ;;
    armv7hl) export ARCH=$MARCH ;;
    arm*)    export ARCH=arm ;;
    # Unless $ARCH is already set, use uname -m for all other archs:
    *)       export ARCH=$MARCH ;;
  esac
fi

case "$ARCH" in
    arm*) TARGET=$ARCH-slackware-linux-gnueabi ;;
    *)    TARGET=$ARCH-slackware-linux ;;
esac

# Define the compilers with their full name, not just "gcc" - or else
# we can not distribute the compilation to a distcc cross-compiler:
export CC=${TARGET}-gcc
export CXX=${TARGET}-g++
export AS=${TARGET}-as

# We need a private directory where we will create distcc symlinks:
DISTCC_CPATH="/var/tmp/${UID}/distcc"

# Create distcc compiler and assembler symlinks, for our host architecture:
( mkdir -p $DISTCC_CPATH
  cd $DISTCC_CPATH
  ln -svf /usr/bin/distcc ${TARGET}-gcc
  ln -svf /usr/bin/distcc ${TARGET}-g++
  ln -svf /usr/bin/distcc ${TARGET}-c++
  ln -svf /usr/bin/distcc ${TARGET}-as
)
# So that every compiler call will actually trigger distcc:
export PATH="$DISTCC_CPATH:$PATH"

# First priority is the localhost (the arm computer), note that this must
# be the literal string "localhost" which is interpreted as "run a compilation
# locally if only a single job must be run":
export DISTCC_HOSTS="localhost 192.168.0.1"
#-----8<------------------------------------------

Setting up my own distcc server:

In /etc/hosts.allow, define distccd hosts or network, otherwise the master
won't be able to connect (distcc runs on port 3632):

#-----8<------------------------------------------
distccd: 192.168.0.0/24
#-----8<------------------------------------------

Create a file with defaults for the rc.distccd script which comes next:

#-----8<------------------------------------------
# Example /etc/default/distccd 
DISTCCD_USER=nobody
DISTCCD_NUMJOBS=5
DISTCCD_ALLOW="192.168.0.0/24"
DISTCCD_PID="/var/run/distcc/distccd.pid"
#-----8<------------------------------------------

Create /etc/rc.d/rc.distccd as follows:

#-----8<------------------------------------------
# /etc/rc.d/rc.distccd
#
#    Start/stop/restart the distcc daemon.
#

# Load defaults:
if [ -f /etc/default/distccd ] ; then
  . /etc/default/distccd
fi

DISTCCD_USER=${DISTCCD_USER:-nobody}
DISTCCD_NUMJOBS=${DISTCCD_NUMJOBS:-5}
DISTCCD_ALLOW=${DISTCCD_ALLOW:-"192.168.0.0/24"}
DISTCCD_PID=${DISTCCD_PID:-/var/run/distcc/distccd.pid}

# If we allow cross-compiling, then define the architecture(s) space-separated:
DISTCCD_TARGET=${DISTCCD_TARGET:-"armv7hl"}

# Determine the ARCH we are running the distcc daemon on:
case "$( uname -m )" in
   i?86) DISTCCARCH=i486 ;;
      *) DISTCCARCH=$( uname -m ) ;;
esac

if [ -n "$DISTCCD_TARGET" ]; then
  # Where will distcc find the crosscompiler:
  DISTCC_BASEDIR=/tftpboot/crossdev/${DISTCCARCH}
  for CARCH in $DISTCCD_TARGET ; do
    DISTCC_PATH="${DISTCC_BASEDIR}/${CARCH}/bin:${DISTCC_PATH}"
  done
  echo "Distcc will look for crosscompilers in '$DISTCC_PATH'"
fi

distccd_start() {
  echo "Starting distcc daemon:  /usr/bin/distccd start"
  mkdir -p /var/run/distcc
  chown $DISTCCD_USER /var/run/distcc
  touch /var/log/distccd.log
  chown $DISTCCD_USER /var/log/distccd.log

  DISTCCD_PATH=$DISTCC_PATH/bin \
  /usr/bin/distccd --daemon -N 5 --user $DISTCCD_USER --allow $DISTCCD_ALLOW --jobs $DISTCCD_NUMJOBS --pid-file $DISTCCD_PID --log-file /var/log/distccd.log
}

distccd_stop() {
  killall distccd
}

distccd_status() {
  PIDS=$(cat $DISTCCD_PID 2>/dev/null)
  if [ "$PIDS" == "" ]; then
    echo "distccd is not running!"
  else
    echo "distccd is running at pid(s) ${PIDS}."
  fi
}

case "$1" in
   'start')
      distccd_start
      ;;
   'stop')
      distccd_stop
      ;;
   'restart')
      distccd_stop
      sleep 1
      distccd_start
      ;;
   'status')
      distccd_status
      ;;
   *)
      echo "usage $0 start|stop|restart|status" ;;
esac
#-----8<------------------------------------------