summaryrefslogtreecommitdiff
path: root/Makefile
blob: 5392589750f6fe4c38c6ac0da988de005ccc8a13 (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
### ALL CONFIGURATION SHOULD IN CONFIG.MK, NOT HERE
include config.mk

### Module directories
MODULES := $(OSDIR) common

### look for include files in
###   each of the modules
CPPFLAGS += $(patsubst %,-I%,$(MODULES))
CPPFLAGS += $(OS) -DVERSION=$(VERSION)

### extra libraries if required
LIBS :=

### each module will add to this
SRC :=

BIN := bin/leocad

### include the description for
###   each module
include $(patsubst %,%/module.mk,$(MODULES))

### determine the object files
OBJ := \
  $(patsubst %.c,%.o,$(filter %.c,$(SRC))) \
  $(patsubst %.cpp,%.o,$(filter %.cpp,$(SRC)))


### link the program
.PHONY: all

all: $(BIN)

bin/leocad: $(OBJ) bin
	$(CC) -o $@ $(OBJ) $(LIBS)

bin:
	mkdir bin

### include the C/C++ include
###   dependencies
include $(OBJ:.o=.d)

### calculate C/C++ include
###   dependencies
%.d: %.c
	./depend.sh $(CC) $(CFLAGS) $(CPPFLAGS) $< > $@
	[ -s $@ ] || rm -f $@

%.d: %.cpp
	./depend.sh $(CXX) $(CXXFLAGS) $(CPPFLAGS) $< > $@
	[ -s $@ ] || rm -f $@


### Various cleaning functions
.PHONY: clean veryclean spotless all

clean:
	find $(MODULES) -name \*.o | xargs rm -f

veryclean: clean
	find $(MODULES) -name \*.d | xargs rm -f
	rm -rf bin

spotless: veryclean
	rm -rf arch


### dependency stuff is done automatically, so these do nothing.
.PHONY: dep depend


### Help function
.PHONY: help

help:
	@echo   'Possible Targets are:'
	@echo   '       help (this is it)'
	@echo   '       all'
	@echo   '       binary'
	@echo   '       source'
	@echo   '       (binary and source can be called as'
	@echo   '        a -zip or -tgz variants)'
	@echo   '       clean'
	@echo   '       veryclean'
	@echo   '       spotless'
	@echo

###  Rules to make various packaging
.PHONY: binary binary-tgz source-zip source-tgz source

arch:
	mkdir arch

binary: binary-zip binary-tgz

binary-zip: arch/leocad-$(VERSION)-linux.zip

binary-tgz: arch/leocad-$(VERSION)-linux.tgz

source: source-tgz source-zip

source-tgz: arch/leocad-$(VERSION)-src.tgz

source-zip: arch/leocad-$(VERSION)-src.zip



arch/leocad-$(VERSION)-linux.zip: arch all
	rm -f $@
	zip -r $@ bin docs examples

arch/leocad-$(VERSION)-linux.tgz: arch all
	rm -f $@
	tar cvzf $@ bin docs examples

arch/leocad-$(VERSION)-src.tgz: arch veryclean
	rm -f $@
	( cd .. ; tar --exclude=leocad/arch/\* -cvzf leocad/$@ leocad )

arch/leocad-$(VERSION)-src.zip: arch veryclean
	rm -f $@
	( cd .. ; zip -r leocad/$@ leocad -x leocad/arch/\* )