summaryrefslogtreecommitdiffstats
path: root/mdk-stage1/dietlibc/Makefile
blob: 74aca4f27600c43314b82458b162cf71fe18fd49 (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
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
all: start.o dietlibc.a elftrunc

ARCH=$(shell uname -m | sed 's/i[4-9]86/i386/')

CFLAGS=-pipe
CROSS=

VPATH=syscalls.c

SYSCALLOBJ=$(patsubst syscalls.s/%.S,%.o,$(wildcard syscalls.s/*.S))

LIBOBJ=$(patsubst lib/%.c,%.o,$(wildcard lib/*.c))

include $(ARCH)/Makefile.add

ifeq ($(CFLAGS),-pipe)
CFLAGS+=-O -fomit-frame-pointer
endif

#CFLAGS += -g
CFLAGS += -Wall

.SUFFIXES:
.SUFFIXES: .S .c

%.o: %.S
	$(CROSS)gcc -I. -Iinclude $(CFLAGS) -c $<

%.o: %.c
	$(CROSS)gcc -I. -Iinclude $(CFLAGS) -c $<
#	$(CROSS)strip -x -R .comment -R .note $@

dietlibc.a: $(SYSCALLOBJ) $(LIBOBJ) __longjmp.o longjmp.o setjmp.o \
start.o unified.o mmap.o mount.o
	$(CROSS)ar cru dietlibc.a $^

libdietc.so: dietlibc.a
	$(CROSS)ld -whole-archive -shared -o $@ $^

$(SYSCALLOBJ): syscalls.h

elftrunc: contrib/elftrunc.c start.o dietlibc.a
	$(CROSS)gcc $(CFLAGS) -nostdlib -o $@ $^

djb: compile load

compile:
	echo 'exec gcc $(CFLAGS) -I$(HOME)/projects/dietlibc/include -c $${1+"$$@"}' > $@
	chmod 755 $@

load:
	echo 'main="$$1"; shift; exec gcc -nostdlib -o "$$main" $(HOME)/projects/dietlibc/start.o "$$main".o $${1+"$$@"} $(HOME)/projects/dietlibc/dietlibc.a -lgcc'  > $@
	chmod 755 $@

clean:
	rm -f *.o *.a t t1 compile load elftrunc exports mapfile libdietc.so
	$(MAKE) -C examples clean

tar: clean
	cd .. && tar cvvf dietlibc.tar.bz2 dietlibc --use=bzip2

exports: dietlibc.a
	nm -g dietlibc.a | grep -w T | awk '{ print $$3 }' | sort -u > exports

.PHONY: t t1
t:
	$(CROSS)gcc -g $(CFLAGS) -fno-builtin -nostdlib -Iinclude -o t t.c start.o dietlibc.a -lgcc -Wl,-Map,mapfile

t1:
	$(CROSS)gcc -g -o t1 t.c

install:
	cp start.o $(prefix)/lib/dietstart.o
	cp dietlibc.a $(prefix)/lib/libdietc.a

.PHONY: sparc ppc mips arm alpha i386

sparc ppc alpha i386:
	$(MAKE) ARCH=$@ CROSS=$@-linux- all t libdietc.so

mips arm:
	$(MAKE) ARCH=$@ CROSS=$@-linux-gnu- all t libdietc.so