From cb2138f8b098feb1b51a407343a4b99e25d5b506 Mon Sep 17 00:00:00 2001 From: Thomas Preud'homme Date: Sat, 18 Jun 2011 00:24:47 +0200 Subject: Make examples' shebang use target tcc bindir path Use @BINDIR@ in shebang of examples to put the right path on the target system. That is, use #!/usr/local/bin/tcc if tcc is installed in /usr/local/bin and #!/usr/bin/tcc if tcc is installed in /usr/bin/tcc. --- Makefile | 14 ++++++++++---- README | 3 ++- examples/ex1.c | 8 -------- examples/ex1.c.template | 8 ++++++++ examples/ex4.c | 26 -------------------------- examples/ex4.c.template | 26 ++++++++++++++++++++++++++ 6 files changed, 46 insertions(+), 39 deletions(-) delete mode 100755 examples/ex1.c create mode 100644 examples/ex1.c.template delete mode 100755 examples/ex4.c create mode 100644 examples/ex4.c.template diff --git a/Makefile b/Makefile index d1dfbda..8a04f8e 100644 --- a/Makefile +++ b/Makefile @@ -141,15 +141,16 @@ ifdef CONFIG_USE_LIBGCC LIBTCC1= endif -TCCLIBS = $(LIBTCC1) $(LIBTCC) $(BCHECK_O) -TCCDOCS = tcc.1 tcc-doc.html tcc-doc.info +TCCLIBS := $(LIBTCC1) $(LIBTCC) $(BCHECK_O) +TCCDOCS := tcc.1 tcc-doc.html tcc-doc.info +TCCEXS := $(patsubst ex%.c.template,ex%.c,$(wildcard examples/ex*.c.template)) ifdef CONFIG_CROSS PROGS+=$(PROGS_CROSS) TCCLIBS+=$(LIBTCC1_CROSS) endif -all: $(PROGS) $(TCCLIBS) $(TCCDOCS) +all: $(PROGS) $(TCCLIBS) $(TCCDOCS) $(TCCEXS) # Host Tiny C Compiler tcc$(EXESUF): tcc.o $(LIBTCC) @@ -324,6 +325,11 @@ tcc.1: tcc-doc.texi tcc-doc.info: tcc-doc.texi -makeinfo tcc-doc.texi +# examples +examples/ex%.c: examples/ex%.c.template + sed '1s/@BINDIR@/$(subst /,\/,$(bindir))/' $< > $@ + chmod a+x $@ + .PHONY: all clean tar distclean install uninstall FORCE # tar release (use 'make -k tar' on a checkouted tree) @@ -341,7 +347,7 @@ export LIBTCC1 $(MAKE) -C tests $@ clean: - rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF) + rm -vf $(PROGS) tcc_p$(EXESUF) tcc.pod *~ *.o *.a *.so* *.out *.exe libtcc_test$(EXESUF) $(TCCEXS) $(MAKE) -C tests $@ ifneq ($(LIBTCC1),) $(MAKE) -C lib $@ diff --git a/README b/README index bfaab39..0ead1ee 100644 --- a/README +++ b/README @@ -65,7 +65,8 @@ operations given a list of numbers (benchmark). ex3.c: compute fibonacci numbers (benchmark). ex4.c: more complicated: X11 program. Very complicated test in fact -because standard headers are being used ! +because standard headers are being used ! As for ex1.c, can also be launched +directly as a script: './ex4.c'. ex5.c: 'hello world' with standard glibc headers. diff --git a/examples/ex1.c b/examples/ex1.c deleted file mode 100755 index 28139f9..0000000 --- a/examples/ex1.c +++ /dev/null @@ -1,8 +0,0 @@ -#! /usr/local/bin/tcc -run -#include - -int main() -{ - printf("Hello World\n"); - return 0; -} diff --git a/examples/ex1.c.template b/examples/ex1.c.template new file mode 100644 index 0000000..8744f58 --- /dev/null +++ b/examples/ex1.c.template @@ -0,0 +1,8 @@ +#! @BINDIR@/tcc -run +#include + +int main() +{ + printf("Hello World\n"); + return 0; +} diff --git a/examples/ex4.c b/examples/ex4.c deleted file mode 100755 index b33b033..0000000 --- a/examples/ex4.c +++ /dev/null @@ -1,26 +0,0 @@ -#!./tcc -run -L/usr/X11R6/lib -lX11 -#include -#include -#include - -/* Yes, TCC can use X11 too ! */ - -int main(int argc, char **argv) -{ - Display *display; - Screen *screen; - - display = XOpenDisplay(""); - if (!display) { - fprintf(stderr, "Could not open X11 display\n"); - exit(1); - } - printf("X11 display opened.\n"); - screen = XScreenOfDisplay(display, 0); - printf("width = %d\nheight = %d\ndepth = %d\n", - screen->width, - screen->height, - screen->root_depth); - XCloseDisplay(display); - return 0; -} diff --git a/examples/ex4.c.template b/examples/ex4.c.template new file mode 100644 index 0000000..81aa00d --- /dev/null +++ b/examples/ex4.c.template @@ -0,0 +1,26 @@ +#! @BINDIR@/tcc -run -L/usr/X11R6/lib -lX11 +#include +#include +#include + +/* Yes, TCC can use X11 too ! */ + +int main(int argc, char **argv) +{ + Display *display; + Screen *screen; + + display = XOpenDisplay(""); + if (!display) { + fprintf(stderr, "Could not open X11 display\n"); + exit(1); + } + printf("X11 display opened.\n"); + screen = XScreenOfDisplay(display, 0); + printf("width = %d\nheight = %d\ndepth = %d\n", + screen->width, + screen->height, + screen->root_depth); + XCloseDisplay(display); + return 0; +} -- cgit v1.3.1