aboutsummaryrefslogtreecommitdiff
path: root/build.sh
blob: 2b4fdfd6fbcc479d598f8daa0ff0126556ed67c3 (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
#!/bin/bash

BUSRC="stack.cpp string.cpp hash.cpp list.cpp trace.cpp stream.cpp formatter.cpp util.cpp sharedcore.cpp exceptionbase.cpp heap.cpp archivebase.cpp archive.cpp queue.cpp archival.cpp sio.cpp stdstream.cpp process.cpp plugger.cpp optparser.cpp signals.cpp array.cpp membuf.cpp file.cpp variant.cpp random.cpp randombasic.cpp randombase.cpp streamstack.cpp exceptioninvaliditerator.cpp exceptionindexoutofbounds.cpp"
BUHDR="stack.h string.h hash.h list.h trace.h stream.h formatter.h util.h sharedcore.h exceptionbase.h heap.h archivebase.h archive.h queue.h archival.h sio.h stdstream.h process.h plugger.h singleton.h optparser.h array.h membuf.h file.h variant.h fmt.h extratypes.h random.h randombasic.h randombase.h streamstack.h exceptioninvaliditerator.h exceptionindexoutofbounds.h"
BUEXPSRC="regex.cpp"
BUEXPHDR="regex.h"
BUUNSSRC="blob.cpp blobbuilder.cpp"
BUUNSHDR="blob.h blobbuilder.h"
BUCOMPAT="config.h compat/linux.h compat/win32.h compat/osx.h"

if [ -z "${CXX}" ]; then
    CXX="g++"
fi

function bld()
{
	OUTFILE="$1"
	if [ ! -e "$OUTFILE" ]; then
		return 1
	fi
	shift
	for INFILE in $*; do
		if [ "$INFILE" -nt "$OUTFILE" ]; then
			return 1
		fi
	done
	return 0
}

function cmd()
{
	printf "%8s $2\n" $1
	shift 2
	$* || exit
}

function gpp()
{
	bld "$1" "$2" || cmd CXX "$1" ${CXX} -ggdb -fPIC -W -Wall -Iminibu -c -o "$1" "$2"
}

function presetup()
{
    for dir in minibu/src minibu/bu minibu/bu/compat; do
        cmd MKDIR ${dir} mkdir -p ${dir}
    done
    cmd FAKE minibu/bu/autoconfig.h touch minibu/bu/autoconfig.h
    for file in $(cd bootstrap; ls); do
        cmd BOOTSTRAP minibu/bu/${file} cp bootstrap/${file} minibu/bu
    done
    for F in $BUSRC; do
        bld minibu/src/$F || cmd CP minibu/src/$F cp ../libbu++/src/stable/$F minibu/src/$F
    done
    for F in $BUHDR; do
        bld minibu/bu/$F || cmd CP minibu/bu/$F cp ../libbu++/src/stable/$F minibu/bu/$F
    done
    for F in $BUEXPSRC; do
        bld minibu/src/$F || cmd CP minibu/src/$F cp ../libbu++/src/experimental/$F minibu/src/$F
    done
    for F in $BUEXPHDR; do
        bld minibu/bu/$F || cmd CP minibu/bu/$F cp ../libbu++/src/experimental/$F minibu/bu/$F
    done
    for F in $BUUNSSRC; do
        bld minibu/src/$F || cmd CP minibu/src/$F cp ../libbu++/src/unstable/$F minibu/src/$F
    done
    for F in $BUUNSHDR; do
        bld minibu/bu/$F || cmd CP minibu/bu/$F cp ../libbu++/src/unstable/$F minibu/bu/$F
    done
    for F in $BUCOMPAT; do
        bld minibu/bu/$F || cmd CP minibu/bu/$F cp ../libbu++/src/$F minibu/bu/$F
    done

    bld src/build.tab.c src/build.y || cmd BISON src/build.tab.c bison -bsrc/build src/build.y
    bld src/build.yy.c src/build.l || cmd FLEX src/build.yy.c flex src/build.l
}

if [ ! -z "$1" ]; then
	if [ "$1" == "clean" -o "$1" == "-c" ]; then
		echo "Cleaning up, deleting all object code and downloaded source code..."
		echo 
		rm -Rf minibu src/*.o
		exit
    elif [ "$1" == "setup" -o "$1" == "-s" ]; then
        echo "Only preforming download / setup"
        echo
        presetup
        exit
	else
		echo "Without parameters build.sh will download extra components and"
        echo "compile build."
        echo
        echo "Parameters:"
        echo "  clean | -c  Delete all opbject code and downloaded source."
        echo "  setup | -s  Download and perform initial setup, but do not"
        echo "              compile."
        echo
        echo "Using ${CXX} to complie code."
        echo
		exit
	fi
fi

presetup

for F in $BUSRC $BUEXPSRC $BUUNSSRC; do
	OUTPUT=${F%.*}.o
	bld minibu/src/$OUTPUT || gpp minibu/src/$OUTPUT minibu/src/$F
done

for F in src/*.c src/*.cpp; do
	OUTPUT=${F%.*}.o
	gpp "$OUTPUT" "$F"
done
bld build src/*.o minibu/src/*.o || cmd LINK build ${CXX} -fPIC -rdynamic -Wl,-export-dynamic -o build src/*.o minibu/src/*.o -ldl
bld build~ build || cmd CP build~ cp build build~