| 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 | |
|---|
| 17 | relative_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 | |
|---|
| 27 | if [ 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 |
|---|
| 68 | fi |
|---|
| 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 | |
|---|
| 94 | for 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 |
|---|
| 98 | done |
|---|
| 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. |
|---|
| 105 | magic_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. |
|---|
| 108 | magic_PROJECT_TOP_DIR=$(cd "${magic_PROJECT_TOP_DIR}" && pwd) |
|---|
| 109 | |
|---|
| 110 | # if --prefix is not specific, it defaults to $PWD/install |
|---|
| 111 | magic_PREFIX="${magic_PREFIX:-${PWD}/install}" |
|---|
| 112 | magic_INSTALL_DIR="${magic_PREFIX}" |
|---|
| 113 | magic_CONFIGURE_DIR="${relative_dir}" |
|---|
| 114 | |
|---|
| 115 | # additional tool specifications |
|---|
| 116 | magic_DOXYGEN="${magic_DOXYGEN:-doxygen}" |
|---|
| 117 | magic_CP=${magic_CP:-cp} |
|---|
| 118 | magic_LN=${magic_LN:-ln} |
|---|
| 119 | magic_RM=${magic_RM:-rm} |
|---|
| 120 | magic_MKDIRS="${magic_MKDIRS:-mkdir}" |
|---|
| 121 | magic_MKDIR="${magic_MKDIR:-mkdir}" |
|---|
| 122 | magic_VALGRIND="${magic_VALGRIND}" |
|---|
| 123 | magic_VALGRIND_OPTIONS="${magic_VALGRIND_OPTIONS}" |
|---|
| 124 | magic_MAKEFLAGS="${magic_MAKEFLAGS}" |
|---|
| 125 | magic_INSTALL="${magic_INSTALL:-install}" |
|---|
| 126 | magic_RSYNC="${magic_RSYNC:-rsync}" |
|---|
| 127 | |
|---|
| 128 | # Target platform definitions |
|---|
| 129 | |
|---|
| 130 | magic_TARGET_PLATFORM_GENERIC="${magic_TARGET_PLATFORM_GENERIC}" |
|---|
| 131 | magic_TARGET_PLATFORM_MINGW32="${magic_TARGET_PLATFORM_MINGW32}" |
|---|
| 132 | magic_TARGET_PLATFORM_CYGWIN="${magic_TARGET_PLATFORM_CYGWIN}" |
|---|
| 133 | magic_TARGET_PLATFORM_LINUX="${magic_TARGET_PLATFORM_LINUX}" |
|---|
| 134 | magic_TARGET_PLATFORM_MACOSX_PPC="${magic_TARGET_PLATFORM_MACOSX_PPC}" |
|---|
| 135 | magic_TARGET_PLATFORM_MACOSX_I386="${magic_TARGET_PLATFORM_MACOSX_I386}" |
|---|
| 136 | magic_TARGET_PLATFORM_MACOSX_UNIVERSAL="${magic_TARGET_PLATFORM_MACOSX_UNIVERSAL}" |
|---|
| 137 | magic_TARGET_USE_AR="${magic_TARGET_USE_AR:-1}" |
|---|
| 138 | magic_TARGET_USE_MACOSX_LIBTOOL="${magic_TARGET_USE_MACOSX_LIBTOOL:-0}" |
|---|
| 139 | |
|---|
| 140 | magic_TARGET_MACOSX_SDK="${magic_TARGET_MACOSX_SDK:-/Developer/SDKs/MacOSX10.4u.sdk}" |
|---|
| 141 | |
|---|
| 142 | # Target compile options |
|---|
| 143 | |
|---|
| 144 | magic_DEBUG="${magic_DEBUG}" |
|---|
| 145 | magic_PROFILE="${magic_PROFILE}" |
|---|
| 146 | magic_OPTIMIZE="${magic_OPTIMIZE}" |
|---|
| 147 | magic_WARNINGS="${magic_WARNINGS}" |
|---|
| 148 | magic_AUTODEPEND="${magic_AUTODEPEND}" |
|---|
| 149 | magic_DEFINES="${magic_DEFINES}" |
|---|
| 150 | magic_INCLUDES="${magic_INCLUDES}" |
|---|
| 151 | |
|---|
| 152 | # Target compiler specifications |
|---|
| 153 | magic_CC="${magic_CC:-${magic_COMPILER_PREFIX}gcc}" |
|---|
| 154 | magic_CXX="${magic_CXX:-${magic_COMPILER_PREFIX}g++}" |
|---|
| 155 | magic_NM="${magic_NM:-${magic_COMPILER_PREFIX}nm}" |
|---|
| 156 | magic_AR="${magic_AR:-${magic_COMPILER_PREFIX}ar}" |
|---|
| 157 | magic_ARFLAGS="${magic_ARFLAGS:-rv}" |
|---|
| 158 | magic_RANLIB="${magic_RANLIB:-${magic_COMPILER_PREFIX}ranlib}" |
|---|
| 159 | magic_LD="${magic_LD:-${magic_COMPILER_PREFIX}ld}" |
|---|
| 160 | magic_AS="${magic_AS:-${magic_COMPILER_PREFIX}as}" |
|---|
| 161 | magic_STRIP="${magic_STRIP:-${magic_COMPILER_PREFIX}strip}" |
|---|
| 162 | magic_STRINGS="${magic_STRINGS:-${magic_COMPILER_PREFIX}strings}" |
|---|
| 163 | magic_WINDRES="${magic_WINDRES:-${magic_COMPILER_PREFIX}windres}" |
|---|
| 164 | magic_OBJDUMP="${magic_OBJDUMP:-${magic_COMPILER_PREFIX}objdump}" |
|---|
| 165 | magic_DLLTOOL="${magic_DLLTOOL:-${magic_COMPILER_PREFIX}dlltool}" |
|---|
| 166 | magic_DLLWRAP="${magic_DLLWRAP:-${magic_COMPILER_PREFIX}dllwrap}" |
|---|
| 167 | magic_LDFLAGS="${magic_LDFLAGS}" |
|---|
| 168 | magic_CXXFLAGS="${magic_CXXFLAGS}" |
|---|
| 169 | magic_CFLAGS="${magic_CFLAGS}" |
|---|
| 170 | magic_MFLAGS="${magic_MFLAGS}" |
|---|
| 171 | magic_MMFLAGS="${magic_MMFLAGS}" |
|---|
| 172 | magic_LDLIBS="${magic_LDLIBS}" |
|---|
| 173 | |
|---|
| 174 | # Native platform specifications |
|---|
| 175 | |
|---|
| 176 | magic_NATIVE_PLATFORM_GENERIC="${magic_NATIVE_PLATFORM_GENERIC}" |
|---|
| 177 | magic_NATIVE_PLATFORM_MINGW32="${magic_NATIVE_PLATFORM_MINGW32}" |
|---|
| 178 | magic_NATIVE_PLATFORM_CYGWIN="${magic_NATIVE_PLATFORM_CYGWIN}" |
|---|
| 179 | magic_NATIVE_PLATFORM_LINUX="${magic_NATIVE_PLATFORM_LINUX}" |
|---|
| 180 | magic_NATIVE_PLATFORM_MACOSX_PPC="${magic_NATIVE_PLATFORM_MACOSX_PPC}" |
|---|
| 181 | magic_NATIVE_PLATFORM_MACOSX_I386="${magic_NATIVE_PLATFORM_MACOSX_I386}" |
|---|
| 182 | magic_NATIVE_PLATFORM_MACOSX_UNIVERSAL="${magic_NATIVE_PLATFORM_MACOSX_UNIVERSAL}" |
|---|
| 183 | magic_NATIVE_USE_AR="${magic_NATIVE_USE_AR:-1}" |
|---|
| 184 | magic_NATIVE_USE_MACOSX_LIBTOOL="${magic_NATIVE_USE_MACOSX_LIBTOOL:-0}" |
|---|
| 185 | magic_NATIVE_MACOSX_SDK="${magic_NATIVE_MACOSX_SDK:-/Developer/SDKs/MacOSX10.4u.sdk}" |
|---|
| 186 | |
|---|
| 187 | # Native compiler specifications |
|---|
| 188 | |
|---|
| 189 | magic_CROSS_COMPILING="${magic_CROSS_COMPILING:-0}" |
|---|
| 190 | magic_NATIVE_COMPILER_PREFIX="${magic_NATIVE_COMPILER_PREFIX:-}" |
|---|
| 191 | magic_NATIVE_CC="${magic_NATIVE_CC:-${magic_NATIVE_COMPILER_PREFIX}gcc}" |
|---|
| 192 | magic_NATIVE_CXX="${magic_NATIVE_CXX:-${magic_NATIVE_COMPILER_PREFIX}g++}" |
|---|
| 193 | magic_NATIVE_NM="${magic_NATIVE_NM:-${magic_NATIVE_COMPILER_PREFIX}nm}" |
|---|
| 194 | magic_NATIVE_AR="${magic_NATIVE_AR:-${magic_NATIVE_COMPILER_PREFIX}ar}" |
|---|
| 195 | magic_NATIVE_ARFLAGS="${magic_NATIVE_ARFLAGS:-rv}" |
|---|
| 196 | magic_NATIVE_RANLIB="${magic_NATIVE_RANLIB:-${magic_NATIVE_COMPILER_PREFIX}ranlib}" |
|---|
| 197 | magic_NATIVE_LD="${magic_NATIVE_LD:-${magic_NATIVE_COMPILER_PREFIX}g++}" |
|---|
| 198 | magic_NATIVE_AS="${magic_NATIVE_AS:-${magic_NATIVE_COMPILER_PREFIX}as}" |
|---|
| 199 | magic_NATIVE_STRIP="${magic_NATIVE_STRIP:-${magic_NATIVE_COMPILER_PREFIX}strip}" |
|---|
| 200 | magic_NATIVE_STRINGS="${magic_NATIVE_STRINGS:-${magic_NATIVE_COMPILER_PREFIX}strings}" |
|---|
| 201 | magic_NATIVE_WINDRES="${magic_NATIVE_WINDRES:-${magic_NATIVE_COMPILER_PREFIX}windres}" |
|---|
| 202 | magic_NATIVE_OBJDUMP="${magic_NATIVE_OBJDUMP:-${magic_NATIVE_COMPILER_PREFIX}objdump}" |
|---|
| 203 | magic_NATIVE_DLLTOOL="${magic_NATIVE_DLLTOOL:-${magic_NATIVE_COMPILER_PREFIX}dlltool}" |
|---|
| 204 | magic_NATIVE_DLLWRAP="${magic_NATIVE_DLLWRAP:-${magic_NATIVE_COMPILER_PREFIX}dllwrap}" |
|---|
| 205 | magic_NATIVE_LDFLAGS="${magic_NATIVE_LDFLAGS}" |
|---|
| 206 | magic_NATIVE_CXXFLAGS="${magic_NATIVE_CXXFLAGS}" |
|---|
| 207 | magic_NATIVE_MFLAGS="${magic_NATIVE_MFLAGS}" |
|---|
| 208 | magic_NATIVE_MMFLAGS="${magic_NATIVE_MMFLAGS}" |
|---|
| 209 | magic_NATIVE_CFLAGS="${magic_NATIVE_CFLAGS}" |
|---|
| 210 | magic_NATIVE_LDLIBS="${magic_NATIVE_LDLIBS}" |
|---|
| 211 | magic_NATIVE_DEBUG="${magic_NATIVE_DEBUG}" |
|---|
| 212 | magic_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: |
|---|
| 217 | set | grep '^magic_' | sort | sed "s/magic_\(.*\)=[\']*\([^']*\)[\']*/\1=\"\2\"/" >vars.sh |
|---|
| 218 | echo ". \"${magic_PROJECT_TOP_DIR}/project.sh\"" >>vars.sh |
|---|
| 219 | set | grep '^magic_' | sort | sed "s/magic_\(.*\)=[\']*\([^']*\)[\']*/\1=\2/" >GNUmakefile |
|---|
| 220 | |
|---|
| 221 | |
|---|
| 222 | |
|---|
| 223 | echo 'include $(CONFIGURE_DIR)/project.mak' >>GNUmakefile |
|---|
| 224 | echo 'include $(CONFIGURE_DIR)/magic.mak' >>GNUmakefile |
|---|
| 225 | |
|---|
| 226 | if [ -f ./reconfigure ]; then |
|---|
| 227 | mv ./reconfigure ./reconfigure-old |
|---|
| 228 | fi |
|---|
| 229 | echo -n "$0 " >>./reconfigure |
|---|
| 230 | for i in "$@"; |
|---|
| 231 | do |
|---|
| 232 | echo -n " \"$i\" " >> ./reconfigure |
|---|
| 233 | done |
|---|
| 234 | echo \"\$@\" >>./reconfigure |
|---|
| 235 | chmod +x ./reconfigure |
|---|
| 236 | |
|---|
| 237 | echo "./GNUmakefile ./vars.sh and ./reconfigure created." |
|---|
| 238 | echo "Now you may do:" |
|---|
| 239 | echo " make compile_info" |
|---|
| 240 | echo " make help" |
|---|
| 241 | echo " make" |
|---|
| 242 | echo " make install" |
|---|
| 243 | echo " make install-dev" |
|---|