btrfs-progs: autoconf: set CFLAGS conditionally
[platform/upstream/btrfs-progs.git] / configure.ac
1 AC_INIT([btrfs-progs],
2         m4_esyscmd([./version.sh --configure]),
3         [linux-btrfs@vger.kernel.org],,
4         [http://btrfs.wiki.kernel.org])
5
6 dnl library version
7 LIBBTRFS_MAJOR=0
8 LIBBTRFS_MINOR=1
9 LIBBTRFS_PATCHLEVEL=1
10
11 CFLAGS=${CFLAGS:-"-g -O1"}
12 AC_SUBST([CFLAGS])
13
14 AC_PREREQ([2.60])
15
16 AC_CONFIG_AUX_DIR([config])
17 dnl AC_USE_SYSTEM_EXTENSIONS must be called before any macros that run
18 dnl the compiler (like AC_PROG_LIBTOOL) to avoid autoconf errors.
19 AC_USE_SYSTEM_EXTENSIONS
20
21 AC_CONFIG_SRCDIR([btrfs.c])
22 AC_PREFIX_DEFAULT([/usr])
23
24 AC_PROG_CC
25 AC_CANONICAL_HOST
26 AC_C_CONST
27 AC_C_VOLATILE
28 AC_C_BIGENDIAN
29
30 AC_SYS_LARGEFILE
31
32 AC_PROG_INSTALL
33 AC_PROG_LN_S
34 AC_PATH_PROG([AR], [ar])
35 AC_PATH_PROG([RM], [rm], [rm])
36 AC_PATH_PROG([RMDIR], [rmdir], [rmdir])
37
38 AC_CHECK_FUNCS([openat], [],
39         [AC_MSG_ERROR([cannot find openat() function])])
40
41 m4_ifndef([PKG_PROG_PKG_CONFIG],
42   [m4_fatal([Could not locate the pkg-config autoconf
43     macros. These are usually located in /usr/share/aclocal/pkg.m4.
44     If your macros are in a different location, try setting the
45     environment variable AL_OPTS="-I/other/macro/dir" before running
46     ./autogen.sh or autoreconf again.])])
47 PKG_PROG_PKG_CONFIG
48
49
50 dnl
51 dnl Calls pkg-config --static
52 dnl
53 AC_DEFUN([PKG_STATIC], [
54   if AC_RUN_LOG([pkg-config --exists --print-errors "$2"]); then
55     $1=`pkg-config --libs --static "$2"`
56     AC_SUBST([$1])
57   else
58     AC_MSG_ERROR([pkg-config description of $2, needed for static build, is not available])
59   fi
60 ])
61
62
63 AC_ARG_ENABLE([backtrace],
64   AS_HELP_STRING([--disable-backtrace], [disable btrfs backtrace]),
65   [], [enable_backtrace=yes]
66 )
67
68 AS_IF([test "x$enable_backtrace" = xno], [
69   AC_DEFINE([BTRFS_DISABLE_BACKTRACE], [1], [disable backtrace stuff in kerncompat.h ])
70 ])
71
72 if test "x$enable_backtrace" = xyes; then
73         AC_CHECK_HEADERS([execinfo.h])
74         AC_CHECK_FUNCS([backtrace backtrace_symbols_fd], [],
75               AC_MSG_ERROR([standard library does not have backtrace support]))
76 fi
77
78
79 AC_ARG_ENABLE([documentation],
80               AS_HELP_STRING([--disable-documentation], [do not build domumentation]),
81   [], [enable_documentation=yes]
82 )
83 AS_IF([test "x$enable_documentation" = xyes], [DISABLE_DOCUMENTATION=0], [DISABLE_DOCUMENTATION=1])
84 AC_SUBST([DISABLE_DOCUMENTATION])
85
86 dnl detect tools to build documentation
87 if test "x$enable_documentation" = xyes; then
88         AC_PATH_PROG([ASCIIDOC], [asciidoc], [asciidoc])
89         AC_PATH_PROG([XMLTO], [xmlto], [xmlto])
90         AC_PATH_PROG([GZIP], [gzip], [gzip])
91         AC_PATH_PROG([MV], [mv], [mv])
92         AC_PROG_SED
93 fi
94
95 AC_ARG_ENABLE([convert],
96               AS_HELP_STRING([--disable-convert], [do not build btrfs-convert]),
97   [], [enable_btrfsconvert=yes]
98 )
99
100 AS_IF([test "x$enable_btrfsconvert" = xyes], [DISABLE_BTRFSCONVERT=0], [DISABLE_BTRFSCONVERT=1])
101 AC_SUBST([DISABLE_BTRFSCONVERT])
102
103 if test "x$enable_btrfsconvert" = xyes; then
104         PKG_CHECK_MODULES(EXT2FS, [ext2fs])
105         PKG_CHECK_MODULES(COM_ERR, [com_err])
106 fi
107
108
109 dnl Define <NAME>_LIBS= and <NAME>_CFLAGS= by pkg-config
110 dnl
111 dnl The default PKG_CHECK_MODULES() action-if-not-found is end the
112 dnl execution with error. The static libs are optional.
113
114 PKG_CHECK_MODULES(BLKID, [blkid])
115 PKG_STATIC(BLKID_LIBS_STATIC, [blkid])
116
117 PKG_CHECK_MODULES(UUID, [uuid])
118 PKG_STATIC(UUID_LIBS_STATIC, [uuid])
119
120 PKG_CHECK_MODULES(ZLIB, [zlib])
121 PKG_STATIC(ZLIB_LIBS_STATIC, [zlib])
122
123 dnl lzo library does not provide pkg-config, let use classic way
124 AC_CHECK_LIB([lzo2], [lzo_version], [
125         LZO2_LIBS="-llzo2"
126         LZO2_CFLAGS=""
127         LZO2_LIBS_STATIC="-llzo2"],[
128         AC_MSG_ERROR([cannot find lzo2 library])
129 ])
130 AC_SUBST([LZO2_LIBS])
131 AC_SUBST([LZO2_LIBS_STATIC])
132 AC_SUBST([LZO2_CFLAGS])
133
134
135 dnl library stuff
136 AC_SUBST([LIBBTRFS_MAJOR])
137 AC_SUBST([LIBBTRFS_MINOR])
138 AC_SUBST([LIBBTRFS_PATCHLEVEL])
139
140 AC_CONFIG_HEADERS([config.h])
141
142 AC_CONFIG_FILES([
143 Makefile
144 Documentation/Makefile
145 version.h
146 ])
147
148 AC_OUTPUT
149
150 AC_MSG_RESULT([
151         ${PACKAGE_NAME} ${PACKAGE_VERSION}
152
153         prefix:            ${prefix}
154         exec prefix:       ${exec_prefix}
155
156         bindir:            ${bindir}
157         libdir:            ${libdir}
158         includedir:        ${includedir}
159
160         compiler:          ${CC}
161         cflags:            ${CFLAGS}
162         ldflags:           ${LDFLAGS}
163
164         documentaton:      ${enable_documentation}
165         backtrace support: ${enable_backtrace}
166         btrfs-convert:     ${enable_btrfsconvert}
167
168         Type 'make' to compile.
169 ])
170