summaryrefslogtreecommitdiffstats
path: root/makefile-djb/Makefile_base
blob: ca1a94c79dda3e5fee9623c4069953a928ff144f (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

# Don't edit this Makefile! Use conf-* for configuration.

######################################

SHELL=/bin/sh

CYAN=\033[3;36m
RED=\033[3;31m
NORM=\033[0m

default: build

# GENERATE : buildarch - choose - compile - load - testflag

buildarch : ${DIR}/warn-auto.sh conf-arch LICENSE README AUTHOR Changelog
	@echo -e "$(CYAN)generating buildarch$(NORM)"
	@( cat ${DIR}/warn-auto.sh; \
	echo "ARCH=`head -1 conf-arch`"; \
	echo 'echo -e "building $(RED)$${ARCH}$(NORM)"'; \
	echo 'P=`pwd` && P=$${P##*/};'; \
	echo 'FILES="$${P}/Makefile* $${P}/warn-auto.sh $${P}/LICENSE $${P}/README $${P}/AUTHOR $${P}/Changelog \
	$${P}/conf-* $${P}/*.h* $${P}/*.c*";'; \
	echo 'for I in $$@; do FILES="$${FILES} $${P}/$$I "; done;'; \
	echo 'cd .. && tar --exclude=*~ -chzf $${P}/$${ARCH} $${FILES} ' \
	) > buildarch
	@chmod 755 buildarch

choose : ${DIR}/warn-auto.sh
	@echo -e "$(CYAN)generating choose$(NORM)"
	@( cat ${DIR}/warn-auto.sh; \
	echo 'result="$$3"'; \
	echo 'case "$$1" in'; \
	echo '   *c*) ./compile $$2.c >/dev/null 2>&1 || result="$$4" ;;'; \
	echo 'esac'; \
	echo 'case "$$1" in'; \
	echo '   *l*) ./load c $$2 >/dev/null 2>&1 || result="$$4" ;;'; \
	echo 'esac'; \
	echo 'case "$$1" in'; \
	echo '   *r*) ./$$2 >/dev/null 2>&1 || result="$$4" ;;'; \
	echo 'esac'; \
	echo 'rm -f $$2.o $$2'; \
	echo 'cat $$result'; \
	) > choose
	@chmod 755 choose

compile : ${DIR}/warn-auto.sh conf-cc
	@echo -e "$(CYAN)generating compile$(NORM)"
	@( cat ${DIR}/warn-auto.sh; \
	echo 'echo -e "`head -1 conf-cc` -c  $(RED)$${1} $(NORM)"'; \
	echo '`head -1 conf-cc` -c "$$1"'; \
	) > compile
	@chmod 755 compile

load : ${DIR}/warn-auto.sh conf-ld
	@echo -e "$(CYAN)generating load$(NORM)"
	@( cat ${DIR}/warn-auto.sh; \
	echo 'choice=$$1; shift;'; \
	echo 'name=$$1; shift;'; \
	echo 'case "$$choice" in'; \
	echo '   *c*)'; \
	echo '      echo -e "`head -1 conf-ld` -o $(RED)$${name} $${name}.o $${1+"$$@"} $(NORM)"'; \
	echo '      `head -1 conf-ld` -o "$$name" "$$name".o $${1+"$$@"}'; \
	echo '      ;;'; \
	echo '   *d*)'; \
	echo '      echo -e "`head -1 conf-ld` $$name -o $(RED)$${name} $${1+"$$@"} $(NORM)"'; \
	echo '      `head -1 conf-ld` -o "$$name" $${1+"$$@"}'; \
	echo '      ;;'; \
	echo '   *s*)'; \
	echo '      echo -e "ar -cr $(RED)$${name} $${1+"$$@"} $(NORM)"'; \
	echo '      rm -f "$$name"; ar -cr "$$name" $${1+"$$@"}; ranlib "$$name"'; \
	echo '      ;;'; \
	echo 'esac'; \
	) > load
	@chmod 755 load

testflag : ${DIR}/warn-auto.sh
	@echo -e "$(CYAN)generating testflag$(NORM)"
	@( cat ${DIR}/warn-auto.sh; \
	echo 'FLAG="$$1"; shift'; \
	echo 'for I in "$$@"; do echo "#include \"$$I\""; done;'; \
	echo 'echo "int main() {"'; \
	echo 'echo "#ifdef "$$FLAG"" '; \
	echo 'echo "   return 0;"'; \
	echo 'echo "#else"'; \
	echo 'echo "   return 1;"'; \
	echo 'echo "#endif"'; \
	echo 'echo }'; \
	) > testflag
	@chmod 755 testflag

# HIGH LEVEL GENERAL TARGETS
buildstd :
	@echo -e "$(CYAN)building `pwd`$(NORM)";
	@for I in ${SUBDIR}; do \
	( echo -e "$(CYAN)building `pwd`/$$I$(NORM)" && cd $$I && make -s ); \
	done;

cleanstd :
	@echo -e "$(CYAN)cleaning `pwd`$(NORM)";
	@for I in ${SUBDIR}; do ( cd $$I && make -s clean ); done;
	@if [ -f conf-arch ]; then if [ -f `head -1 conf-arch` ]; then rm `head -1 conf-arch`; fi; fi
	@if [ -f buildarch ]; then rm buildarch; fi
	@if [ -f choose ]; then rm choose; fi
	@if [ -f compile ]; then rm compile; fi
	@if [ -f load ]; then rm load; fi
	@if [ -f testflag ]; then rm testflag; fi
	@if [ "x`ls *~ 2>/dev/null`"  != "x" ]; then rm *~; fi
	@if [ "x`ls *.a 2>/dev/null`" != "x" ]; then rm *.a; fi
	@if [ "x`ls *.o 2>/dev/null`" != "x" ]; then rm *.o; fi
	@if [ "x`ls *.so* 2>/dev/null`" != "x" ]; then rm *.so*; fi

# PACKAGE SPECIFIC TARGETS