33ad7e956fb5783fca2f4b791c61867a1b5983d0
[external/syslinux.git] / core / Makefile
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.
11 ##
12 ## -----------------------------------------------------------------------
13
14 #
15 # Makefile for the SYSLINUX core
16 #
17
18 # No builtin rules
19 MAKEFLAGS += -r
20 MAKE      += -r
21
22 topdir = ..
23 include $(topdir)/MCONFIG.embedded
24 -include $(topdir)/version.mk
25
26 OPTFLAGS =
27 INCLUDES = -I./include -I$(com32)/include
28
29 # This is very similar to cp437; technically it's for Norway and Denmark,
30 # but it's unlikely the characters that are different will be used in
31 # filenames by other users.
32 CODEPAGE = cp865
33
34 # The targets to build in this directory...
35 BTARGET  = kwdhash.gen \
36            ldlinux.bss ldlinux.sys ldlinux.bin \
37            isolinux.bin isolinux-debug.bin pxelinux.0
38
39 # All primary source files for the main syslinux files
40 NASMSRC  := $(wildcard *.asm)
41 NASMHDR  := $(wildcard *.inc)
42 CSRC     := $(wildcard *.c */*.c */*/*.c)
43 SSRC     := $(wildcard *.S */*.S */*/*.S)
44 CHDR     := $(wildcard *.h)
45 OTHERSRC := keywords
46 ALLSRC    = $(NASMSRC) $(NASMHDR) $(CSRC) $(SSRC) $(CHDR) $(OTHERSRC)
47
48 COBJ     := $(patsubst %.c,%.o,$(CSRC))
49 SOBJ     := $(patsubst %.S,%.o,$(SSRC))
50
51 LIB      = libcore.a
52 LIBS     = $(LIB) $(com32)/lib/libcomcore.a $(LIBGCC)
53 LIBOBJS  = $(COBJ) $(SOBJ)
54
55 NASMDEBUG = -g -F dwarf
56 NASMOPT  += $(NASMDEBUG)
57
58 PREPCORE = ../lzo/prepcore
59
60 # CFLAGS        += -DDEBUG=1
61
62 # The DATE is set on the make command line when building binaries for
63 # official release.  Otherwise, substitute a hex string that is pretty much
64 # guaranteed to be unique to be unique from build to build.
65 ifndef HEXDATE
66 HEXDATE := $(shell $(PERL) ../now.pl $(SRCS))
67 endif
68 ifndef DATE
69 DATE    := $(shell sh ../gen-id.sh $(VERSION) $(HEXDATE))
70 endif
71
72 all: $(BTARGET)
73
74 kwdhash.gen: keywords genhash.pl
75         $(PERL) genhash.pl < keywords > kwdhash.gen
76
77 .PRECIOUS: %.elf
78
79 %.raw: %.elf
80         $(OBJCOPY) -O binary $< $(@:.bin=.raw)
81
82 # GNU make 3.82 gets confused by the first form
83 .PRECIOUS: %.raw
84
85 %.bin: %.raw $(PREPCORE)
86         $(PREPCORE) $< $@
87
88 %.o: %.asm kwdhash.gen ../version.gen
89         $(NASM) -f elf $(NASMOPT) -DDATE_STR="'$(DATE)'" \
90                 -DHEXDATE="$(HEXDATE)" \
91                 -l $(@:.o=.lsr) -o $@ -MP -MD .$@.d $<
92
93 %.elf: %.o $(LIBS) syslinux.ld
94         $(LD) $(LDFLAGS) -T syslinux.ld -M -o $@ $< \
95                 --start-group $(LIBS) --end-group \
96                 > $(@:.elf=.map)
97         $(OBJDUMP) -h $@ > $(@:.elf=.sec)
98         $(PERL) lstadjust.pl $(@:.elf=.lsr) $(@:.elf=.sec) $(@:.elf=.lst)
99
100 $(LIB): $(LIBOBJS)
101         rm -f $@
102         $(AR) cq $@ $^
103         $(RANLIB) $@
104
105 pxelinux.0: pxelinux.bin
106         cp -f $< $@
107
108 ldlinux.bss: ldlinux.bin
109         dd if=$< of=$@ bs=512 count=1
110
111 ldlinux.sys: ldlinux.bin
112         dd if=$< of=$@ bs=512 skip=1
113
114 codepage.cp: ../codepage/$(CODEPAGE).cp
115         cp -f $< $@
116
117 codepage.o: codepage.S codepage.cp
118
119 install: installer
120
121 install-lib: installer
122
123 install-all: install install-lib
124
125 netinstall: installer
126
127 tidy dist:
128         rm -f codepage.cp *.o *.elf *.a stupid.* patch.offset .depend .*.d
129         rm -f *.elf.tmp *.sym
130         rm -f *.lsr *.lst *.map *.sec *.raw
131         rm -f */*.o */*/*.o */*.lst */*/*.lst */.*.d */*/.*.d
132         rm -f $(OBSOLETE) $(LIB)
133
134 clean: tidy
135
136 spotless: clean
137         rm -f $(BTARGET) *.bin *_bin.c
138
139 # Include dependencies file
140 -include .*.d */.*.d */*/.*.d