UNIXworkcode

  1  #!/bin/sh
  2  
  3  HOST=`uname -n`
  4  PREFIX=`pwd`/work
  5  INSTALL_DIR=$PREFIX
  6  
  7  EPREFIX=$PREFIX
  8  
  9  BINDIR=
 10  SBINDIR=
 11  LIBDIR=
 12  LIBEXECDIR=
 13  DATADIR=
 14  SYSCONFDIR=
 15  SHAREDSTATEDIR=
 16  LOCALSTATEDIR=
 17  INCLUDEDIR=
 18  INFODIR=
 19  MANDIR=
 20  
 21  OS=`uname -s`
 22  OS_VERSION=`uname -r`
 23  
 24  TEMP_DIR=".tmp-`uname -n`"
 25  mkdir -p $TEMP_DIR
 26  if [ $? -ne 0 ]; then
 27  	echo "Cannot create tmp dir"
 28  	echo "Abort"
 29  fi
 30  touch $TEMP_DIR/options
 31  touch $TEMP_DIR/features
 32  
 33  # features
 34  
 35  # help text
 36  printhelp()
 37  {
 38  	echo "Usage: $0 [OPTIONS]..."
 39  	cat << __EOF__
 40  Installation directories:
 41    --prefix=PREFIX         path prefix for architecture-independent files
 42                            [/usr]
 43    --exec-prefix=EPREFIX   path prefix for architecture-dependent files
 44                            [PREFIX]
 45  
 46    --bindir=DIR            user executables [EPREFIX/bin]
 47    --sbindir=DIR           system admin executables [EPREFIX/sbin]
 48    --libexecdir=DIR        program executables [EPREFIX/libexec]
 49    --sysconfdir=DIR        system configuration files [PREFIX/etc]
 50    --sharedstatedir=DIR    modifiable architecture-independent data [PREFIX/com]
 51    --localstatedir=DIR     modifiable single-machine data [PREFIX/var]
 52    --libdir=DIR            object code libraries [EPREFIX/lib]
 53    --includedir=DIR        C header files [PREFIX/include]
 54    --datarootdir=DIR       read-only arch.-independent data root [PREFIX/share]
 55    --datadir=DIR           read-only architecture-independent data [DATAROOTDIR]
 56    --infodir=DIR           info documentation [DATAROOTDIR/info]
 57    --mandir=DIR            man documentation [DATAROOTDIR/man]
 58  
 59  Optional Features:
 60    --enable-pg
 61  
 62  __EOF__
 63  }
 64  
 65  #
 66  # parse arguments 
 67  #
 68  for ARG in $@
 69  do
 70      if [[ $ARG == --prefix=* ]]; then
 71          PREFIX=${ARG:9}
 72      elif [[ $ARG = --exec-prefix=* ]]; then
 73      	EPREFIX=${ARG:14}
 74      elif [[ $ARG = --bindir=* ]]; then
 75      	BINDIR=${ARG:9}
 76      elif [[ $ARG = --sbindir=* ]]; then
 77      	SBINDIR=${ARG:10}
 78      elif [[ $ARG = --libdir=* ]]; then
 79      	LIBDIR=${ARG:9}
 80      elif [[ $ARG = --libexecdir=* ]]; then
 81      	LIBEXECDIR=${ARG:13}
 82      elif [[ $ARG = --datadir=* ]]; then
 83      	DATADIR=${ARG:10}
 84      elif [[ $ARG = --sysconfdir=* ]]; then
 85      	SYSCONFDIR=${ARG:13}
 86      elif [[ $ARG = --sharedstatedir=* ]]; then
 87      	SHAREDSTATEDIR=${ARG:17}
 88      elif [[ $ARG = --localstatedir=* ]]; then
 89      	LOCALSTATEDIR=${ARG:16}
 90      elif [[ $ARG = --includedir=* ]]; then
 91      	INCLUDEDIR=${ARG:12}
 92      elif [[ $ARG = --infodir=* ]]; then
 93      	INFODIR=${ARG:10}
 94      elif [[ $ARG = --mandir=* ]]; then
 95      	MANDIR=${ARG:9}
 96      elif [ $ARG = "--help" ]; then
 97  		printhelp
 98          exit 0	
 99      elif [[ $ARG == --enable-pg ]]; then
100      	FEATURE_PG=on
101      elif [[ $ARG == --disable-pg ]]; then
102      	unset FEATURE_PG
103      fi
104  done
105  
106  # set dir variables
107  if [ -z "$BINDIR" ]; then
108  	BINDIR=$EPREFIX/bin
109  fi
110  if [ -z "$SBINDIR" ]; then
111  	SBINDIR=$EPREFIX/sbin
112  fi
113  if [ -z "$LIBDIR" ]; then
114  	LIBDIR=$EPREFIX/lib
115  fi
116  if [ -z "$LIBEXEC" ]; then
117  	LIBEXECDIR=$EPREFIX/libexec
118  fi
119  if [ -z "$DATADIR" ]; then
120  	DATADIR=$PREFIX/share
121  fi
122  if [ -z "$SYSCONFDIR" ]; then
123  	SYSCONFDIR=$PREFIX/etc
124  fi
125  if [ -z "$SHAREDSTATEDIR" ]; then
126  	SHAREDSTATEDIR=$PREFIX/com
127  fi
128  if [ -z "$LOCALSTATEDIR" ]; then
129  	LOCALSTATEDIR=$PREFIX/var
130  fi
131  if [ -z "$INCLUDEDIR" ]; then
132  	INCLUDEDIR=$PREFIX/include
133  fi
134  if [ -z "$INFODIR" ]; then
135  	INFODIR=$PREFIX/info
136  fi
137  if [ -z "$MANDIR" ]; then
138  	MANDIR=$PREFIX/man
139  fi
140  
141  which pkg-config > /dev/null
142  if [ $? -eq 0 ]; then
143      PKG_CONFIG=pkg-config
144  else
145      PKG_CONFIG=false
146  fi
147  
148  # Simple uname based platform detection
149  # $PLATFORM is used for platform dependent dependency selection
150  printf "detect platform... "
151  if [ $OS = SunOS ]; then
152      PLATFORM="solaris sunos unix svr4"
153  fi
154  if [ $OS = Linux ]; then
155      PLATFORM="linux unix"
156  fi
157  if [ $OS = FreeBSD ]; then
158      PLATFORM="freebsd bsd unix"
159  fi
160  if [ $OS = Darwin ]; then
161      PLATFORM="macos osx bsd unix"
162  fi
163  echo $OS | grep "MINGW" > /dev/null
164  if [ $? -eq 0 ]; then
165      PLATFORM="windows mingw"
166  fi
167  
168  if [ -z "$PLATFORM" ]; then
169      PLATFORM="unix"
170  fi
171  
172  for p in $PLATFORM
173  do
174  	PLATFORM_NAME=$p
175  	break
176  done
177  echo $PLATFORM_NAME
178  
179  isplatform()
180  {
181      for p in $PLATFORM
182      do
183          if [ $p = $1 ]; then
184              return 0
185          fi
186      done
187      return 1
188  }
189  isnotplatform()
190  {
191      for p in $PLATFORM
192      do
193          if [ $p = $1 ]; then
194              return 1
195          fi
196      done
197      return 0
198  }
199  
200  # generate config.mk and config.h
201  cat > $TEMP_DIR/config.mk << __EOF__
202  #
203  # config.mk generated by configure
204  #
205  
206  # general vars
207  HOST=$HOST
208  PREFIX=$PREFIX
209  INSTALL_DIR=$INSTALL_DIR
210  
211  EPREFIX=$EPREFIX
212  
213  BINDIR=$BINDIR
214  SBINDIR=$SBINDIR
215  LIBDIR=$LIBDIR
216  LIBEXECDIR=$LIBEXECDIR
217  DATADIR=$DATADIR
218  SYSCONFDIR=$SYSCONFDIR
219  SHAREDSTATEDIR=$SHAREDSTATEDIR
220  LOCALSTATEDIR=$LOCALSTATEDIR
221  INCLUDEDIR=$INCLUDEDIR
222  INFODIR=$INFODIR
223  MANDIR=$MANDIR
224  
225  __EOF__
226  
227  echo > $TEMP_DIR/make.mk
228  
229  ENV_CFLAGS=$CFLAGS
230  ENV_LDFLAGS=$LDFLAGS
231  ENV_CXXFLAGS=$CXXFLAGS
232  
233  # Toolchain detection
234  # this will insert make vars to config.mk
235  . make/toolchain.sh
236  
237  # add user specified flags to config.mk
238  echo >> $TEMP_DIR/config.mk
239  if [ ! -z "${ENV_CFLAGS}" ]; then
240      echo "CFLAGS += $ENV_CFLAGS" >> $TEMP_DIR/config.mk
241  fi
242  if [ ! -z "${ENV_CXXFLAGS}" ]; then
243      echo "CXXFLAGS += $ENV_CXXFLAGS" >> $TEMP_DIR/config.mk
244  fi
245  if [ ! -z "${ENV_LDFLAGS}" ]; then
246      echo "LDFLAGS += $ENV_LDFLAGS" >> $TEMP_DIR/config.mk
247  fi
248  
249  #
250  # DEPENDENCIES
251  #
252  
253  dependency_libpq()
254  {
255      printf "checking for libpq... "
256      # dependency libpq 
257      while true
258      do
259          if [ -z "$PKG_CONFIG" ]; then
260          	break
261          fi
262  		$PKG_CONFIG libpq
263          if [ $? -ne 0 ] ; then
264              break
265          fi
266          CFLAGS="$CFLAGS `$PKG_CONFIG --cflags libpq`"
267          LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs libpq`"
268  		echo yes
269          return 0
270      done
271  	
272  	echo no
273  	return 1
274  }
275  dependency_openssl()
276  {
277      printf "checking for openssl... "
278      # dependency openssl 
279      while true
280      do
281          if [ -z "$PKG_CONFIG" ]; then
282          	break
283          fi
284  		$PKG_CONFIG openssl
285          if [ $? -ne 0 ] ; then
286              break
287          fi
288          CFLAGS="$CFLAGS `$PKG_CONFIG --cflags openssl`"
289          LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs openssl`"
290  		echo yes
291          return 0
292      done
293  	
294  	echo no
295  	return 1
296  }
297  dependency_libxml2()
298  {
299      printf "checking for libxml2... "
300      # dependency libxml2 
301      while true
302      do
303          if [ -z "$PKG_CONFIG" ]; then
304          	break
305          fi
306  		$PKG_CONFIG libxml-2.0
307          if [ $? -ne 0 ] ; then
308              break
309          fi
310          CFLAGS="$CFLAGS `$PKG_CONFIG --cflags libxml-2.0`"
311          LDFLAGS="$LDFLAGS `$PKG_CONFIG --libs libxml-2.0`"
312  		echo yes
313          return 0
314      done
315  	
316  	echo no
317  	return 1
318  }
319  
320  DEPENDENCIES_FAILED=
321  ERROR=0
322  # general dependencies
323  CFLAGS=
324  LDFLAGS=
325  while true
326  do
327      if isnotplatform "linux"; then
328          break
329      fi
330      while true
331      do
332          
333          CFLAGS="$CFLAGS -DLINUX"    
334          LDFLAGS="$LDFLAGS -lpthread -ldl -lm -lldap"    
335  		cat >> $TEMP_DIR/make.mk << __EOF__
336  # platform dependend source files
337  PLATFORM_DAEMONOBJ = event_linux.o
338  
339  # platform dependend vars
340  OBJ_EXT = .o
341  LIB_EXT = .so
342  APP_EXT =
343  
344  __EOF__
345          
346          break
347      done
348      
349      break
350  done
351  while true
352  do
353      if isnotplatform "bsd"; then
354          break
355      fi
356      if isplatform "macos"; then
357          break
358      fi
359      while true
360      do
361          
362          CFLAGS="$CFLAGS -DBSD"    
363          LDFLAGS="$LDFLAGS -lpthread -lm -lldap"    
364  		cat >> $TEMP_DIR/make.mk << __EOF__
365  # platform dependend source files
366  PLATFORM_DAEMONOBJ = event_bsd.o
367  
368  # platform dependend vars
369  OBJ_EXT = .o
370  LIB_EXT = .so
371  APP_EXT =
372  
373  __EOF__
374          
375          break
376      done
377      
378      break
379  done
380  while true
381  do
382      if isnotplatform "macos"; then
383          break
384      fi
385      while true
386      do
387          
388          CFLAGS="$CFLAGS -DBSD -DOSX"    
389          LDFLAGS="$LDFLAGS -lpthread -ldl -lm -lldap"    
390  		cat >> $TEMP_DIR/make.mk << __EOF__
391  # platform dependend source files
392  PLATFORM_DAEMONOBJ = event_bsd.o
393  
394  # platform dependend vars
395  OBJ_EXT = .o
396  LIB_EXT = .dylib
397  APP_EXT =
398  
399  __EOF__
400          
401          break
402      done
403      
404      break
405  done
406  while true
407  do
408      if isnotplatform "solaris"; then
409          break
410      fi
411      while true
412      do
413          
414          CFLAGS="$CFLAGS -DSOLARIS -D_REENTRANT -D_POSIX_PTHREAD_SEMANTICS"    
415          LDFLAGS="$LDFLAGS -lsocket -lnsl -lsendfile -lposix4 -lpthread -ldl -lm -lmd -lldap"    
416  		cat >> $TEMP_DIR/make.mk << __EOF__
417  # platform dependend source files
418  PLATFORM_DAEMONOBJ = event_solaris.o
419  
420  # platform dependend vars
421  OBJ_EXT = .o
422  LIB_EXT = .so
423  APP_EXT =
424  
425  __EOF__
426          
427          break
428      done
429      
430      break
431  done
432  
433  # add general dependency flags to config.mk
434  echo >> $TEMP_DIR/config.mk
435  if [ ! -z "${CFLAGS}" ]; then
436      echo "CFLAGS += $CFLAGS" >> $TEMP_DIR/config.mk
437  fi
438  if [ ! -z "${CXXFLAGS}" ]; then
439      echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk
440  fi
441  if [ ! -z "${LDFLAGS}" ]; then
442      echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk
443  fi
444  
445  #
446  # OPTION VALUES
447  #
448  
449  #
450  # TARGETS
451  #
452  CFLAGS=
453  CXXFLAGS=
454  LDFLAGS=
455  
456  # Target
457  CFLAGS=
458  LDFLAGS=
459  CXXFLAGS=
460  
461  dependency_libxml2
462  if [ $? -ne 0 ]; then
463  	DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED libxml2 "
464  	ERROR=1
465  fi
466  dependency_openssl
467  if [ $? -ne 0 ]; then
468  	DEPENDENCIES_FAILED="$DEPENDENCIES_FAILED openssl "
469  	ERROR=1
470  fi
471  
472  
473  echo >> $TEMP_DIR/config.mk
474  if [ ! -z "${CFLAGS}" ]; then
475      echo "CFLAGS  += $CFLAGS" >> $TEMP_DIR/config.mk
476  fi
477  if [ ! -z "${CXXFLAGS}" ]; then
478      echo "CXXFLAGS += $CXXFLAGS" >> $TEMP_DIR/config.mk
479  fi
480  if [ ! -z "${LDFLAGS}" ]; then
481      echo "LDFLAGS += $LDFLAGS" >> $TEMP_DIR/config.mk
482  fi
483  
484  if [ $ERROR -ne 0 ]; then
485  	echo
486  	echo "Error: Unresolved dependencies"
487  	echo $DEPENCIES_FAILED
488  	rm -Rf $TEMP_DIR
489  	exit 1
490  fi
491  
492  echo "configure finished"
493  echo
494  echo "Build Config:"
495  echo "  PREFIX:    $PREFIX"
496  echo "  TOOLCHAIN: $TOOLCHAIN_NAME"
497  echo
498  cat $TEMP_DIR/config.mk $TEMP_DIR/make.mk > config.mk
499  rm -Rf $TEMP_DIR
500  
501