aboutsummaryrefslogtreecommitdiff
path: root/shellcode/Makefile
blob: e7833cdb48a2ecaab1329d6da9064de57d5b0e6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
RM := rm
ASM := nasm
CC := gcc
LD := ld
OBJCOPY := objcopy
XXD := xxd
CFLAGS = -c -Wall -fpic -Os
LDFLAGS =
SUBDIR ?= .
TARGETS = $(patsubst %.c,%.o,$(wildcard $(SUBDIR)/*.c)) $(patsubst %.asm,%.o,$(wildcard $(SUBDIR)/*.asm))

all: $(TARGETS)

%.o : %.c
	$(CC) $(CFLAGS) -o $@ $<
	$(LD) $(LDFLAGS) -N -Ttext 0x0 -e _start -Map $(patsubst %.o,%.map,$@) $@ -o $(patsubst %.o,%,$@)
	$(OBJCOPY) -R .note -R .comment -S -O binary $(patsubst %.o,%,$@) $(patsubst %.o,%.bin,$@)
	$(XXD) -i $(patsubst %.o,%.bin,$@)

%.o : %.asm
	$(ASM) -o $@ $<

clean:
	$(RM) -f $(patsubst %.o,%.map,$(TARGETS)) $(patsubst %.o,%.bin,$(TARGETS)) $(patsubst %.o,%,$(TARGETS)) $(TARGETS)

.PHONY: all clean