Make tests public. Rewrite most tests. Add tests.
[pintos-anon] / src / Makefile.userprog
1 # -*- makefile -*-
2
3 include $(SRCDIR)/Make.config
4
5 $(PROGS): CPPFLAGS += -I$(SRCDIR)/lib/user -I.
6
7 # Linker flags.
8 $(PROGS): LDFLAGS = -nostdlib -static -Wl,-T,$(LDSCRIPT)
9 $(PROGS): LDLIBS = $(shell $(CC) -print-libgcc-file-name)
10 $(PROGS): LDSCRIPT = $(SRCDIR)/lib/user/normal.lds
11 # Uncomment the following line to round up section sizes
12 # to full pages (for debugging only).
13 #$(PROGS): LDSCRIPT = $(SRCDIR)/lib/user/fullpage.lds
14
15 # Library code shared between kernel and user programs.
16 lib_SRC  = lib/debug.c                  # Debug code.
17 lib_SRC += lib/random.c                 # Pseudo-random numbers.
18 lib_SRC += lib/stdio.c                  # I/O library.
19 lib_SRC += lib/stdlib.c                 # Utility functions.
20 lib_SRC += lib/string.c                 # String functions.
21
22 # User level only library code.
23 lib/user_SRC  = lib/user/debug.c        # Debug helpers.
24 lib/user_SRC += lib/user/syscall.c      # System calls.
25 lib/user_SRC += lib/user/console.c      # Console code.
26
27 LIB_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(lib_SRC) $(lib/user_SRC)))
28 LIB_DEP = $(patsubst %.o,%.d,$(LIB_OBJ))
29 LIB = lib/user/entry.o libc.a
30
31 PROGS_SRC = $(foreach prog,$(PROGS),$($(prog)_SRC))
32 PROGS_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(PROGS_SRC)))
33 PROGS_DEP = $(patsubst %.o,%.d,$(PROGS_OBJ))
34
35 all: $(PROGS)
36
37 define TEMPLATE
38 $(1)_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$($(1)_SRC)))
39 $(1): $$($(1)_OBJ) $$(LIB) $$(LDSCRIPT)
40         $$(CC) $$(LDFLAGS) $$($(1)_OBJ) $$(LIB) $$(LDLIBS) -o $$@
41 endef
42
43 $(foreach prog,$(PROGS),$(eval $(call TEMPLATE,$(prog))))
44
45 libc.a: $(LIB_OBJ)
46         rm -f $@
47         ar r $@ $^
48         ranlib $@
49
50 clean::
51         rm -f $(PROGS) $(PROGS_OBJ) $(PROGS_DEP)
52         rm -f $(LIB_DEP) $(LIB_OBJ) lib/user/entry.[do] libc.a 
53
54 .PHONY: all clean
55
56 -include $(LIB_DEP) $(PROGS_DEP)