include: BIT64 should always produce a uint64_t
[hvf.git] / build.mk
blob90700cd853c4b396cdf5484e12415554692cbf62
2 # Copyright (c) 2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 # SOFTWARE.
23 HVF_VERSION= 0.16-rc3
25 SRCTOP!= hg root
27 OBJCOPY= s390x-linux-objcopy
28 SECTIONS?= .text .data .rodata .rodata.str1.2
30 CC= s390x-linux-gcc
31 CPPFLAGS.ALL= -DVERSION="\"$(HVF_VERSION)\"" \
32 -I $(SRCTOP)/include \
33 -include $(SRCTOP)/include/types.h \
34 $(DEFS)
35 CPPFLAGS.31= $(CPPFLAGS.ALL)
36 CPPFLAGS.64= $(CPPFLAGS.ALL)
37 CFLAGS.ALL= -Wall \
38 -O2 \
39 -g \
40 -m$(BITS) \
41 -mbackchain \
42 -msoft-float \
43 -fno-strict-aliasing \
44 -fno-builtin \
45 -nostartfiles \
46 -nostdlib \
47 -nostdinc
48 CFLAGS.31= $(CFLAGS.ALL) $(CPPFLAGS.31)
49 CFLAGS.64= $(CFLAGS.ALL) $(CPPFLAGS.64)
51 LD= s390x-linux-ld
52 LINKER_SCRIPT= linker.script
53 LDFLAGS.ALL= -T$(LINKER_SCRIPT)
54 LDFLAGS.31= $(LDFLAGS.ALL) -melf_s390
55 LDFLAGS.64= $(LDFLAGS.ALL) -melf64_s390
57 AR= s390x-linux-ar
59 C_SRCS:=${SRCS:M*.c}
60 S_SRCS:=${SRCS:M*.s}
61 Y_SRCS:=${SRCS:M*.y}
62 L_SRCS:=${SRCS:M*.l}
64 GENSRCS:=${Y_SRCS:C/\.y$/.c/} \
65 ${L_SRCS:C/\.l$/.c/}
66 GENHDRS:=${Y_SRCS:C/\.y$/.h/} \
67 ${L_SRCS:C/\.l$/.h/}
69 OBJS:=${C_SRCS:%.c=%.o} \
70 ${S_SRCS:%.s=%.o} \
71 ${GENSRCS:%.c=%.o}
73 all: bin lib
75 clean:
76 .if defined(BIN)
77 rm -f $(BIN) $(BIN).raw
78 .endif
79 .if defined(LIB)
80 rm -f $(LIB).a
81 .endif
82 rm -f $(OBJS) $(CLEANSRCS)
83 .if !empty(GENSRCS) || !empty(GENHDRS)
84 rm -f $(GENSRCS) $(GENHDRS)
85 .endif
87 .if defined(BIN)
88 bin: $(BIN)
89 $(BIN): $(OBJS) $(LINKER_SCRIPT)
90 $(LD) $(LDFLAGS.$(BITS)) -o $(BIN) $(OBJS) $(LD_ADD)
92 $(BIN).raw: $(BIN)
93 $(OBJCOPY) -O binary ${SECTIONS:%=-j %} ${.ALLSRC} ${.TARGET}
94 .else
95 bin:
96 .endif
98 .if defined(LIB)
99 lib: $(LIB).a
100 $(LIB).a: $(OBJS)
101 $(AR) cr ${.TARGET} ${.ALLSRC}
102 .else
103 lib:
104 .endif()
106 # remove built-in .[yl] -> .o rules
107 .y.o:
108 .l.o:
110 .c.o:
111 $(CC) $(CFLAGS.$(BITS)) -c -o ${.TARGET} ${.IMPSRC}
113 .s.o:
114 $(CC) $(CFLAGS.$(BITS)) -D_ASM -x assembler-with-cpp -c -o ${.TARGET} ${.IMPSRC}
116 .y.c:
117 cd ${.IMPSRC:H} && $(SRCTOP)/build/byacc/yacc \
118 -b ${.IMPSRC:T:R} \
119 -d -P -p ${.IMPSRC:T:R:S/grammar//} \
120 -o ${.IMPSRC:T:R}.c ${.IMPSRC:T}
122 .l.c:
123 cd ${.IMPSRC:H} && $(SRCTOP)/build/re2c/re2c \
124 -o ${.IMPSRC:T:R}.c ${.IMPSRC:T}