2018-04-30 14:38:44 +00:00
|
|
|
NASM=nasm
|
|
|
|
LD=ld
|
|
|
|
COMPILE_64=elf64
|
|
|
|
|
|
|
|
# LD often has several different linking modes. This sets the mode
|
|
|
|
# explicitly, but if you're running on 64-bit Linux LD will use this
|
|
|
|
# mode by default and the '-m' argument is unnecessary.
|
|
|
|
LINK_64=elf_x86_64
|
|
|
|
|
|
|
|
default: help
|
|
|
|
|
2018-05-01 03:46:25 +00:00
|
|
|
PROGRAMS=hello strlen subroutines includes argv
|
2018-04-30 14:38:44 +00:00
|
|
|
|
2018-05-01 03:46:25 +00:00
|
|
|
all: $(PROGRAMS) ## Build everything at once
|
|
|
|
|
|
|
|
%.o: %.s functions.asm
|
2018-04-30 14:38:44 +00:00
|
|
|
$(NASM) -f $(COMPILE_64) $<
|
|
|
|
|
2018-05-01 03:46:25 +00:00
|
|
|
# Lesson 1 was skipped because it was just Lesson 2 without a proper
|
|
|
|
# exit handler... and who does that?
|
|
|
|
|
2018-04-30 14:38:44 +00:00
|
|
|
hello: hello.o ## Build Lesson 2: Print string with known length, exit cleanly
|
|
|
|
$(LD) -m $(LINK_64) -o $@ $<
|
|
|
|
|
2018-05-01 03:46:25 +00:00
|
|
|
strlen: strlen.o ## Build Lesson 3: Determine length programmatically
|
2018-04-30 14:38:44 +00:00
|
|
|
$(LD) -m $(LINK_64) -o $@ $<
|
|
|
|
|
2018-05-01 03:46:25 +00:00
|
|
|
subroutines: subroutines.o ## Build Lesson 4: Separate strlen() and puts() into subroutine.
|
2018-04-30 14:38:44 +00:00
|
|
|
$(LD) -m $(LINK_64) -o $@ $<
|
|
|
|
|
2018-05-01 03:46:25 +00:00
|
|
|
includes: includes.o ## Build Lesson 5: Separate strlen() and puts() into their own files.
|
|
|
|
$(LD) -m $(LINK_64) -o $@ $<
|
|
|
|
|
|
|
|
# Lesson 6 is wrapped in Lesson 7: using null-terminated strings, but
|
|
|
|
# lesson 7 then adds a line feed, so the jump isn't too big.
|
|
|
|
|
|
|
|
argv: argv.o ## Build Lesson 7 and 8: Line feeds and command line arguments
|
2018-04-30 16:09:48 +00:00
|
|
|
$(LD) -m $(LINK_64) -o $@ $<
|
|
|
|
|
2018-05-28 16:36:46 +00:00
|
|
|
stdin: stdin.o ## Build Lesson 9: Reading from stdin
|
|
|
|
$(LD) -m $(LINK_64) -o $@ $<
|
|
|
|
|
2018-04-30 14:38:44 +00:00
|
|
|
help: run-help ## Print this helpful message (default)
|
|
|
|
|
|
|
|
clean:
|
2018-05-01 03:46:25 +00:00
|
|
|
rm -f $(PROGRAMS) *.o
|
2018-04-30 14:38:44 +00:00
|
|
|
|
|
|
|
include ../makefiles/help.make
|
|
|
|
|