Compiling all 'C' files

%.o: %.c
        $(CC) $(CFLAGS) -c $<

  • This is not a rule in and of itself, but used by other rules (if another rule needs a .o file, it will compile it with this rule)
  • % is a wildcard that means one .o file for each .c file of the same name
  • $< equates to the dependency list matched by the rule ( %.c )
  • $@ refers to the full target name
  • $* refers to the part that was matched by the "%" character

Turning on optimization

export CFLAGS="-O3 -march=<architecture>" &&
CXXFLAGS=$CFLAGS
where architecture can equal things like i586, i686, etc.

...or (from the Linux From Scratch page)...

Ed. note "Reboant" dropped a note about how using -Os (optimize for size) showed incredibly good results. So if you want is small binary size rather than fast execution time, you might want to take a look at this.

How to do a global replacement

say, from old_string to new_string
CPPFLAGS=-Dold_string=new_string

How to execute a shell command and assign its result to a variable

# finds the device node number for 'mem'
VER = $(shell  cat /proc/devices | grep mem | awk '{print $$1}')

all: Test

Test:
   echo $(VER)
-- MattWalsh - 21 Mar 2002
Topic revision: r3 - 28 Nov 2006 - MattWalsh
 
This site is powered by the TWiki collaboration platformCopyright © 2008-2012 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.
Ideas, requests, problems regarding TWiki? Send feedback