1# pic_flag.at -- override the pic_flag at configure time   -*- Autotest -*-
2
3#   Copyright (C) 2010-2015 Free Software Foundation, Inc.
4#
5#   This file is part of GNU Libtool.
6#
7# GNU Libtool is free software; you can redistribute it and/or
8# modify it under the terms of the GNU General Public License as
9# published by the Free Software Foundation; either version 2 of
10# the License, or (at your option) any later version.
11#
12# GNU Libtool is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with GNU Libtool; see the file COPYING.  If not, a copy
19# can be downloaded from  http://www.gnu.org/licenses/gpl.html,
20# or obtained by writing to the Free Software Foundation, Inc.,
21# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22####
23
24AT_SETUP([override pic_flag at configure time])
25
26# Just try to configure the Libtool package with -fpic if we can compile
27# with it, for C and C++.
28
29AT_DATA([foo.c],
30[[int data = 42;
31int func(void) { return data; }
32]])
33
34cp foo.c foo.cpp
35C_pic_flag='-fpic -DPIC'
36AT_CHECK([$CC $CPPFLAGS $CFLAGS $C_pic_flag -c foo.c || exit 77],
37	 [], [stdout], [stderr])
38# The configure test for the PIC flag also checks for warnings.
39AT_CHECK([$GREP fpic stdout stderr && exit 77], [1])
40AT_CHECK([[$GREP '[uU]nknown.*option' stdout stderr && exit 77]], [1])
41
42CXX_pic_flag='-fpic -DPIC'
43if $CXX $CPPFLAGS $CXXFLAGS $CXX_pic_flag -c foo.cpp; then :; else
44  CXX_pic_flag=
45fi
46
47# Set up a tests/demo.at style project.
48_LT_DEMO_SETUP
49
50# Bootstrap, and configure it so that we can extract libtool --config
51# settings.
52LT_AT_BOOTSTRAP([], [-I m4], [], [--add-missing], [],
53    [ignore], [ignore])
54
55LT_AT_CONFIGURE([lt_cv_prog_compiler_pic="$C_pic_flag" ]dnl
56		[lt_cv_prog_compiler_pic_CXX="$CXX_pic_flag"],
57		[./configure])
58: ${MAKE=make}
59AT_CHECK([$MAKE], [], [stdout], [ignore])
60AT_CHECK([if ./libtool --features | $GREP 'enable shared libraries'; then ]dnl
61	 [  $GREP ' -fpic' stdout; else exit 77; fi], [], [ignore], [ignore])
62
63AT_CLEANUP
64