summaryrefslogtreecommitdiff
path: root/gcc/melt-cc-script.proto
blob: 4c7718af4a29e4b2b22fd0b6d70db989c70906bc (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
#! /bin/sh
#:! line starting with #:! are removed from this melt-cc-script.proto 
#:! -*- bash -*-
#    Copyright (C) 2008, 2009 Free Software Foundation, Inc.
#    Contributed by Basile Starynkevitch <basile@starynkevitch.net>
# 
# This file :MELT_SCRIPT: is part of GCC.
# 
# GCC is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3, or (at your option)
# any later version.
# 
# GCC is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with GCC; see the file COPYING3.   If not see
# <http://www.gnu.org/licenses/>. 

#:! :MELT_CC: & :MELT_CFLAGS: &:MELT_HEADERDIR:  are substituted in the first 30 lines

melt_cc=":MELT_CC:"
melt_cflags=":MELT_CFLAGS:"
melt_headerdir=":MELT_HEADERDIR:"

if [ -n "$MELT_CC" ]; then
    melt_cc=$MELT_CC
fi

if [ -n "$MELT_EXTRACFLAGS" ]; then
    melt_cflags="$melt_cflags $MELT_EXTRACFLAGS"
fi

#set -x
## script invoked by cc1 with two arguments : the generated C source to compile
## and the naked (without suffix) dynamically-loadable stuff to generate

## for commodity, we pass -D -U -I -O* to gcc, and -F to set the cflags,
## -C to set the compiler, and -x & -v for debugging and -n to omit
## line info, -d for dynamic object structures
while getopts "D:I:U:F:C:O:xvnd" flag ; do
    : the $flag 
    case "$flag" in
	D) melt_cflags="$melt_cflags -D$OPTARG";;
	U) melt_cflags="$melt_cflags -U$OPTARG";;
	I) melt_cflags="$melt_cflags -U$OPTARG";;
	O) melt_cflags="$melt_cflags -O$OPTARG";;
	F) melt_cflags="$melt_cflags $OPTARG";;
	C) melt_cc="$OPTARG";;
	n)  melt_cflags="$melt_cflags -DMELTGCC_NOLINENUMBERING";;
	d) melt_cflags="$melt_cflags -DMELTGCC_DYNAMIC_OBJSTRUCT";;
	x) set -x;;
	v) set -v;;
	*) echo unrecognized flag $flag;;
    esac
done
shift `expr $OPTIND - 1`

csource=$1
dynstuff=$2


## on some machines, try to guess the dynstuff from the csource
if [ -z $dynstuff ]; then
    case `uname` in
	Linux|SunOS|Solaris) 
	    dynstuff=`basename $csource .c`.so;;
    esac
fi

case $dynstuff in
    *.so) nakedynstuff=`basename $dynstuff .so`;;
    *.sl) nakedynstuff=`basename $dynstuff .sl`;;
    *.la) nakedynstuff=`basename $dynstuff .la`;;
    *.lo) nakedynstuff=`basename $dynstuff .lo`;;
    *.shlib) nakedynstuff=`basename $dynstuff .shlib`;;
    *.dylib) nakedynstuff=`basename $dynstuff .dylib`;;
    *) nakedynstuff=`echo $dynstuff | sed 's/\.[a-z]*$//'`;;
esac

: ${TMPDIR=/tmp}

if which tempfile > /dev/null 2>&1; then
    datf=`tempfile  -p bdat`
elif which mktemp > /dev/null 2>&1; then
    datf=`mktemp -t bdat.XXXXXXXX`
else
    datf=$TMPDIR/bdat$$-$RANDOM
fi

rm -f $datf $datf.c $datf.*

#pwd

# generate the temporary timestamp & md5s file
md5src=`md5sum $csource`     

trap "rm -f $datf.* $datf $nakedynstuff.o" EXIT

date "+const char basilys_compiled_timestamp[]=\"%c $csource\";" > $datf.c
echo "const char basilys_md5[]=\"$md5src\";" >> $datf.c
echo "const char basilys_csource[]=\"$csource\";" >> $datf.c

case `uname` in
Linux|SunOS|Solaris)
	$melt_cc -Wall -fPIC $melt_cflags -I "$melt_headerdir" $csource -c -o $nakedynstuff.o
	$melt_cc -Wall -fPIC -shared $melt_cflags -I "$melt_headerdir"  $datf.c $nakedynstuff.o  -o $nakedynstuff.so
	;;
*) 
	libtool --mode=compile -prefer-pic $melt_cc $melt_cflags $csource  -I "$melt_headerdir" -o $nakedynstuff.lo;
	libtool --mode=compile -prefer-pic $melt_cc $melt_cflags $datf.c -o $datf.lo
	libtool --mode=link -module $melt_cc  $makedynstuff.lo $datf.lo -o  $nakedynstuff.la
	rm -f $datf.*
	;;
esac

#echo done $0 $* '@@@@'
#echo