Add t/example, a basic example build environment suitable for a tutorial.

This commit is contained in:
Avery Pennarun 2010-11-17 19:49:41 -08:00
commit eae3e7cdef
14 changed files with 51 additions and 8 deletions

3
t/example/.gitignore vendored Normal file
View file

@ -0,0 +1,3 @@
*.o
CC
hello

10
t/example/CC.do Normal file
View file

@ -0,0 +1,10 @@
redo-ifchange config.sh
. ./config.sh
cat <<-EOF
redo-ifchange \$1.c
gcc -MD -MF \$3.deps.tmp -o \$3 -c \$1.c
DEPS=\$(sed -e "s/^\$3://" -e 's/\\\\//g' <\$3.deps.tmp)
rm -f \$3.deps.tmp
redo-ifchange \$DEPS
EOF
chmod +x $3

6
t/example/Makefile Normal file
View file

@ -0,0 +1,6 @@
all:
%: FORCE
+redo $@
.PHONY: FORCE

1
t/example/all.do Normal file
View file

@ -0,0 +1 @@
redo-ifchange hello

1
t/example/clean.do Normal file
View file

@ -0,0 +1 @@
rm -f *.tmp *~ *.o hello CC

1
t/example/config.sh Normal file
View file

@ -0,0 +1 @@
CFLAGS="-Wall"

2
t/example/default.o.do Normal file
View file

@ -0,0 +1,2 @@
redo-ifchange CC
. ./CC "$@"

4
t/example/hello.do Normal file
View file

@ -0,0 +1,4 @@
DEPS="main.o
mystr.o"
redo-ifchange $DEPS
gcc -o $3 $DEPS

8
t/example/main.c Normal file
View file

@ -0,0 +1,8 @@
#include <stdio.h>
#include "mystr.h"
int main()
{
printf("%s\n", mystr);
return 0;
}

4
t/example/mystr.c Normal file
View file

@ -0,0 +1,4 @@
#include "mystr.h"
char *mystr = "Hello, world!";

6
t/example/mystr.h Normal file
View file

@ -0,0 +1,6 @@
#ifndef __MYSTR_H
#define __MYSTR_H
extern char *mystr;
#endif