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