Check for the compiler's availability early in the `make' run, in
[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): LDLIBS = $(shell $(CC) -print-libgcc-file-name)
8 $(PROGS): LDSCRIPT = $(SRCDIR)/lib/user/normal.lds
9 # Uncomment the following line to round up section sizes
10 # to full pages (for debugging only).
11 #$(PROGS): LDSCRIPT = $(SRCDIR)/lib/user/fullpage.lds
12
13 # Library code shared between kernel and user programs.
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                 # Utility functions.
18 lib_SRC += lib/string.c                 # String functions.
19
20 # User level only library code.
21 lib/user_SRC  = lib/user/debug.c        # Debug helpers.
22 lib/user_SRC += lib/user/syscall.c      # System calls.
23 lib/user_SRC += lib/user/console.c      # Console code.
24
25 LIB_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(lib_SRC) $(lib/user_SRC)))
26 LIB_DEP = $(patsubst %.o,%.d,$(LIB_OBJ))
27 LIB = lib/user/entry.o libc.a
28
29 PROGS_SRC = $(foreach prog,$(PROGS),$($(prog)_SRC))
30 PROGS_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$(PROGS_SRC)))
31 PROGS_DEP = $(patsubst %.o,%.d,$(PROGS_OBJ))
32
33 all: $(PROGS)
34
35 define TEMPLATE
36 $(1)_OBJ = $(patsubst %.c,%.o,$(patsubst %.S,%.o,$($(1)_SRC)))
37 $(1): $$($(1)_OBJ) $$(LIB) $$(LDSCRIPT)
38         $$(CC) $$(LDFLAGS) $$($(1)_OBJ) $$(LIB) $$(LDLIBS) -o $$@
39 endef
40
41 $(foreach prog,$(PROGS),$(eval $(call TEMPLATE,$(prog))))
42
43 libc.a: $(LIB_OBJ)
44         rm -f $@
45         ar r $@ $^
46         ranlib $@
47
48 clean::
49         rm -f $(PROGS) $(PROGS_OBJ) $(PROGS_DEP)
50         rm -f $(LIB_DEP) $(LIB_OBJ) lib/user/entry.[do] libc.a 
51
52 .PHONY: all clean
53
54 -include $(LIB_DEP) $(PROGS_DEP)