Lesson 8

Dates: 6/19/2017
Application compilation and installation on Linux
Linux System Administration

Makefile with phony targets

  • When a target in a Makefile rather means just an action than a file, it is called a phony target.
  • Makefile with phony targets (clean, install, and uninstall):
    SLIB = libScalar_Product.a
    CC = gcc
    CFLAGS = -O3
    LIBPATH = .
    INSTPATH = /usr/local
    $(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) 
            -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 in the command prefixes mean:
    • "-" - don't quit on error. For example, -rm won't quit if there is no files to delete.
    • "@" - don't print the command itself.

  • Take me to the Course Website