root/trunk/magicmakefile/branches/v3/configure

Revision 268, 10.1 kB (checked in by jeffk@…, 22 months ago)

workaround for awk differences in bsd vs linux vs mac in configure script

  • Property svn:executable set to *
Line 
1#! /bin/sh
2
3##############################################################################################
4#
5# The magic.makefile configure script, Copyright 2004-2006 by Jeff Koftinoff <jeffk@jdkoftinoff.com>
6# version 3.
7#
8# Simplifies the building of a c/c++ library, it's tests, tools, examples, and documentation.
9#
10# See https://clicker.jdkoftinoff.com/projects/trac/jdks/wiki/MagicMakefileV3
11# for more information, including license information (GPL)
12#
13
14
15# set relative_dir to the directory part of arg 0. Usually this is ../.. or somesuch.
16
17relative_dir="$(dirname "$0")"
18
19# load project specific bash definitions
20
21
22. "${relative_dir}/project.sh"
23
24# if we are called with --help or the script is called from the same directory that it is in,
25# then we must just print our usage information and exit
26
27if [ x"$1" = x"--help" -o x"${relative_dir}" = x"." ]; then
28    echo "configure script based on J.D. Koftinoff Software's MagicMake system."
29    echo "See https://clicker.jdkoftinoff.com/projects/trac/jdks/wiki/MagicMakefileV3 for more information"
30    echo ""
31    echo "example usage:"
32    echo "Step 1: make a directory to put build results in:"
33    echo "  mkdir b"
34    echo ""
35    echo "Step 2: cd into this directory:"
36    echo "  cd b"
37    echo ""
38    echo "Step 3: run this configure script:"
39    echo ""
40    echo "  ../configure"
41    echo ""
42    echo "Some example typical command line arguments for configure:"
43    echo ""
44    echo "Build native binaries on a generic posix machine:"
45    echo "  ../configure --target-platform-posix=1"
46    echo ""
47    echo "Build native binaries on a linux machine:"
48    echo "  ../configure --target-platform-linux=1"
49    echo ""
50    echo "Build native binaries on a mac os x machine:"
51    echo "  ../configure --target-platform-macosx=1"
52    echo ""
53    echo "Build universal binaries on a mac os x machine:"
54    echo "  ../configure --target-platform-macosx-universal=1"
55    echo ""
56    echo "Build on a mac os x machine and cross compile for windows via mingw32 cross compiler"
57    echo "  ../configure --native-platform-macosx-universal=1 --cross-compiling=1 --compiler-prefix=i386-mingw32- --target-platform-mingw32=1"
58    echo ""
59    echo "Build on a linux machine and cross compile for windows via mingw32 cross compiler"
60    echo "  ../configure --native-platform-linux=1 --cross-compiling=1 --compiler-prefix=i386-mingw32-  --target-platform-mingw32=1"
61    echo ""
62    echo "Further options for installation path of 'make install' and 'make install-dev' destinations:"
63    echo "  ../configure --prefix=/opt/local"
64    echo "without the --prefix option, the system defaults to $PWD/install - not /usr/local like gnu autoconf would"
65    echo ""
66    echo "After running the configure stage, a GNUmakefile will be created for you to run with gnu make"
67    exit 1
68fi
69
70
71# before we parse the command line arguments, do some rudimentary native machine investigation.
72
73
74# parse all long options and set them as variables, allowing command line to override everything
75# options are in the form of:
76#   --abcd-efghi-jklmn=some_value
77#
78# and they get transformed via awk into environment vars in the form:
79#   magic_ABCD_EFGHI_JKLMN="some_value"
80#
81# A bunch of variables have default values but can be overriden by the command line
82# at the end of this script, all variables with the "magic_" prefix are outputted to the
83# GNUmakefile and the vars.sh  in the appropriate format. The script file './reconfigure' is created
84# with the current command line parameters
85#
86# This looks tricky but is really not so bad: The for loop prints each parameter, one per line
87# into a single instance of awk so it is quick.
88#
89# The awk script extracts the variable name as var, and the part after the first '=' as val
90# It changes - to _, -- to nothing, converts the string to uppercase, prefixes the
91# variable name with magic_, and prints val inside quotes.
92#
93
94for i in "$@"
95  do
96    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"; }' `
97    eval $p
98done
99
100
101
102# setup all defaults:
103
104# 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.
105magic_PROJECT_TOP_DIR="${magic_PROJECT_TOP_DIR:-${PWD}/${relative_dir}}"
106
107# Then we get the real path name of this directory by cd'ing into it and running 'pwd' in it.
108magic_PROJECT_TOP_DIR=$(cd "${magic_PROJECT_TOP_DIR}" && pwd)
109
110# if --prefix is not specific, it defaults to $PWD/install
111magic_PREFIX="${magic_PREFIX:-${PWD}/install}"
112magic_INSTALL_DIR="${magic_PREFIX}"
113magic_CONFIGURE_DIR="${relative_dir}"
114
115# additional tool specifications
116magic_DOXYGEN="${magic_DOXYGEN:-doxygen}"
117magic_CP=${magic_CP:-cp}
118magic_LN=${magic_LN:-ln}
119magic_RM=${magic_RM:-rm}
120magic_MKDIRS="${magic_MKDIRS:-mkdir}"
121magic_MKDIR="${magic_MKDIR:-mkdir}"
122magic_VALGRIND="${magic_VALGRIND}"
123magic_VALGRIND_OPTIONS="${magic_VALGRIND_OPTIONS}"
124magic_MAKEFLAGS="${magic_MAKEFLAGS}"
125magic_INSTALL="${magic_INSTALL:-install}"
126magic_RSYNC="${magic_RSYNC:-rsync}"
127
128# Target platform definitions
129
130magic_TARGET_PLATFORM_GENERIC="${magic_TARGET_PLATFORM_GENERIC}"
131magic_TARGET_PLATFORM_MINGW32="${magic_TARGET_PLATFORM_MINGW32}"
132magic_TARGET_PLATFORM_CYGWIN="${magic_TARGET_PLATFORM_CYGWIN}"
133magic_TARGET_PLATFORM_LINUX="${magic_TARGET_PLATFORM_LINUX}"
134magic_TARGET_PLATFORM_MACOSX_PPC="${magic_TARGET_PLATFORM_MACOSX_PPC}"
135magic_TARGET_PLATFORM_MACOSX_I386="${magic_TARGET_PLATFORM_MACOSX_I386}"
136magic_TARGET_PLATFORM_MACOSX_UNIVERSAL="${magic_TARGET_PLATFORM_MACOSX_UNIVERSAL}"
137magic_TARGET_USE_AR="${magic_TARGET_USE_AR:-1}"
138magic_TARGET_USE_MACOSX_LIBTOOL="${magic_TARGET_USE_MACOSX_LIBTOOL:-0}"
139
140magic_TARGET_MACOSX_SDK="${magic_TARGET_MACOSX_SDK:-/Developer/SDKs/MacOSX10.4u.sdk}"
141
142# Target compile options
143
144magic_DEBUG="${magic_DEBUG}"
145magic_PROFILE="${magic_PROFILE}"
146magic_OPTIMIZE="${magic_OPTIMIZE}"
147magic_WARNINGS="${magic_WARNINGS}"
148magic_AUTODEPEND="${magic_AUTODEPEND}"
149magic_DEFINES="${magic_DEFINES}"
150magic_INCLUDES="${magic_INCLUDES}"
151
152# Target compiler specifications
153magic_CC="${magic_CC:-${magic_COMPILER_PREFIX}gcc}"
154magic_CXX="${magic_CXX:-${magic_COMPILER_PREFIX}g++}"
155magic_NM="${magic_NM:-${magic_COMPILER_PREFIX}nm}"
156magic_AR="${magic_AR:-${magic_COMPILER_PREFIX}ar}"
157magic_ARFLAGS="${magic_ARFLAGS:-rv}"
158magic_RANLIB="${magic_RANLIB:-${magic_COMPILER_PREFIX}ranlib}"
159magic_LD="${magic_LD:-${magic_COMPILER_PREFIX}ld}"
160magic_AS="${magic_AS:-${magic_COMPILER_PREFIX}as}"
161magic_STRIP="${magic_STRIP:-${magic_COMPILER_PREFIX}strip}"
162magic_STRINGS="${magic_STRINGS:-${magic_COMPILER_PREFIX}strings}"
163magic_WINDRES="${magic_WINDRES:-${magic_COMPILER_PREFIX}windres}"
164magic_OBJDUMP="${magic_OBJDUMP:-${magic_COMPILER_PREFIX}objdump}"
165magic_DLLTOOL="${magic_DLLTOOL:-${magic_COMPILER_PREFIX}dlltool}"
166magic_DLLWRAP="${magic_DLLWRAP:-${magic_COMPILER_PREFIX}dllwrap}"
167magic_LDFLAGS="${magic_LDFLAGS}"
168magic_CXXFLAGS="${magic_CXXFLAGS}"
169magic_CFLAGS="${magic_CFLAGS}"
170magic_MFLAGS="${magic_MFLAGS}"
171magic_MMFLAGS="${magic_MMFLAGS}"
172magic_LDLIBS="${magic_LDLIBS}"
173
174# Native platform specifications
175
176magic_NATIVE_PLATFORM_GENERIC="${magic_NATIVE_PLATFORM_GENERIC}"
177magic_NATIVE_PLATFORM_MINGW32="${magic_NATIVE_PLATFORM_MINGW32}"
178magic_NATIVE_PLATFORM_CYGWIN="${magic_NATIVE_PLATFORM_CYGWIN}"
179magic_NATIVE_PLATFORM_LINUX="${magic_NATIVE_PLATFORM_LINUX}"
180magic_NATIVE_PLATFORM_MACOSX_PPC="${magic_NATIVE_PLATFORM_MACOSX_PPC}"
181magic_NATIVE_PLATFORM_MACOSX_I386="${magic_NATIVE_PLATFORM_MACOSX_I386}"
182magic_NATIVE_PLATFORM_MACOSX_UNIVERSAL="${magic_NATIVE_PLATFORM_MACOSX_UNIVERSAL}"
183magic_NATIVE_USE_AR="${magic_NATIVE_USE_AR:-1}"
184magic_NATIVE_USE_MACOSX_LIBTOOL="${magic_NATIVE_USE_MACOSX_LIBTOOL:-0}"
185magic_NATIVE_MACOSX_SDK="${magic_NATIVE_MACOSX_SDK:-/Developer/SDKs/MacOSX10.4u.sdk}"
186
187# Native compiler specifications
188
189magic_CROSS_COMPILING="${magic_CROSS_COMPILING:-0}"
190magic_NATIVE_COMPILER_PREFIX="${magic_NATIVE_COMPILER_PREFIX:-}"
191magic_NATIVE_CC="${magic_NATIVE_CC:-${magic_NATIVE_COMPILER_PREFIX}gcc}"
192magic_NATIVE_CXX="${magic_NATIVE_CXX:-${magic_NATIVE_COMPILER_PREFIX}g++}"
193magic_NATIVE_NM="${magic_NATIVE_NM:-${magic_NATIVE_COMPILER_PREFIX}nm}"
194magic_NATIVE_AR="${magic_NATIVE_AR:-${magic_NATIVE_COMPILER_PREFIX}ar}"
195magic_NATIVE_ARFLAGS="${magic_NATIVE_ARFLAGS:-rv}"
196magic_NATIVE_RANLIB="${magic_NATIVE_RANLIB:-${magic_NATIVE_COMPILER_PREFIX}ranlib}"
197magic_NATIVE_LD="${magic_NATIVE_LD:-${magic_NATIVE_COMPILER_PREFIX}g++}"
198magic_NATIVE_AS="${magic_NATIVE_AS:-${magic_NATIVE_COMPILER_PREFIX}as}"
199magic_NATIVE_STRIP="${magic_NATIVE_STRIP:-${magic_NATIVE_COMPILER_PREFIX}strip}"
200magic_NATIVE_STRINGS="${magic_NATIVE_STRINGS:-${magic_NATIVE_COMPILER_PREFIX}strings}"
201magic_NATIVE_WINDRES="${magic_NATIVE_WINDRES:-${magic_NATIVE_COMPILER_PREFIX}windres}"
202magic_NATIVE_OBJDUMP="${magic_NATIVE_OBJDUMP:-${magic_NATIVE_COMPILER_PREFIX}objdump}"
203magic_NATIVE_DLLTOOL="${magic_NATIVE_DLLTOOL:-${magic_NATIVE_COMPILER_PREFIX}dlltool}"
204magic_NATIVE_DLLWRAP="${magic_NATIVE_DLLWRAP:-${magic_NATIVE_COMPILER_PREFIX}dllwrap}"
205magic_NATIVE_LDFLAGS="${magic_NATIVE_LDFLAGS}"
206magic_NATIVE_CXXFLAGS="${magic_NATIVE_CXXFLAGS}"
207magic_NATIVE_MFLAGS="${magic_NATIVE_MFLAGS}"
208magic_NATIVE_MMFLAGS="${magic_NATIVE_MMFLAGS}"
209magic_NATIVE_CFLAGS="${magic_NATIVE_CFLAGS}"
210magic_NATIVE_LDLIBS="${magic_NATIVE_LDLIBS}"
211magic_NATIVE_DEBUG="${magic_NATIVE_DEBUG}"
212magic_NATIVE_PROFILE="${magic_NATIVE_PROFILE}"
213
214
215
216# extract all environment vars with the "magic_" prefix and save them in vars.sh and GNUmakefile in the appropriate form:
217set | grep '^magic_' | sort | sed "s/magic_\(.*\)=[\']*\([^']*\)[\']*/\1=\"\2\"/" >vars.sh
218echo ". \"${magic_PROJECT_TOP_DIR}/project.sh\"" >>vars.sh
219set | grep '^magic_' | sort | sed "s/magic_\(.*\)=[\']*\([^']*\)[\']*/\1=\2/" >GNUmakefile
220
221
222
223echo 'include $(CONFIGURE_DIR)/project.mak' >>GNUmakefile
224echo 'include $(CONFIGURE_DIR)/magic.mak' >>GNUmakefile
225
226if [ -f ./reconfigure ]; then
227 mv ./reconfigure ./reconfigure-old
228fi
229echo -n "$0 "  >>./reconfigure
230for i in "$@";
231do
232  echo -n " \"$i\" " >> ./reconfigure
233done
234echo \"\$@\" >>./reconfigure
235chmod +x ./reconfigure
236
237echo "./GNUmakefile  ./vars.sh  and ./reconfigure created."
238echo "Now you may do:"
239echo "  make compile_info"
240echo "  make help"
241echo "  make"
242echo "  make install"
243echo "  make install-dev"
Note: See TracBrowser for help on using the browser.