• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1## -----------------------------------------------------------------------
2##
3##   Copyright 1998-2009 H. Peter Anvin - All Rights Reserved
4##   Copyright 2009-2014 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.
11##
12## -----------------------------------------------------------------------
13
14#
15# Makefile for the SYSLINUX core
16#
17
18VPATH = $(SRC)
19
20# No builtin rules
21MAKEFLAGS += -r
22MAKE      += -r
23
24include $(MAKEDIR)/embedded.mk
25-include $(objdir)/version.mk
26
27OPTFLAGS =
28INCLUDES = -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
30
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.
34CODEPAGE = cp865
35
36# The targets to build in this directory...
37BTARGET  = kwdhash.gen \
38	   ldlinux.bss ldlinux.sys ldlinux.bin \
39	   isolinux.bin isolinux-debug.bin pxelinux.0 lpxelinux.0
40
41# All primary source files for the main syslinux files
42NASMSRC	 := $(wildcard $(SRC)/*.asm)
43NASMHDR  := $(wildcard $(SRC)/*.inc)
44CSRC	 := $(shell find $(SRC) -name '*.c' -print)
45SSRC	 := $(shell find $(SRC) -name '*.S' -print)
46CHDR	 := $(shell find $(SRC) -name '*.h' -print)
47OTHERSRC := keywords
48ALLSRC    = $(NASMSRC) $(NASMHDR) $(CSRC) $(SSRC) $(CHDR) $(OTHERSRC)
49
50COBJ	 := $(subst $(SRC)/,,$(patsubst %.c,%.o,$(CSRC)))
51SOBJ	 := $(subst $(SRC)/,,$(patsubst %.S,%.o,$(SSRC)))
52
53# To make this compatible with the following $(filter-out), make sure
54# we prefix everything with $(SRC)
55CORE_PXE_CSRC = \
56	$(addprefix $(SRC)/fs/pxe/, dhcp_option.c pxe.c tftp.c urlparse.c bios.c)
57
58LPXELINUX_CSRC = $(CORE_PXE_CSRC) \
59	$(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)
63
64PXELINUX_CSRC = $(CORE_PXE_CSRC) \
65	$(shell find $(SRC)/legacynet -name '*.c' -print)
66
67LPXELINUX_OBJS = $(subst $(SRC)/,,$(LPXELINUX_CSRC:%.c=%.o))
68PXELINUX_OBJS  = $(subst $(SRC)/,,$(PXELINUX_CSRC:%.c=%.o))
69
70UNITTEST_CSRC = $(shell find $(SRC) -path '*/tests/*.c' -print)
71UNITTEST_OBJS = $(subst $(SRC)/,,$(UNITTEST_CSRC:%.c=%.o))
72
73# Don't include console and network stack specific objects or unit tests
74FILTER_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))
79
80ifdef EFI_BUILD
81# EFI is single-threaded, and doesn't use the LZO assembly decoder
82FILTER_OBJS += $(subst $(SRC)/,, \
83	$(patsubst %.S,%.o, $(wildcard $(SRC)/lzo/*.S)) \
84	$(patsubst %.c,%.o, $(wildcard $(SRC)/thread/*.c)) \
85	$(patsubst %.S,%.o, $(wildcard $(SRC)/thread/*.S)))
86endif
87
88COBJS	 = $(filter-out $(FILTER_OBJS),$(COBJ))
89SOBJS	 = $(filter-out $(FILTER_OBJS),$(SOBJ))
90
91ifdef EFI_BUILD
92COBJS += $(subst $(SRC)/,,$(CORE_PXE_CSRC:%.c=%.o) fs/pxe/ftp.o fs/pxe/ftp_readdir.o \
93	fs/pxe/http.o fs/pxe/http_readdir.o)
94endif
95
96LIB	 = libcom32.a
97LIBS	 = $(LIB) --whole-archive $(objdir)/com32/lib/libcom32core.a
98LIBDEP   = $(filter-out -% %start%,$(LIBS))
99LIBOBJS	 = $(COBJS) $(SOBJS)
100
101NASMDEBUG = -g -F dwarf
102NASMOPT  += $(NASMDEBUG)
103
104PREPCORE = $(OBJ)/../lzo/prepcore
105
106CFLAGS += -D__SYSLINUX_CORE__ -D__FIRMWARE_$(FIRMWARE)__ \
107	  -I$(objdir) -DLDLINUX=\"$(LDLINUX)\"
108
109# The DATE is set on the make command line when building binaries for
110# official release.  Otherwise, substitute a hex string that is pretty much
111# guaranteed to be unique to be unique from build to build.
112ifndef HEXDATE
113HEXDATE := $(shell $(PERL) $(SRC)/../now.pl $(SRCS))
114endif
115ifndef DATE
116DATE    := $(shell sh $(SRC)/../gen-id.sh $(VERSION) $(HEXDATE))
117endif
118
119# Set up the NASM and LD options for the architecture
120NASM_ELF = "unknown"
121LD_PIE = "unknown"
122ifeq ($(ARCH),i386)
123	NASM_ELF = elf
124	LD_PIE = -pie
125endif
126ifeq ($(ARCH),x86_64)
127	NASM_ELF = elf64
128	#LD_PIE = --pic-executable
129	LD_PIE =
130endif
131
132ifdef EFI_BUILD
133all: makeoutputdirs $(filter-out %bios.o,$(COBJS) $(SOBJS)) codepage.o
134else
135all: makeoutputdirs $(BTARGET)
136endif
137
138makeoutputdirs:
139	@mkdir -p $(sort $(dir $(COBJ) $(SOBJ)))
140
141kwdhash.gen: keywords genhash.pl
142	$(PERL) $(SRC)/genhash.pl < $(SRC)/keywords > $(OBJ)/kwdhash.gen
143
144.PRECIOUS: %.elf
145
146%.raw: %.elf
147	$(OBJCOPY) -O binary -S $< $(@:.bin=.raw)
148
149# GNU make 3.82 gets confused by the first form
150.PRECIOUS: $(OBJ)/%.raw
151
152%.bin: %.raw $(PREPCORE)
153	$(PREPCORE) $< $@
154
155%.o: %.asm kwdhash.gen $(OBJ)/../version.gen
156	$(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
157		-DHEXDATE="$(HEXDATE)" \
158		-D$(ARCH) \
159		-I$(SRC)/ \
160		-l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
161
162AUXLIBS = libisolinux.a libisolinux-debug.a libldlinux.a \
163	libpxelinux.a liblpxelinux.a
164LDSCRIPT = $(SRC)/$(ARCH)/syslinux.ld
165
166%.elf: %.o $(LIBDEP) $(LDSCRIPT) $(AUXLIBS)
167	$(LD) $(LDFLAGS) -Bsymbolic $(LD_PIE) -E --hash-style=gnu -T $(LDSCRIPT) -M -o $@ $< \
168		--start-group $(LIBS) $(subst $(*F).elf,lib$(*F).a,$@) --end-group \
169		> $(@:.elf=.map)
170	$(OBJDUMP) -h $@ > $(@:.elf=.sec)
171	$(PERL) $(SRC)/lstadjust.pl $(@:.elf=.lsr) $(@:.elf=.sec) $(@:.elf=.lst)
172
173libisolinux.a: rawcon.o localboot.o isolinux-c.o
174	rm -f $@
175	$(AR) cq $@ $^
176	$(RANLIB) $@
177
178libisolinux-debug.a: libisolinux.a
179	cp $^ $@
180
181# Legacy network stack
182libpxelinux.a: rawcon.o pxeboot.o pxelinux-c.o $(PXELINUX_OBJS)
183	rm -f $@
184	$(AR) cq $@ $^
185	$(RANLIB) $@
186
187# LwIP network stack
188liblpxelinux.a: rawcon.o pxeboot.o pxelinux-c.o $(LPXELINUX_OBJS)
189	rm -f $@
190	$(AR) cq $@ $^
191	$(RANLIB) $@
192
193libldlinux.a: plaincon.o localboot.o ldlinux-c.o
194	rm -f $@
195	$(AR) cq $@ $^
196	$(RANLIB) $@
197
198$(LIB): $(LIBOBJS)
199	rm -f $@
200	$(AR) cq $@ $^
201	$(RANLIB) $@
202
203pxelinux.o: pxelinux.asm kwdhash.gen ../version.gen
204	$(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
205		-DHEXDATE="$(HEXDATE)" \
206		-D$(ARCH) \
207		-I$(SRC)/ \
208		-DIS_LPXELINUX=0 \
209		-l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
210
211pxelinux.0: pxelinux.bin
212	cp -f $< $@
213
214lpxelinux.o: pxelinux.asm kwdhash.gen ../version.gen
215	$(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
216		-DHEXDATE="$(HEXDATE)" \
217		-D$(ARCH) \
218		-I$(SRC)/ \
219		-DIS_LPXELINUX=1 \
220		-l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
221
222lpxelinux.0: lpxelinux.bin
223	cp -f $< $@
224
225ldlinux.bss: ldlinux.bin
226	dd if=$< of=$@ bs=512 count=1
227
228ldlinux.sys: ldlinux.bin
229	dd if=$< of=$@ bs=512 skip=2
230
231codepage.cp: $(OBJ)/../codepage/$(CODEPAGE).cp
232	cp -f $< $@
233
234codepage.o: codepage.S codepage.cp
235
236install: installer
237
238install-lib: installer
239
240install-all: install install-lib
241
242netinstall: installer
243
244tidy dist:
245	find . -type f \( -name '*.o' -o -name '*.a' -o -name '.*.d' \
246		-o -name '*.lst' \) -print | xargs -rt rm -f
247	rm -f codepage.cp *.elf stupid.* patch.offset .depend
248	rm -f *.elf.tmp *.sym
249	rm -f *.lsr *.map *.sec *.raw
250	rm -f $(OBSOLETE) $(LIB)
251
252clean: tidy
253
254spotless: clean
255	rm -f $(BTARGET) *.bin *_bin.c
256
257# Include dependencies file
258-include $(shell find . -name '.*.d' -print)
259