forked from pasdoc/pasdoc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile-autodetect
139 lines (125 loc) · 4.79 KB
/
Makefile-autodetect
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
137
138
139
# -*- mode: Makefile -*-
#
###########################################################################
# This Makefile does some dirty tricks to autodetect many things
# about current OS. It does not do anything specific to pasdoc.
#
# It's contents are mostly taken from fpcmake sources,
# see fpc/utils/fpcm/fpcmake.ini in FPC source tree,
# and from Makefiles generated by fpcmake.
#
# Some handy things defined by this Makefile:
#
# - $(PATHSEP) is set to path seperator on this system.
#
# - $(MKDIRPROG) is set the command that behaves like "mkdir"
# on POSIX-like environments (so you can pass "-p" to it, and so on).
#
# Note that this will work even if you're on Windows and have only a
# subset of MinGW tools that are installed with FPC
# (and you don't have Cygwin or full MinGW Msys environment available).
# In such case `make' runs your commands within a Windows shell,
# so you can't simply write "mkdir", because then it will be understood
# as Windows shell built-in "mkdir" command.
# This Makefile will set MKDIRPROG to "gmkdir" command (installed with FPC),
# (actually even to the full path to "gmkdir" command...)
# so everything will work.
#
# - $(PACKAGEBASEDIR) is set to base temporary directory on this system,
# that can be used to create temporary file tree for archives.
#
###########################################################################
###########################################################################
# Things below are a simplified version of section [osdetect] of fpcmake.ini
###########################################################################
# We need only / in the path also remove the current dir,
# also remove trailing /'s
override PATH:=$(patsubst %/,%,$(subst \,/,$(PATH)))
# Detect unix
# Darwin is handled specially
ifneq ($(findstring darwin,$(OSTYPE)),)
inUnix=1 #darwin
SEARCHPATH:=$(filter-out .,$(subst :, ,$(PATH)))
else
# Determine if we've a unix searchpath by looking for a ;
# that normally doesn't exists in the unix PATH var.
ifeq ($(findstring ;,$(PATH)),)
inUnix=1
SEARCHPATH:=$(filter-out .,$(subst :, ,$(PATH)))
else
SEARCHPATH:=$(subst ;, ,$(PATH))
endif
endif
# Add path where make is located
SEARCHPATH+=$(patsubst %/,%,$(subst \,/,$(dir $(MAKE))))
# Search for PWD
# Also sets SRCEXEEXT
PWD:=$(strip $(wildcard $(addsuffix /pwd.exe,$(SEARCHPATH))))
ifeq ($(PWD),)
PWD:=$(strip $(wildcard $(addsuffix /pwd,$(SEARCHPATH))))
ifeq ($(PWD),)
$(error You need the GNU utils package to use this Makefile)
else
PWD:=$(firstword $(PWD))
SRCEXEEXT=
endif
else
PWD:=$(firstword $(PWD))
SRCEXEEXT=.exe
endif
# Path Separator, the subst trick is necessary for the \ that can't exists
# at the end of a line
ifdef inUnix
PATHSEP=/
else
PATHSEP:=$(subst /,\,/)
endif
###########################################################################
# Detecting inCygWin
# (but not the way like fpcmake does it; fpcmake way doesn't work...)
###########################################################################
ifdef inUnix
ifneq ($(strip $(wildcard $(addsuffix /cygpath$(SRCEXEEXT),$(SEARCHPATH)))),)
inCygWin=1
endif
endif
###########################################################################
# Detecting $(MKDIRPROG), this is copied from Makefile generated by fpcmake
###########################################################################
ifndef MKDIRPROG
MKDIRPROG:=$(strip $(wildcard $(addsuffix /gmkdir$(SRCEXEEXT),$(SEARCHPATH))))
ifeq ($(MKDIRPROG),)
MKDIRPROG:=$(strip $(wildcard $(addsuffix /mkdir$(SRCEXEEXT),$(SEARCHPATH))))
ifeq ($(MKDIRPROG),)
MKDIRPROG= __missing_command_MKDIRPROG
else
MKDIRPROG:=$(firstword $(MKDIRPROG))
endif
else
MKDIRPROG:=$(firstword $(MKDIRPROG))
endif
endif
###########################################################################
# Guessing $(PACKAGEBASEDIR)
###########################################################################
# Temporary directory used for preparing archives
ifdef TEMP
PACKAGEBASEDIR := $(TEMP)
ifdef inCygWin
# Under Cygwin, make $(PACKAGEBASEDIR) directory as native Windows path
# (not using Cygwin's /cygdrive/... etc.) because we may use it with some non-Cygwin tools.
#
# Also, using "--mixed" instead of "--windows", we get path with forward slashes,
# must easier to use in Makefile due to uncertain how to quote things reliably in Makefile.
PACKAGEBASEDIR := $(shell cygpath --mixed $(PACKAGEBASEDIR))
else
# Convert to forward slashes, to make using these paths on Windows easier.
PACKAGEBASEDIR := $(subst \,/,$(PACKAGEBASEDIR))
endif
else
# /tmp is a good guess for Unices, and for Win32 if someone uses Cygwin's make.
# Use a subdir in /tmp/, to allow using this from multiple user accounts
# (especially important since we may not clean after ourselves properly,
# so with simple /tmp/ other user would not have permissions to remove /tmp/pasdoc)
PACKAGEBASEDIR := /tmp/pasdoc-$(USER)
endif