3b35616d6bae0eded022f8dfb347ae144477cb06
[pintos-anon] / src / tests / userprog / Makefile
1 include ../../Make.config
2
3 SHELL = /bin/sh
4
5 LDFLAGS = -nostdlib -static
6 LDLIBS = $(shell $(CC) -print-libgcc-file-name)
7
8 # Uncomment the line below to round up segment sizes to full pages for
9 # testing purposes only.
10 #LDFLAGS += -Wl,-T,fullpage.x
11
12 VPATH = ../..
13
14 DEFINES = -DUSER
15 CPPFLAGS = -nostdinc -I../.. -I- -I../../lib -I../../lib/user
16
17 # C library sources linked into every test program.
18 LIB_SRC  = lib/debug.c                  # Debug code.
19 LIB_SRC += lib/random.c                 # Pseudo-random numbers.
20 LIB_SRC += lib/stdio.c                  # I/O library.
21 LIB_SRC += lib/stdlib.c                 # atoi()
22 LIB_SRC += lib/string.c                 # String functions.
23 LIB_SRC += lib/user/syscall.c           # System calls.
24 LIB_SRC += lib/user/syscall-stub.S      # System call stub.
25 LIB_SRC += lib/user/console.c           # Console code.
26
27 LIB_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(LIB_SRC)))
28 LIB_DEP = $(patsubst %.o,%.d,$(LIB_OBJ))
29 LIB = libc.a lib/user/entry.o
30
31 PROGS = bubsort echo halt insult lineup matmult recursor shell
32 bubsort_SRC = bubsort.c
33 echo_SRC = echo.c
34 halt_SRC = halt.c
35 insult_SRC = insult.c
36 lineup_SRC = lineup.c
37 matmult_SRC = matmult.c
38 recursor_SRC = recursor.c
39 shell_SRC = shell.c
40
41 PROGS_SRC = $(foreach prog,$(PROGS),$($(prog)_SRC))
42 PROGS_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(PROGS_SRC)))
43 PROGS_DEP = $(patsubst %.o,%.d,$(PROGS_OBJ))
44
45 all: $(PROGS)
46
47 define TEMPLATE
48 $(1)_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$($(1)_SRC)))
49 $(1): $$($(1)_OBJ) $$(LIB) | ./lib/user
50 endef
51
52 ./lib/user:
53         $(MKDIR) -p lib/user
54
55 $(foreach prog,$(PROGS),$(eval $(call TEMPLATE,$(prog))))
56
57 $(PROGS): $(LIB)
58
59 libc.a: $(LIB_OBJ)
60         rm -f $@
61         ar r $@ $^
62         ranlib $@
63
64 clean:
65         rm -f $(PROGS) $(PROGS_OBJ) $(PROGS_DEP)
66         rm -f $(LIB_DEP) $(LIB_OBJ) lib/user/entry.[do] libc.a 
67
68 .PHONY: all clean
69
70 -include $(LIB_DEP) $(PROGS_DEP)