CSC231 Makefile for linking ASM and C Files
Revision as of 09:10, 22 October 2012 by Thiebaut (talk | contribs) (moved CSC231 Makefile for Lab 5 to CSC231 Makefile for linking ASM and C Files)
--D. Thiebaut 01:23, 27 October 2010 (UTC)
Revised --D. Thiebaut 10:10, 22 October 2012 (EDT)
References
Makefile
CC = gcc
LD = gcc
NASM = nasm
CFLAGS = -c -m32
LFLAGS = -m32
NASMFLAGS = -f elf -F stabs
PROG = printBinary
OBJS = asm_io.o $(PROG).o driver.o
default: $(PROG)
$(PROG): $(OBJS)
$(LD) $(LFLAGS) $(OBJS) -o $(PROG)
asm_io.o: asm_io.asm
$(NASM) $(NASMFLAGS) asm_io.asm
$(PROG).o: $(PROG).asm asm_io.inc
$(NASM) $(NASMFLAGS) $(PROG).asm
driver.o: driver.c
$(CC) $(CFLAGS) driver.c
clean:
rm -rf *.o *~
real_clean:
rm -rf *.o $(PROG) *~
Usage
- Edit any of driver.c, asm_io.asm, asm_io.inc, or printBinary.asm, and to generate the executable, simply type:
make
- and the executable will be generated. Run it with
./printBinary
- If you want to force a "re-make", simply touch any of the .asm or .c files. See examples below:
[231a@grendel ~/handout]$ make make: Nothing to be done for `default'. [231a@grendel ~/handout]$ touch driver.c [231a@grendel ~/handout]$ make gcc -c -m32 driver.c gcc -m32 asm_io.o printBinary.o driver.o -o printBinary [231a@grendel ~/handout]$ make make: Nothing to be done for `default'. [231a@grendel ~/handout]$ touch asm_io.inc [231a@grendel ~/handout]$ make nasm -f elf -F stabs printBinary.asm gcc -m32 asm_io.o printBinary.o driver.o -o printBinary [231a@grendel ~/handout]$ touch asm_io.asm [231a@grendel ~/handout]$ make nasm -f elf -F stabs asm_io.asm gcc -m32 asm_io.o printBinary.o driver.o -o printBinary [231a@grendel ~/handout]$