summaryrefslogtreecommitdiff
path: root/Makefile
blob: 5dde80eb53cba950522c2acfc22e89d78e5083cb (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
BINARIES := makerun

CFLAGS := -Wall -Wextra -Wundef -Wpointer-arith -Wcast-align \
	-Wwrite-strings -Wstrict-prototypes \
	-Wnested-externs -pedantic -std=c99 \
	-Wno-format-zero-length -Wformat-security -Wstrict-aliasing=2 \
	-Wmissing-format-attribute -Wunused -Wunreachable-code \
	-Wformat=2 -Werror-implicit-function-declaration \
	-Wmissing-declarations -Wmissing-prototypes

ECHO := echo
INSTALL := install
MKDIR := mkdir
MKDIRFLAGS := -p

# Detect host platform
HOST := $(shell uname -s)
ifeq ($(HOST),)
  # Assume RISC OS, as uname's broken there)
  HOST := riscos
else
  ifeq ($(HOST),RISC OS)
    HOST := riscos
  endif
endif

ifeq ($(HOST),riscos)
  ifeq ($(TARGET),)
    TARGET := riscos
  endif
endif

ifeq ($(TARGET),riscos)
  ifeq ($(HOST),riscos)
    GCCSDK_INSTALL_ENV := <NSLibs$$Dir>
    CC := gcc
    EXEEXT :=
    SUBTARGET :=
  else
    GCCSDK_INSTALL_CROSSBIN ?= /home/riscos/cross/bin
    GCCSDK_INSTALL_ENV ?= /home/riscos/env
    CC := $(wildcard $(GCCSDK_INSTALL_CROSSBIN)/*gcc)
    ifneq (,$(findstring arm-unknown-riscos-gcc,$(CC)))
      EXEEXT := ,e1f
      SUBTARGET := -elf-
    else
      ifneq (,$(findstring arm-riscos-gnueabi-gcc,$(CC)))
        EXEEXT := ,e1f
        SUBTARGET := -elfeabi-
      else
        ifneq (,$(findstring arm-riscos-gnueabihf-gcc,$(CC)))
          EXEEXT := ,e1f
          SUBTARGET := -elfeabihf-
        else
          EXEEXT := ,ff8
          SUBTARGET := -aof-
        endif
      endif
    endif
  endif

  CFLAGS += -Driscos -mpoke-function-name -I$(GCCSDK_INSTALL_ENV)/include
  LIBS = -L$(GCCSDK_INSTALL_ENV)/lib -lOSLib32
  PREFIX = $(GCCSDK_INSTALL_ENV)
else
  CFLAGS += -g
  LIBS =
  PREFIX = $(GCCSDK_INSTALL_CROSSBIN)/..
endif

-include Makefile.config

BINDIR = build-$(TARGET)$(SUBTARGET)bin

BINS = $(addprefix $(BINDIR)/, $(addsuffix $(EXEEXT), $(BINARIES)))

.PHONY: all clean install uninstall

all: $(BINS)

$(BINDIR)/%$(EXEEXT): %.c
	@$(ECHO) "   BUILD: $@"
	@$(MKDIR) $(MKDIRFLAGS) $(BINDIR)
	@$(CC) $(CFLAGS) -o $@ $< $(LIBS)

install: $(BINS)
	$(MKDIR) $(MKDIRFLAGS) $(DESTDIR)$(PREFIX)/bin
	$(INSTALL) -m 755 $(BINS) $(DESTDIR)$(PREFIX)/bin

uninstall:
	$(RM) $(addprefix $(DESTDIR)$(PREFIX)/bin/, $(addsuffix $(EXEEXT), $(BINARIES)))

clean:
	$(RM) -r $(BINDIR)