CC = gcc -g -ggdb
LD = ld
ARCH = -arch i386
CFLAGS = -Wall -O2 -Iinclude
LDFLAGS = $(ARCH) -Wl,-no_pie
NASM = nasm -f macho32 -Iinclude -g
TARGETS = helloASM
TARGETS+= helloC
OBJECTS = hello.o main.o
ENTRYPOINT = start
.SUFFIXES: .c .asm
.c.o:
@echo Compiling $< ...
@$(CC) -c $(CFLAGS) $(ARCH) -o $@ $<
.asm.o:
@echo Assembling $< ...
@$(NASM) $< -o $@
all: $(TARGETS)
helloC: $(OBJECTS)
@echo Linking $(OBJECTS) ...
$(CC) $(LDFLAGS) $(OBJECTS) -o $@
helloASM: hello.o
@echo Linking $(OBJECTS) ...
$(LD) -static -e $(ENTRYPOINT) $< -o $@
.PHONY: clean uninstall
clean:
$(RM) *.o *~ $(TARGETS)