summaryrefslogtreecommitdiff
path: root/Makefile
blob: cc06e436e9bca0348ba26ce1ea777c64c73b0937 (plain) (blame)
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
# Makefile for hax's table stuff
#
# Written by: Test_User <hax@andrewyu.org>
#
# This is free and unencumbered software released into the public
# domain.
#
# Anyone is free to copy, modify, publish, use, compile, sell, or
# distribute this software, either in source code form or as a compiled
# binary, for any purpose, commercial or non-commercial, and by any
# means.
#
# In jurisdictions that recognize copyright laws, the author or authors
# of this software dedicate any and all copyright interest in the
# software to the public domain. We make this dedication for the benefit
# of the public at large and to the detriment of our heirs and
# successors. We intend this dedication to be an overt act of
# relinquishment in perpetuity of all present and future rights to this
# software under copyright law.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
# IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR
# OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
# ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
# OTHER DEALINGS IN THE SOFTWARE.

ORIGINAL_CFLAGS := $(CFLAGS)
ORIGINAL_LDFLAGS := $(LDFLAGS)

INCLUDEFLAGS =

LDFLAGS =

.makeopts:
	> .makeopts
	printf '%s\n' 'LAST_SAFE_STACK = $(SAFE_STACK)' >> .makeopts
	printf '%s\n' 'LAST_HAX_STRING_PATH = $(HAX_STRING_PATH)' >> .makeopts
	printf '%s\n' 'LAST_CFLAGS = $(ORIGINAL_CFLAGS)' >> .makeopts
	printf '%s\n' 'LAST_LDFLAGS = $(ORIGINAL_LDFLAGS)' >> .makeopts
	printf '%s\n' 'LAST_CC = $(CC)' >> .makeopts

$(shell [ -e .makeopts ] || > .makeopts)

include .makeopts

rebuild = 0

# tabs not allowed :(
ifneq ($(SAFE_STACK),)
ifneq ($(SAFE_STACK),$(LAST_SAFE_STACK))
rebuild = 1
endif
else
SAFE_STACK := $(LAST_SAFE_STACK)
endif

ifneq ($(HAX_STRING_PATH),)
ifneq ($(HAX_STRING_PATH),$(LAST_HAX_STRING_PATH))
rebuild = 1
endif
else
HAX_STRING_PATH := $(LAST_HAX_STRING_PATH)
endif

ifneq ($(ORIGINAL_CFLAGS),)
ifneq ($(ORIGINAL_CFLAGS),$(LAST_CFLAGS))
rebuild = 1
endif
else
ORIGINAL_CFLAGS := $(LAST_CFLAGS)
CFLAGS += $(LAST_CFLAGS)
endif

ifneq ($(ORIGINAL_LDFLAGS),)
ifneq ($(ORIGINAL_LDFLAGS),$(LAST_LDFLAGS))
rebuild = 1
endif
else
ORIGINAL_LDFLAGS := $(LAST_LDFLAGS)
LDFLAGS += $(LAST_LDFLAGS)
endif

ifneq ($(CC),)
ifneq ($(CC),$(LAST_CC))
rebuild = 1
endif
else
CC := $(LAST_CC)
endif

ifeq ($(rebuild),1)
.PHONY: .makeopts
endif

CFLAGS += $(INCLUDEFLAGS) -fPIC -fno-plt -D_REENTRANT -ggdb3 -Wall -Wextra -Wsign-conversion -Wno-unknown-warning-option -Wno-unused-parameter -Wno-implicit-fallthrough -Wno-alloc-size -std=gnu99

ifneq ($(HAX_STRING_PATH),)
CFLAGS += -I$(HAX_STRING_PATH)
endif

LDFLAGS += -lhax_string_utils

ifneq ($(HAX_STRING_PATH),)
LDFLAGS += -L$(HAX_STRING_PATH)
endif


ifeq ($(SAFE_STACK),1)
CFLAGS += -fstack-check
endif


DEPS = $(shell $(CC) $(CFLAGS) -M -MT $(1).$(2) $(1).c | sed 's_\\$$__') .makeopts Makefile


.PHONY: all clean
# 'lib' prefix mandated bleh
all: libhax_table.a libhax_table.so

%.o: %.c
	$(CC) $(CFLAGS) -c $< -o $@

lib%.so: %.o
	$(LD) $(LDFLAGS) -shared $< -o $@

lib%.a: %.o
	$(AR) rcs $@ $<

$(call DEPS,hax_table,o)

clean:
	for file in `find . -name '*.so'`; do $(RM) $$file; done
	for file in `find . -name '*.o'`; do $(RM) $$file; done
	for file in `find . -name '*.a'`; do $(RM) $$file; done