Lesson 11

Dates: 4/6/2016
Application compilation and installation on Linux
Linux System Administration

Makefile with suffix rules

  • When there is need to compile many *.c codes into *.o binaries, the suffix rule can be implemented to avoid many target lines in the Makefile.
  • Makefile with the suffix rule:
    SLIB = libScalar_Product.a
    CC = gcc
    CFLAGS = -O3
    LIBPATH = .
    INSTPATH = /usr/local
    $(APP): main.o $(SLIB) 
            $(CC) $(CFLAGS) -o $@ main.o -L$(LIBPATH) -lScalar_Product
            @echo "Compiling" $< 
            $(CC) -c $<
    $(SLIB): Scalar_Product.o
            ar -cru $@ $<
            ranlib $@ 
            -rm -f *.o *.a $(APP) 
            @cp -p $(APP) $(INSTPATH)/bin ;\
            chown root:root $(INSTPATH)/bin/$(APP) ;\
            cp -p $(SLIB) $(INSTPATH)/lib ;\
            chown root:root $(INSTPATH)/lib/$(SLIB) ;\
            echo "Install $(APP) and $(SLIB) into $(INSTPATH)" 
            -@rm -f $(INSTPATH)/bin/$(APP)
            -@rm -f $(INSTPATH)/lib/$(SLIB)
            @echo "Removed $(APP) and $(SLIB) from $(INSTPATH)"

  • Special symbols:
    $@ name of current target.
    $< name of current dependency.
    $* name of current dependency without extension.
    $?  list of dependencies changed more recently than current target.

  • Take me to the Course Website