From 617004c4e7cc229c3f736008fec414981b783d64 Mon Sep 17 00:00:00 2001 From: Thierry Reding Date: Thu, 13 Sep 2012 22:23:59 +0200 Subject: [PATCH 1/2] build: Don't cross-compile GLSL builtin compiler The builtin_compiler binary is used during the build process to generate code for the builtin GLSL functions. Since this binary needs to be run on the build host, it must not be cross-compiled. This patch fixes the build system to compile a second version of the source files and the builtin_compiler binary itself for the build system. It does so by defining the CC_FOR_BUILD and CXX_FOR_BUILD variables, which are searched for by the configure script and point to the location of native C and C++ compilers. --- Makefile.am | 2 + configure.ac | 12 +- m4/ax_prog_cc_for_build.m4 | 140 ++++++++++++++++++++++ m4/ax_prog_cxx_for_build.m4 | 123 +++++++++++++++++++ src/glsl/.gitignore | 1 - src/glsl/Makefile.am | 21 ++-- src/glsl/builtin_compiler/.gitignore | 6 + src/glsl/builtin_compiler/Makefile.am | 61 ++++++++++ src/glsl/{ => builtin_compiler}/builtin_stubs.cpp | 0 9 files changed, 347 insertions(+), 19 deletions(-) create mode 100644 m4/ax_prog_cc_for_build.m4 create mode 100644 m4/ax_prog_cxx_for_build.m4 create mode 100644 src/glsl/builtin_compiler/.gitignore create mode 100644 src/glsl/builtin_compiler/Makefile.am rename src/glsl/{ => builtin_compiler}/builtin_stubs.cpp (100%) diff --git a/Makefile.am b/Makefile.am index e411218..b72f3cd 100644 --- a/Makefile.am +++ b/Makefile.am @@ -19,6 +19,8 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. +ACLOCAL_AMFLAGS = -I m4 + SUBDIRS = src doxygen: diff --git a/configure.ac b/configure.ac index 4193496..184d1ed 100644 --- a/configure.ac +++ b/configure.ac @@ -9,7 +9,8 @@ See docs/autoconf.html for more details on the options for Mesa.]) AC_INIT([Mesa], [9.1.0], [https://bugs.freedesktop.org/enter_bug.cgi?product=Mesa]) AC_CONFIG_AUX_DIR([bin]) -AC_CANONICAL_HOST +AC_CONFIG_MACRO_DIR([m4]) +AC_CANONICAL_SYSTEM AM_INIT_AUTOMAKE([foreign]) dnl http://people.gnome.org/~walters/docs/build-api.txt @@ -23,9 +24,6 @@ m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])]) m4_ifdef([AM_PROG_AR], [AM_PROG_AR]) -LT_PREREQ([2.2]) -LT_INIT([disable-static]) - dnl Set internal versions OSMESA_VERSION=8 AC_SUBST([OSMESA_VERSION]) @@ -44,7 +42,9 @@ LIBKMS_XORG_REQUIRED=1.0.0 dnl Check for progs AC_PROG_CPP AC_PROG_CC +AX_PROG_CC_FOR_BUILD AC_PROG_CXX +AX_PROG_CXX_FOR_BUILD AM_PROG_CC_C_O AM_PROG_AS AC_CHECK_PROGS([MAKE], [gmake make]) @@ -53,6 +53,9 @@ AC_PROG_SED AC_PROG_MKDIR_P AC_PATH_PROG([MKDEP], [makedepend]) +LT_PREREQ([2.2]) +LT_INIT([disable-static]) + if test "x$MKDEP" = "x"; then AC_MSG_ERROR([makedepend is required to build Mesa]) fi @@ -1958,6 +1961,7 @@ AC_CONFIG_FILES([configs/current src/gbm/Makefile src/gbm/main/gbm.pc src/glsl/Makefile + src/glsl/builtin_compiler/Makefile src/glsl/glcpp/Makefile src/glsl/tests/Makefile src/glx/Makefile diff --git a/m4/ax_prog_cc_for_build.m4 b/m4/ax_prog_cc_for_build.m4 new file mode 100644 index 0000000..08095a8 --- /dev/null +++ b/m4/ax_prog_cc_for_build.m4 @@ -0,0 +1,140 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_prog_cc_for_build.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_CC_FOR_BUILD +# +# DESCRIPTION +# +# This macro searches for a C compiler that generates native executables, +# that is a C compiler that surely is not a cross-compiler. This can be +# useful if you have to generate source code at compile-time like for +# example GCC does. +# +# The macro sets the CC_FOR_BUILD and CPP_FOR_BUILD macros to anything +# needed to compile or link (CC_FOR_BUILD) and preprocess (CPP_FOR_BUILD). +# The value of these variables can be overridden by the user by specifying +# a compiler with an environment variable (like you do for standard CC). +# +# It also sets BUILD_EXEEXT and BUILD_OBJEXT to the executable and object +# file extensions for the build platform, and GCC_FOR_BUILD to `yes' if +# the compiler we found is GCC. All these variables but GCC_FOR_BUILD are +# substituted in the Makefile. +# +# LICENSE +# +# Copyright (c) 2008 Paolo Bonzini +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 5 + +AU_ALIAS([AC_PROG_CC_FOR_BUILD], [AX_PROG_CC_FOR_BUILD]) +AC_DEFUN([AX_PROG_CC_FOR_BUILD], [dnl +AC_REQUIRE([AC_PROG_CC])dnl +AC_REQUIRE([AC_PROG_CPP])dnl +AC_REQUIRE([AC_EXEEXT])dnl +AC_REQUIRE([AC_CANONICAL_SYSTEM])dnl +dnl +pushdef([AC_TRY_COMPILER], [ +cat > conftest.$ac_ext << EOF +#line __oline__ "configure" +#include "confdefs.h" +[$1] +EOF +# If we can't run a trivial program, we are probably using a cross +compiler. +# Fail miserably. +if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} && (./conftest; +exit) 2>/dev/null; then + [$2]=yes +else + echo "configure: failed program was:" >&AC_FD_CC + cat conftest.$ac_ext >&AC_FD_CC + [$2]=no +fi +[$3]=no +rm -fr conftest*])dnl + +dnl Use the standard macros, but make them use other variable names +dnl +pushdef([cross_compiling], [#])dnl +pushdef([ac_cv_prog_CPP], ac_cv_build_prog_CPP)dnl +pushdef([ac_cv_prog_gcc], ac_cv_build_prog_gcc)dnl +pushdef([ac_cv_prog_cc_works], ac_cv_build_prog_cc_works)dnl +pushdef([ac_cv_prog_cc_cross], ac_cv_build_prog_cc_cross)dnl +pushdef([ac_cv_prog_cc_g], ac_cv_build_prog_cc_g)dnl +pushdef([ac_cv_exeext], ac_cv_build_exeext)dnl +pushdef([ac_cv_objext], ac_cv_build_objext)dnl +pushdef([ac_exeext], ac_build_exeext)dnl +pushdef([ac_objext], ac_build_objext)dnl +pushdef([CC], CC_FOR_BUILD)dnl +pushdef([CPP], CPP_FOR_BUILD)dnl +pushdef([CFLAGS], CFLAGS_FOR_BUILD)dnl +pushdef([CPPFLAGS], CPPFLAGS_FOR_BUILD)dnl +pushdef([LDFLAGS], LDFLAGS_FOR_BUILD)dnl +pushdef([host], build)dnl +pushdef([host_alias], build_alias)dnl +pushdef([host_cpu], build_cpu)dnl +pushdef([host_vendor], build_vendor)dnl +pushdef([host_os], build_os)dnl +pushdef([ac_cv_host], ac_cv_build)dnl +pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl +pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl +pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl +pushdef([ac_cv_host_os], ac_cv_build_os)dnl +pushdef([ac_cpp], ac_build_cpp)dnl +pushdef([ac_compile], ac_build_compile)dnl +pushdef([ac_link], ac_build_link)dnl +pushdef([ac_tool_prefix], [#])dnl + +AC_PROG_CC +AC_PROG_CPP +AC_EXEEXT + +dnl Restore the old definitions +dnl +popdef([AC_TRY_COMPILER])dnl +popdef([ac_tool_prefix])dnl +popdef([ac_link])dnl +popdef([ac_compile])dnl +popdef([ac_cpp])dnl +popdef([ac_cv_host_os])dnl +popdef([ac_cv_host_vendor])dnl +popdef([ac_cv_host_cpu])dnl +popdef([ac_cv_host_alias])dnl +popdef([ac_cv_host])dnl +popdef([host_os])dnl +popdef([host_vendor])dnl +popdef([host_cpu])dnl +popdef([host_alias])dnl +popdef([host])dnl +popdef([CPPFLAGS])dnl +popdef([CFLAGS])dnl +popdef([CPP])dnl +popdef([CC])dnl +popdef([ac_objext])dnl +popdef([ac_exeext])dnl +popdef([ac_cv_objext])dnl +popdef([ac_cv_exeext])dnl +popdef([ac_cv_prog_cc_g])dnl +popdef([ac_cv_prog_cc_works])dnl +popdef([ac_cv_prog_cc_cross])dnl +popdef([ac_cv_prog_gcc])dnl +popdef([cross_compiling])dnl + +dnl Finally, set Makefile variables +dnl +BUILD_EXEEXT=$ac_build_exeext +BUILD_OBJEXT=$ac_build_objext +AC_SUBST(BUILD_EXEEXT)dnl +AC_SUBST(BUILD_OBJEXT)dnl +AC_SUBST([CFLAGS_FOR_BUILD])dnl +AC_SUBST([CPPFLAGS_FOR_BUILD])dnl +AC_SUBST([LDFLAGS_FOR_BUILD])dnl +]) diff --git a/m4/ax_prog_cxx_for_build.m4 b/m4/ax_prog_cxx_for_build.m4 new file mode 100644 index 0000000..4a099f9 --- /dev/null +++ b/m4/ax_prog_cxx_for_build.m4 @@ -0,0 +1,123 @@ +# =========================================================================== +# http://www.gnu.org/software/autoconf-archive/ax_prog_cxx_for_build.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PROG_CXX_FOR_BUILD +# +# DESCRIPTION +# +# This macro searches for a C++ compiler that generates native executables, +# that is a C++ compiler that surely is not a cross-compiler. This can be +# useful if you have to generate source code at compile-time like for +# example GCC does. +# +# The macro sets the CXX_FOR_BUILD and CXXCPP_FOR_BUILD macros to anything +# needed to compile or link (CXX_FOR_BUILD) and preprocess (CXXCPP_FOR_BUILD). +# The value of these variables can be overridden by the user by specifying +# a compiler with an environment variable (like you do for standard CXX). +# +# LICENSE +# +# Copyright (c) 2008 Paolo Bonzini +# Copyright (c) 2012 Avionic Design GmbH +# +# Based on the AX_PROG_CC_FOR_BUILD macro by Paolo Bonzini. +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 5 + +AU_ALIAS([AC_PROG_CXX_FOR_BUILD], [AX_PROG_CXX_FOR_BUILD]) +AC_DEFUN([AX_PROG_CXX_FOR_BUILD], [dnl +AC_REQUIRE([AX_PROG_CC_FOR_BUILD])dnl +AC_REQUIRE([AC_PROG_CXX])dnl +AC_REQUIRE([AC_PROG_CXXCPP])dnl +AC_REQUIRE([AC_CANONICAL_SYSTEM])dnl +dnl +pushdef([AC_TRY_COMPILER], [ +cat > conftest.$ac_ext << EOF +#line __oline__ "configure" +#include "confdefs.h" +[$1] +EOF +# If we can't run a trivial program, we are probably using a cross +compiler. +# Fail miserably. +if AC_TRY_EVAL(ac_link) && test -s conftest${ac_exeext} && (./conftest; +exit) 2>/dev/null; then + [$2]=yes +else + echo "configure: failed program was:" >&AC_FD_CC + cat conftest.$ac_ext >&AC_FD_CC + [$2]=no +fi +[$3]=no +rm -fr conftest*])dnl + +dnl Use the standard macros, but make them use other variable names +dnl +pushdef([cross_compiling], [#])dnl +pushdef([ac_cv_prog_CXXCPP], ac_cv_build_prog_CXXCPP)dnl +pushdef([ac_cv_prog_gxx], ac_cv_build_prog_gxx)dnl +pushdef([ac_cv_prog_cxx_works], ac_cv_build_prog_cxx_works)dnl +pushdef([ac_cv_prog_cxx_cross], ac_cv_build_prog_cxx_cross)dnl +pushdef([ac_cv_prog_cxx_g], ac_cv_build_prog_cxx_g)dnl +pushdef([CXX], CXX_FOR_BUILD)dnl +pushdef([CXXCPP], CXXCPP_FOR_BUILD)dnl +pushdef([CXXFLAGS], CXXFLAGS_FOR_BUILD)dnl +pushdef([CXXCPPFLAGS], CXXCPPFLAGS_FOR_BUILD)dnl +pushdef([host], build)dnl +pushdef([host_alias], build_alias)dnl +pushdef([host_cpu], build_cpu)dnl +pushdef([host_vendor], build_vendor)dnl +pushdef([host_os], build_os)dnl +pushdef([ac_cv_host], ac_cv_build)dnl +pushdef([ac_cv_host_alias], ac_cv_build_alias)dnl +pushdef([ac_cv_host_cpu], ac_cv_build_cpu)dnl +pushdef([ac_cv_host_vendor], ac_cv_build_vendor)dnl +pushdef([ac_cv_host_os], ac_cv_build_os)dnl +pushdef([ac_cxxcpp], ac_build_cxxcpp)dnl +pushdef([ac_compile], ac_build_compile)dnl +pushdef([ac_link], ac_build_link)dnl +pushdef([ac_tool_prefix], [#])dnl + +AC_PROG_CXX +AC_PROG_CXXCPP + +dnl Restore the old definitions +dnl +popdef([AC_TRY_COMPILER])dnl +popdef([ac_tool_prefix])dnl +popdef([ac_link])dnl +popdef([ac_compile])dnl +popdef([ac_cxxcpp])dnl +popdef([ac_cv_host_os])dnl +popdef([ac_cv_host_vendor])dnl +popdef([ac_cv_host_cpu])dnl +popdef([ac_cv_host_alias])dnl +popdef([ac_cv_host])dnl +popdef([host_os])dnl +popdef([host_vendor])dnl +popdef([host_cpu])dnl +popdef([host_alias])dnl +popdef([host])dnl +popdef([CXXCPPFLAGS])dnl +popdef([CXXFLAGS])dnl +popdef([CXXCPP])dnl +popdef([CXX])dnl +popdef([ac_cv_prog_cxx_g])dnl +popdef([ac_cv_prog_cxx_works])dnl +popdef([ac_cv_prog_cxx_cross])dnl +popdef([ac_cv_prog_gxx])dnl +popdef([cross_compiling])dnl + +dnl Finally, set Makefile variables +dnl +AC_SUBST([CXXFLAGS_FOR_BUILD])dnl +AC_SUBST([CXXCPPFLAGS_FOR_BUILD])dnl +]) diff --git a/src/glsl/.gitignore b/src/glsl/.gitignore index 81240b9..068d487 100644 --- a/src/glsl/.gitignore +++ b/src/glsl/.gitignore @@ -4,6 +4,5 @@ glsl_parser.cc glsl_parser.h glsl_parser.output builtin_function.cpp -builtin_compiler glsl_test /Makefile diff --git a/src/glsl/Makefile.am b/src/glsl/Makefile.am index 20639c9..b9e82f5 100644 --- a/src/glsl/Makefile.am +++ b/src/glsl/Makefile.am @@ -19,10 +19,6 @@ # FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS # IN THE SOFTWARE. - -# builtin_compiler is built before libglsl to generate builtin_function.cpp for libglsl. -# For this to work, a dummy version of builtin_function.cpp, builtin_stubs.cpp, is used. - AM_CFLAGS = \ -I$(top_srcdir)/include \ -I$(top_srcdir)/src/mapi \ @@ -39,7 +35,7 @@ AM_LFLAGS = --nounistd -o$(LEX_OUTPUT_ROOT).c include Makefile.sources noinst_LTLIBRARIES = libglslcommon.la libglsl.la -noinst_PROGRAMS = glsl_compiler glsl_test builtin_compiler +noinst_PROGRAMS = glsl_compiler glsl_test # common sources for builtin_compiler and libglsl libglslcommon_la_SOURCES = \ @@ -76,12 +72,6 @@ glsl_test_SOURCES = \ glsl_test_LDADD = libglsl.la -builtin_compiler_SOURCES = \ - $(GLSL2_SOURCES) \ - builtin_stubs.cpp - -builtin_compiler_LDADD = libglslcommon.la - # automake <=1.11 and automake >=1.12 have different conventions for naming C++ header files # made by yacc. To work with both, we write our own rule rather than using automake's. # When (if) we require automake >=1.12 in configure.ac, this can be removed, and we can use @@ -92,13 +82,16 @@ glsl_parser.cc glsl_parser.h: glsl_parser.yy BUILT_SOURCES = glsl_parser.h builtin_function.cpp CLEANFILES = glsl_lexer.cc glsl_parser.cc $(BUILT_SOURCES) -builtin_function.cpp: $(srcdir)/builtins/profiles/* $(srcdir)/builtins/ir/* $(srcdir)/builtins/glsl/* $(srcdir)/builtins/tools/generate_builtins.py $(srcdir)/builtins/tools/texture_builtins.py builtin_compiler$(EXEEXT) - $(AM_V_GEN) $(PYTHON2) $(PYTHON_FLAGS) $(srcdir)/builtins/tools/generate_builtins.py ./builtin_compiler > builtin_function.cpp || rm -f builtin_function.cpp +builtin_function.cpp: $(srcdir)/builtins/profiles/* $(srcdir)/builtins/ir/* $(srcdir)/builtins/glsl/* $(srcdir)/builtins/tools/generate_builtins.py $(srcdir)/builtins/tools/texture_builtins.py builtin_compiler/builtin_compiler$(EXEEXT) + $(AM_V_GEN) $(PYTHON2) $(PYTHON_FLAGS) $(srcdir)/builtins/tools/generate_builtins.py builtin_compiler/builtin_compiler > builtin_function.cpp || rm -f builtin_function.cpp glcpp/libglcpp.la: cd glcpp ; $(MAKE) $(AM_MAKEFLAGS) -SUBDIRS = glcpp +builtin_compiler/builtin_compiler$(EXEEXT): + cd builtin_compiler ; $(MAKE) $(AM_MAKEFLAGS) + +SUBDIRS = builtin_compiler glcpp # Provide compatibility with scripts for the old Mesa build system for # a while by putting a link to the library in the current directory. diff --git a/src/glsl/builtin_compiler/.gitignore b/src/glsl/builtin_compiler/.gitignore new file mode 100644 index 0000000..40c551b --- /dev/null +++ b/src/glsl/builtin_compiler/.gitignore @@ -0,0 +1,6 @@ +builtin_compiler +glcpp-lex.c +glcpp-parse.c +glcpp-parse.h +glcpp-parse.output +/Makefile diff --git a/src/glsl/builtin_compiler/Makefile.am b/src/glsl/builtin_compiler/Makefile.am new file mode 100644 index 0000000..b1ff883 --- /dev/null +++ b/src/glsl/builtin_compiler/Makefile.am @@ -0,0 +1,61 @@ +# Copyright © 2012 Jon TURNEY +# +# Permission is hereby granted, free of charge, to any person obtaining a +# copy of this software and associated documentation files (the "Software"), +# to deal in the Software without restriction, including without limitation +# the rights to use, copy, modify, merge, publish, distribute, sublicense, +# and/or sell copies of the Software, and to permit persons to whom the +# Software is furnished to do so, subject to the following conditions: +# +# The above copyright notice and this permission notice (including the next +# paragraph) shall be included in all copies or substantial portions of the +# Software. +# +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL +# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS +# IN THE SOFTWARE. + +CC = @CC_FOR_BUILD@ +CFLAGS = @CFLAGS_FOR_BUILD@ +CXX = @CXX_FOR_BUILD@ +CXXFLAGS_FOR_BUILD = @CXXFLAGS_FOR_BUILD@ + +AM_CFLAGS = \ + -I $(top_srcdir)/src/mapi \ + -I $(top_srcdir)/src/mesa \ + -I $(GLSL_SRCDIR) \ + -I $(GLSL_SRCDIR)/glcpp \ + $(DEFINES) $(API_DEFINES) + +AM_CXXFLAGS = $(AM_CFLAGS) + +AM_YFLAGS = -v -d +AM_LFLAGS = --nounistd -o$(LEX_OUTPUT_ROOT).c + +include ../Makefile.sources + +noinst_PROGRAMS = builtin_compiler + +builtin_compiler_SOURCES = \ + $(GLSL_SRCDIR)/glcpp/glcpp-lex.l \ + $(GLSL_SRCDIR)/glcpp/glcpp-parse.y \ + $(LIBGLCPP_FILES) \ + $(GLSL_SRCDIR)/glsl_lexer.ll \ + $(GLSL_SRCDIR)/glsl_parser.cc \ + $(LIBGLSL_FILES) \ + $(LIBGLSL_CXX_FILES) \ + $(top_srcdir)/src/mesa/program/hash_table.c \ + $(top_srcdir)/src/mesa/program/symbol_table.c \ + $(GLSL_COMPILER_CXX_FILES) \ + builtin_stubs.cpp + +BUILT_SOURCES = \ + glcpp-lex.c \ + glcpp-parse.c \ + glcpp-parse.h + +CLEANFILES = $(BUILT_SOURCES) diff --git a/src/glsl/builtin_stubs.cpp b/src/glsl/builtin_compiler/builtin_stubs.cpp similarity index 100% rename from src/glsl/builtin_stubs.cpp rename to src/glsl/builtin_compiler/builtin_stubs.cpp -- 1.7.12