Add t/example, a basic example build environment suitable for a tutorial.
This commit is contained in:
parent
2b71e662cb
commit
eae3e7cdef
14 changed files with 51 additions and 8 deletions
|
|
@ -64,9 +64,9 @@ But the easiest way to show it is with an example.
|
||||||
|
|
||||||
Create a file called default.o.do:
|
Create a file called default.o.do:
|
||||||
redo-ifchange $1.c
|
redo-ifchange $1.c
|
||||||
gcc -MD -MF deps.tmp -c -o $3 $1.c
|
gcc -MD -MF $3.deps.tmp -c -o $3 $1.c
|
||||||
DEPS=$(sed -e "s/^$3://" -e 's/\\//g' <deps.tmp)
|
DEPS=$(sed -e "s/^$3://" -e 's/\\//g' <$3.deps.tmp)
|
||||||
rm -f deps.tmp
|
rm -f $3.deps.tmp
|
||||||
redo-ifchange $DEPS
|
redo-ifchange $DEPS
|
||||||
|
|
||||||
Create a file called myprog.do:
|
Create a file called myprog.do:
|
||||||
|
|
|
||||||
4
t/all.do
4
t/all.do
|
|
@ -1,3 +1 @@
|
||||||
redo-ifchange hello yellow bellow c d
|
redo-ifchange hello yellow bellow c d example/all
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,2 @@
|
||||||
|
redo example/clean
|
||||||
rm -f c c.c c.c.c c.c.c.b c.c.c.b.b d
|
rm -f c c.c c.c.c c.c.c.b c.c.c.b.b d
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
3
t/example/.gitignore
vendored
Normal file
3
t/example/.gitignore
vendored
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
*.o
|
||||||
|
CC
|
||||||
|
hello
|
||||||
10
t/example/CC.do
Normal file
10
t/example/CC.do
Normal 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
6
t/example/Makefile
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
all:
|
||||||
|
|
||||||
|
%: FORCE
|
||||||
|
+redo $@
|
||||||
|
|
||||||
|
.PHONY: FORCE
|
||||||
1
t/example/all.do
Normal file
1
t/example/all.do
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
redo-ifchange hello
|
||||||
1
t/example/clean.do
Normal file
1
t/example/clean.do
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
rm -f *.tmp *~ *.o hello CC
|
||||||
1
t/example/config.sh
Normal file
1
t/example/config.sh
Normal file
|
|
@ -0,0 +1 @@
|
||||||
|
CFLAGS="-Wall"
|
||||||
2
t/example/default.o.do
Normal file
2
t/example/default.o.do
Normal file
|
|
@ -0,0 +1,2 @@
|
||||||
|
redo-ifchange CC
|
||||||
|
. ./CC "$@"
|
||||||
4
t/example/hello.do
Normal file
4
t/example/hello.do
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
DEPS="main.o
|
||||||
|
mystr.o"
|
||||||
|
redo-ifchange $DEPS
|
||||||
|
gcc -o $3 $DEPS
|
||||||
8
t/example/main.c
Normal file
8
t/example/main.c
Normal 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
4
t/example/mystr.c
Normal file
|
|
@ -0,0 +1,4 @@
|
||||||
|
|
||||||
|
#include "mystr.h"
|
||||||
|
|
||||||
|
char *mystr = "Hello, world!";
|
||||||
6
t/example/mystr.h
Normal file
6
t/example/mystr.h
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#ifndef __MYSTR_H
|
||||||
|
#define __MYSTR_H
|
||||||
|
|
||||||
|
extern char *mystr;
|
||||||
|
|
||||||
|
#endif
|
||||||
Loading…
Add table
Add a link
Reference in a new issue