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