Fixed parsing of maybe types in statements
[delight/core.git] / package / simple.sh
blob5dd9038b9c108672dd7901bbbd7a0975b133e2f2
1 #!/bin/sh
3 # Usage: simple.sh <pkg name>
4 # Creates gdc-<pkg name>.tar.gz, etc.
7 # Special package types:
8 # --skyos: different package prefix directories, metafile, filesystem workarounds
9 # --macos: don't include shared libgcc
11 # set -x
13 make_skyos_package=
14 make_macos_package=
15 keep_gcov=
16 keep_gcc=
17 no_cleanup=
18 have_install_root=
19 MAKE=${MAKE:-make}
21 while test "$#" -gt 0; do
22 case "$1" in
23 --with-install-root=*) have_install_root=${1##--with-install-root=} ;;
24 --macos) make_macos_package=yes ;;
25 --skyos) make_skyos_package=yes ;;
26 --keepgcc) keep_gcc=yes ;;
27 --keepgcov) keep_gcov=yes ;;
28 --nocleanup) no_cleanup=yes ;;
29 --results-file=*) results_file=${1##--results-file=} ;;
30 -*) echo "error: invalid option $1"
31 exit 1
34 if test -z "$pkg_name"; then
35 pkg_name=gdc-$1
36 else
37 echo "error: extra argument $1"
38 exit 1
41 esac
42 shift
43 done
45 if test ! -r gcc/d/pkgvars; then
46 echo "This script most be run from the top-level GCC build directory."
47 exit 1
50 build_dir=`pwd`
52 # Grab some configuration info
53 . gcc/d/pkgvars
55 # Find the correct 'strip' program for the host
56 host_strip=strip
57 target_strip=strip
59 if test "$target" != "$build"; then
60 if $target_alias-strip -h; then
61 target_strip=$target_alias-strip
62 else
63 echo "warning: probably have the wrong strip for $target"
66 if test "$host" != "$build"; then
67 if test "$host" = "$target"; then
68 host_strip=$target_strip
69 else
70 echo "warning: probably have the wrong strip for $host"
74 if test -n "$have_install_root"; then
75 inst_root=$have_install_root
76 else
77 inst_root=/tmp/gdcinstroot$$
78 mkdir -p "$inst_root" || exit 1
79 $MAKE install "DESTDIR=$inst_root" > /dev/null || exit 1
82 # $srcdir can be relative to <build>/gcc
83 cd gcc
85 gdc_version=`sed -e 's/gdc \(.*\), using.*/\1/' "$srcdir/d/gdc-version"`
87 if test -z "$pkg_name"; then
88 pkg_name="gdc-$gdc_version-$target_alias"
91 # If this is a native compiler, try to build rdmd
92 # (This should be moved into the GCC build)
93 if test "$build" = "$host" && test "$host" = "$target"; then
94 if test ! -f "$inst_root/$prefix/bin/rdmd$exeext"; then
95 "$inst_root/$prefix/bin/gdc" -o "$inst_root/$prefix/bin/rdmd$exeext" \
96 $srcdir/d/rdmd.d || exit 1
98 if test -d "$inst_root/$prefix/share/man/man1"; then
99 # Note: No ".1" extension -- assumes MacOS Universal build
100 cp $srcdir/d/rdmd.1 "$inst_root/$prefix/share/man/man1/rdmd" || exit 1
101 else
102 cp $srcdir/d/rdmd.1 "$inst_root/$prefix/man/man1" || exit 1
106 #pkg_root=/tmp/$pkg_name
107 pkg_root=/tmp/gdc
109 file_list=/tmp/gdcpkglist$$
110 rm -f "$file_list" && touch "$file_list" || exit 1
112 cd "$inst_root/$prefix" || exit 1
114 # Use lib*/... to pick up multilib. Assume that picking up libexec
115 # does not cause problems because of the rest of the search pattern.
117 if test -n "$keep_gcc"; then
118 find . > "$file_list"
119 else
120 ls bin/*gdc* >> "$file_list"
121 ls bin/*gdmd* >> "$file_list"
122 ls bin/*rdmd* >> "$file_list"
123 ls -d include/d >> "$file_list"
124 ls -d include/d2 >> "$file_list"
125 find lib*/gcc -name '*.o' -o -name 'libgcc*.a' >> "$file_list"
126 if test -z "$make_macos_package"; then
127 ls lib*/libgcc* >> "$file_list"
129 ls lib*/libgphobos* >> "$file_list"
130 find libexec -name '*cc1d*' >> "$file_list"
131 find libexec -name '*collect2*' >> "$file_list"
132 ls man/man1/*gdc* >> "$file_list"
133 ls man/man1/*gdmd* >> "$file_list"
134 ls man/man1/*rdmd* >> "$file_list"
135 ls share/man/man1/*gdc* >> "$file_list"
136 ls share/man/man1/*gdmd* >> "$file_list"
137 ls share/man/man1/*rdmd* >> "$file_list"
139 if test -n "$keep_gcov"; then
140 ls bin/*gcov* >> "$file_list"
141 # Don't need lib* here -- it's all buried under lib/gcc/<target alias>
142 find lib -name 'libgcov*' >> "$file_list"
143 ls man/man1/*gcov* >> "$file_list"
144 ls share/man/man1/*gcov* >> "$file_list"
148 if test -n "$make_skyos_package"; then
149 tgt=$pkg_root/$prefix
150 else
151 tgt=$pkg_root
154 mkdir -p "$tgt"
156 # simulate: rsync -a --files-from="$file_list" -rH . "$tgt"
157 while true; do
158 read src || break
159 if test -z "$src"; then continue; fi
160 tar cf - "$src" | tar xf - -C "$tgt"
161 done < "$file_list"
164 # Apple build installs gdc-4.0, but not 'gdc'. For a stand-alone package,
165 # there should be a unprefixed 'gdc' and 'gdmd'. Cross compilers should
166 # *not* have unprefixed in <prefix>/bin.
167 if test "$host" = "$target"; then
168 cd "$tgt/bin" || exit 1
169 for prg in gdc gdmd; do
170 if test "$prg" = gdmd; then
171 ext=''
172 else
173 ext=$exeext
175 if ! test -f $prg$ext; then
176 # ln -s $prg-* $prg is successful even if there is no match..
177 if ls $prg-*; then
178 ln -s $prg-* $prg$ext || exit 1
179 elif ls *-$prg$ext; then
180 ln -s *-$prg$ext $prg$ext || exit 1
181 else
182 echo "error: no $prg-like executable in bin"
183 exit 1
186 done
189 cd "$tgt" || exit 1
191 # This is missing some files for MacOS universal, but the Apple build
192 # script has already stripped them.
193 $host_strip bin/* > /dev/null
194 $host_strip libexec/gcc/$target_alias/$gcc_version/* > /dev/null
195 $host_strip $target_alias/bin/* > /dev/null
196 # TODO: these options are specific to binutils?
197 $target_strip -S -X lib*/lib*.*
198 $target_strip -S -X lib/gcc/$target_alias/$gcc_version/* > /dev/null
200 if test "$build" != "$host"; then
201 echo "note: removing specs as it is mostly like wrong"
202 #rm -f find . -name specs
203 rm lib/gcc/$target_alias/$gcc_version/specs
206 cd "$build_dir/gcc"
208 doc_dir="$tgt/share/doc/gdc"
209 mkdir -p "$doc_dir" || exit 1
210 cp -p "$srcdir/d/README" "$doc_dir/README.GDC" || exit 1
211 cp -p "$srcdir/d/GDC.html" "$doc_dir" || exit 1
213 if test -z "$results_file"; then
214 results_file=/tmp/gdc-packages-list
216 rm -f "$results_file" && \
217 touch "$results_file" \
218 || exit 1
220 file_base="/tmp/$pkg_name"
221 tar_file="$file_base.tar"
223 if test -n "$make_skyos_package"; then
224 # kill hard link variants
225 rm -f "$pkg_root/$prefix"/bin/*-*
227 cd "$build_dir/gcc"
229 skyos_date=`date "+%B %e, %Y"`
230 sed -e "s/@gdc_version@/$gdc_version/" -e "s/@skyos_date@/$skyos_date/" \
231 "$srcdir/d/package/install.sif" > "$inst_root/boot/install.sif"
233 cd "$pkg_root/boot" || exit 1
234 tar cf "$tar_file" * || exit 1
235 else
236 cd `dirname "$pkg_root"` || exit 1
237 tar cf "$tar_file" `basename "$pkg_root"` || exit 1
239 echo "$tar_file" >> "$results_file"
241 gzip -c9 "$tar_file" > "$tar_file.gz" || exit 1
242 echo "$tar_file.gz" >> "$results_file" || exit 1
244 bzip2 -c9 "$tar_file" > "$tar_file.bz2" || exit 1
245 echo "$tar_file.bz2" >> "$results_file" || exit 1
247 if test -n "$make_skyos_package"; then
248 cp "$tar_file.gz" "$file_base.pkg" || exit 1
249 echo "$file_base.pkg" >> "$results_file" || exit 1
252 if test -z "$no_cleanup"; then
253 rm -f "$file_list"
254 rm -rf "$pkg_root"
255 if test -z "$have_install_root"; then
256 rm -rf "$inst_root"