summaryrefslogtreecommitdiff
path: root/fpcsrc/compiler/utils/samplecfg
blob: 93dc2c04e0c2ccf37d9984f951dd1ffc5a42462f (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
#!/bin/sh
#
#  $Id: samplecfg,v 1.13 2005/02/19 18:50:20 florian Exp $
#
#  Generate Sample Free Pascal configuration file
#

HOSTOS=`uname -s | tr A-Z a-z`
echo Running on $HOSTOS

if [ $# = 0 ]; then
  echo 'Usage :'
  echo 'samplecfg fpcdir confdir'
  echo 'fpcdir = Path where FPC is installed'
  echo 'confdir = Path to /etc'
  exit 1
fi
if [ "$2" ]; then
  sysdir="$2"
  [ -d "$sysdir" ] || mkdir "$sysdir"
else
  sysdir=/etc
fi
FPCBIN=`dirname "$1"`/../../bin/fpc
FPBIN=`dirname "$1"`/../../bin/fp
FPPKGBIN=`dirname "$1"`/../../bin/fppkg
FPCMKCFGBIN=`dirname "$1"`/../../bin/fpcmkcfg
# Look for one in the PATH, if no new one was installed.
if [ ! -f $FPCMKCFGBIN ]; then
  FPCMKCFGBIN=fpcmkcfg
fi

sysfpdirbase=`dirname "$1"`/`"$FPCBIN" -iV`
sysfpdirbase2=$sysfpdirbase/ide
sysfpdir=$sysfpdirbase2/text

# Detect if we have write permission in sysdir.
if [ -w "$sysdir" ] ; then
  echo Write permission in $sysdir.
  fpccfgfile="$sysdir"/fpc.cfg
  fppkgfile="$sysdir"/fppkg.cfg
  defaultfile="$sysdir"/fppkg/default
  compilerconfigdir="-d CompilerConfigDir=$sysdir/fppkg"
else
  echo No write premission in $sysdir.
  fpccfgfile="$HOME"/.fpc.cfg
  fppkgfile="$HOME"/.config/fppkg.cfg
  defaultfile="$HOME"/.fppkg/config/default
fi
#

# Don't mess with IDE configuration if fp binary does not exist
if [ -f "$FPBIN" ] ; then

# Assume local FP IDE configuration unless writing system-wide version possible
  fpinifile="$HOME"/.fp/fp.ini
  fpcfgfile="$HOME"/.fp/fp.cfg

# Detect if we have write permission in sysfpdir, or that the directory can be made
  if ( [ -d "$sysfpdirbase" ] && [ -w "$sysfpdirbase" ] && ! [ -d "$sysfpdirbase2" ] ) ||
     ( [ -d "$sysfpdirbase2" ] && [ -w "$sysfpdirbase2" ] && ! [ -d "$sysfpdir" ] ) ||
     ( [ -d "$sysfpdir" ] && [ -w "$sysfpdir" ] ) ; then
    fpinifile="$sysfpdir"/fp.ini
    fpcfgfile="$sysfpdir"/fp.cfg
  fi
#
fi

# set right path to FPC with $fpcversion
FPCPATH=`dirname "$1"`/\$fpcversion
# set right prefix to FPC
FPCGLOBALPREFIX=`dirname "$1"`/../../

# Write (.)fpc.cfg
echo Writing sample configuration file to $fpccfgfile
${FPCMKCFGBIN} -d "basepath=$FPCPATH" -o $fpccfgfile

if ! [ -f "$FPBIN" ] ; then
  exit
fi

# Write fp.cfg
echo Writing sample configuration file to $fpcfgfile
${FPCMKCFGBIN} -p -1 -d "basepath=$FPCPATH" -o $fpcfgfile

# Write fp.ini
echo Writing sample configuration file to $fpinifile
${FPCMKCFGBIN} -p -2 -o $fpinifile

# Do not write fppkg configuration when fppkg is not available
if ! [ -f "$FPPKGBIN" ] ; then
  exit
fi

# Write fppkg.cfg
echo Writing sample configuration file to $fppkgfile
${FPCMKCFGBIN} -p -3 $compilerconfigdir -o $fppkgfile

# Write default
echo Writing sample configuration file to $defaultfile
${FPCMKCFGBIN} -p -4 -d "GlobalPrefix=$FPCGLOBALPREFIX" -o $defaultfile