makefile rules to build as static library and install/uninstall
[miniglut] / Makefile
1 PREFIX = /usr/local
2
3 olib = miniglut.o
4 otest = test.o
5 alib = libminiglut.a
6 bin = test
7
8 CFLAGS = -pedantic -Wall -g
9
10 isx86 ?= $(shell uname -m | sed 's/x86_64/x86/; s/i.86/x86/')
11
12 sys ?= $(shell uname -s | sed 's/MINGW.*/mingw/')
13 ifeq ($(sys), mingw)
14         olib = miniglut.w32.o
15         otest = miniglut.w32.o
16         bin = test.exe
17
18         LDFLAGS = -mconsole -lopengl32 -lgdi32 -lwinmm
19 else ifeq ($(sys)-$(isx86), Linux-x86)
20         LDFLAGS = -lX11 -lGL
21 else
22         # for other UNIX or non-x86 where sys_ and trig functions are not
23         # implemented, just use libc
24         CFLAGS += -DMINIGLUT_USE_LIBC
25         LDFLAGS = -lX11 -lGL -lm
26         ifeq ($(sys), IRIX)
27                 CC = gcc
28         endif
29 endif
30
31 $(bin): $(otest) $(alib)
32         $(CC) -o $@ $(otest) $(alib) $(LDFLAGS)
33
34 $(alib): $(olib)
35         $(AR) rcs $@ $(olib)
36
37 %.w32.o: %.c
38         $(CC) -o $@ $(CFLAGS) -c $<
39
40 .PHONY: clean
41 clean:
42         rm -f $(alib) $(olib) $(otest) $(bin)
43
44 .PHONY: install
45 install: $(alib)
46         mkdir -p $(DESTDIR)$(PREFIX)/include $(DESTDIR)$(PREFIX)/lib
47         cp miniglut.h $(DESTDIR)$(PREFIX)/include/miniglut.h
48         cp $(alib) $(DESTDIR)$(PREFIX)/lib/$(alib)
49
50 .PHONY: uninstall
51 uninstall:
52         rm -f $(DESTDIR)$(PREFIX)/include/miniglut.h
53         rm -f $(DESTDIR)$(PREFIX)/lib/$(alib)
54
55 .PHONY: cross
56 cross:
57         $(MAKE) CC=i686-w64-mingw32-gcc sys=mingw
58
59 .PHONY: cross-clean
60 cross-clean:
61         $(MAKE) CC=i686-w64-mingw32-gcc sys=mingw clean