Lesson 11

Dates: 4/5/2017
Application compilation and installation on Linux
Linux System Administration


Makefile with macros


  • Parameters that appear in the Makefile multiple times or that need to be modified, depending on the environment, can be expressed through macronames.
  • Makefile with macros example:
    #First, we define the MACRONAMES:
    SLIB = libScalar_Product.a
    APP=app.x
    CC = gcc
    CFLAGS = -O3
    LIBPATH = .  
    
    #Then we refer to them by $(MACRONAMES):
    $(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) 
    
    




  • Take me to the Course Website