Merge branch 'nocomapi'
[syslinux/sherbszt.git] / core / Makefile
blob14c10c2a6ff8b4e6194b2b57c1e7e3fcbe1107fe
1 ## -----------------------------------------------------------------------
2 ##
3 ## Copyright 1998-2009 H. Peter Anvin - All Rights Reserved
4 ## Copyright 2009-2010 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 := $(wildcard $(SRC)/*.asm)
43 NASMHDR := $(wildcard $(SRC)/*.inc)
44 CSRC := $(shell find $(SRC) -name '*.c' -print)
45 SSRC := $(shell find $(SRC) -name '*.S' -print)
46 CHDR := $(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 $(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 $(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 ifdef EFI_BUILD
81 # EFI is single-threaded.
82 FILTER_OBJS += $(subst $(SRC)/,, \
83 $(patsubst %.c,%.o, $(wildcard $(SRC)/thread/*.c)) \
84 $(patsubst %.S,%.o, $(wildcard $(SRC)/thread/*.S)))
85 endif
87 COBJS = $(filter-out $(FILTER_OBJS),$(COBJ))
88 SOBJS = $(filter-out $(FILTER_OBJS),$(SOBJ))
90 ifdef EFI_BUILD
91 COBJS += $(subst $(SRC)/,,$(CORE_PXE_CSRC:%.c=%.o) fs/pxe/ftp.o fs/pxe/ftp_readdir.o \
92 fs/pxe/http.o fs/pxe/http_readdir.o)
93 endif
95 LIB = libcom32.a
96 LIBS = $(LIB) --whole-archive $(objdir)/com32/lib/libcom32core.a
97 LIBDEP = $(filter-out -% %start%,$(LIBS))
98 LIBOBJS = $(COBJS) $(SOBJS)
100 NASMDEBUG = -g -F dwarf
101 NASMOPT += $(NASMDEBUG)
103 PREPCORE = $(OBJ)/../lzo/prepcore
105 CFLAGS += -D__SYSLINUX_CORE__ -D__FIRMWARE_$(FIRMWARE)__ \
106 -I$(objdir) -DLDLINUX=\"$(LDLINUX)\"
108 # The DATE is set on the make command line when building binaries for
109 # official release. Otherwise, substitute a hex string that is pretty much
110 # guaranteed to be unique to be unique from build to build.
111 ifndef HEXDATE
112 HEXDATE := $(shell $(PERL) $(SRC)/../now.pl $(SRCS))
113 endif
114 ifndef DATE
115 DATE := $(shell sh $(SRC)/../gen-id.sh $(VERSION) $(HEXDATE))
116 endif
118 # Set up the NASM and LD options for the architecture
119 NASM_ELF = "unknown"
120 LD_PIE = "unknown"
121 ifeq ($(ARCH),i386)
122 NASM_ELF = elf
123 LD_PIE = -pie
124 endif
125 ifeq ($(ARCH),x86_64)
126 NASM_ELF = elf64
127 #LD_PIE = --pic-executable
128 LD_PIE =
129 endif
131 ifdef EFI_BUILD
132 all: makeoutputdirs $(filter-out %bios.o,$(COBJS) $(SOBJS)) codepage.o
133 else
134 all: makeoutputdirs $(BTARGET)
135 endif
137 makeoutputdirs:
138 @mkdir -p $(sort $(dir $(COBJ) $(SOBJ)))
140 kwdhash.gen: keywords genhash.pl
141 $(PERL) $(SRC)/genhash.pl < $(SRC)/keywords > $(OBJ)/kwdhash.gen
143 .PRECIOUS: %.elf
145 %.raw: %.elf
146 $(OBJCOPY) -O binary -S $< $(@:.bin=.raw)
148 # GNU make 3.82 gets confused by the first form
149 .PRECIOUS: $(OBJ)/%.raw
151 %.bin: %.raw $(PREPCORE)
152 $(PREPCORE) $< $@
154 %.o: %.asm kwdhash.gen $(OBJ)/../version.gen
155 $(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
156 -DHEXDATE="$(HEXDATE)" \
157 -D$(ARCH) \
158 -I$(SRC)/ \
159 -l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
161 AUXLIBS = libisolinux.a libisolinux-debug.a libldlinux.a \
162 libpxelinux.a liblpxelinux.a
163 LDSCRIPT = $(SRC)/$(ARCH)/syslinux.ld
165 %.elf: %.o $(LIBDEP) $(LDSCRIPT) $(AUXLIBS)
166 $(LD) $(LDFLAGS) -Bsymbolic $(LD_PIE) -E --hash-style=gnu -T $(LDSCRIPT) -M -o $@ $< \
167 --start-group $(LIBS) $(subst $(*F).elf,lib$(*F).a,$@) --end-group \
168 > $(@:.elf=.map)
169 $(OBJDUMP) -h $@ > $(@:.elf=.sec)
170 $(PERL) $(SRC)/lstadjust.pl $(@:.elf=.lsr) $(@:.elf=.sec) $(@:.elf=.lst)
172 libisolinux.a: rawcon.o localboot.o isolinux-c.o
173 rm -f $@
174 $(AR) cq $@ $^
175 $(RANLIB) $@
177 libisolinux-debug.a: libisolinux.a
178 cp $^ $@
180 # Legacy network stack
181 libpxelinux.a: rawcon.o pxeboot.o pxelinux-c.o $(PXELINUX_OBJS)
182 rm -f $@
183 $(AR) cq $@ $^
184 $(RANLIB) $@
186 # LwIP network stack
187 liblpxelinux.a: rawcon.o pxeboot.o pxelinux-c.o $(LPXELINUX_OBJS)
188 rm -f $@
189 $(AR) cq $@ $^
190 $(RANLIB) $@
192 libldlinux.a: plaincon.o localboot.o ldlinux-c.o
193 rm -f $@
194 $(AR) cq $@ $^
195 $(RANLIB) $@
197 $(LIB): $(LIBOBJS)
198 rm -f $@
199 $(AR) cq $@ $^
200 $(RANLIB) $@
202 pxelinux.o: pxelinux.asm kwdhash.gen ../version.gen
203 $(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
204 -DHEXDATE="$(HEXDATE)" \
205 -D$(ARCH) \
206 -I$(SRC)/ \
207 -DIS_LPXELINUX=0 \
208 -l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
210 pxelinux.0: pxelinux.bin
211 cp -f $< $@
213 lpxelinux.o: pxelinux.asm kwdhash.gen ../version.gen
214 $(NASM) -f $(NASM_ELF) $(NASMOPT) -DDATE_STR="'$(DATE)'" \
215 -DHEXDATE="$(HEXDATE)" \
216 -D$(ARCH) \
217 -I$(SRC)/ \
218 -DIS_LPXELINUX=1 \
219 -l $(@:.o=.lsr) -o $@ -MP -MD $(dir $@).$(notdir $@).d $<
221 lpxelinux.0: lpxelinux.bin
222 cp -f $< $@
224 ldlinux.bss: ldlinux.bin
225 dd if=$< of=$@ bs=512 count=1
227 ldlinux.sys: ldlinux.bin
228 dd if=$< of=$@ bs=512 skip=2
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)