aboutsummaryrefslogtreecommitdiff
path: root/project/setup.sh
blob: a5dc451f30e4bd9d2da1a24223a7ab7f544d31be (plain) (blame)
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
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
#!/usr/bin/env bash

revision=0
[[ $STATIC = 1 ]] || STATIC=0

[[ -s revision.sh ]] && . revision.sh

if [[ -d .svn ]] && which svn >/dev/null 2>&1
then
    revision="$( svn info . | awk '$1=="Revision:" {print $2}' )"
    if which svnversion >/dev/null 2>&1
    then
	rev="$(svnversion|sed 's/.*://')"
	(( ${revision//[!0-9]/} < ${rev//[!0-9]/} )) && revision=$rev
    fi
    echo "revision=$revision" > revision.sh
fi

revision_num="${revision//[!0-9]/}"
revision_next=$revision_num
[[ $revision = $revision_num ]] || let revision_next++

tim=($(date '+%s %Y-%m-%d %T %Y'))

have_md5=0
[[ -r /usr/include/openssl/md5.h ]] && have_md5=1

have_sha=0
[[ -r /usr/include/openssl/sha.h ]] && have_sha=1

#---

if [[ $M32 = 1 ]]
then
    force_m32=1
    libdir=lib
    xflags="-m32"
    defines=-DFORCE_M32=1
else
    force_m32=0
    libdir=lib64
    xflags=
    defines=
fi

[[ -r /usr/include/bits/fcntl.h ]] \
	&& grep -qw fallocate /usr/include/bits/fcntl.h \
	&& defines="$defines -DHAVE_FALLOCATE=1"

[[ -r /usr/include/fcntl.h ]] \
	&& grep -qw posix_fallocate /usr/include/fcntl.h \
	&& defines="$defines -DHAVE_POSIX_FALLOCATE=1"

#gcc $xflags system.c -o system.tmp && ./system.tmp >Makefile.setup
gcc $xflags -E -DPRINT_SYSTEM_SETTINGS system.c \
	| awk -F= '/^result_/ {printf("%s := %s\n",substr($1,8),gensub(/"/,"","g",$2))}' \
	> Makefile.setup

#rm -f system.tmp
SYSTEM=$(awk '$1=="SYSTEM" {print $3}' Makefile.setup)
#echo "SYSTEM=|$SYSTEM|" >&2

libpng="-lpng -lz"
case "$SYSTEM" in
    mac)
	[[ -s /usr/local/lib/libpng.a ]] && libpng="/usr/local/lib/libpng.a -lz"
	;;

    i386)
	[[ -s /usr/lib/libpng.a ]] && libpng="/usr/lib/libpng.a -lz"
	;;

    x86_64)
	[[ -s /usr/lib64/libpng.a ]] && libpng="/usr/lib64/libpng.a -lz"
	;;
esac    

#----- have_pcre

have_pcre=0
pcre_a=
[[ -r /usr/include/pcre.h || -r /usr/local/include/pcre.h ]] && have_pcre=1

if (( STATIC && have_pcre ))
then
    have_pcre=0
    for lib in /usr/local/$libdir /usr/$libdir /$libdir
    do
	if [[ -s $lib/libpcre.a ]]
	then
	    have_pcre=1
	    pcre_a=$lib/libpcre.a
	    break;
	fi
    done
fi
have_pcre=0

#--------------------------------------------------

INSTALL_PATH=/usr/local

if [[ -d $INSTALL_PATH/bin ]]
then
    HAVE_INSTBIN=1
    INSTBIN=$INSTALL_PATH/bin
else
    HAVE_INSTBIN=0
    INSTBIN=/tmp
fi

if [[ -d $INSTALL_PATH/bin32 ]]
then
    HAVE_INSTBIN_32=1
    INSTBIN_32=$INSTALL_PATH/bin32
else
    HAVE_INSTBIN_32=0
    INSTBIN_32=/tmp
fi

if [[ -d $INSTALL_PATH/bin64 ]]
then
    HAVE_INSTBIN_64=1
    INSTBIN_64=$INSTALL_PATH/bin64
elif [[ -d $INSTALL_PATH/bin-x86_64 ]]
then
    HAVE_INSTBIN_64=1
    INSTBIN_64=$INSTALL_PATH/bin-x86_64
else
    HAVE_INSTBIN_64=0
    INSTBIN_64=/tmp
fi

HAVE_WORK=0
[[ -d ./work ]] && HAVE_WORK=1

HAVE_WORK_SRC=0
[[ -d ./work/src ]] && HAVE_WORK_SRC=1

[[ $NOWIIMM = 1 || $NO_WIIMM = 1 ]] && HAVE_WORK=0 HAVE_WORK_SRC=0

HAVE_XSRC=0
[[ -h xsrc ]] && rm xsrc
if [[ -d xsrc ]]
then
    HAVE_XSRC=1
    cat <<- __EOT__ >xsrc/xversion.tmp
	#ifndef SZS_X_VERSION_H
	#define SZS_X_VERSION_H 1

	#define XSRC_BASE_VERSION "$1"
	#define XSRC_VERSION_NUM "$2"
	#define XSRC_VERSION_INT $3

	#endif // SZS_X_VERSION_H
	__EOT__
	diff -N xsrc/xversion.tmp xsrc/xversion.h >/dev/null \
		|| mv xsrc/xversion.tmp xsrc/xversion.h
elif [[ ! -a xsrc && -d ../wiimms-szs-tools/xsrc ]]
then
    ln -s ../wiimms-szs-tools/xsrc ./xsrc
    HAVE_XSRC=1
fi

#--------------------------------------------------

cat <<- ---EOT--- >>Makefile.setup
	
	REVISION	:= $revision
	REVISION_NUM	:= $revision_num
	REVISION_NEXT	:= $revision_next
	BINTIME		:= ${tim[0]}
	DATE		:= ${tim[1]}
	TIME		:= ${tim[2]}
	YEAR		:= ${tim[3]}

	FORCE_M32	:= $force_m32
	HAVE_MD5	:= $have_md5
	HAVE_SHA	:= $have_sha
	STATIC		:= $STATIC
	XFLAGS		+= $xflags
	DEFINES1	:= $defines -DDEBUG_ASSERT=1
	LIBPNG		:= $libpng

	HAVE_PCRE	:= $have_pcre
	PCRE_A		:= $pcre_a

	HAVE_INSTBIN	:= $HAVE_INSTBIN
	HAVE_INSTBIN_32	:= $HAVE_INSTBIN_32
	HAVE_INSTBIN_64	:= $HAVE_INSTBIN_64

	INSTALL_PATH	:= $INSTALL_PATH
	INSTBIN		:= $INSTBIN
	INSTBIN_32	:= $INSTBIN_32
	INSTBIN_64	:= $INSTBIN_64

	HAVE_WORK	:= $HAVE_WORK
	HAVE_WORK_SRC	:= $HAVE_WORK_SRC
	HAVE_XSRC	:= $HAVE_XSRC

	---EOT---