Lesson 11

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

Makefile with suffix rules and object file dependencies

  • The suffix rule discussed in the previous slide doesn't contain dependencies for the targets. Below, we include the dependencies for the object files.
  • Makefile with the suffix rule and object file dependencies:
    SLIB = libScalar_Product.a
    CC = gcc
    CFLAGS = -O3
    LIBPATH = .
    INSTPATH = /usr/local
    OBJS = main.o
    $(APP): main.o $(SLIB) 
            $(CC) $(CFLAGS) -o $@ main.o -L$(LIBPATH) -lScalar_Product
            @echo "Compiling" $< 
            $(CC) -c $<
    $(SLIB): Scalar_Product.o
            ar -cru $@ $<
            ranlib $@ 
    $(OBJS): Scalar_Product.h 
            -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)"

  • Take me to the Course Website