-
Notifications
You must be signed in to change notification settings - Fork 29
/
configure
executable file
·187 lines (162 loc) · 8.2 KB
/
configure
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
#! /bin/bash -e
##############################################################################################
#
# The magic.makefile configure script, Copyright 2004-2012 by J.D. Koftinoff Software, Ltd. -
# Jeff Koftinoff <jeffk@jdkoftinoff.com>
#
# Simplifies the building of a c/c++ library, tests, tools, examples, and documentation.
#
# http://wiki.github.com/jdkoftinoff/magicmake/
#
# Copyright (c) 2012, J.D. Koftinoff Software, Ltd. - Jeff Koftinoff <jeffk@jdkoftinoff.com>
# All rights reserved.
#
# Permission to use, copy, modify, and/or distribute this software for any
# purpose with or without fee is hereby granted, provided that the above
# copyright notice and this permission notice appear in all copies.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
# WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
# set relative_dir to the directory part of arg 0. Usually this is ../.. or somesuch.
relative_dir="$(dirname "$0")"
magic_PROJECT_TOP_DIR="$(cd ${relative_dir} && pwd)"
# if we are called with --help
if [ x"$1" = x"--help" ]; then
echo "configure script based on J.D. Koftinoff Software Ltd.'s MagicMake system."
echo "See http://wiki.github.com/jdkoftinoff/magicmake/ "
echo ""
echo "example usage:"
echo "Step 1: make a directory to put build results in:"
echo " mkdir b"
echo ""
echo "Step 2: cd into this directory:"
echo " cd b"
echo ""
echo "Step 3: run this configure script:"
echo ""
echo " ../configure"
echo ""
echo "Some example typical command line arguments for configure:"
echo ""
echo "Build native binaries on a generic posix machine:"
echo " ../configure --target-platform-posix=1"
echo ""
echo "Build native binaries on a linux machine:"
echo " ../configure --target-platform-linux=1"
echo ""
echo "Build native binaries on a mac os x machine:"
echo " ../configure --target-platform-macosx=1"
echo ""
echo "Build universal binaries on a mac os x machine:"
echo " ../configure --target-platform-macosx-universal=1"
echo ""
echo "Build on a mac os x machine and cross compile for windows via mingw32 cross compiler"
echo " ../configure --native-platform-macosx-universal=1 --cross-compiling=1 --compiler-prefix=i386-mingw32- --target-platform-mingw32=1"
echo ""
echo "Build on a linux machine and cross compile for windows via mingw32 cross compiler"
echo " ../configure --native-platform-linux=1 --cross-compiling=1 --compiler-prefix=i386-mingw32- --target-platform-mingw32=1"
echo ""
echo "Further options for installation path of 'make install' and 'make install-dev' destinations:"
echo " ../configure --prefix=/opt/local"
echo "without the --prefix option, the system defaults to /opt/local/PACKAGE_NAME-PACKAGE_VERSION - not /usr/local like gnu autoconf would"
echo ""
echo "After running the configure stage, a Makefile will be created for you to run with gnu make"
exit 1
fi
# parse all long options and set them as variables, allowing command line to override everything
# options are in the form of:
# --abcd-efghi-jklmn=some_value
#
# and they get transformed via awk into environment vars in the form:
# magic_ABCD_EFGHI_JKLMN="some_value"
#
# The script file './reconfigure' is created with the current command line parameters
#
# This looks tricky but is really not so bad: The for loop prints each parameter, one per line
# into a single instance of awk so it is quick.
#
# The awk script extracts the variable name as var, and the part after the first '=' as val
# It changes - to _, -- to nothing, converts the string to uppercase, prefixes the
# variable name with magic_, and prints val inside quotes.
#
for i in "$@"; do
p=`echo $i | awk '{ line=$0; i = index($0,"="); var = substr(line,0,i); gsub("=","",var); val = substr(line,i+1); gsub("-","_",var); sub("__","",var); print "magic_" toupper(var) "=\"" val "\"\n"; }' `
eval $p
done
# we have our command line args. If the project.mk file does not exist then
# create it if the --init arg was set
function print_var
{
name="$1"
mk_file="$2"
eval value=\$magic_${name}
echo "${name}=${value}" >>"$mk_file"
echo "${name} is: ${value}"
}
if [ ! -f "${relative_dir}/project.mk" ]; then
# defaults for init mode if project.mk does not exist
magic_PROJECT=${magic_PROJECT:-$(basename $magic_PROJECT_TOP_DIR)}
magic_PROJECT_NAME=${magic_PROJECT_NAME:-$magic_PROJECT}
magic_PROJECT_VERSION=${magic_PROJECT_VERSION:-$(date +%Y%m%d)}
magic_PROJECT_EMAIL=${magic_PROJECT_EMAIL:-"${USER}@${HOSTNAME}"}
magic_PROJECT_LICENSE=${magic_PROJECT_LICENSE:-"private"}
magic_PROJECT_MAINTAINER=${magic_PROJECT_MAINTAINER:-"${magic_PROJECT_EMAIL}"}
magic_PROJECT_COPYRIGHT=${magic_PROJECT_COPYRIGHT:-"Copyright $(date +%Y)"}
magic_PROJECT_DESCRIPTION=${magic_PROJECT_DESCRIPTION:-"${magic_PROJECT_NAME}"}
magic_PROJECT_WEBSITE=${magic_PROJECT_WEBSITE:-"http://${HOSTNAME}/${magic_PROJECT}"}
magic_PROJECT_IDENTIFIER=${magic_PROJECT_IDENTIFIER:-"${HOSTNAME}.${magic_PROJECT}"}
if [ "$1" != "--init" ]; then
echo "magicmake configure: no project.mk file found in $magic_PROJECT_TOP_DIR" 1>&2
echo "re-run configure with the following command line to create initial project.mk file:" 1>&2
echo 1>&2
echo "\"$0\" --init \"--project=$magic_PROJECT\" \"--project-name=$magic_PROJECT_NAME\" \"--project-version=$magic_PROJECT_VERSION\" \"--project-email=$magic_PROJECT_EMAIL\" \"--project-license=$magic_PROJECT_LICENSE\" \"--project-maintainer=$magic_PROJECT_MAINTAINER\" \"--project-copyright=$magic_PROJECT_COPYRIGHT\" \"--project-description=$magic_PROJECT_DESCRIPTION\" \"--project-website=$magic_PROJECT_WEBSITE\" \"--project-identifier=$magic_PROJECT_IDENTIFIER\" "
exit 1
else
proj_mk="${relative_dir}/project.mk"
for v in PROJECT PROJECT_NAME PROJECT_VERSION PROJECT_EMAIL PROJECT_LICENSE PROJECT_MAINTAINER PROJECT_COPYRIGHT PROJECT_DESCRIPTION PROJECT_WEBSITE PROJECT_IDENTIFIER; do
print_var $v "$proj_mk"
done
echo "TOP_LIB_DIRS+=." >>"$proj_mk"
echo "CONFIG_TOOLS+=$magic_CONFIG_TOOLS" >>"$proj_mk"
echo "PKGCONFIG_PACKAGES+=$magic_PKGCONFIG_PACKAGES" >>"$proj_mk"
mkdir -p "$magic_PROJECT_TOP_DIR"/include "$magic_PROJECT_TOP_DIR"/src "$magic_PROJECT_TOP_DIR"/tools "$magic_PROJECT_TOP_DIR"/docs-dev "$magic_PROJECT_TOP_DIR"/docs "$magic_PROJECT_TOP_DIR"/docs-dev "$magic_PROJECT_TOP_DIR"/tests "$magic_PROJECT_TOP_DIR"/examples "$magic_PROJECT_TOP_DIR"/etc/common "$magic_PROJECT_TOP_DIR"/share/common "$magic_PROJECT_TOP_DIR"/man/common
echo "project.mk file created, ready for use."
exit 0
fi
fi
# setup all defaults:
# The PROJECT_TOP_DIR variable, if not set already, is then set to the full relative path needed to get to the configure script from the PWD.
magic_PROJECT_TOP_DIR="${magic_PROJECT_TOP_DIR:-${PWD}/${relative_dir}}"
# Then we get the real path name of this directory by cd'ing into it and running 'pwd' in it.
magic_PROJECT_TOP_DIR=$(cd "${magic_PROJECT_TOP_DIR}" && pwd)
magic_CONFIGURE_DIR=$(cd "${relative_dir}" && pwd)
magic_BUILD_DIR="$PWD/tmp-target"
magic_NATIVE_BUILD_DIR="$PWD/tmp-native"
M=Makefile
unset magic_
# extract all environment vars with the "magic_" prefix and save them in ${M} in the appropriate form:
rm -f ${M}
set | grep '^magic_' | sort | sed -n "s/magic_\(.*\)=\('*\)\([^']*\)\(.*\)/\1=\3/p" >${M}
echo '.PHONY : first_target' >>${M}
echo 'first_target : everything' >>${M}
echo >>${M}
echo 'include $(PROJECT_TOP_DIR)/project.mk' >>${M}
echo 'include $(PROJECT_TOP_DIR)/magic.mk' >>${M}
if [ -n "$magic_MAKEFILES_DIR" ]; then
echo '-include $(MAKEFILES_DIR)/*.mk' >>${M}
fi
if [ -f ./reconfigure ]; then
mv ./reconfigure ./reconfigure-old
fi
echo "$0 \\" >>./reconfigure
for i in "$@";
do
echo " \"$i\" \\" >> ./reconfigure
done
echo \"\$@\" >>./reconfigure
chmod +x ./reconfigure