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