Move initialisation code into its own section, if supported by the linker.
[gwm.git] / configure.ac
blob73422765979941590f99e8883164d48ad4514172
1 AC_INIT(gwm, 0.0, gtw@gnu.org)
2 AC_PREREQ([2.60])
3 AC_CONFIG_SRCDIR(gwm.c)
4 AM_INIT_AUTOMAKE
5 AC_CONFIG_FILES(Makefile gwm.ld)
6 AC_CONFIG_HEADERS(config.h)
8 if test -f config.options; then
9   . ./config.options
12 gwm_packages=""
14 # GWM_MANDATORY_PACKAGE(PKG-NAME)
15 AC_DEFUN([GWM_MANDATORY_PACKAGE],[
16   AC_MSG_CHECKING([for $1])
17   PKG_CHECK_EXISTS([$1],
18                    [AC_MSG_RESULT(yes)
19                    gwm_packages="$gwm_packages $1"],
20                    [AC_MSG_ERROR(no)])
23 # GWM_OPTIONAL_PACKAGE(PKG-NAME, [LABEL], [DEPENDENCIES])
24 AC_DEFUN([GWM_OPTIONAL_PACKAGE],[
25   gwm_label=m4_ifval([$2], [$2], [$1])
26   gwm_name=`echo $ECHO_N $gwm_label | tr 'a-z' 'A-Z' | tr -c 'a-zA-Z0-9' _`
27   gwm_have_deps=yes
28   for gwm_i in [$3]; do
29     if eval test "x\$gwm_found_$gwm_i" != "xyes"; then gwm_have_deps=no; fi
30   done
31   if test $gwm_have_deps = yes; then
32     AC_MSG_CHECKING([for $gwm_label])
33     if eval test "x\$with_$gwm_label" = xno; then
34       AC_MSG_RESULT(disabled)
35     else
36       PKG_CHECK_EXISTS([$1],
37                        [AC_MSG_RESULT(yes)
38                        gwm_packages="$gwm_packages $1"
39                        eval "gwm_found_$gwm_label=yes"
40                        AC_DEFINE_UNQUOTED(USE_$gwm_name, 1)],
41                        [AC_MSG_RESULT(no)])
42     fi
43   fi
46 AH_BOTTOM([/* If we haven't been told that we're debugging, assume we aren't. */
47 #ifndef DEBUG
48 #define NDEBUG 1
49 #endif])
51 # Checks for programs:
52 AC_PROG_CC
53 AC_USE_SYSTEM_EXTENSIONS
54 PKG_PROG_PKG_CONFIG
56 # Checks for libraries:
57 AC_ARG_WITH(composite,[  --with-composite        use the X Composite extension.])
58 AC_ARG_WITH(damage,   [  --with-damage           use the X DAMAGE extension.])
59 AC_ARG_WITH(render,   [  --with-render           use the X RENDER extension.])
60 AC_ARG_WITH(shape,    [  --with-shape            use the X SHAPE extension.])
61 AC_ARG_WITH(xfixes,   [  --with-xfixes           use the XFIXES extension.])
63 AH_TEMPLATE(USE_COMPOSITE,[Use the X Composite extension.])
64 AH_TEMPLATE(USE_DAMAGE,[Use the X DAMAGE extension.])
65 AH_TEMPLATE(USE_RENDER,[Use the X RENDER extension.])
66 AH_TEMPLATE(USE_SHAPE,[Use the X SHAPE extension.])
67 AH_TEMPLATE(USE_XFIXES,[Use the XFIXES extension.])
69 GWM_MANDATORY_PACKAGE(xcb)
70 GWM_OPTIONAL_PACKAGE(fontconfig)
71 GWM_OPTIONAL_PACKAGE(freetype2)
72 GWM_OPTIONAL_PACKAGE(xcb-composite, composite)
73 GWM_OPTIONAL_PACKAGE(xcb-damage, damage)
74 GWM_OPTIONAL_PACKAGE(xcb-render, render, fontconfig freetype2)
75 GWM_OPTIONAL_PACKAGE(xcb-shape, shape)
76 GWM_OPTIONAL_PACKAGE(xcb-xfixes, xfixes)
78 AM_CONDITIONAL(RENDER, [test x$gwm_found_render = xyes])
80 AC_SEARCH_LIBS(iconv, iconv)
82 # Checks for header files:
83 AC_CHECK_HEADERS(iconv.h mcheck.h sys/mman.h poll.h sys/param.h)
85 # Checks for types:
86 AC_TYPE_UINT64_T
88 # Checks for functions:
89 AC_CHECK_FUNCS(iconv mtrace ppoll)
91 # Check for a reasonable section alignment to pass to the linker.  First,
92 # try looking for typical compile-time constants in system header files...
93 AC_MSG_CHECKING([linker section alignment])
94 gwm_align=512
95 gwm_found_align=no
96 while test $gwm_align -le 65536; do
97   AC_COMPILE_IFELSE([AC_LANG_SOURCE([[
98 #if HAVE_SYS_PARAM_H
99 #include <sys/param.h>
100 #endif
101 #if HAVE_UNISTD_H
102 #include <unistd.h>
103 #endif
105 #if EXEC_PAGESIZE == ]] $gwm_align [[ || PAGE_SIZE == ]] $gwm_align [[ || PAGESIZE == ]] $gwm_align [[
106 int main() { return 0; }
107 #else
108 Failure.
109 #endif
110 ]])], [gwm_found_align=yes; break], [])
111   gwm_align=$(expr $gwm_align \* 2)
112 done
113 if test $gwm_found_align = no; then
114   # No luck so far...
115   if test $cross_compiling != yes; then
116     for gwm_prog in pagesize "getconf PAGE_SIZE"; do
117       if $gwm_prog > /dev/null 2>&1; then
118         gwm_align=512
119         gwm_found_align=no
120         while test $gwm_align -le 65536; do
121           if test $($gwm_prog 2> /dev/null) = $gwm_align; then
122             gwm_found_align=yes
123             break
124           fi
125           gwm_align=$(expr $gwm_align \* 2)
126         done
127         if test $gwm_found_align = yes; then break; fi
128       fi
129     done
130   fi
132 if test $gwm_found_align = no; then
133   gwm_align=4096 # complete guess
135 AC_MSG_RESULT([$gwm_align])
136 SECTION_ALIGN=$gwm_align
137 AC_SUBST(SECTION_ALIGN)
139 AC_MSG_CHECKING([for linker script support])
140 gwm_ldflags="$LDFLAGS"
141 LDFLAGS="$LDFLAGS -Wl,-Tconftest.ld"
142 cat > conftest.ld <<EOF
143 SECTIONS
145   init_start = .;
146   .gwminit.text : { init*(.text ) }
147   .gwminit.rodata : { init*(.rodata ) }
148   init_end = .;
150 INSERT AFTER .text;
152 AC_LINK_IFELSE([AC_LANG_SOURCE([[
153 extern char init_start, init_end;
154 int main() { (void) ( &init_end - &init_start ); return 0; }
155 ]])], [gwm_linker_scripts=yes
156        AC_DEFINE(HAVE_INIT_SECTION, 1)
157        AC_MSG_RESULT(yes)], [AC_MSG_RESULT(no)])
158 LDFLAGS="$gwm_ldflags"
159 AM_CONDITIONAL(LINKER_SCRIPTS, [test x$gwm_linker_scripts = xyes])
160 AH_TEMPLATE(HAVE_INIT_SECTION,[Define if the linker supports scripts (used to locate the init section).])
162 PKG_CFLAGS=$($PKG_CONFIG --cflags $gwm_packages)
163 PKG_LIBS=$($PKG_CONFIG --libs $gwm_packages)
165 AC_SUBST(PKG_CFLAGS)
166 AC_SUBST(PKG_LIBS)
168 AC_OUTPUT