xref: /freebsd/contrib/netbsd-tests/share/mk/t_prog.sh (revision c22165b4f1f5d38b681921797a44b3ba8c13b7e0)
157718be8SEnji Cooper# Copyright 2012 Google Inc.
257718be8SEnji Cooper# All rights reserved.
357718be8SEnji Cooper#
457718be8SEnji Cooper# Redistribution and use in source and binary forms, with or without
557718be8SEnji Cooper# modification, are permitted provided that the following conditions are
657718be8SEnji Cooper# met:
757718be8SEnji Cooper#
857718be8SEnji Cooper# * Redistributions of source code must retain the above copyright
957718be8SEnji Cooper#   notice, this list of conditions and the following disclaimer.
1057718be8SEnji Cooper# * Redistributions in binary form must reproduce the above copyright
1157718be8SEnji Cooper#   notice, this list of conditions and the following disclaimer in the
1257718be8SEnji Cooper#   documentation and/or other materials provided with the distribution.
1357718be8SEnji Cooper# * Neither the name of Google Inc. nor the names of its contributors
1457718be8SEnji Cooper#   may be used to endorse or promote products derived from this software
1557718be8SEnji Cooper#   without specific prior written permission.
1657718be8SEnji Cooper#
1757718be8SEnji Cooper# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1857718be8SEnji Cooper# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1957718be8SEnji Cooper# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
2057718be8SEnji Cooper# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2157718be8SEnji Cooper# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2257718be8SEnji Cooper# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2357718be8SEnji Cooper# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2457718be8SEnji Cooper# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2557718be8SEnji Cooper# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2657718be8SEnji Cooper# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2757718be8SEnji Cooper# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2857718be8SEnji Cooper
2957718be8SEnji Cooperatf_test_case defaults__build_and_install
3057718be8SEnji Cooperdefaults__build_and_install_head() {
3157718be8SEnji Cooper	atf_set "require.progs" "/usr/bin/mandoc"
3257718be8SEnji Cooper}
3357718be8SEnji Cooperdefaults__build_and_install_body() {
34*640235e2SEnji Cooper	if [ ! -e /usr/bin/gcc -a -e /usr/bin/clang ]; then
35*640235e2SEnji Cooper		export HAVE_LLVM=yes
36*640235e2SEnji Cooper	fi
37*640235e2SEnji Cooper
3857718be8SEnji Cooper	cat >hello.c <<EOF
3957718be8SEnji Cooper#include <stdio.h>
4057718be8SEnji Cooperint main(void) { printf("Hello, test!\n"); return 0; }
4157718be8SEnji CooperEOF
4257718be8SEnji Cooper	cat >hello.1 <<EOF
4357718be8SEnji CooperManpage of hello(1).
4457718be8SEnji CooperEOF
4557718be8SEnji Cooper
4657718be8SEnji Cooper	cat >Makefile <<EOF
4757718be8SEnji CooperBINDIR = /the/bin/dir
4857718be8SEnji CooperPROG = hello
4957718be8SEnji Cooper.include <bsd.prog.mk>
5057718be8SEnji CooperEOF
5157718be8SEnji Cooper
5257718be8SEnji Cooper	atf_check -o ignore make
5357718be8SEnji Cooper	mkdir -p root/the/bin/dir
5457718be8SEnji Cooper	mkdir -p root/usr/share/man/man1
5557718be8SEnji Cooper	mkdir -p root/usr/share/man/html1
5657718be8SEnji Cooper	create_make_conf mk.conf owngrp DESTDIR="$(pwd)/root"
5757718be8SEnji Cooper	atf_check -o ignore make install
5857718be8SEnji Cooper
5957718be8SEnji Cooper	atf_check -o inline:'Hello, test!\n' ./root/the/bin/dir/hello
6057718be8SEnji Cooper	atf_check -o inline:'Manpage of hello(1).\n' \
6157718be8SEnji Cooper	    cat root/usr/share/man/man1/hello.1
6257718be8SEnji Cooper	atf_check -o match:'Manpage of hello' \
6357718be8SEnji Cooper	    cat root/usr/share/man/html1/hello.html
6457718be8SEnji Cooper}
6557718be8SEnji Cooper
6657718be8SEnji Cooperatf_test_case without_man__build_and_install
6757718be8SEnji Cooperwithout_man__build_and_install_body() {
68*640235e2SEnji Cooper	if [ ! -e /usr/bin/gcc -a -e /usr/bin/clang ]; then
69*640235e2SEnji Cooper		export HAVE_LLVM=yes
70*640235e2SEnji Cooper	fi
71*640235e2SEnji Cooper
7257718be8SEnji Cooper	cat >hello.c <<EOF
7357718be8SEnji Cooper#include <stdio.h>
7457718be8SEnji Cooperint main(void) { printf("Hello, test!\n"); return 0; }
7557718be8SEnji CooperEOF
7657718be8SEnji Cooper
7757718be8SEnji Cooper	cat >Makefile <<EOF
7857718be8SEnji CooperBINDIR = /the/bin/dir
7957718be8SEnji CooperPROG = hello
8057718be8SEnji CooperMAN =
8157718be8SEnji Cooper.include <bsd.prog.mk>
8257718be8SEnji CooperEOF
8357718be8SEnji Cooper
8457718be8SEnji Cooper	atf_check -o ignore make
8557718be8SEnji Cooper	mkdir -p root/the/bin/dir
8657718be8SEnji Cooper	create_make_conf mk.conf owngrp DESTDIR="$(pwd)/root"
8757718be8SEnji Cooper	atf_check -o ignore make install
8857718be8SEnji Cooper
8957718be8SEnji Cooper	atf_check -o inline:'Hello, test!\n' ./root/the/bin/dir/hello
9057718be8SEnji Cooper}
9157718be8SEnji Cooper
9257718be8SEnji Cooperatf_init_test_cases() {
9357718be8SEnji Cooper	atf_add_test_case defaults__build_and_install
9457718be8SEnji Cooper	atf_add_test_case without_man__build_and_install
9557718be8SEnji Cooper}
96