Lesson 11

Dates: 4/10/2014
Application compilation and installation on Linux
Linux for Engineering and IT Applications


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
    APP=app.x
    CC = gcc
    CFLAGS = -O3
    LIBPATH = .
    INSTPATH = /usr/local
    OBJS = main.o
    
    $(APP): main.o $(SLIB) 
            $(CC) $(CFLAGS) -o $@ main.o -L$(LIBPATH) -lScalar_Product
    
    .c.o: 
            @echo "Compiling" $< 
            $(CC) -c $<
    
    $(SLIB): Scalar_Product.o
            ar -cru $@ $<
            ranlib $@ 
    
    $(OBJS): Scalar_Product.h 
    
    clean:
            -rm -f *.o *.a $(APP) 
    
    install: 
            @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)" 
              
    uninstall:
            -@rm -f $(INSTPATH)/bin/$(APP)
            -@rm -f $(INSTPATH)/lib/$(SLIB)
            @echo "Removed $(APP) and $(SLIB) from $(INSTPATH)"
    
    




  • Take me to the Course Website