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=-pthread -DOS_MACOSX" >> build_config.mk 21 echo "PLATFORM_LDFLAGS=-lpthread" >> 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 *) 34 echo "Unknown platform!" 35 exit 1 36esac 37 38echo "PLATFORM=$PLATFORM" >> build_config.mk 39 40# On GCC, use libc's memcmp, not GCC's memcmp 41PORT_CFLAGS="-fno-builtin-memcmp" 42 43# Detect C++0x -- this determines whether we'll use port_noatomic.h 44# or port_posix.h by: 45# 1. Rrying to compile with -std=c++0x and including <cstdatomic>. 46# 2. If g++ returns error code, we know to use port_posix.h 47g++ $CFLAGS -std=c++0x -x c++ - -o /dev/null 2>/dev/null <<EOF 48 #include <cstdatomic> 49 int main() {} 50EOF 51if [ "$?" = 0 ]; then 52 PORT_CFLAGS+=" -DLEVELDB_PLATFORM_POSIX -DLEVELDB_CSTDATOMIC_PRESENT -std=c++0x" 53else 54 PORT_CFLAGS+=" -DLEVELDB_PLATFORM_POSIX" 55fi 56 57# Test whether Snappy library is installed 58# http://code.google.com/p/snappy/ 59g++ $CFLAGS -x c++ - -o /dev/null 2>/dev/null <<EOF 60 #include <snappy.h> 61 int main() {} 62EOF 63if [ "$?" = 0 ]; then 64 echo "SNAPPY=1" >> build_config.mk 65else 66 echo "SNAPPY=0" >> build_config.mk 67fi 68 69echo "PORT_CFLAGS=$PORT_CFLAGS" >> build_config.mk 70