Mercurial > repo
comparison gcccomp @ 5020:fb86bf0b485a
<oerjan> fetch http://oerjan.nvg.org/gcccomp
author | HackBot |
---|---|
date | Mon, 06 Oct 2014 05:38:14 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
5019:917b2cefb4c5 | 5020:fb86bf0b485a |
---|---|
1 #!/bin/bash | |
2 LANG="$1" | |
3 echo >>"$2" | |
4 | |
5 case "$LANG" in | |
6 c) | |
7 HEAD='#include <stdio.h>\n#include <stdlib.h>\n#include <string.h>\n#include <sys/types.h>\n#include <unistd.h>\nint main(int argc, char **argv) {\nint main(void) { printf("Calling main from itself not supported.\n"); exit(1); }\n' | |
8 TAIL='; return 0; }' | |
9 EXT='c' | |
10 GCC='gcc' | |
11 FLAGS='-std=gnu99' | |
12 ;; | |
13 | |
14 c++) | |
15 HEAD='#include <iostream>\n#include <cstdio>\n#include <cstdlib>\n#include <cstring>\nusing namespace std;\nint main(int argc, char **argv) {' | |
16 TAIL='; return 0; }' | |
17 EXT='cc' | |
18 GCC='g++' | |
19 FLAGS='-std=gnu++0x' | |
20 ;; | |
21 | |
22 assembler) | |
23 HEAD='.globl main; main: pushq %rbp; movq %rsp, %rbp;' | |
24 TAIL='movl $0, %eax; leave; ret;' | |
25 EXT='s' | |
26 GCC='gcc' | |
27 FLAGS='' | |
28 ;; | |
29 | |
30 java) | |
31 HEAD='class Main { public static void main(String[] args) {' | |
32 TAIL='; } }' | |
33 EXT='java' | |
34 GCC='gcj' | |
35 FLAGS='--main=Main' | |
36 ;; | |
37 esac | |
38 | |
39 SOURCE="/tmp/source.$$.$EXT" | |
40 | |
41 ( | |
42 echo -e "$HEAD" | |
43 cat "$2" | |
44 echo "$TAIL" | |
45 ) > "$SOURCE" | |
46 | |
47 "$GCC" -x "$LANG" "$SOURCE" $FLAGS -o /tmp/compiled.$$ 2> /dev/null || | |
48 "$GCC" -x "$LANG" "$2" $FLAGS -o /tmp/compiled.$$ 2> /dev/null || | |
49 echo 'Does not compile.' | |
50 rm -f "$SOURCE" | |
51 | |
52 #ulimit -u 3 | |
53 if [ -x /tmp/compiled.$$ ] ; then /tmp/compiled.$$; fi 2>&1 | |
54 rm -f /tmp/compiled.$$ |