-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
51 lines (40 loc) · 905 Bytes
/
Makefile
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
.SUFFIXES: .asm .inc .o
vpath %.inc $(LIBRARY_DIR)
OS = $(shell uname -s)
BINARY_DIR = bin
LIBRARY_DIR = lib
SOURCE_DIR = src
LD = ld
LDFLAGS =
AS = nasm
ASFLAGS = -g -I$(LIBRARY_DIR)/ -Wall -Werror
ifeq ($(OS),Darwin)
# SDKPATH = $(shell xcode-select -p)/SDKs/MacOSX.sdk/usr/lib
ASFLAGS += -f macho64
LDFLAGS += -e _start -macos_version_min 10.7.0 # -L$(SDKPATH) -lSystem
else
ifeq ($(OS),Linux)
ASFLAGS += -f elf64
endif
endif
SOURCES = $(notdir $(wildcard src/*.asm))
PROGRAMS = $(basename $(SOURCES))
OBJECTS = $(addsuffix .o,$(PROGRAMS))
BINARIES = $(addprefix $(BINARY_DIR)/,$(PROGRAMS))
.PHONY: all
all: $(BINARIES)
$(BINARY_DIR)/%: %.o
mkdir -p $(BINARY_DIR)
$(LD) $(LDFLAGS) -o $@ $<
%.o: src/%.asm
$(AS) $(ASFLAGS) -o $@ $<
.PHONY: clean
clean:
rm -rf $(BINARIES) src/*.o
.PHONY: run
run: all
./bin/args foo bar
./bin/exec
./bin/count
./bin/input
./bin/prime 10