0

I have to run these 4 commands on the terminal each time I want to execute the program using libraries.

The lines are

cc -m32 -c mylib.c
ar -rcs libmylib.a mylib.o
cc -m32 -c prog.c
cc -m32 prog.o -L. -lmylib
./a.out

How do I make a makefile for the above commands and run it?

Aakash Anuj
  • 3,773
  • 7
  • 35
  • 47
  • possible duplicate of [Makefile for a library](http://stackoverflow.com/questions/11791076/makefile-for-a-library) – Beta Aug 03 '12 at 16:44

1 Answers1

0

It's quite simple:

CFLAGS=-m32
ARFLAGS=-rcs

.PHONY: all clean

all: prog

mylib.o: mylib.c
libmylib.a: mylib.o
    ar $(ARFLAGS) $@ $^

prog.o: prog.c
prog: prog.o libmylib.a

clean:
    rm -f *.o prog libmylib.a