Added my own implementation of "Hello world" as an example.
This commit is contained in:
13
INSTALL
Normal file
13
INSTALL
Normal file
@@ -0,0 +1,13 @@
|
||||
To build hello, run the following commands:
|
||||
./configure
|
||||
make
|
||||
|
||||
To build a static binary, run:
|
||||
./configure --static
|
||||
make
|
||||
|
||||
To install the binary and the man page, run:
|
||||
make install
|
||||
|
||||
To only install the binary, run:
|
||||
make install-bin
|
||||
5
Makefile
Normal file
5
Makefile
Normal file
@@ -0,0 +1,5 @@
|
||||
help:
|
||||
@echo "Run ./configure first!"
|
||||
@echo "Or even better: take a look at the file README."
|
||||
install: help
|
||||
all: help
|
||||
5
Makefile.dist
Normal file
5
Makefile.dist
Normal file
@@ -0,0 +1,5 @@
|
||||
help:
|
||||
@echo "Run ./configure first!"
|
||||
@echo "Or even better: take a look at the file README."
|
||||
install: help
|
||||
all: help
|
||||
72
Makefile.in
Normal file
72
Makefile.in
Normal file
@@ -0,0 +1,72 @@
|
||||
# @Makefile.in@
|
||||
|
||||
PREFIX := @PREFIX@
|
||||
BINDIR := @BINDIR@
|
||||
MAN1DIR := @MAN1DIR@
|
||||
|
||||
MAIN := hello
|
||||
OBJS := hello.o
|
||||
#LIBS :=
|
||||
MAN1 := hello.1
|
||||
|
||||
MANGZ := @MANGZ@
|
||||
ifeq ($(MANGZ), 1)
|
||||
MAN1 := $(addsuffix .gz, $(MAN1))
|
||||
endif
|
||||
|
||||
CC := @CC@
|
||||
CP := @CP@
|
||||
GZIP := @GZIP@
|
||||
INSTALL := @INSTALL@
|
||||
RM := @RM@
|
||||
STRIP := @STRIP@
|
||||
TAR := @TAR@
|
||||
|
||||
.PHONY: help strip install install-bin install-man install-man1 uninstall \
|
||||
clean distclean mrproper dist
|
||||
.DEFAULT: $(MAIN)
|
||||
|
||||
$(MAIN): $(OBJS)
|
||||
ifeq (@STATIC@, 1)
|
||||
$(CC) --static -g -o $(MAIN) $(LIBS) $(OBJS)
|
||||
else
|
||||
$(CC) -g -o $(MAIN) $(LIBS) $(OBJS)
|
||||
endif
|
||||
|
||||
%.o : %.c
|
||||
$(CC) $(CFLAGS) $(CPPFLAGS) -c $< -o $@
|
||||
|
||||
help:
|
||||
@echo "There is no help."
|
||||
|
||||
strip: $(MAIN)
|
||||
$(STRIP) $(MAIN)
|
||||
|
||||
install: install-bin install-man
|
||||
|
||||
install-bin: strip
|
||||
$(INSTALL) $(MAIN) $(BINDIR)
|
||||
|
||||
install-man: install-man1
|
||||
|
||||
install-man1: $(MAN1)
|
||||
$(INSTALL) $^ $(MAN1DIR)
|
||||
|
||||
%.gz : %
|
||||
$(GZIP) -c $< > $@
|
||||
|
||||
uninstall:
|
||||
-$(RM) $(BINDIR)/$(MAIN)
|
||||
cd $(MAN1DIR) ; -$(RM) $(MAN1)
|
||||
|
||||
clean:
|
||||
$(RM) -f *.o $(MAIN)
|
||||
|
||||
distclean: clean
|
||||
$(CP) Makefile.dist Makefile
|
||||
mrproper: distclean
|
||||
|
||||
dist: distclean
|
||||
cd .. ; $(TAR) -czf $(notdir $(PWD)).tar.gz $(notdir $(PWD))
|
||||
|
||||
#end
|
||||
48
README
Normal file
48
README
Normal file
@@ -0,0 +1,48 @@
|
||||
Hello World.
|
||||
|
||||
ABOUT
|
||||
=====
|
||||
|
||||
hello is the famous example application implemented in C.
|
||||
|
||||
But this package not only provides this marvellous program including its
|
||||
documentation. Also there comes a configure script and a sample makefile
|
||||
with it.
|
||||
|
||||
The configure script ('configure' plus its own two configuration files
|
||||
'configure.files' and 'configure.macros') is capable to read in the makefile
|
||||
template 'Makefile.in' to produce the real makefile 'Makefile'.
|
||||
|
||||
Together with the standard unix tool 'make' the makefile can assist you to
|
||||
- compile the hello source code ('hello.c') into a binary ('hello')
|
||||
- install the binary onto your system
|
||||
- install the manual page of hello ('hello.1') onto your system
|
||||
- proceed the development of hello
|
||||
|
||||
|
||||
INSTALL
|
||||
=======
|
||||
For information about building and installing hello, see the file INSTALL.
|
||||
|
||||
|
||||
DEPENDENCIES
|
||||
============
|
||||
|
||||
Dependencies to build hello:
|
||||
- a C library (tested with GNU C library glibc-2.6.1)
|
||||
If not building a static binary, only the headers are needed.
|
||||
- a C compiler and linker (tested with GNU Compiler Collection gcc-4.1.2)
|
||||
- a make tool (tested with GNU Make 3.81)
|
||||
- a bourne compatible shell (tested with bash 3.2)
|
||||
- some other tools, used by the configure script:
|
||||
cut, expr, grep, mktemp, rm, sed, tr
|
||||
- some other tools, used by the makefile:
|
||||
cp, gzip, install, rm, strip, tar
|
||||
|
||||
Dependencies to use hello:
|
||||
- a C library (tested with GNU C library glibc-2.6.1)
|
||||
If compiled a static binary, the C library is not needed at run time.
|
||||
|
||||
Dependecies to use the hello documentation:
|
||||
- a man page viewer
|
||||
|
||||
291
configure
vendored
Executable file
291
configure
vendored
Executable file
@@ -0,0 +1,291 @@
|
||||
#!/bin/sh
|
||||
#
|
||||
# configure
|
||||
#
|
||||
# A simple script to configure Makefiles
|
||||
# (i.e. read Makefile.in, replace strings and write Makefile).
|
||||
#
|
||||
# heinzel <heinzel@heinzelwelt.de>
|
||||
#
|
||||
# $Id: configure,v 1.1 2007/11/26 23:37:48 heinzel Exp $
|
||||
#
|
||||
VERSION='configure Version 0.1 $Revision: 1.1 $ ($Date: 2007/11/26 23:37:48 $ $Author: heinzel $)'
|
||||
|
||||
### config ###
|
||||
FILES=""
|
||||
FILES_DEF="configure.files"
|
||||
|
||||
TEMPLATE_SUFFIX=".in"
|
||||
MACROS_DEF="configure.macros"
|
||||
|
||||
MACROS="CTEMPLATE"
|
||||
MACRO_CTEMPLATE="@CFILE@ (created by configure script)"
|
||||
|
||||
### functions ###
|
||||
function print_help() {
|
||||
cat <<EOH
|
||||
configure create files by processing templates and replace macros.
|
||||
For now macros are simple name-value pairs. Use strings like @NAME@ within
|
||||
the template files and configure will replace those strings by the named
|
||||
value while creating the resulting files.
|
||||
|
||||
Usage: ./configure [OPTIONS]
|
||||
|
||||
Options:
|
||||
-h, --help
|
||||
-V, --version
|
||||
|
||||
Generic Options (and default values):
|
||||
EOH
|
||||
for m in $MACROS ; do
|
||||
case "$m" in
|
||||
CFILE|CTEMPLATE)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
|
||||
name="`echo $m | tr [[:upper:]] [[:lower:]]`"
|
||||
text="`eval_macro $m`"
|
||||
case "$text" in
|
||||
0)
|
||||
output=" --without-${name}"
|
||||
;;
|
||||
1)
|
||||
output=" --with-${name}"
|
||||
;;
|
||||
*)
|
||||
output=" --${name} $text"
|
||||
;;
|
||||
esac
|
||||
echo "$output"
|
||||
done
|
||||
echo ""
|
||||
cat <<EOH
|
||||
Files:
|
||||
This script will create following files: $FILES
|
||||
or read file names to create from '$FILES_DEF'
|
||||
The templates have to end with '$TEMPLATE_SUFFIX'
|
||||
The macros can be defined in '$MACROS_DEF'
|
||||
EOH
|
||||
}
|
||||
|
||||
function print_version() {
|
||||
echo "$VERSION"
|
||||
}
|
||||
|
||||
function set_macro() {
|
||||
case "$1" in
|
||||
'')
|
||||
return 1
|
||||
;;
|
||||
--with-*|--enable-*)
|
||||
name="`echo $1 | cut -f1 -d= | cut -f4- -d- | tr [[:lower:]] [[:upper:]]`"
|
||||
text="1"
|
||||
;;
|
||||
--without-*|--disable-*)
|
||||
name="`echo $1 | cut -f1 -d= | cut -f4- -d- | tr [[:lower:]] [[:upper:]]`"
|
||||
text="0"
|
||||
;;
|
||||
--*=*)
|
||||
name="`echo $1 | cut -f1 -d= | cut -c3- | tr [[:lower:]] [[:upper:]]`"
|
||||
text="`echo $1 | cut -f2- -d=`"
|
||||
;;
|
||||
--*)
|
||||
name="`echo $1 | cut -c3- | tr [[:lower:]] [[:upper:]]`"
|
||||
text="$2"
|
||||
;;
|
||||
*=*)
|
||||
name="`echo $1 | cut -f1 -d= | tr [[:lower:]] [[:upper:]]`"
|
||||
text="`echo $1 | cut -f2- -d=`"
|
||||
;;
|
||||
*)
|
||||
name="`echo $1 | tr [[:lower:]] [[:upper:]]`"
|
||||
text=""
|
||||
;;
|
||||
esac
|
||||
eval MACRO_${name}=${text}
|
||||
if ! expr " $MACROS " : ".* $name .*" >/dev/null ; then
|
||||
MACROS="$MACROS ${name}"
|
||||
fi
|
||||
}
|
||||
|
||||
function eval_macro() {
|
||||
local name="$1"
|
||||
local text=""
|
||||
local return=""
|
||||
|
||||
eval text="\$MACRO_${name}"
|
||||
while : ; do
|
||||
# Test if text contains more macros.
|
||||
echo "$text" | grep -E "@[A-Z][A-Z0-9]*@" >/dev/null
|
||||
r=$?
|
||||
if test "1${r}" != "10" ; then
|
||||
# Text is macro free.
|
||||
return="$text"
|
||||
break
|
||||
else
|
||||
# Get the last macro name from text...
|
||||
sm_name="`echo $text | sed -e 's=^.*@\([A-Z][A-Z0-9]*\)@.*$=\1='`"
|
||||
# Resolve it...
|
||||
sm_text="`eval_macro $sm_name`"
|
||||
# Substitute macro...
|
||||
text="`echo $text | sed -e 's=@'${sm_name}'@='${sm_text}'=g'`"
|
||||
fi
|
||||
done
|
||||
|
||||
echo "$return"
|
||||
}
|
||||
|
||||
function load_defaults() {
|
||||
local inc="${MACROS_DEF:-configure.macros}"
|
||||
local i=0
|
||||
local line=""
|
||||
|
||||
if test "X${inc}" = "X" ; then
|
||||
return 1
|
||||
fi
|
||||
if test ! -r "$inc" -o -d "$inc" ; then
|
||||
echo "${inc}: not a readable file." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
while read line ; do
|
||||
i="`expr $i + 1`"
|
||||
case "$line" in
|
||||
\#*|\ *|'')
|
||||
continue
|
||||
;;
|
||||
*=*)
|
||||
set_macro "$line"
|
||||
;;
|
||||
*)
|
||||
echo "Warning: $inc: unexpected line ($i)." >&2
|
||||
;;
|
||||
esac
|
||||
done < "$inc"
|
||||
}
|
||||
|
||||
function configure() {
|
||||
local file="$1"
|
||||
local ext="${TEMPLATE_SUFFIX:-.in}"
|
||||
local template=""
|
||||
|
||||
local static_file=""
|
||||
|
||||
local expr=""
|
||||
local name=""
|
||||
local text=""
|
||||
|
||||
if test "X${file}" = "X" ; then
|
||||
echo "No filename given." >&2
|
||||
return 1
|
||||
fi
|
||||
template="${file}${ext}"
|
||||
if test ! -r "$template" -o -d "$template" ; then
|
||||
echo "$file: cannot read template ($template)."
|
||||
return 1
|
||||
fi
|
||||
|
||||
set_macro CFILE="$file"
|
||||
ctext="`eval_macro CTEMPLATE`"
|
||||
cexpr="s=@${template}@=${ctext}=g"
|
||||
|
||||
if test "X${CONFIGURE_STATIC_FILE}" != "X" ; then
|
||||
static_file="$CONFIGURE_STATIC_FILE"
|
||||
read expr < "$static_file"
|
||||
else
|
||||
static_file="`mktemp configure.tmp.XXXXXX`"
|
||||
if test "1$?" -ne "10" -o "X${static_file}" = "X" \
|
||||
-o ! -w "$static_file" ; then
|
||||
echo "Cannot create temp file." >&2
|
||||
return 1
|
||||
fi
|
||||
CONFIGURE_STATIC_FILE="$static_file"
|
||||
|
||||
expr=""
|
||||
for name in $MACROS ; do
|
||||
case "$name" in
|
||||
CFILE|CTEMPLATE)
|
||||
continue
|
||||
;;
|
||||
esac
|
||||
text="`eval_macro $name`"
|
||||
expr="s=@$name@=$text=g
|
||||
$expr"
|
||||
done
|
||||
|
||||
echo "$expr" > "$static_file"
|
||||
fi
|
||||
|
||||
sed -e "$cexpr" -e "$expr" "$template" > "$file"
|
||||
}
|
||||
|
||||
function clean_up() {
|
||||
if test "X${CONFIGURE_STATIC_FILE}" != "X" -a -f "$CONFIGURE_STATIC_FILE" ; then
|
||||
rm "$CONFIGURE_STATIC_FILE"
|
||||
fi
|
||||
}
|
||||
|
||||
### set options ###
|
||||
load_defaults
|
||||
|
||||
while test "1$#" -gt "10" ; do
|
||||
case "$1" in
|
||||
-h|--help)
|
||||
print_help
|
||||
exit 0
|
||||
;;
|
||||
-V|--version)
|
||||
print_version
|
||||
exit 0
|
||||
;;
|
||||
--with-*|--without-*)
|
||||
set_macro "$1"
|
||||
shift
|
||||
;;
|
||||
--enable-*|--disable-*)
|
||||
set_macro "$1"
|
||||
shift
|
||||
;;
|
||||
--*=*)
|
||||
set_macro "$1"
|
||||
shift
|
||||
;;
|
||||
--*)
|
||||
case "$2" in
|
||||
''|-*)
|
||||
set_macro "${1}=1"
|
||||
shift
|
||||
;;
|
||||
*)
|
||||
set_macro "$1" "$2"
|
||||
shift
|
||||
shift
|
||||
;;
|
||||
esac
|
||||
;;
|
||||
esac
|
||||
done
|
||||
|
||||
### action ###
|
||||
|
||||
files="$FILES"
|
||||
if test "X${FILES_DEF}" != "X" -a -f "$FILES_DEF" ; then
|
||||
read buf < "$FILES_DEF"
|
||||
files="$files $buf"
|
||||
fi
|
||||
|
||||
|
||||
if test "X${files}" = "X" ; then
|
||||
echo "No files to configure." >&2
|
||||
echo " Make sure '$FILES_DEF' is there and readable." >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
for f in $files ; do
|
||||
echo "Creating file $f..."
|
||||
configure $f
|
||||
done
|
||||
|
||||
clean_up
|
||||
### end ###
|
||||
1
configure.files
Normal file
1
configure.files
Normal file
@@ -0,0 +1 @@
|
||||
Makefile
|
||||
35
configure.macros
Normal file
35
configure.macros
Normal file
@@ -0,0 +1,35 @@
|
||||
# configure.macros
|
||||
|
||||
# Directories
|
||||
PREFIX="/usr/local"
|
||||
BINDIR="@PREFIX@/bin"
|
||||
SBINDIR="@PREFIX@/sbin"
|
||||
MANDIR="@PREFIX@/share/man"
|
||||
MAN1DIR="@MANDIR@/man1"
|
||||
MAN2DIR="@MANDIR@/man2"
|
||||
MAN3DIR="@MANDIR@/man3"
|
||||
MAN4DIR="@MANDIR@/man4"
|
||||
MAN5DIR="@MANDIR@/man5"
|
||||
MAN6DIR="@MANDIR@/man6"
|
||||
MAN7DIR="@MANDIR@/man7"
|
||||
MAN8DIR="@MANDIR@/man8"
|
||||
MAN9DIR="@MANDIR@/man9"
|
||||
|
||||
# Programms
|
||||
CAT="cat"
|
||||
CC="cc"
|
||||
CP="cp"
|
||||
GZIP="gzip"
|
||||
INSTALL="install"
|
||||
RM="rm"
|
||||
SHELL="/bin/sh"
|
||||
STRIP="strip"
|
||||
TAR="tar"
|
||||
ZCAT="zcat"
|
||||
|
||||
# Magic macros
|
||||
# @CFILE@ will be expanded to the name of the file, that will be created.
|
||||
# Also the current template name (e.g. @Makefile.in@) can be used as a macro
|
||||
# that will be expanded to another macro named CTEMPLATE (which can be
|
||||
# defined here or will default to a buildin text).
|
||||
#end
|
||||
26
hello.1
Normal file
26
hello.1
Normal file
@@ -0,0 +1,26 @@
|
||||
.\" hello.1
|
||||
.TH HELLO 1 "Nov. 2007" "heinzel" "User Commands"
|
||||
|
||||
.SH NAME
|
||||
hello \- Send greetings to everyone
|
||||
|
||||
.SH SYNOPSIS
|
||||
.B hello
|
||||
|
||||
.SH DESCRIPTION
|
||||
.B hello
|
||||
print the message "Hello World." to standard output.
|
||||
|
||||
.SH OPTIONS
|
||||
none
|
||||
|
||||
.SH BUGS
|
||||
.B hello
|
||||
is maybe the only program that has no bugs.
|
||||
|
||||
.SH AUTHOR
|
||||
heinzel <heinzel@heinzelwelt.de>
|
||||
|
||||
.SH SEE ALSO
|
||||
.BR echo (1)
|
||||
|
||||
Reference in New Issue
Block a user