#! /bin/sh # Copyright (C) 2012-2015 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License # along with this program. If not, see . # Test some generic Automake-provided internal macros and make functions. am_create_testdir=empty . test-init.sh plan_ 13 # Filter out Automake comments. grep -v '^##' "$am_amdir"/header-vars.mk > defn.mk \ || fatal_ "fetching makefile fragment headers-vars.am" # WARNING: there are a lot of embedded tabs in the makefile # fragments used by this script. They are all deliberate. # DO NOT "NORMALIZE" THEM TO SPACES! i=0 T () { i=$(($i + 1)) mkdir T$i.d cd T$i.d { echo 'include ../defn.mk' # Make sure $(shell ...) invocations use a POSIX shell -- /bin/sh is # borked and non-POSIX on a few systems, most notably Solaris 10. # That has already caused spurious failures in the past. echo "SHELL = ${SHELL}" echo 'lower = abcdefghijklmnopqrstuvwxyz' echo 'upper = ABCDEFGHIJKLMNOPQRSTUVWXYZ' echo 'digits = 0123456789' # The rest of the makefile come from the standard input passed to this # function. cat } > Makefile test_name=$1; shift command_ok_ "$test_name" $MAKE ${1+"$@"} test cd .. } T 'sanity check' FOO=ok <<'END' FOO = ko test: test $(FOO) = ok touch sane END test -f T1.d/sane || fatal_ "function 'T' is buggy" T 'am.util.strip-first-word' <<'END' test: test '$(call am.util.strip-first-word,)' = '' test '$(call am.util.strip-first-word,1)' = '' test '$(call am.util.strip-first-word,1 1)' = '1' test '$(call am.util.strip-first-word,1 2)' = '2' test '$(call am.util.strip-first-word,1 2 3 4 5 6 7 8)' = '2 3 4 5 6 7 8' test '$(call am.util.strip-first-word, 1 2 )' = '2' END T 'am.util.strip-last-word' <<'END' test: test '$(call am.util.strip-last-word,)' = '' test '$(call am.util.strip-last-word,1)' = '' test '$(call am.util.strip-last-word,1 1)' = '1' test '$(call am.util.strip-last-word,1 2)' = '1' test '$(call am.util.strip-last-word,1 2 3 4 5 6 7 8)' = '1 2 3 4 5 6 7' test '$(call am.util.strip-last-word, 1 2 )' = '1' END T 'am.util.uniq' <<'END' test: test '$(call am.util.uniq,)' = '' test '$(call am.util.uniq,1)' = '1' test '$(call am.util.uniq,1 1)' = '1' test '$(call am.util.uniq,1 2)' = '1 2' test '$(call am.util.uniq,2 1)' = '2 1' test '$(call am.util.uniq,1 2 3)' = '1 2 3' test '$(call am.util.uniq,2 3 1)' = '2 3 1' test '$(call am.util.uniq,1 1 1)' = '1' test '$(call am.util.uniq,1 2 1)' = '1 2' test '$(call am.util.uniq,2 1 1)' = '2 1' test '$(call am.util.uniq,2 1 1)' = '2 1' test '$(call am.util.uniq,2 2 1)' = '2 1' test '$(call am.util.uniq,1 1 1 3 1 1 1)' = '1 3' test '$(call am.util.uniq,3 1 1 4 1 4 1 1)' = '3 1 4' test '$(call am.util.uniq, 1 3 1 )' = '1 3' END T 'am.util.strip-suffixes' <<'END' test: test '$(call am.util.strip-suffixes,,)' = '' test '$(call am.util.strip-suffixes, ,)' = '' test '$(call am.util.strip-suffixes,, )' = '' test '$(call am.util.strip-suffixes, , )' = '' test '$(call am.util.strip-suffixes,x,)' = '' test '$(call am.util.strip-suffixes,x y, )' = '' test '$(call am.util.strip-suffixes,,x y)' = 'x y' test '$(call am.util.strip-suffixes, ,x y)' = 'x y' test '$(call am.util.strip-suffixes,.c,foo.c)' = 'foo' test '$(call am.util.strip-suffixes,.foo,a.foo b.foo)' = 'a b' test '$(call am.util.strip-suffixes, x y, ax ay ax)' = 'a a a' test '$(call am.util.strip-suffixes,x,ax)' = 'a' test '$(call am.util.strip-suffixes,x,xa)' = 'xa' test '$(call am.util.strip-suffixes,x,xx)' = 'x' test '$(call am.util.strip-suffixes,x,xux)' = 'xu' test '$(call am.util.strip-suffixes, .c .c++, \ foo.c bar.c++ baz.cxx zap.c)' = 'foo bar baz.cxx zap' test '$(call am.util.strip-suffixes, .a .b, \ 1.a.a 2.a.b 3.b.a 4.b.b)' = '1.a 2.a 3.b 4.b' # Corner cases: the *first* matched suffix is stripped test '$(call am.util.strip-suffixes,.a .b,x.a.a)' = 'x.a' test '$(call am.util.strip-suffixes,.a .b,x.a.b)' = 'x.a' test '$(call am.util.strip-suffixes,.a .b,x.b.a)' = 'x.b' test '$(call am.util.strip-suffixes,.a .b,x.b.b)' = 'x.b' test '$(call am.util.strip-suffixes, .a .b.a, foo.b.a bar.a)' \ = 'foo.b bar' test '$(call am.util.strip-suffixes, .b.a .a, foo.b.a bar.a)' \ = 'foo bar' END T 'am.util.toupper' <<'END' test: test '$(call am.util.toupper,a)' = A test '$(call am.util.toupper,A)' = A test '$(call am.util.toupper,aba)' = ABA test '$(call am.util.toupper,a b)' = 'A B' test '$(call am.util.toupper, a B)' = ' A B' test '$(call am.util.toupper,Ab )' = 'AB ' test '$(call am.util.toupper,A B c )' = 'A B C ' test '$(call am.util.toupper,0)' = 0 test '$(call am.util.toupper,0d)' = 0D test '$(call am.util.toupper,@:&/?-)' = '@:&/?-' test '$(call am.util.toupper,a@B)' = A@B test '$(call am.util.toupper,zxzxzxZXZxzxzxzxzx)' = ZXZXZXZXZXZXZXZXZX test '$(call am.util.toupper,$(lower))' = '$(upper)' test '$(call am.util.toupper,$(upper))' = '$(upper)' END T 'am.util.tolower' <<'END' test: test '$(call am.util.tolower,A)' = a test '$(call am.util.tolower,a)' = a test '$(call am.util.tolower,ABA)' = aba test '$(call am.util.tolower,A B)' = 'a b' test '$(call am.util.tolower, A b)' = ' a b' test '$(call am.util.tolower,aB )' = 'ab ' test '$(call am.util.tolower,a b C )' = 'a b c ' test '$(call am.util.tolower,0)' = 0 test '$(call am.util.tolower,0D)' = 0d test '$(call am.util.tolower,@:&/?-)' = '@:&/?-' test '$(call am.util.tolower,a@B)' = a@b test '$(call am.util.tolower,ZXZXZXzxzXZXZXZXZX)' = zxzxzxzxzxzxzxzxzx test '$(call am.util.tolower,$(upper))' = '$(lower)' test '$(call am.util.tolower,$(lower))' = '$(lower)' END T 'am.util.canon' <<'END' comma = , dollar = $$ bslash = \\ test: test '$(call am.util.canon,A)' = A test '$(call am.util.canon, b)' = b test '$(call am.util.canon, foo )' = foo test '$(call am.util.canon,$(upper)$(lower)$(digits)_)' = '$(upper)$(lower)$(digits)_' test '$(call am.util.canon,@)' = '@' test '$(call am.util.canon,%)' = '_' test '$(call am.util.canon,.&@!;)' = '__@__' test '$(call am.util.canon,')' = '_' test '$(call am.util.canon,$(dollar))' = '_' test '$(call am.util.canon,$(bslash))' = '_' test '$(call am.util.canon,$(comma))' = '_' test '$(call am.util.canon,$(bslash)$(comma))' = '__' test '$(call am.util.canon,x$(comma)@$(bslash))' = 'x_@_' END FOO_ENVIRON=ok; export FOO_ENVIRON FOO_UNDEF=; unset FOO_UNDEF FOO_INDIR=; unset FOO_INDIR T 'am.vars.is-undef' FOO_CMDLINE=ok <<'END' FOO_MAKEFILE_1 = ok FOO_MAKEFILE_2 := ok override FOO_OVERRIDE_1 = ok override FOO_OVERRIDE_2 := ok FOO_EMPTY_1 = FOO_EMPTY_2 := # Help avoiding typos. X = $(call am.vars.is-undef,$1) test: @echo UNDEF: test '$(call X,FOO_UNDEF)' = yes @echo ENVIRON: test '$(call X,FOO_ENVIRON)' = yes @echo MAKEFILE 1: test -z '$(call X,FOO_MAKEFILE_1)' @echo MAKEFILE 2: test -z '$(call X,FOO_MAKEFILE_2)' @echo CMDLINE: test -z '$(call X,FOO_CMDLINE)' @echo OVERRIDE 1: test -z '$(call X,FOO_OVERRIDE_1)' @echo OVERRIDE 2: test -z '$(call X,FOO_OVERRIDE_2)' @echo EMPTY 1: test -z '$(call X,FOO_EMPTY_1)' @echo EMPTY 2: test -z '$(call X,FOO_EMPTY_2)' @echo DEFAULT: test -z '$(call X,CC)' @echo EXTRA SPACES: test '$(call X, FOO_UNDEF )' = yes @echo SANITY CHECKS: test '$(FOO_ENVIRON)' = ok test '$(FOO_CMDLINE)' = ok END unset FOO_ENVIRON T 'am.chars.newline (1)' <<'END' test: @echo OK > fo1$(am.chars.newline)@touch ba1$(am.chars.newline)-false > qu1 test `cat fo1` = OK test -f ba1 test -f qu1 END T 'am.chars.newline (2)' <<'END' my_newline = $(am.chars.newline) test: @echo OK > fo2$(my_newline)@touch ba2$(my_newline)-false > qu2 test `cat fo2` = OK test -f ba2 test -f qu2 END T 'am.chars.newline (3)' <<'END' my_newline = $(am.chars.newline) command-1 = test x = x$(am.chars.newline) command-2 = test y = y$(my_newline) test: $(command-1)$(command-2)touch n3 test -f n3 END T 'am.util.file-exists' <<'END' prepare: : > 'a' test -f 'a' : > '?' test -f '?' : > 'foo bar' test -f 'foo bar' mkdir 'a b' test -d 'a b' : > 'a b'/'c d' test -f 'a b'/'c d' test: prepare test x'$(call am.util.file-exists,.)' = x'yes' test x'$(call am.util.file-exists,Makefile)' = x'yes' test x'$(call am.util.file-exists,.././defn.mk)' = x'yes' test x'$(call am.util.file-exists,none)' = x test x'$(call am.util.file-exists,Makefile oops)' = x test x'$(call am.util.file-exists,foo bar)' = x'yes' test x'$(call am.util.file-exists,a b)' = x'yes' test x'$(call am.util.file-exists,a b/c d)' = x'yes' test x'$(call am.util.file-exists,*)' = x test x'$(call am.util.file-exists,a)' = x'yes' test x'$(call am.util.file-exists,[ab])' = x test x'$(call am.util.file-exists,?)' = x'yes' END :