Mercurial > repo
comparison interps/c-intercal/etc/cftoec.sh @ 996:859f9b4339e6
<Gregor> tar xf egobot.tar.xz
author | HackBot |
---|---|
date | Sun, 09 Dec 2012 19:30:08 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
995:6883f5911eb7 | 996:859f9b4339e6 |
---|---|
1 #! /bin/sh | |
2 # This shell-script takes one argument, the path to a source | |
3 # distribution of cfunge, and compiles that source distribution into a | |
4 # library (libick_ecto_b98.a) suitable for linking to C-INTERCAL | |
5 # programs. The cfunge distribution itself is not modified; all changes | |
6 # are made on a copy. | |
7 | |
8 die() { echo "Error: $1"; exit 1; } | |
9 | |
10 if [ -z "$1" ] || [ -z "$2" ]; then | |
11 echo "Usage: $0 ick-source-path cfunge-path" | |
12 exit 1 | |
13 fi | |
14 | |
15 # test x$1 != x || ( | |
16 # echo Please give the path to the root of a cfunge source | |
17 # echo distribution as an argument to this script. | |
18 # exit 1 | |
19 # ) || exit 1 | |
20 | |
21 ICKSRC_PATH="$1" | |
22 CFUNGE_PATH="$2" | |
23 BUILD_PATH="$(pwd)" | |
24 | |
25 ICKSRC_PATH=`(cd $ICKSRC_PATH; pwd)` || ( | |
26 echo Please give the path to the root of C-INTERCAL source | |
27 echo distribution as the first argument to this script\; the directory | |
28 echo or file you gave does not exist. | |
29 exit 1 | |
30 ) || exit 1 | |
31 | |
32 CFUNGE_PATH=`(cd $CFUNGE_PATH; pwd)` || ( | |
33 echo Please give the path to the root of a cfunge source | |
34 echo distribution as the second argument to this script\; the directory | |
35 echo or file you gave does not exist. | |
36 exit 1 | |
37 ) || exit 1 | |
38 | |
39 test -f "$CFUNGE_PATH/src/interpreter.c" || ( | |
40 echo Please give the path to the root of a cfunge source | |
41 echo distribution as the second argument to this script. | |
42 echo You gave $CFUNGE_PATH, but it does not appear to be a cfunge | |
43 echo source distribution. | |
44 exit 1 | |
45 ) || exit 1 | |
46 | |
47 test -f "$ICKSRC_PATH/etc/IFFI.spec" || ( | |
48 echo Please give the path to the root of the C-INTERCAL source | |
49 echo distribution as the first argument of this script. | |
50 echo You gave $ICKSRC_PATH, but it does not appear to be a C-INTERCAL | |
51 echo source distribution. | |
52 exit 1 | |
53 ) || exit 1 | |
54 | |
55 echo Compiling cfunge into a library suitable for use with C-INTERCAL: | |
56 | |
57 rm -rf cftoec_temp || die "Failed to remove any old temp directory" | |
58 mkdir -p cftoec_temp || die "Failed to create temp directory" | |
59 cd cftoec_temp || die "Failed to change directory to temp directory" | |
60 | |
61 # Select compiler | |
62 if [ -z "$CC" ]; then | |
63 CC=cc | |
64 fi | |
65 | |
66 CFLAGS="-std=c99 -DUSE32 -DDISABLE_GC -DFUNGE_EXTERNAL_LIBRARY -D_POSIX_C_SOURCE=200112L -D_XOPEN_SOURCE=600 -D_XOPEN_SOURCE_EXTENDED -DFUNGE_OLD_HANDPRINT=0x43464649 '-DFUNGE_NEW_HANDPRINT=\"http://example.com/\"'" | |
67 # If GCC 4.1 or later is used add: | |
68 # -O1 -combine -fwhole-program -fvisibility=hidden. | |
69 # At least -O1 needed or -fwhole-program have no effect. Which is needed for | |
70 # this trick. | |
71 if "$CC" --version 2>&1 | grep -q GCC; then | |
72 GCC_VERSION="$("$CC" --version 2>&1 | awk '/[^ ]+ \(GCC\)/ {print $3}')" | |
73 GCC_MAJOR="$(echo "$GCC_VERSION" | cut -d. -f 1)" | |
74 GCC_MINOR="$(echo "$GCC_VERSION" | cut -d. -f 2)" | |
75 # We need GCC 4.1 or later. | |
76 if [ "$GCC_MAJOR" -eq 4 ]; then | |
77 if [ "$GCC_MINOR" -ge 1 ]; then | |
78 IS_GCC=yes | |
79 fi | |
80 elif [ "$GCC_MAJOR" -gt 4 ]; then | |
81 IS_GCC=yes | |
82 fi | |
83 fi | |
84 if [ "$IS_GCC" ]; then | |
85 CFLAGS="$CFLAGS -O1 -combine -fwhole-program -fvisibility=hidden" | |
86 fi | |
87 # Allow optional -O2 or such: | |
88 if [ "$CFUNGE_CFLAGS" ]; then | |
89 CFLAGS="$CFLAGS $CFUNGE_CFLAGS" | |
90 fi | |
91 # Please enable this when making changes. Requested by the cfunge author. | |
92 #CFLAGS="$CFLAGS -Wall -Wextra -pedantic -Wpointer-arith -Wimplicit -Wnested-externs -Wcast-align -Wcast-qual -Wbad-function-cast -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations -Wparentheses -Wshadow -Wundef -Wpacked -Wfloat-equal -Wstrict-aliasing=2 -Wformat=2 -Wdisabled-optimization -Wmissing-noreturn -Wmissing-format-attribute -Wdeclaration-after-statement -Wunused-function -Wunused-label -Wunused-value -Wunused-variable -Wwrite-strings" | |
93 | |
94 echo " " Duplicating cfunge source tree so that it can be modified... | |
95 cp -r $CFUNGE_PATH/src $CFUNGE_PATH/lib $CFUNGE_PATH/tools . | |
96 | |
97 # Comment these lines back in if patching is needed | |
98 # echo " " Patching cfunge source tree for use with C-INTERCAL... | |
99 # patch -p0 < ../cfunge.patch | |
100 | |
101 echo " " Adding the IFFI fingerprint... | |
102 cp -r "$ICKSRC_PATH/etc/IFFI" "$ICKSRC_PATH/etc/IFFI.spec" src/fingerprints | |
103 | |
104 echo " " Regenerating fingerprint lists... | |
105 tools/gen_fprint_list.sh > /dev/null || die "Failed to regen list." | |
106 | |
107 # Trust the filenames that are in the cfunge directory tree; if the user's | |
108 # trying to trick themselves into running this on something that looks like | |
109 # the cfunge directory tree but which has spaces or quotes in the filenames, | |
110 # I really can't be bothered to save them from themself. Dump all the resulting | |
111 # object files in this temp directory. | |
112 echo " " Compiling source... | |
113 if [ "$IS_GCC" ]; then | |
114 FILES="$(find . -name '*.c' -printf "%p ")" | |
115 # Pipe needed due to messy double quoting. | |
116 # It is impossible to use -o -c and multiple files all at once. GCC errors | |
117 # if you try. However the *.o will be equal to one of the source filenames | |
118 # but placed in the current directory and with .c replaced with .o | |
119 echo "$CC $CFLAGS -c $FILES" | sh | |
120 else | |
121 find . -name '*.c' -printf "$CC $CFLAGS -c %p -o %f.o\n" | sh | |
122 fi | |
123 | |
124 # Remove any existing library or ar would just add to the existing one. | |
125 rm -f ../libick_ecto_b98.a | |
126 | |
127 echo " " Creating library... | |
128 ar cr ../libick_ecto_b98.a *.o | |
129 ranlib ../libick_ecto_b98.a | |
130 | |
131 echo " " Cleaning up... | |
132 rm -rf * | |
133 cd .. | |
134 rm -rf cftoec_temp | |
135 | |
136 echo Finished, unless there were errors. |