========================================================== CPW Pt.4 Recursive Descent Parser, CPW Pt.5 Unique Strings ========================================================== - C Programming Workout Part 4: A __recursive descent parser__ for a calculator. - C Programming Workout Part 5: A data structure for __unique strings__. Fix the Makefile for the ABC Compiler Project! ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ The makefile from session 13 has a bug. If you have more than one test program you will get a linker error. In the makefile you have to change the lines ---- CODE (type=mk) ------------------------------------------------------------ # our rule: to build target link its object file against library object files %: %.o $(obj) | $(obsolete.deps) $(CC) -o $@ $(LDFLAGS) $^ -------------------------------------------------------------------------------- into ---- CODE (type=mk) ------------------------------------------------------------ # our rule: to build target link its object file against library object files %: %.o $(lib.o) | $(obsolete.deps) $(CC) -o $@ $^ $(LDFLAGS) -------------------------------------------------------------------------------- Here the complete makefile with the fix: :import: session13/abc/Makefile [fold] After the bug fix you should of course commit it to your git repository. Optional Modification for the Makefile ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ We use variables like _CC_, _CPPFLAGS_, _LDFLAGS_ in our makefile for selecting the compiler and specifying flags to the linker. You know that you can predefine these variables when you run make. For example ---- CODE (type=txt) ----------------------------------------------------------- make CPPFLAGS="-Wall -DNDEBUG -O3" LDFLAGS=-lm -------------------------------------------------------------------------------- If you would like to have this value hard coded in the makefile simply add a definition like this (quotes are then not needed): ---- CODE (type=txt) ----------------------------------------------------------- CPPFLAGS := -Wall -O3 LDFLAGS := -lm -------------------------------------------------------------------------------- Of course, hard coding values has disadvantages. You now longer change this values when you invoke make from the command line. A better alternative might be to add certain default values: ---- CODE (type=txt) ----------------------------------------------------------- CPPFLAGS += -Wall # always use -Wall for the compiler LDFLAGS += -lm # always link against the math library -------------------------------------------------------------------------------- It extends the variables for some additional values that you always want to have. Now with ---- CODE (type=txt) ----------------------------------------------------------- make CPPFLAGS="-DNDEBUG -O3" LDFLAGS=-lm -------------------------------------------------------------------------------- you compile with _CPPFLAGS="-DNDEBUG -Wall -O3"_ and _LDFLAGS=-lm_. And with ---- CODE (type=txt) ----------------------------------------------------------- make -------------------------------------------------------------------------------- you only use the defaults _CPPFLAGS="-Wall"_ and _LDFLAGS=-lm_. :links: recursive descent parser -> doc:session17/page02 unique strings -> doc:session17/page03