Add -DPINTOS to DEFINES.
[pintos-anon] / src / Makefile.userprog
1 # -*- makefile -*-
2
3 include $(SRCDIR)/Make.config
4
5 SHELL = /bin/sh
6
7 VPATH = $(SRCDIR)
8
9 DEFINES = -DPINTOS -DUSER
10 CPPFLAGS = -nostdinc -I$(SRCDIR) -I- -I$(SRCDIR)/lib -I$(SRCDIR)/lib/user -I.
11
12 # Linker flags.
13 LDFLAGS = -nostdlib -static -s
14 LDLIBS = $(shell $(CC) -print-libgcc-file-name)
15
16 # C library sources linked into every test program.
17 LIB_SRC  = lib/debug.c                  # Debug code.
18 LIB_SRC += lib/random.c                 # Pseudo-random numbers.
19 LIB_SRC += lib/stdio.c                  # I/O library.
20 LIB_SRC += lib/stdlib.c                 # atoi()
21 LIB_SRC += lib/string.c                 # String functions.
22 LIB_SRC += lib/user/syscall.c           # System calls.
23 LIB_SRC += lib/user/syscall-stub.S      # System call stub.
24 LIB_SRC += lib/user/console.c           # Console code.
25
26 LIB_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(LIB_SRC)))
27 LIB_DEP = $(patsubst %.o,%.d,$(LIB_OBJ))
28 LIB = lib/user/entry.o libc.a
29
30 PROGS_SRC = $(foreach prog,$(PROGS),$($(subst -,_,$(prog))_SRC))
31 PROGS_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(PROGS_SRC)))
32 PROGS_DEP = $(patsubst %.o,%.d,$(PROGS_OBJ))
33
34 all: $(PROGS)
35
36 define TEMPLATE
37 $(2)_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$($(2)_SRC)))
38 $(1): $$($(2)_OBJ) $$(LIB)
39         $$(CC) $$(LDFLAGS) $$^ $$(LDLIBS) -o $$@
40 endef
41
42 $(foreach prog,$(PROGS),$(eval $(call TEMPLATE,$(prog),$(subst -,_,$(prog)))))
43
44 $(PROGS): $(LIB)
45
46 libc.a: $(LIB_OBJ)
47         rm -f $@
48         ar r $@ $^
49         ranlib $@
50
51 clean::
52         rm -f $(PROGS) $(PROGS_OBJ) $(PROGS_DEP)
53         rm -f $(LIB_DEP) $(LIB_OBJ) lib/user/entry.[do] libc.a 
54
55 .PHONY: all clean
56
57 -include $(LIB_DEP) $(PROGS_DEP)