~ubuntu-branches/ubuntu/utopic/apt-build/utopic

« back to all changes in this revision

Viewing changes to debian/postinst

  • Committer: Package Import Robot
  • Author(s): Dominique Lasserre
  • Date: 2012-04-11 23:13:55 UTC
  • mfrom: (8.1.2 experimental)
  • Revision ID: package-import@ubuntu.com-20120411231355-aqshq0pbkcydr8ne
Tags: 0.12.43
* QA upload.
* Upload to unstable
* Patch from Kumar Appaiah: Fix compiler links with host names. Closes:
  #502377
* Patch from Kumar Appaiah: Add gfortran support. Closes: #502379

Show diffs side-by-side

added added

removed removed

Lines of Context:
4
4
 
5
5
CONFFILE="/etc/apt/apt-build.conf"
6
6
 
7
 
 
8
 
find_arch()
9
 
{
10
 
    # We need to set RET empty in case of /proc/cpuinfo is missing
11
 
    RET=
12
 
    case "`dpkg-architecture -qDEB_HOST_ARCH`" in
13
 
        i[3-9]86|x86|x86pc|k5|k6|k6-2|k6-3|pentium*|athlon*|i586-i686)
14
 
                if [ -r /proc/cpuinfo ]; then
15
 
                    case "`grep 'vendor_id' /proc/cpuinfo | cut -d ':' -f 2 | head -n 1`" in
16
 
                        *AMD*)
17
 
                            db_input critical apt-build/arch_amd || true
18
 
                            db_go
19
 
                            db_get apt-build/arch_amd
20
 
                            ;;
21
 
                        *Intel*)
22
 
                            db_input critical apt-build/arch_intel || true
23
 
                            db_go
24
 
                            db_get apt-build/arch_intel
25
 
                            ;;
26
 
                    esac
27
 
                fi
28
 
                ;;
29
 
        sparc*)
30
 
                db_input critical apt-build/arch_sparc || true
31
 
                db_go
32
 
                db_get apt-build/arch_sparc
33
 
                ;;
34
 
        alpha)
35
 
                db_input critical apt-build/arch_alpha || true
36
 
                db_go
37
 
                db_get apt-build/arch_alpha
38
 
                ;;
39
 
        arm*)
40
 
                db_input critical apt-build/arch_arm || true
41
 
                db_go
42
 
                db_get apt-build/arch_arm
43
 
                ;;
44
 
        amd64|*-amd64)
45
 
                db_input critical apt-build/arch_amd64 || true
46
 
                db_go
47
 
                db_get apt-build/arch_amd64
48
 
                ;;
49
 
   esac
50
 
   arch="$RET"
51
 
}
52
 
 
53
 
get_config()
54
 
{
55
 
    db_get apt-build/olevel
56
 
    olevel="$RET"
57
 
    find_arch
58
 
    db_get apt-build/build_dir
59
 
    build_dir="$RET"
60
 
    db_get apt-build/repository_dir
61
 
    repository_dir="$RET"
62
 
    db_get apt-build/add_to_sourceslist
63
 
    add_to_sourceslist="$RET"
64
 
    db_get apt-build/options
65
 
    options="$RET"
66
 
    db_get apt-build/make_options
67
 
    make_options="$RET"
68
 
}
69
 
 
70
 
case "$1" in
71
 
    configure)
 
7
# remove obsolete config file from apt-build <= 0.12.37
 
8
if dpkg-maintscript-helper supports rm_conffile 2>/dev/null ; then
 
9
  dpkg-maintscript-helper rm_conffile /etc/apt/sources.list.d/apt-build -- "$@"
 
10
fi
 
11
 
 
12
if [ "$1" = "configure" ] ; then
72
13
        . /usr/share/debconf/confmodule
73
 
        get_config
74
 
 
 
14
  
 
15
  db_get apt-build/olevel
 
16
        case "$RET" in
 
17
          "Light")
 
18
                  Olevel="-O1"
 
19
                  ;;
 
20
          "Medium")
 
21
                  Olevel="-O2"
 
22
                  ;;
 
23
          "Strong")
 
24
                  Olevel="-O3"
 
25
      ;;
 
26
        esac
 
27
  
 
28
  db_get apt-build/build_dir
 
29
  build_dir="$RET"
 
30
  
 
31
  db_get apt-build/repository_dir
 
32
  repository_dir="$RET"
 
33
  
 
34
  db_get apt-build/add_to_sourceslist
 
35
  add_to_sourceslist="$RET"
 
36
  
 
37
  db_get apt-build/options
 
38
  options="$RET"
 
39
  
 
40
  db_get apt-build/make_options
 
41
  make_options="$RET"
 
42
  
 
43
  db_get apt-build/archtype
 
44
  #march=-march="$RET"
 
45
  mtune=-mtune="$RET"
 
46
  
75
47
        # Create build_dir
76
 
        if [ ! -e "$build_dir" ]; then
77
 
            mkdir -p "$build_dir"
 
48
        if [ ! -e "$build_dir" ] ; then
 
49
          mkdir -p "$build_dir"
78
50
        fi
79
 
 
 
51
  
80
52
        # Create repository_dir
81
 
        if [ ! -e "$repository_dir" ]; then
82
 
            mkdir -p "$repository_dir"
83
 
            cd "$repository_dir"
84
 
            ln -s . stable
85
 
            ln -s . dists
86
 
            ln -s . apt-build
87
 
            ln -s . main
88
 
            ln -s . binary-`dpkg --print-architecture`
89
 
        fi
90
 
        
91
 
        sed s/__arch__/`dpkg --print-architecture`/ /usr/share/apt-build/Release > "$repository_dir/Release"
92
 
 
93
 
        # Add to sources.list if asked
94
 
        if [ "$add_to_sourceslist" = "true" ] && [ -z "`grep "$repository_dir" /etc/apt/sources.list`" ]; then
95
 
            tempfile=`tempfile -m 644`
96
 
            echo "deb file:$repository_dir apt-build main" > $tempfile
97
 
            mv $tempfile /etc/apt/sources.list.d/apt-build.list
98
 
        fi
 
53
        if [ ! -e "$repository_dir" ] ; then
 
54
            mkdir -p "$repository_dir"/dists/apt-build/main
 
55
      ln -s ../../.. "$repository_dir"/dists/apt-build/main/binary-$(dpkg --print-architecture)
 
56
  fi
 
57
  
 
58
  # link release file for apt-build distribution (for upgrade from 0.12.41)
 
59
  if [ ! -e "$repository_dir"/dists/apt-build/Release ] ; then
 
60
    ln -s ../../Release "$repository_dir"/dists/apt-build/Release
 
61
  fi
 
62
  
 
63
  sed s/__arch__/$(dpkg --print-architecture)/ /usr/share/apt-build/Release > "$repository_dir/Release"
 
64
  
 
65
  
 
66
  # prepare sources.list entry
 
67
  eval $(apt-config shell etcdir Dir::Etc)
 
68
  eval $(apt-config shell sourceslist Dir::Etc::sourcelist)
 
69
  eval $(apt-config shell sourcesparts Dir::Etc::sourceparts)
 
70
  sourceslist=/"$etcdir""$sourceslist"
 
71
  sourcesparts=/"$etcdir""$sourcesparts"
 
72
  aptbuildsource="$sourcesparts"/apt-build.list
 
73
  debline="deb file:$repository_dir apt-build main"
 
74
  src_enabled="false"
 
75
  
 
76
  # run loop to prevent errors if some sources does not exist
 
77
  for source in "$sourceslist" "$sourcesparts"/*.list ; do
 
78
    if [ -e "$source" ] ; then
 
79
            # comment in all sources lists if asked
 
80
            if [ "$add_to_sourceslist" = "false" ] ; then
 
81
        sed -i -e "s|^[:space:]*$debline.*|#$debline|" "$source"
 
82
      
 
83
      # check if source entry is already enabled
 
84
      elif grep -Eq "^[[:space:]]*$debline" "$source" ; then
 
85
        src_enabled="true"
 
86
      fi
 
87
    fi
 
88
  done
 
89
  
 
90
  # do not modify anything if source entry is already enabled
 
91
  if [ "$add_to_sourceslist" = "true" ] && [ $src_enabled = "false" ] ; then
 
92
    if [ ! -e "$sourcesparts" ] ; then
 
93
      mkdir -p "$sourcesparts"
 
94
    fi
 
95
    
 
96
    if [ ! -e "$aptbuildsource" ] ; then
 
97
      echo "$debline" > "$aptbuildsource"
 
98
    fi
 
99
    
 
100
    if grep -q "$debline" "$aptbuildsource" ; then
 
101
      # modify only first occurrence of $debline to prevent duplicate entries
 
102
      sed -i -e "0,\|^.*$debline|s||$debline|" "$aptbuildsource"
 
103
    else
 
104
      echo "$debline" >> "$aptbuildsource"
 
105
    fi
 
106
  fi
99
107
 
100
108
        # Remove one-byte Packages file created by old postinst
101
 
        if [ -f $repository_dir/Packages.gz ] && [ $(zcat $repository_dir/Packages.gz | wc -c) -eq 1 ]; then
102
 
            rm -f $repository_dir/Packages.gz
103
 
        fi
 
109
        if [ -f $repository_dir/Packages.gz ] && [ $(zcat $repository_dir/Packages.gz | wc -c) -eq 1 ] ; then
 
110
    rm -f $repository_dir/Packages.gz
 
111
  fi
104
112
        
105
 
        if [ ! -e "$repository_dir/Packages.gz" ]; then
106
 
            gzip -9 < /dev/null > "$repository_dir/Packages.gz"
 
113
        if [ ! -e "$repository_dir/Packages.gz" ] ; then
 
114
          gzip -9 < /dev/null > "$repository_dir/Packages.gz"
107
115
        fi
108
 
            
109
 
        # Configure
110
 
 
111
 
        echo "build-dir = $build_dir" > $CONFFILE
112
 
        echo "repository-dir = $repository_dir" >> $CONFFILE
113
 
 
114
 
        case "$olevel" in
115
 
            "Light")
116
 
                echo "Olevel = -O1" >> $CONFFILE
117
 
                ;;
118
 
            "Medium")
119
 
                echo "Olevel = -O2" >> $CONFFILE
120
 
                ;;
121
 
            "Strong")
122
 
                echo "Olevel = -O3" >> $CONFFILE
123
 
                ;;
124
 
        esac
125
 
 
126
 
#       echo "march = -march=$arch" >> $CONFFILE
127
 
        echo "mtune = -mtune=$arch" >> $CONFFILE
128
 
        echo "options = \" $options\"" >> $CONFFILE
129
 
        echo "make_options = \" $make_options\"" >> $CONFFILE
130
 
 
131
 
        exit 0
132
 
        ;;
133
 
 
134
 
    upgrade|abort-upgrade|abort-remove|abort-deconfigure)
135
 
        ;;
136
 
 
137
 
    *)
138
 
         echo "postinst called with unknown argument \`$1'" >&2
139
 
         exit 0
140
 
    ;;
141
 
esac
142
 
 
 
116
        
 
117
  
 
118
        # Configuration options
 
119
  # if config file does not exist
 
120
  if [ ! -e $CONFFILE ] ; then
 
121
    echo "build-dir =" > $CONFFILE
 
122
    echo "repository-dir =" >> $CONFFILE
 
123
    echo "Olevel =" >> $CONFFILE
 
124
    #echo "march =" >> $CONFFILE
 
125
    echo "mtune =" >> $CONFFILE
 
126
    echo "options =" >> $CONFFILE
 
127
    echo "make_options =" >> $CONFFILE
 
128
  fi
 
129
  
 
130
  cp -a -f $CONFFILE $CONFFILE.tmp
 
131
  
 
132
  # (re)add deleted or commented variables
 
133
  test -z "build-dir" || grep -Eq '^[[:space:]]*build-dir =' $CONFFILE || \
 
134
    echo "build-dir =" >> $CONFFILE
 
135
  test -z "repository-dir" || grep -Eq '^[[:space:]]*repository-dir =' $CONFFILE || \
 
136
    echo "repository-dir =" >> $CONFFILE
 
137
  test -z "Olevel" || grep -Eq '^[[:space:]]*Olevel =' $CONFFILE || \
 
138
    echo "Olevel =" >> $CONFFILE
 
139
  #test -z "march" || grep -Eq '^[[:space:]]*march =' $CONFFILE || \
 
140
  #  echo "march =" >> $CONFFILE
 
141
  test -z "mtune" || grep -Eq '^[[:space:]]*mtune =' $CONFFILE || \
 
142
    echo "mtune =" >> $CONFFILE
 
143
  test -z "options" || grep -Eq '^[[:space:]]*options =' $CONFFILE || \
 
144
    echo "options =" >> $CONFFILE
 
145
  test -z "make_options" || grep -Eq '^[[:space:]]*make_options =' $CONFFILE || \
 
146
    echo "make_options =" >> $CONFFILE
 
147
  
 
148
  sed -e "s|^[:space:]*build-dir =.*|build-dir = $build_dir|" \
 
149
      -e "s|^[:space:]*repository-dir =.*|repository-dir = $repository_dir|" \
 
150
      -e "s|^[:space:]*Olevel =.*|Olevel = $Olevel|" \
 
151
      -e "s|^[:space:]*mtune =.*|mtune = $mtune|" \
 
152
      -e "s|^[:space:]*options =.*|options = \" $options\"|" \
 
153
      -e "s|^[:space:]*make_options =.*|make_options = \" $make_options\"|" \
 
154
      < $CONFFILE > $CONFFILE.tmp
 
155
  
 
156
  mv -f $CONFFILE.tmp $CONFFILE
 
157
fi
143
158
 
144
159
#DEBHELPER#