core/Makefile: sort to be reproducible
[syslinux.git] / core / Makefile
blob50ff35af61f50beec3122c8d0184200c8e187366
1 ## -----------------------------------------------------------------------
2 ##
3 ## Copyright 1998-2009 H. Peter Anvin - All Rights Reserved
4 ## Copyright 2009-2016 Intel Corporation; author: H. Peter Anvin
5 ##
6 ## This program is free software; you can redistribute it and/or modify
7 ## it under the terms of the GNU General Public License as published by
8 ## the Free Software Foundation, Inc., 53 Temple Place Ste 330,
9 ## Boston MA 02111-1307, USA; either version 2 of the License, or
10 ## (at your option) any later version; incorporated herein by reference.
12 ## -----------------------------------------------------------------------
15 # Makefile for the SYSLINUX core
18 VPATH = $(SRC)
20 # No builtin rules
21 MAKEFLAGS += -r
22 MAKE += -r
24 include $(MAKEDIR)/embedded.mk
25 -include $(objdir)/version.mk
27 OPTFLAGS =
28 INCLUDES = -I$(SRC)/include -I$(com32)/include -I$(com32)/include/sys -I$(com32)/lib \
29 -I$(SRC)/lwip/src/include -I$(SRC)/lwip/src/include/ipv4 -I$(SRC)/fs/pxe
31 # This is very similar to cp437; technically it's for Norway and Denmark,
32 # but it's unlikely the characters that are different will be used in
33 # filenames by other users.
34 CODEPAGE = cp865
36 # The targets to build in this directory...
37 BTARGET = kwdhash.gen \
38 ldlinux.bss ldlinux.sys ldlinux.bin \
39 isolinux.bin isolinux-debug.bin pxelinux.0 lpxelinux.0
41 # All primary source files for the main syslinux files
42 NASMSRC := $(sort $(wildcard $(SRC)/*.asm))
43 NASMHDR := $(sort $(wildcard $(SRC)/*.inc))
44 CSRC := $(sort $(shell find $(SRC) -name '*.c' -print))
45 SSRC := $(sort $(shell find $(SRC) -name '*.S' -print))
46 CHDR := $(sort $(shell find $(SRC) -name '*.h' -print))
47 OTHERSRC := keywords
48 ALLSRC = $(NASMSRC) $(NASMHDR) $(CSRC) $(SSRC) $(CHDR) $(OTHERSRC)
50 COBJ := $(subst $(SRC)/,,$(patsubst %.c,%.o,$(CSRC)))
51 SOBJ := $(subst $(SRC)/,,$(patsubst %.S,%.o,$(SSRC)))
53 # To make this compatible with the following $(filter-out), make sure
54 # we prefix everything with $(SRC)
55 CORE_PXE_CSRC = \
56 $(addprefix $(SRC)/fs/pxe/, dhcp_option.c pxe.c tftp.c urlparse.c bios.c)
58 LPXELINUX_CSRC = $(CORE_PXE_CSRC) \
59 $(sort $(shell find $(SRC)/lwip -name '*.c' -print)) \
60 $(addprefix $(SRC)/fs/pxe/, \
61 core.c dnsresolv.c ftp.c ftp_readdir.c gpxeurl.c http.c \
62 http_readdir.c idle.c isr.c tcp.c)
64 PXELINUX_CSRC = $(CORE_PXE_CSRC) \
65 $(sort $(shell find $(SRC)/legacynet -name '*.c' -print))
67 LPXELINUX_OBJS = $(subst $(SRC)/,,$(LPXELINUX_CSRC:%.c=%.o))
68 PXELINUX_OBJS = $(subst $(SRC)/,,$(PXELINUX_CSRC:%.c=%.o))
70 UNITTEST_CSRC = $(shell find $(SRC) -path '*/tests/*.c' -print)
71 UNITTEST_OBJS = $(subst $(SRC)/,,$(UNITTEST_CSRC:%.c=%.o))
73 # Don't include console and network stack specific objects or unit tests
74 FILTER_OBJS = %rawcon.o %plaincon.o %pxelinux-c.o %ldlinux-c.o \
75 %isolinux-c.o %localboot.o %pxeboot.o \
76 $(subst $(OBJ)/,,$(UNITTEST_OBJS)) \
77 $(subst $(OBJ)/,,$(LPXELINUX_OBJS)) \
78 $(subst $(OBJ)/,,$(PXELINUX_OBJS))
80 ifeq ($(FWCLASS),EFI)
81 # EFI is single-threaded, and doesn't use the LZO assembly decoder
82 FILTER_OBJS += $(subst $(SRC)/,, \
83 $(patsubst %.S,%.o, $(sort $(wildcard $(SRC)/lzo/*.S))) \
84 $(patsubst %.c,%.o, $(sort $(wildcard $(SRC)/thread/*.c))) \
85 $(patsubst %.S,%.o, $(sort $(wildcard $(SRC)/thread/*.S)))) \
86 $(patsubst %.asm,%.o, $(sort $(wildcard $(SRC)/*.asm))) \
87 $(patsubst %.c,%.o, $(sort $(wildcard $(SRC)/bios*.c)))
88 endif
90 COBJS = $(filter-out $(FILTER_OBJS),$(COBJ))
91 SOBJS = $(filter-out $(FILTER_OBJS),$(SOBJ))
93 ifeq ($(FWCLASS),EFI)
94 COBJS += $(subst $(SRC)/,,$(CORE_PXE_CSRC:%.c=%.o) fs/pxe/ftp.o fs/pxe/ftp_readdir.o \
95 fs/pxe/http.o fs/pxe/http_readdir.o)
96 endif
98 LIB = libcom32.a
99 LIBS = $(LIB) --whole-archive $(objdir)/com32/lib/libcom32core.a
100 LIBDEP = $(filter-out -% %start%,$(LIBS))
101 LIBOBJS = $(COBJS) $(SOBJS)
103 NASMDEBUG = -g -F dwarf
104 NASMOPT += $(NASMDEBUG)
106 PREPCORE = $(OBJ)/../lzo/prepcore
108 CFLAGS += -D__SYSLINUX_CORE__ -D__FIRMWARE_$(FIRMWARE)__ \
109 -I$(objdir) -DLDLINUX=\"$(LDLINUX)\"
111 # The DATE is set on the make command line when building binaries for
112 # official release. Otherwise, substitute a hex string that is pretty much
113 # guaranteed to be unique to be unique from build to build.
114 ifndef HEXDATE
115 HEXDATE := $(shell $(PERL) $(SRC)/../now.pl $(SRCS))
116 endif
117 ifndef DATE
118 DATE := $(shell sh $(SRC)/../gen-id.sh $(VERSION) $(HEXDATE))
119 endif
121 ifeq ($(FWCLASS),EFI)
122 all: makeoutputdirs $(filter-out %bios.o,$(COBJS) $(SOBJS)) codepage.o
123 else
124 all: makeoutputdirs $(BTARGET)
125 endif
127 makeoutputdirs:
128 @mkdir -p $(sort $(dir $(COBJ) $(SOBJ)))
130 kwdhash.gen: keywords genhash.pl
131 $(PERL) $(SRC)/genhash.pl < $(SRC)/keywords > $(OBJ)/kwdhash.gen
133 ifeq ($(FWCLASS),BIOS)
135 .PRECIOUS: %.elf
136 %.raw: %.elf
137 $(OBJCOPY) -O binary -S $< $(@:.bin=.raw)
139 # GNU make 3.82 gets confused by plain %.raw; make 4.0 requires it
140 .PRECIOUS: $(OBJ)/%.raw %.raw
141 %.bin: %.raw $(PREPCORE)
142 $(PREPCORE) $< $@
144 %.o: %.asm kwdhash.gen $(OBJ)/../version.gen
145 $(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
146 -DHEXDATE="$(HEXDATE)" \
147 -D$(ARCH) \
148 -I$(SRC)/ \
149 -l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
151 AUXLIBS = libisolinux.a libisolinux-debug.a libldlinux.a \
152 libpxelinux.a liblpxelinux.a
154 LDSCRIPT = $(SRC)/$(ARCH)/syslinux.ld
156 NASM_ELF = elf
158 %.elf: %.o $(LIBDEP) $(LDSCRIPT) $(AUXLIBS)
159 $(LD) $(LDFLAGS) -pie -Bsymbolic \
160 -T $(LDSCRIPT) \
161 --unresolved-symbols=report-all \
162 -E --hash-style=gnu -M -o $@ $< \
163 --start-group $(LIBS) $(subst $(*F).elf,lib$(*F).a,$@) --end-group \
164 > $(@:.elf=.map)
165 if [ `$(NM) -D -u $@ | wc -l` -ne 0 ]; then \
166 $(NM) -D -u $@ 1>&2; rm -f $@; false; fi
167 $(OBJDUMP) -h $@ > $(@:.elf=.sec)
168 $(PERL) $(SRC)/lstadjust.pl $(@:.elf=.lsr) $(@:.elf=.sec) $(@:.elf=.lst)
170 libisolinux.a: rawcon.o localboot.o isolinux-c.o
171 rm -f $@
172 $(AR) cq $@ $^
173 $(RANLIB) $@
175 libisolinux-debug.a: libisolinux.a
176 cp $^ $@
178 # Legacy network stack
179 libpxelinux.a: rawcon.o pxeboot.o pxelinux-c.o $(PXELINUX_OBJS)
180 rm -f $@
181 $(AR) cq $@ $^
182 $(RANLIB) $@
184 # LwIP network stack
185 liblpxelinux.a: rawcon.o pxeboot.o pxelinux-c.o $(LPXELINUX_OBJS)
186 rm -f $@
187 $(AR) cq $@ $^
188 $(RANLIB) $@
190 libldlinux.a: plaincon.o localboot.o ldlinux-c.o
191 rm -f $@
192 $(AR) cq $@ $^
193 $(RANLIB) $@
195 pxelinux.o: pxelinux.asm kwdhash.gen ../version.gen
196 $(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
197 -DHEXDATE="$(HEXDATE)" \
198 -D$(ARCH) \
199 -I$(SRC)/ \
200 -DIS_LPXELINUX=0 \
201 -l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
203 pxelinux.0: pxelinux.bin
204 cp -f $< $@
206 lpxelinux.o: pxelinux.asm kwdhash.gen ../version.gen
207 $(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
208 -DHEXDATE="$(HEXDATE)" \
209 -D$(ARCH) \
210 -I$(SRC)/ \
211 -DIS_LPXELINUX=1 \
212 -l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
214 lpxelinux.0: lpxelinux.bin
215 cp -f $< $@
217 ldlinux.bss: ldlinux.bin
218 dd if=$< of=$@ bs=512 count=1
220 ldlinux.sys: ldlinux.bin
221 dd if=$< of=$@ bs=512 skip=2
223 endif # BIOS
225 $(LIB): $(LIBOBJS)
226 rm -f $@
227 $(AR) cq $@ $^
228 $(RANLIB) $@
230 codepage.cp: $(OBJ)/../codepage/$(CODEPAGE).cp
231 cp -f $< $@
233 codepage.o: codepage.S codepage.cp
235 install: installer
237 install-lib: installer
239 install-all: install install-lib
241 netinstall: installer
243 tidy dist:
244 find . -type f \( -name '*.o' -o -name '*.a' -o -name '.*.d' \
245 -o -name '*.lst' \) -print | xargs -rt rm -f
246 rm -f codepage.cp *.elf stupid.* patch.offset .depend
247 rm -f *.elf.tmp *.sym
248 rm -f *.lsr *.map *.sec *.raw
249 rm -f $(OBSOLETE) $(LIB)
251 clean: tidy
253 spotless: clean
254 rm -f $(BTARGET) *.bin *_bin.c
256 # Include dependencies file
257 -include $(shell find . -name '.*.d' -print)