-
Notifications
You must be signed in to change notification settings - Fork 4
/
library.mak
62 lines (48 loc) · 1.53 KB
/
library.mak
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
55
56
57
58
59
60
61
62
OBJDIR = ../lib
BUILDDIR = ../bin
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
CSRC = $(call rwildcard,./,*.c)
CPPSRC = $(call rwildcard,./,*.cpp)
OBJS = $(patsubst %.c, $(OBJDIR)/%_$(OUTPUT).o, $(CSRC))
OBJS += $(patsubst %.cpp, $(OBJDIR)/%_$(OUTPUT).o, $(CPPSRC))
TOOLCHAIN_BASE = /usr/local/foxos-x86_64_elf_gcc
CFLAGS = -O2 -mno-red-zone -ffreestanding -fno-exceptions -fpic -g -I ../libfoxos/include -Iinclude -I../libc/include -I../libtinf/include -I../libcfg/include -I../libfoxdb/include -nostdinc -fno-stack-protector -fdata-sections -ffunction-sections
CPPFLAGS = $(CFLAGS)
LDFLAGS = -r
CFLAGS += $(USER_CFLAGS)
CPPFLAGS += $(USER_CPPFLAGS)
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
ifeq (,$(wildcard $(TOOLCHAIN_BASE)/bin/foxos-ar))
AR = ar
else
AR = $(TOOLCHAIN_BASE)/bin/foxos-ar
endif
$(OUTPUT): $(OBJS)
@echo LD $^
@$(LD) $(LDFLAGS) -o $(BUILDDIR)/[email protected] $^
@echo AR $(BUILDDIR)/[email protected]
@$(AR) rcs $(BUILDDIR)/$@ $(BUILDDIR)/[email protected]
@echo Successfully built library $(OUTPUT)
$(OBJDIR)/%_$(OUTPUT).o: %.c
@echo "CC $^ -> $@"
@mkdir -p $(@D)
@$(CC) $(CFLAGS) -c -o $@ $^
$(OBJDIR)/%_$(OUTPUT).o: %.cpp
@echo "CC $^ -> $@"
@mkdir -p $(@D)
@$(CC) $(CPPFLAGS) -c -o $@ $^
.PHONY: build