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