aboutsummaryrefslogtreecommitdiffstats
path: root/core/Makefile
blob: de39acada6e7dfbe587b4ce434a49e91f675011e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
## -----------------------------------------------------------------------
##
##   Copyright 1998-2008 H. Peter Anvin - All Rights Reserved
##
##   This program is free software; you can redistribute it and/or modify
##   it under the terms of the GNU General Public License as published by
##   the Free Software Foundation, Inc., 53 Temple Place Ste 330,
##   Boston MA 02111-1307, USA; either version 2 of the License, or
##   (at your option) any later version; incorporated herein by reference.
##
## -----------------------------------------------------------------------

#
# Makefile for the SYSLINUX core
#

# No builtin rules
MAKEFLAGS += -r
MAKE      += -r

CC	 = gcc

TMPFILE = $(shell mktemp /tmp/gcc_ok.XXXXXX)
gcc_ok   = $(shell tmpf=$(TMPFILE); if $(CC) $(1) dummy.c -o $$tmpf 2>/dev/null; \
	           then echo '$(1)'; else echo '$(2)'; fi; rm -f $$tmpf)

M32       := $(call gcc_ok,-m32,) $(call gcc_ok,-ffreestanding,) \
	$(call gcc_ok,-fno-stack-protector,) \
	$(call gcc_ok,-fno-top-level-reorder,$(call gcc_ok,-fno-unit-at-a-time))

LD       = ld
LDFLAGS	 = -m elf_i386
OBJCOPY  = objcopy
OBJDUMP  = objdump

OPTFLAGS = -g -Os -march=i386 -falign-functions=0 -falign-jumps=0 -falign-loops=0 -fomit-frame-pointer
INCLUDES = 
CFLAGS	 = $(M32) -mregparm=3 -DREGPARM=3 -W -Wall -msoft-float $(OPTFLAGS) $(INCLUDES)

NASM	 = nasm
NASMOPT  = -O9999
NINCLUDE =

PERL     = perl

VERSION := $(shell cat ../version)

# _bin.c files required by both BTARGET and ITARGET installers
BINFILES = bootsect_bin.c ldlinux_bin.c \
	   extlinux_bss_bin.c extlinux_sys_bin.c

# syslinux.exe is BTARGET so as to not require everyone to have the
# mingw suite installed
BTARGET  = kwdhash.gen \
	   ldlinux.bss ldlinux.sys ldlinux.bin \
	   pxelinux.0 isolinux.bin isolinux-debug.bin \
	   extlinux.bin extlinux.bss extlinux.sys
ITARGET  =

# All primary source files for the main syslinux files
NASMSRC	 = $(wildcard *.asm)
NASMHDR  = $(wildcard *.inc)
CSRC	 = $(wildcard *.c)
CHDR	 = $(wildcard *.h)
OTHERSRC = keywords
ALLSRC   = $(NASMSRC) $(NASMHDR) $(CSRC) $(CHDR) $(OTHERSRC)

# The DATE is set on the make command line when building binaries for
# official release.  Otherwise, substitute a hex string that is pretty much
# guaranteed to be unique to be unique from build to build.
ifndef HEXDATE
HEXDATE := $(shell $(PERL) now.pl $(SRCS))
endif
ifndef DATE
DATE    := $(HEXDATE)
endif

#
# NOTE: If you don't have the mingw compiler suite installed, you probably
# want to remove win32 from this list; otherwise you're going to get an
# error every time you try to build.
#

all:	all-local

all-local: $(BTARGET) $(BINFILES)

installer: installer-local

installer-local: $(ITARGET) $(BINFILES)

kwdhash.gen: keywords genhash.pl
	$(PERL) genhash.pl < keywords > kwdhash.gen

.PRECIOUS: %.elf

# Standard rule for {isolinux,isolinux-debug}.bin
iso%.bin: iso%.elf
	$(OBJCOPY) -O binary $< $@
	$(PERL) checksumiso.pl $@

# Standard rule for {ldlinux,pxelinux,extlinux}.bin
%.bin: %.elf
	$(OBJCOPY) -O binary $< $@

%.o: %.asm kwdhash.gen ../version.gen
	$(NASM) $(NASMOPT) -f elf -F stabs -DDATE_STR="'$(DATE)'" \
		-DHEXDATE="$(HEXDATE)" \
		-l $(@:.o=.lsr) -o $@ $<

%.elf: %.o syslinux.ld
	$(LD) $(LDFLAGS) -T syslinux.ld -M -o $@ $< > $(@:.elf=.map)
	$(OBJDUMP) -h $@ > $(@:.elf=.sec)
	$(PERL) lstadjust.pl $(@:.elf=.lsr) $(@:.elf=.sec) $(@:.elf=.lst)

pxelinux.0: pxelinux.bin
	cp -f $< $@

ldlinux.bss: ldlinux.bin
	dd if=$< of=$@ bs=512 count=1

ldlinux.sys: ldlinux.bin
	dd if=$< of=$@ bs=512 skip=1

extlinux.bss: extlinux.bin
	dd if=$< of=$@ bs=512 count=1

extlinux.sys: extlinux.bin
	dd if=$< of=$@ bs=512 skip=1

bootsect_bin.c: ldlinux.bss ../bin2c.pl
	$(PERL) ../bin2c.pl syslinux_bootsect < $< > $@

ldlinux_bin.c: ldlinux.sys ../bin2c.pl
	$(PERL) ../bin2c.pl syslinux_ldlinux < $< > $@

extlinux_bss_bin.c: extlinux.bss ../bin2c.pl
	$(PERL) ../bin2c.pl extlinux_bootsect < $< > $@

extlinux_sys_bin.c: extlinux.sys ../bin2c.pl
	$(PERL) ../bin2c.pl extlinux_image 512 < $< > $@

install: installer

install-lib: installer

install-all: install install-lib

netinstall: installer

tidy dist:
	rm -f *.o *.elf *_bin.c stupid.* patch.offset
	rm -f *.lsr *.lst *.map *.sec
	rm -f $(OBSOLETE)

clean: tidy
	rm -f $(ITARGET)

spotless: clean
	rm -f $(BTARGET) .depend *.so.*

.depend:
	rm -f .depend
	for csrc in $(CSRC) ; do $(CC) $(INCLUDE) -MM $$csrc >> .depend ; done
	for nsrc in $(NASMSRC) ; do $(NASM) -DDEPEND $(NINCLUDE) -o `echo $$nsrc | sed -e 's/\.asm/\.o/'` -M $$nsrc >> .depend ; done

local-depend:
	rm -f .depend
	$(MAKE) .depend

depend: local-depend

# Include dependencies file
include .depend