master
text 139 lines 4.59 KB
Raw
1 all: build-all
2 # Dummy command so that make thinks it has done something
3 @true
4
5 include config-host.mak
6 CFLAGS = -O2 -g -I $(SRC_PATH)/../../include/hw/s390x/ipl
7 LDFLAGS ?=
8 MAKEFLAGS += -rR
9
10 GIT_SUBMODULES = roms/SLOF
11
12 NULL :=
13 SPACE := $(NULL) #
14 TARGET_PREFIX := $(patsubst %/,%:$(SPACE),$(TARGET_DIR))
15
16 quiet-@ = $(if $(V),,@$(if $1,printf "%s\n" "$(TARGET_PREFIX)$1" && ))
17 quiet-command = $(call quiet-@,$2 $@)$1
18
19 VPATH_SUFFIXES = %.c %.h %.S %.m %.mak %.sh %.rc Kconfig% %.json.in
20 set-vpath = $(if $1,$(foreach PATTERN,$(VPATH_SUFFIXES),$(eval vpath $(PATTERN) $1)))
21 $(call set-vpath, $(SRC_PATH))
22
23 # Flags for dependency generation
24 QEMU_DGFLAGS = -MMD -MP -MT $@ -MF $(@D)/$(*F).d
25
26 %.o: %.c
27 $(call quiet-command,$(CC) $(EXTRA_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) \
28 -c -o $@ $<,Compiling)
29
30 %.o: %.S
31 $(call quiet-command,$(CCAS) $(EXTRA_CFLAGS) $(QEMU_DGFLAGS) $(CFLAGS) \
32 -c -o $@ $<,Assembling)
33
34 .PHONY : all clean build-all distclean
35
36 OBJECTS = start.o main.o bootmap.o jump2ipl.o sclp.o menu.o netmain.o \
37 virtio.o virtio-net.o virtio-scsi.o virtio-blkdev.o cio.o dasd-ipl.o \
38 virtio-ccw.o clp.o pci.o virtio-pci.o secure-ipl.o
39
40 SLOF_DIR := $(SRC_PATH)/../../roms/SLOF
41
42 LIBC_INC := -nostdinc -I$(SLOF_DIR)/lib/libc/include
43 LIBNET_INC := -I$(SLOF_DIR)/lib/libnet
44
45 EXTRA_CFLAGS += -Wall
46 EXTRA_CFLAGS += -ffreestanding -fno-delete-null-pointer-checks -fno-common -fPIE
47 EXTRA_CFLAGS += -fwrapv -fno-strict-aliasing -fno-asynchronous-unwind-tables
48 EXTRA_CFLAGS += -msoft-float
49 EXTRA_CFLAGS += -std=gnu99
50 EXTRA_CFLAGS += $(LIBC_INC) $(LIBNET_INC)
51 EXTRA_LDFLAGS += -static-pie -nostdlib -z noexecstack -z text
52
53 cc-test = $(CC) -Werror $1 -c -o /dev/null -xc /dev/null >/dev/null 2>/dev/null
54 cc-option = if $(call cc-test, $1); then \
55 echo "$(TARGET_PREFIX)$1 detected" && echo "EXTRA_CFLAGS += $1" >&3; else \
56 echo "$(TARGET_PREFIX)$1 not detected" $(if $2,&& echo "EXTRA_CFLAGS += $2" >&3); fi
57
58 config-cc.mak: Makefile
59 $(quiet-@)($(call cc-option,-Wno-stringop-overflow); \
60 $(call cc-option,-fno-stack-protector); \
61 $(call cc-option,-Wno-array-bounds); \
62 $(call cc-option,-Wno-gnu); \
63 $(call cc-option,-march=z900,-march=z10)) 3> config-cc.mak
64 -include config-cc.mak
65
66 # libc files:
67
68 LIBC_CFLAGS = $(EXTRA_CFLAGS) $(CFLAGS) $(LIBC_INC) $(LIBNET_INC) \
69 -MMD -MP -MT $@ -MF $(@:%.o=%.d)
70
71 CTYPE_OBJS = isdigit.o isxdigit.o toupper.o
72 %.o : $(SLOF_DIR)/lib/libc/ctype/%.c
73 $(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
74
75 STRING_OBJS = strcat.o strchr.o strrchr.o strcpy.o strlen.o strncpy.o \
76 strcmp.o strncmp.o strcasecmp.o strncasecmp.o strstr.o \
77 memset.o memcpy.o memmove.o memcmp.o
78 %.o : $(SLOF_DIR)/lib/libc/string/%.c
79 $(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
80
81 STDLIB_OBJS = atoi.o atol.o strtoul.o strtol.o rand.o malloc.o free.o
82 %.o : $(SLOF_DIR)/lib/libc/stdlib/%.c
83 $(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
84
85 STDIO_OBJS = sprintf.o snprintf.o vfprintf.o vsnprintf.o vsprintf.o fprintf.o \
86 printf.o putc.o puts.o putchar.o stdchnls.o fileno.o
87 %.o : $(SLOF_DIR)/lib/libc/stdio/%.c
88 $(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
89
90 sbrk.o: $(SLOF_DIR)/slof/sbrk.c
91 $(call quiet-command,$(CC) $(LIBC_CFLAGS) -c -o $@ $<,Compiling)
92
93 LIBCOBJS := $(STRING_OBJS) $(CTYPE_OBJS) $(STDLIB_OBJS) $(STDIO_OBJS) sbrk.o
94
95 libc.a: $(LIBCOBJS)
96 $(call quiet-command,$(AR) -rc $@ $^,Creating static library)
97
98 # libnet files:
99
100 LIBNETOBJS := args.o dhcp.o dns.o icmpv6.o ipv6.o tcp.o udp.o bootp.o \
101 dhcpv6.o ethernet.o ipv4.o ndp.o tftp.o pxelinux.o
102 LIBNETCFLAGS = $(EXTRA_CFLAGS) $(CFLAGS) $(LIBC_INC) $(LIBNET_INC) \
103 -DDHCPARCH=0x1F -MMD -MP -MT $@ -MF $(@:%.o=%.d)
104
105 %.o : $(SLOF_DIR)/lib/libnet/%.c
106 $(call quiet-command,$(CC) $(LIBNETCFLAGS) -c -o $@ $<,Compiling)
107
108 libnet.a: $(LIBNETOBJS)
109 $(call quiet-command,$(AR) -rc $@ $^,Creating static library)
110
111 # Main targets:
112
113 build-all: s390-ccw.img
114
115 s390-ccw.elf: $(OBJECTS) libnet.a libc.a
116 $(call quiet-command,$(CC) $(EXTRA_LDFLAGS) $(LDFLAGS) -o $@ $^,Linking)
117
118 s390-ccw.img: s390-ccw.elf
119 $(call quiet-command,$(STRIP) --strip-unneeded $< -o $@,Stripping $< into)
120
121 $(OBJECTS): Makefile
122
123 ALL_OBJS = $(sort $(OBJECTS) $(LIBCOBJS) $(LIBNETOBJS))
124 -include $(ALL_OBJS:%.o=%.d)
125
126 clean:
127 rm -f *.o *.d *.img *.elf *~ *.a
128
129 distclean:
130 rm -f config-cc.mak
131
132 .PHONY: git-submodule-update
133 $(SRC_PATH)/../../.git-submodule-status: git-submodule-update config-host.mak
134 Makefile: $(SRC_PATH)/../../.git-submodule-status
135
136 git-submodule-update:
137 ifneq ($(GIT_SUBMODULES_ACTION),ignore)
138 $(quiet-@)GIT=git "$(SRC_PATH)/../../scripts/git-submodule.sh" $(GIT_SUBMODULES_ACTION) $(GIT_SUBMODULES)
139 endif