next up previous contents index
Next: Using lint Up: Running It Previous: The Program and the

   
A Makefile

For the sake of convenience, we give here a typical makefile for use with the term processor, yacc and lex. This example illustrates a naming convention: the input files are called file1.k and file2.k, all user-provided C code is in the file examplemain.c, the yacc input is in exampley.y, and the lex input is in examplel.l. Note that the makefile makes extensive use of make's defaults, and that it attempts to avoid superfluous recompilations.  

# /* Makefile for the term processor */ # /* 2 input .k-files plus yacc and lex usage. */ IT = example KFILES = file1.k file2.k YOURFILES = ${KFILES} ${IT}y.y ${IT}l.l ${IT}main.c ALLOBJS = k.o rk.o csgiok.o unpk.o\ ${KFILES:k=o} ${IT}y.o ${IT}l.o ${IT}main.o GENERATED_BY_KC = k.c rk.c csgiok.c unpk.c ${KFILES:k=c}\ k.h rk.h csgiok.h unpk.h ${KFILES:k=h} YFLAGS = -d
${IT}: ${ALLOBJS} ${CC} ${CFLAGS} ${ALLOBJS} -ll -o $@
${GENERATED_BY_KC}: kctimestamp
kctimestamp: ${KFILES} kc ${KFILES}; touch kctimestamp
${ALLOBJS}: k.h ${IT}main.o ${IT}l.o: x.tab.h ${IT}main.o ${KFILES:k=o}: ${KFILES:k=h} ${IT}main.o rk.o: rk.h ${IT}main.o csgiok.o: csgiok.h ${IT}main.o unpk.o: unpk.h
# /* making copies to prevent unnecessary recompilation after yacc run */ x.tab.h: y.tab.h -cmp -s x.tab.h y.tab.h || cp y.tab.h x.tab.h
# /* if you clean up, don't forget to remove the file kctimestamp */
This makefile is rather complicated, for the following reason. The target (${IT}) depends on a number of object files, which depend on a number of .c and .h files, some of which depend on the .k files. However, if example.k is changed the term processor does not always change all .c and .h files, and we want to avoid recompilations of unchanged files. For this reason, an intermediate target kctimestamp is introduced that `remembers' when kc was last executed successfully.

The last rule (for x.tab.h) helps to avoid recompilations when yacc overwrites the file y.tab.h but doesn't change it.

There is still a problem with this makefile. It assumes that if kctimestamp is up to date the generated files are also accurate. The user can mess this up.

How to adapt this to your situation? If you have a different number of .k files, you will have to adapt the definition of the KFILES macro. If you do not use yacc you can remove the lines containing x.tab.h (2 lines) and the filenames ${IT}y.[yo]. If you do not use lex you can remove the filenames ${IT}l.[lo] and the loader option -ll. In either case it is sufficient to remove the object file names from the definition of the macro ALLOBJS. This is also true for other files that need not be included in the final program. For example, if no rewriting functions are used you can delete rk.o from ALLOBJS and it will not be compiled.


next up previous contents index
Next: Using lint Up: Running It Previous: The Program and the

2000-04-17