-
Notifications
You must be signed in to change notification settings - Fork 2
/
Makefile.module
54 lines (42 loc) · 1.28 KB
/
Makefile.module
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
52
53
54
OBJDIR = ../../lib
BUILDDIR = ../../bin
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
CPPSRC = $(call rwildcard,./,*.cpp)
CSRC = $(call rwildcard,./,*.c)
ASMSRC = $(call rwildcard,./,*.asm)
OBJS = $(patsubst %.cpp, $(OBJDIR)/$(MODULE_NAME)/%.o, $(CPPSRC))
OBJS += $(patsubst %.c, $(OBJDIR)/$(MODULE_NAME)/%.o, $(CSRC))
OBJS += $(patsubst %.asm, $(OBJDIR)/$(MODULE_NAME)/%_asm.o, $(ASMSRC))
TOOLCHAIN_BASE = /usr/local/foxos-x86_64_elf_gcc
ifeq (,$(wildcard $(TOOLCHAIN_BASE)/bin/foxos-gcc))
CC = gcc
else
CC = $(TOOLCHAIN_BASE)/bin/foxos-gcc
endif
ifeq (,$(wildcard $(TOOLCHAIN_BASE)/bin/foxos-nasm))
ASM = nasm
else
ASM = $(TOOLCHAIN_BASE)/bin/foxos-nasm
endif
ifeq (,$(wildcard $(TOOLCHAIN_BASE)/bin/foxos-gcc))
LD = ld
else
LD = $(TOOLCHAIN_BASE)/bin/foxos-ld
endif
LDFLAGS = -r
module: $(OBJS)
@echo LD $^
@$(LD) $(LDFLAGS) -o $(BUILDDIR)/$(MODULE_NAME) $^
@echo "Compiled using asm: $(ASM), cc: $(CC), ld: $(LD)"
$(OBJDIR)/$(MODULE_NAME)/%.o: %.cpp
@echo "CPP $^ -> $@"
@mkdir -p $(@D)
@$(CC) $(CPPFLAGS) -c -o $@ $^
$(OBJDIR)/$(MODULE_NAME)/%.o: %.c
@echo "CC $^ -> $@"
@mkdir -p $(@D)
@$(CC) $(CFLAGS) -c -o $@ $^
$(OBJDIR)/$(MODULE_NAME)/%_asm.o: %.asm
@echo "ASM $^ -> $@"
@mkdir -p $(@D)
@$(ASM) $(ASMFLAGS) -o $@ $^