pintos: Avoid literal control character in Perl variable name.
[pintos-anon] / src / Makefile.userprog
1 # -*- makefile -*-
2
3 $(PROGS): CPPFLAGS += -I$(SRCDIR)/lib/user -I.
4
5 # Linker flags.
6 $(PROGS): LDFLAGS += -nostdlib -static -Wl,-T,$(LDSCRIPT)
7 $(PROGS): LDSCRIPT = $(SRCDIR)/lib/user/user.lds
8
9 # Library code shared between kernel and user programs.
10 lib_SRC  = lib/debug.c                  # Debug code.
11 lib_SRC += lib/random.c                 # Pseudo-random numbers.
12 lib_SRC += lib/stdio.c                  # I/O library.
13 lib_SRC += lib/stdlib.c                 # Utility functions.
14 lib_SRC += lib/string.c                 # String functions.
15 lib_SRC += lib/arithmetic.c             # 64-bit arithmetic for GCC.
16 lib_SRC += lib/ustar.c                  # Unix standard tar format utilities.
17
18 # User level only library code.
19 lib/user_SRC  = lib/user/debug.c        # Debug helpers.
20 lib/user_SRC += lib/user/syscall.c      # System calls.
21 lib/user_SRC += lib/user/console.c      # Console code.
22
23 LIB_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(lib_SRC) $(lib/user_SRC)))
24 LIB_DEP = $(patsubst %.o,%.d,$(LIB_OBJ))
25 LIB = lib/user/entry.o libc.a
26
27 PROGS_SRC = $(foreach prog,$(PROGS),$($(prog)_SRC))
28 PROGS_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(PROGS_SRC)))
29 PROGS_DEP = $(patsubst %.o,%.d,$(PROGS_OBJ))
30
31 all: $(PROGS)
32
33 define TEMPLATE
34 $(1)_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$($(1)_SRC)))
35 $(1): $$($(1)_OBJ) $$(LIB) $$(LDSCRIPT)
36         $$(CC) $$(LDFLAGS) $$($(1)_OBJ) $$(LIB) -o $$@
37 endef
38
39 $(foreach prog,$(PROGS),$(eval $(call TEMPLATE,$(prog))))
40
41 libc.a: $(LIB_OBJ)
42         rm -f $@
43         ar r $@ $^
44         ranlib $@
45
46 clean::
47         rm -f $(PROGS) $(PROGS_OBJ) $(PROGS_DEP)
48         rm -f $(LIB_DEP) $(LIB_OBJ) lib/user/entry.[do] libc.a 
49
50 .PHONY: all clean
51
52 -include $(LIB_DEP) $(PROGS_DEP)