Lesson 11

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


Makefile with target "all"


  • Target "all" in a Makefile envokes a sequence of other targets.
  • Makefile with target all:
    SLIB = libScalar_Product.a
    APP=app.x
    CC = gcc
    CFLAGS = -O3
    LIBPATH = .
    INSTPATH = /usr/local
    
    all: $(APP) install clean
    
    $(APP): main.o $(SLIB) 
            $(CC) $(CFLAGS) -o $(APP) main.o -L$(LIBPATH) -lScalar_Product
    
    main.o: main.c Scalar_Product.h
            $(CC) $(CFLAGS) -c main.c
    
    Scalar_Product.o: Scalar_Product.c
            $(CC) $(CFLAGS) -c Scalar_Product.c
    
    $(SLIB): Scalar_Product.o
            ar -cru $(SLIB) Scalar_Product.o
            ranlib $(SLIB) 
    
    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