1#!/bin/sh 2 3# Detects OS we're compiling on and generates build_config.mk, 4# which in turn gets read while processing Makefile. 5 6# build_config.mk will set the following variables: 7# - PORT_CFLAGS will either set: 8# -DLEVELDB_PLATFORM_POSIX if cstatomic is present 9# -DLEVELDB_PLATFORM_NOATOMIC if it is not 10# - PLATFORM_CFLAGS with compiler flags for the platform 11# - PLATFORM_LDFLAGS with linker flags for the platform 12 13# Delete existing build_config.mk 14rm -f build_config.mk 15 16# Detect OS 17case `uname -s` in 18 Darwin) 19 PLATFORM=OS_MACOSX 20 echo "PLATFORM_CFLAGS=-DOS_MACOSX" >> build_config.mk 21 echo "PLATFORM_LDFLAGS=" >> build_config.mk 22 ;; 23 Linux) 24 PLATFORM=OS_LINUX 25 echo "PLATFORM_CFLAGS=-pthread -DOS_LINUX" >> build_config.mk 26 echo "PLATFORM_LDFLAGS=-lpthread" >> build_config.mk 27 ;; 28 SunOS) 29 PLATFORM=OS_SOLARIS 30 echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_SOLARIS" >> build_config.mk 31 echo "PLATFORM_LDFLAGS=-lpthread -lrt" >> build_config.mk 32 ;; 33 FreeBSD) 34 PLATFORM=OS_FREEBSD 35 echo "PLATFORM_CFLAGS=-D_REENTRANT -DOS_FREEBSD" >> build_config.mk 36 echo "PLATFORM_LDFLAGS=-lpthread" >> build_config.mk 37 ;; 38 *) 39 echo "Unknown platform!" 40 exit 1 41esac 42 43echo "PLATFORM=$PLATFORM" >> build_config.mk 44 45# On GCC, use libc's memcmp, not GCC's memcmp 46PORT_CFLAGS="-fno-builtin-memcmp" 47 48# Detect C++0x -- this determines whether we'll use port_noatomic.h 49# or port_posix.h by: 50# 1. Rrying to compile with -std=c++0x and including <cstdatomic>. 51# 2. If g++ returns error code, we know to use port_posix.h 52g++ $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF 53 #include <cstdatomic> 54 int main() {} 55EOF 56if [ "$?" = 0 ]; then 57 PORT_CFLAGS="$PORT_CFLAGS -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT -std=c++0x" 58else 59 PORT_CFLAGS="$PORT_CFLAGS -DLEVELDB_PLATFORM_POSIX" 60fi 61 62# Test whether Snappy library is installed 63# http://code.google.com/p/snappy/ 64g++ $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 65 #include <snappy.h> 66 int main() {} 67EOF 68if [ "$?" = 0 ]; then 69 echo "SNAPPY=1" >> build_config.mk 70else 71 echo "SNAPPY=0" >> build_config.mk 72fi 73 74echo "PORT_CFLAGS=$PORT_CFLAGS" >> build_config.mk 75