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