Centralize configurables; better "make install" etc
[profile/ivi/syslinux.git] / com32 / menu / Makefile
1 ## -----------------------------------------------------------------------
2 ##
3 ##   Copyright 2001-2008 H. Peter Anvin - All Rights Reserved
4 ##
5 ##   This program is free software; you can redistribute it and/or modify
6 ##   it under the terms of the GNU General Public License as published by
7 ##   the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
8 ##   Boston MA 02110-1301, USA; either version 2 of the License, or
9 ##   (at your option) any later version; incorporated herein by reference.
10 ##
11 ## -----------------------------------------------------------------------
12
13 ##
14 ## Simple menu system
15 ##
16
17 TMPFILE = $(shell mktemp /tmp/gcc_ok.XXXXXX)
18 CC      = gcc
19
20 gcc_ok   = $(shell tmpf=$(TMPFILE); if $(CC) $(1) -c -x c /dev/null -o $$tmpf 2>/dev/null; \
21                    then echo $(1); else echo $(2); fi; rm -f $$tmpf)
22
23 M32     := $(call gcc_ok,-m32,) $(call gcc_ok,-fno-stack-protector,)
24
25 LD         = ld -m elf_i386
26 AR         = ar
27 NASM       = nasm
28 NASMOPT    = -O9999
29 RANLIB     = ranlib
30 CFLAGS     = $(M32) -mregparm=3 -DREGPARM=3 -W -Wall -march=i386 -Os \
31              -fomit-frame-pointer -D__COM32__ \
32              -nostdinc -iwithprefix include \
33              -I../libutil/include -I../include \
34              -Wp,-MT,$@,-MD,$(dir $@).$(notdir $@).d
35 LNXCFLAGS  = -W -Wall -O -g -I../libutil/include -D_GNU_SOURCE
36 LNXSFLAGS  = -g
37 LNXLDFLAGS = -g
38 SFLAGS     = -D__COM32__ -march=i386
39 LDFLAGS    = -T ../lib/com32.ld
40 OBJCOPY    = objcopy
41 PPMTOLSS16 =    ../ppmtolss16
42 LIBGCC    := $(shell $(CC) --print-libgcc)
43 LIBS       = ../libutil/libutil_com.a ../lib/libcom32.a $(LIBGCC)
44 LNXLIBS    = ../libutil/libutil_lnx.a
45
46 .SUFFIXES: .lss .c .o .elf .c32 .lnx
47
48 BINDIR   = /usr/bin
49 LIBDIR   = /usr/lib
50 DATADIR  = /usr/share
51 AUXDIR   = $(DATADIR)/syslinux
52 INCDIR   = /usr/include
53 COM32DIR = $(AUXDIR)/com32
54
55 MODULES   = menu.c32 vesamenu.c32
56 TESTFILES =
57
58 COMMONOBJS = menumain.o readconfig.o passwd.o printmsg.o colors.o \
59         background.o refstr.o execute.o
60
61 all: $(MODULES) $(TESTFILES)
62
63 .PRECIOUS: %.o
64 %.o: %.S
65         $(CC) $(SFLAGS) -c -o $@ $<
66
67 .PRECIOUS: %.o
68 %.o: %.c
69         $(CC) $(CFLAGS) -c -o $@ $<
70
71 .PRECIOUS: %.elf
72 %.elf: %.o $(LIBS)
73         $(LD) $(LDFLAGS) -o $@ $^
74
75 .PRECIOUS: %.lo
76 %.lo: %.S
77         $(CC) $(LNXSFLAGS) -c -o $@ $<
78
79 .PRECIOUS: %.lo
80 %.lo: %.c
81         $(CC) $(LNXCFLAGS) -c -o $@ $<
82
83 .PRECIOUS: %.lnx
84 %.lnx: %.lo $(LNXLIBS)
85         $(CC) $(LNXLDFLAGS) -o $@ $^
86
87 %.c32: %.elf
88         $(OBJCOPY) -O binary $< $@
89
90 menu.elf : menu.o $(COMMONOBJS) $(LIBS)
91         $(LD) $(LDFLAGS) -o $@ $^
92
93 vesamenu.elf : vesamenu.o $(COMMONOBJS) $(LIBS)
94         $(LD) $(LDFLAGS) -o $@ $^
95
96 tidy dist:
97         rm -f *.o *.lo *.a *.lst *.elf .*.d
98
99 clean: tidy
100         rm -f *.lss *.c32 *.lnx *.com
101
102 spotless: clean
103         rm -f *~ \#*
104
105 install: all
106         mkdir -m 755 -p $(INSTALLROOT)$(AUXDIR)
107         install -m 644 $(MODULES) $(INSTALLROOT)$(AUXDIR)
108
109 -include .*.d