summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorsaurabhb172020-02-26 16:36:01 +0530
committersaurabhb172020-02-26 16:36:01 +0530
commit1fa449fed953fa11f6bd0ea82cc2d3b115ee0781 (patch)
treead18839d8b4eb1f13419d07878cc4ec4c9b70032 /scripts
parentc38609295ad4b617aef472b9c575aee18710a50f (diff)
downloadKiCad-eSim-1fa449fed953fa11f6bd0ea82cc2d3b115ee0781.tar.gz
KiCad-eSim-1fa449fed953fa11f6bd0ea82cc2d3b115ee0781.tar.bz2
KiCad-eSim-1fa449fed953fa11f6bd0ea82cc2d3b115ee0781.zip
Remaining files transfered
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/kicad-install.sh408
-rwxr-xr-xscripts/lib_convert.py51
-rw-r--r--scripts/library-repos-install.bat89
-rwxr-xr-xscripts/library-repos-install.sh273
-rwxr-xr-xscripts/osx_build_wx.sh166
-rwxr-xr-xscripts/osx_fixbundle.sh129
-rwxr-xr-xscripts/test_kicad_plugin.py85
-rwxr-xr-xscripts/test_plugin.py48
8 files changed, 1249 insertions, 0 deletions
diff --git a/scripts/kicad-install.sh b/scripts/kicad-install.sh
new file mode 100755
index 0000000..a0f9781
--- /dev/null
+++ b/scripts/kicad-install.sh
@@ -0,0 +1,408 @@
+#!/bin/bash -e
+# Install KiCad from source onto either:
+# -> a Ubuntu/Debian/Mint or
+# -> a Red Hat
+# compatible linux system.
+#
+# The "install_prerequisites" step is the only "distro dependent" one. That step could be modified
+# for other linux distros.
+#
+# There are 3 package groups in a KiCad install:
+# 1) Compiled source code in the form of executable programs.
+# 2) User manuals and other documentation typically as *.pdf files.
+# 3) a) Schematic parts, b) layout footprints, and c) 3D models for footprints.
+#
+# To achieve 1) source is checked out from its repo and compiled by this script then executables
+# are installed using CMake.
+# To achieve 2) documentation is checked out from its repo and installed using CMake.
+# TO achieve 3a) and 3c) they are checked out from their repos and installed using CMake.
+# To achieve 3b) a global fp-lib-table is put into your home directory which points to
+# http://github.com/KiCad. No actual footprints are installed locally, internet access is used
+# during program operation to fetch footprints from github as if it was a remote drive in the cloud.
+# If you want to install those same KiCad footprints locally, you may run a separate script
+# named library-repos-install.sh found in this same directory. That script requires that "git" be on
+# your system whereas this script does not. The footprints require some means to download them and
+# bzr-git seems not up to the task. wget or curl would also work.
+
+
+# Since bash is invoked with -e by the first line of this script, all the steps in this script
+# must succeed otherwise bash will abort at the first non-zero error code. Therefore any script
+# functions must be crafted to anticipate numerous conditions, such that no command fails unless it
+# is a serious situation.
+
+
+# Set where the 3 source trees will go, use a full path
+WORKING_TREES=~/kicad_sources
+
+STABLE=5054 # a sensible mix of features and stability
+TESTING=last:1 # the most recent
+
+# Set this to STABLE or TESTING or other known revision number:
+REVISION=$TESTING
+
+# For info on revision syntax:
+# $ bzr help revisionspec
+
+
+# CMake Options
+OPTS="$OPTS -DBUILD_GITHUB_PLUGIN=ON" # needed by $STABLE revision
+
+# Python scripting, uncomment only one to enable:
+
+# Basic python scripting: gives access to wizards like footprint wizards (recommended)
+# be sure you have python 2.7 installed
+#OPTS="$OPTS -DKICAD_SCRIPTING=ON"
+
+# More advanced python scripting: gives access to wizards like footprint wizards and creates a python module
+# to edit board files (.kicad_pcb files) outside kicad, by python scripts
+#OPTS="$OPTS -DKICAD_SCRIPTING=ON -DKICAD_SCRIPTING_MODULES=ON"
+
+# Most advanced python scripting: you can execute python scripts inside Pcbnew to edit the current loaded board
+# mainly for advanced users
+#OPTS="$OPTS -DKICAD_SCRIPTING=ON -DKICAD_SCRIPTING_MODULES=ON -DKICAD_SCRIPTING_WXPYTHON=ON"
+
+# Use https under bazaar to retrieve repos because this does not require a
+# launchpad.net account. Whereas lp:<something> requires a launchpad account.
+# https results in read only access.
+REPOS=https://code.launchpad.net
+
+# This branch is a bzr/launchpad import of the Git repository
+# at https://github.com/KiCad/kicad-library.git.
+# It has schematic parts and 3D models in it.
+LIBS_REPO=$REPOS/~kicad-product-committers/kicad/library
+
+SRCS_REPO=$REPOS/~kicad-product-committers/kicad/product
+DOCS_REPO=$REPOS/~kicad-developers/kicad/doc
+
+
+usage()
+{
+ echo ""
+ echo " usage:"
+ echo ""
+ echo "./kicad-install.sh <cmd>"
+ echo " where <cmd> is one of:"
+ echo " --install-or-update (does full installation or update.)"
+ echo " --remove-sources (removes source trees for another attempt.)"
+ echo " --uninstall-libraries (removes KiCad supplied libraries.)"
+ echo " --uninstall-kicad (uninstalls all of KiCad but leaves source trees.)"
+ echo ""
+ echo "example:"
+ echo ' $ ./kicad-install.sh --install-or-update'
+}
+
+
+install_prerequisites()
+{
+ # Find a package manager, PM
+ PM=$( command -v yum || command -v apt-get )
+
+ # assume all these Debian, Mint, Ubuntu systems have same prerequisites
+ if [ "$(expr match "$PM" '.*\(apt-get\)')" == "apt-get" ]; then
+ #echo "debian compatible system"
+ prerequisite_list="
+ bzr
+ bzrtools
+ build-essential
+ cmake
+ cmake-curses-gui
+ debhelper
+ doxygen
+ grep
+ libbz2-dev
+ libcairo2-dev
+ libglew-dev
+ libssl-dev
+ libwxgtk3.0-dev
+ "
+
+ for p in ${prerequisite_list}
+ do
+ sudo apt-get install $p || exit 1
+ done
+
+ # Only install the scripting prerequisites if required.
+ if [ "$(expr match "$OPTS" '.*\(-DKICAD_SCRIPTING=ON\)')" == "-DKICAD_SCRIPTING=ON" ]; then
+ #echo "KICAD_SCRIPTING=ON"
+ scripting_prerequisites="
+ python-dev
+ python-wxgtk3.0-dev
+ swig
+ "
+
+ for sp in ${scripting_prerequisites}
+ do
+ sudo apt-get install $sp || exit 1
+ done
+ fi
+
+ # assume all yum systems have same prerequisites
+ elif [ "$(expr match "$PM" '.*\(yum\)')" == "yum" ]; then
+ #echo "red hat compatible system"
+ # Note: if you find this list not to be accurate, please submit a patch:
+ sudo yum groupinstall "Development Tools" || exit 1
+
+ prerequisite_list="
+ bzr
+ bzrtools
+ bzip2-libs
+ bzip2-devel
+ cmake
+ cmake-gui
+ doxygen
+ cairo-devel
+ glew-devel
+ grep
+ openssl-devel
+ wxGTK3-devel
+ "
+
+ for p in ${prerequisite_list}
+ do
+ sudo yum install $p || exit 1
+ done
+
+ echo "Checking wxGTK version. Maybe you have to symlink /usr/bin/wx-config-3.0 to /usr/bin/wx-config"
+ V=`wx-config --version | cut -f 1 -d '.'` || echo "Error running wx-config."
+ if [ $V -lt 3 ]
+ then
+ echo "Error: wx-config is reporting version prior to 3"
+ exit
+ else
+ echo "All ok"
+ fi
+ # Only install the scripting prerequisites if required.
+ if [ "$(expr match "$OPTS" '.*\(-DKICAD_SCRIPTING=ON\)')" == "-DKICAD_SCRIPTING=ON" ]; then
+ #echo "KICAD_SCRIPTING=ON"
+ scripting_prerequisites="
+ swig
+ wxPython
+ "
+
+ for sp in ${scripting_prerequisites}
+ do
+ sudo yum install $sp || exit 1
+ done
+ fi
+ else
+ echo
+ echo "Incompatible System. Neither 'yum' nor 'apt-get' found. Not possible to continue."
+ echo
+ exit 1
+ fi
+
+ # ensure bzr name and email are set. No message since bzr prints an excellent diagnostic.
+ bzr whoami || {
+ echo "WARNING: You have not set bzr whoami, so I will set a dummy."
+ export BZR_EMAIL="Kicad Build <nobody@foo>"
+ }
+}
+
+
+rm_build_dir()
+{
+ local dir="$1"
+
+ echo "removing directory $dir"
+
+ if [ -e "$dir/install_manifest.txt" ]; then
+ # this file is often created as root, so remove as root
+ sudo rm "$dir/install_manifest.txt" 2> /dev/null
+ fi
+
+ if [ -d "$dir" ]; then
+ rm -rf "$dir"
+ fi
+}
+
+
+cmake_uninstall()
+{
+ # assume caller set the CWD, and is only telling us about it in $1
+ local dir="$1"
+
+ cwd=`pwd`
+ if [ "$cwd" != "$dir" ]; then
+ echo "missing dir $dir"
+ elif [ ! -e install_manifest.txt ]; then
+ echo
+ echo "Missing file $dir/install_manifest.txt."
+ else
+ echo "uninstalling from $dir"
+ sudo make uninstall
+ sudo rm install_manifest.txt
+ fi
+}
+
+
+# Function set_env_var
+# sets an environment variable globally.
+set_env_var()
+{
+ local var=$1
+ local val=$2
+
+ if [ -d /etc/profile.d ]; then
+ if [ ! -e /etc/profile.d/kicad.sh ] || ! grep "$var" /etc/profile.d/kicad.sh >> /dev/null; then
+ echo
+ echo "Adding environment variable $var to file /etc/profile.d/kicad.sh"
+ echo "Please logout and back in after this script completes for environment"
+ echo "variable to get set into environment."
+ sudo sh -c "echo export $var=$val >> /etc/profile.d/kicad.sh"
+ fi
+
+ elif [ -e /etc/environment ]; then
+ if ! grep "$var" /etc/environment >> /dev/null; then
+ echo
+ echo "Adding environment variable $var to file /etc/environment"
+ echo "Please reboot after this script completes for environment variable to get set into environment."
+ sudo sh -c "echo $var=$val >> /etc/environment"
+ fi
+ fi
+}
+
+
+install_or_update()
+{
+ echo "step 1) installing pre-requisites"
+ install_prerequisites
+
+
+ echo "step 2) make $WORKING_TREES if it does not exist"
+ if [ ! -d "$WORKING_TREES" ]; then
+ sudo mkdir -p "$WORKING_TREES"
+ echo " mark $WORKING_TREES as owned by me"
+ sudo chown -R `whoami` "$WORKING_TREES"
+ fi
+ cd $WORKING_TREES
+
+
+ echo "step 3) checking out the source code from launchpad repo..."
+ if [ ! -d "$WORKING_TREES/kicad.bzr" ]; then
+ bzr checkout -r $REVISION $SRCS_REPO kicad.bzr
+ echo " source repo to local working tree."
+ else
+ cd kicad.bzr
+ bzr up -r $REVISION
+ echo " local source working tree updated."
+ cd ../
+ fi
+
+ echo "step 4) checking out the schematic parts and 3D library repo."
+ if [ ! -d "$WORKING_TREES/kicad-lib.bzr" ]; then
+ bzr checkout $LIBS_REPO kicad-lib.bzr
+ echo ' kicad-lib checked out.'
+ else
+ cd kicad-lib.bzr
+ bzr up
+ echo ' kicad-lib repo updated.'
+ cd ../
+ fi
+
+ echo "step 5) checking out the documentation from launchpad repo..."
+ if [ ! -d "$WORKING_TREES/kicad-doc.bzr" ]; then
+ bzr checkout $DOCS_REPO kicad-doc.bzr
+ echo " docs checked out."
+ else
+ cd kicad-doc.bzr
+ bzr up
+ echo " docs working tree updated."
+ cd ../
+ fi
+
+
+ echo "step 6) compiling source code..."
+ cd kicad.bzr
+ if [ ! -d "build" ]; then
+ mkdir build && cd build
+ cmake $OPTS ../ || exit 1
+ else
+ cd build
+ # Although a "make clean" is sometimes needed, more often than not it slows down the update
+ # more than it is worth. Do it manually if you need to in this directory.
+ # make clean
+ fi
+ make -j4 || exit 1
+ echo " kicad compiled."
+
+
+ echo "step 7) installing KiCad program files..."
+ sudo make install
+ echo " kicad program files installed."
+
+
+ echo "step 8) installing libraries..."
+ cd ../../kicad-lib.bzr
+ rm_build_dir build
+ mkdir build && cd build
+ cmake ../
+ sudo make install
+ echo " kicad-lib.bzr installed."
+
+
+ echo "step 9) as non-root, install global fp-lib-table if none already installed..."
+ # install ~/fp-lib-table
+ if [ ! -e ~/fp-lib-table ]; then
+ make install_github_fp-lib-table
+ echo " global fp-lib-table installed."
+ fi
+
+
+ echo "step 10) installing documentation..."
+ cd ../../kicad-doc.bzr
+ rm_build_dir build
+ mkdir build && cd build
+ cmake ../
+ sudo make install
+ echo " kicad-doc.bzr installed."
+
+ echo "step 11) check for environment variables..."
+ if [ -z "${KIGITHUB}" ]; then
+ set_env_var KIGITHUB https://github.com/KiCad
+ fi
+
+ echo
+ echo 'All KiCad "--install-or-update" steps completed, you are up to date.'
+ echo
+}
+
+
+if [ $# -eq 1 -a "$1" == "--remove-sources" ]; then
+ echo "deleting $WORKING_TREES"
+ rm_build_dir "$WORKING_TREES/kicad.bzr/build"
+ rm_build_dir "$WORKING_TREES/kicad-lib.bzr/build"
+ rm_build_dir "$WORKING_TREES/kicad-doc.bzr/build"
+ rm -rf "$WORKING_TREES"
+ exit
+fi
+
+
+if [ $# -eq 1 -a "$1" == "--install-or-update" ]; then
+ install_or_update
+ exit
+fi
+
+
+if [ $# -eq 1 -a "$1" == "--uninstall-libraries" ]; then
+ cd "$WORKING_TREES/kicad-lib.bzr/build"
+ cmake_uninstall "$WORKING_TREES/kicad-lib.bzr/build"
+ exit
+fi
+
+
+if [ $# -eq 1 -a "$1" == "--uninstall-kicad" ]; then
+ cd "$WORKING_TREES/kicad.bzr/build"
+ cmake_uninstall "$WORKING_TREES/kicad.bzr/build"
+
+ cd "$WORKING_TREES/kicad-lib.bzr/build"
+ cmake_uninstall "$WORKING_TREES/kicad-lib.bzr/build"
+
+ # this may fail since "uninstall" support is a recent feature of this repo:
+ cd "$WORKING_TREES/kicad-doc.bzr/build"
+ cmake_uninstall "$WORKING_TREES/kicad-doc.bzr/build"
+
+ exit
+fi
+
+
+usage
diff --git a/scripts/lib_convert.py b/scripts/lib_convert.py
new file mode 100755
index 0000000..18abc72
--- /dev/null
+++ b/scripts/lib_convert.py
@@ -0,0 +1,51 @@
+#!/usr/bin/python
+
+# Convert a footprint library from one format to another, e.g. legacy to pretty.
+
+# 1) Build target _pcbnew after enabling scripting in cmake.
+# $ make _pcbnew
+
+# 2) Changed dir to pcbnew
+# $ cd pcbnew
+# $ pwd
+# build/pcbnew
+
+# 3) Entered following command line, script takes to arguments: oldLibPath & newLibPath
+# $ PYTHONPATH=. <path_to>/lib_convert.py /usr/local/share/kicad/modules/smd_dil.mod /tmp/smd_dil.pretty
+
+# 4) inspect one footprint found in new librarypath /tmp/smd_dil.pretty
+# $ less /tmp/smd_dil.pretty/msoic-10.kicad_mod
+
+
+from __future__ import print_function
+from pcbnew import *
+import sys
+
+if len( sys.argv ) < 3 :
+ print( "usage: script srcLibraryPath dstLibraryPath" )
+ sys.exit(1)
+
+
+src_libpath = sys.argv[1]
+dst_libpath = sys.argv[2]
+
+
+src_type = IO_MGR.GuessPluginTypeFromLibPath( src_libpath );
+dst_type = IO_MGR.GuessPluginTypeFromLibPath( dst_libpath );
+
+src_plugin = IO_MGR.PluginFind( src_type )
+dst_plugin = IO_MGR.PluginFind( dst_type )
+
+try:
+ dst_plugin.FootprintLibDelete( dst_libpath )
+except:
+ None # ignore, new may not exist if first run
+
+dst_plugin.FootprintLibCreate( dst_libpath )
+
+list_of_parts = src_plugin.FootprintEnumerate( src_libpath )
+
+for part_id in list_of_parts:
+ module = src_plugin.FootprintLoad( src_libpath, part_id )
+ dst_plugin.FootprintSave( dst_libpath, module )
+
diff --git a/scripts/library-repos-install.bat b/scripts/library-repos-install.bat
new file mode 100644
index 0000000..09027b5
--- /dev/null
+++ b/scripts/library-repos-install.bat
@@ -0,0 +1,89 @@
+REM This file was created using <kicad_src>/scripts/library-repos-install.sh on linux.
+REM Run it from a directory you desire as the base for all libraries.
+git clone https://github.com/KiCad/kicad-library
+git clone https://github.com/KiCad/Displays_7-Segment.pretty
+git clone https://github.com/KiCad/Air_Coils_SML_NEOSID.pretty
+git clone https://github.com/KiCad/Sockets_BNC.pretty
+git clone https://github.com/KiCad/Buzzers_Beepers.pretty
+git clone https://github.com/KiCad/Capacitors_Elko_ThroughHole.pretty
+git clone https://github.com/KiCad/Capacitors.pretty
+git clone https://github.com/KiCad/Capacitors_SMD.pretty
+git clone https://github.com/KiCad/Capacitors_ThroughHole.pretty
+git clone https://github.com/KiCad/Choke_Axial_ThroughHole.pretty
+git clone https://github.com/KiCad/Choke_Radial_ThroughHole.pretty
+git clone https://github.com/KiCad/Choke_SMD.pretty
+git clone https://github.com/KiCad/Choke_Toroid_ThroughHole.pretty
+git clone https://github.com/KiCad/Choke_Common-Mode_Wurth.pretty
+git clone https://github.com/KiCad/Connect.pretty
+git clone https://github.com/KiCad/Connectors_Serial_MOLEX.pretty
+git clone https://github.com/KiCad/Converters_DCDC_ACDC.pretty
+git clone https://github.com/KiCad/Crystals.pretty
+git clone https://github.com/KiCad/Crystals_Oscillators_SMD.pretty
+git clone https://github.com/KiCad/Diodes_SMD.pretty
+git clone https://github.com/KiCad/Diodes_ThroughHole.pretty
+git clone https://github.com/KiCad/Discret.pretty
+git clone https://github.com/KiCad/Display.pretty
+git clone https://github.com/KiCad/Divers.pretty
+git clone https://github.com/KiCad/EuroBoard_Outline.pretty
+git clone https://github.com/KiCad/Fiducials.pretty
+git clone https://github.com/KiCad/Filters_HF_Coils_NEOSID.pretty
+git clone https://github.com/KiCad/Footprint_Symbols.pretty
+git clone https://github.com/KiCad/Fuse_Holders_and_Fuses.pretty
+git clone https://github.com/KiCad/Heatsinks.pretty
+git clone https://github.com/KiCad/Housings_ROHM.pretty
+git clone https://github.com/KiCad/Housings_SIP9.pretty
+git clone https://github.com/KiCad/Housings_SOT-23_SOT-143_TSOT-6.pretty
+git clone https://github.com/KiCad/Housings_SOT-89.pretty
+git clone https://github.com/KiCad/Housings_SOT.pretty
+git clone https://github.com/KiCad/Housings_TO-50.pretty
+git clone https://github.com/KiCad/Housings_TO-78.pretty
+git clone https://github.com/KiCad/Housings_TO-92.pretty
+git clone https://github.com/KiCad/Inductors.pretty
+git clone https://github.com/KiCad/Inductors_NEOSID.pretty
+git clone https://github.com/KiCad/IR-DirectFETs.pretty
+git clone https://github.com/KiCad/Iut.pretty
+git clone https://github.com/KiCad/Labels.pretty
+git clone https://github.com/KiCad/LEDs.pretty
+git clone https://github.com/KiCad/Hall-Effect_Transducers_LEM.pretty
+git clone https://github.com/KiCad/Measurement_Points.pretty
+git clone https://github.com/KiCad/Measurement_Scales.pretty
+git clone https://github.com/KiCad/Mechanical_Sockets.pretty
+git clone https://github.com/KiCad/Mounting_Holes.pretty
+git clone https://github.com/KiCad/Muonde.pretty
+git clone https://github.com/KiCad/NF-Transformers_ETAL.pretty
+git clone https://github.com/KiCad/Oddities.pretty
+git clone https://github.com/KiCad/Transistors_OldSowjetAera.pretty
+git clone https://github.com/KiCad/Opto-Devices.pretty
+git clone https://github.com/KiCad/Oscillator-Modules.pretty
+git clone https://github.com/KiCad/Oscillators.pretty
+git clone https://github.com/KiCad/Pentawatts.pretty
+git clone https://github.com/KiCad/PFF_PSF_PSS_Leadforms.pretty
+git clone https://github.com/KiCad/Pin_Arrays.pretty
+git clone https://github.com/KiCad/Potentiometers.pretty
+git clone https://github.com/KiCad/Power_Integrations.pretty
+git clone https://github.com/KiCad/Printtrafo_CHK.pretty
+git clone https://github.com/KiCad/Relays_ThroughHole.pretty
+git clone https://github.com/KiCad/Resistors_SMD.pretty
+git clone https://github.com/KiCad/Resistors_ThroughHole.pretty
+git clone https://github.com/KiCad/Resistors_Universal.pretty
+git clone https://github.com/KiCad/QFP.pretty
+git clone https://github.com/KiCad/SMD_Packages.pretty
+git clone https://github.com/KiCad/Sockets_DIP.pretty
+git clone https://github.com/KiCad/Sockets_Mini-Universal.pretty
+git clone https://github.com/KiCad/Sockets.pretty
+git clone https://github.com/KiCad/Sockets_MOLEX_KK-System.pretty
+git clone https://github.com/KiCad/Sockets_PGA.pretty
+git clone https://github.com/KiCad/Sockets_WAGO734.pretty
+git clone https://github.com/KiCad/SOIC_Packages.pretty
+git clone https://github.com/KiCad/SSOP_Packages.pretty
+git clone https://github.com/KiCad/Capacitors_Tantalum_SMD.pretty
+git clone https://github.com/KiCad/Terminal_Blocks.pretty
+git clone https://github.com/KiCad/Transformers_SMPS_ThroughHole.pretty
+git clone https://github.com/KiCad/Transistors_SMD.pretty
+git clone https://github.com/KiCad/Transistors_TO-220.pretty
+git clone https://github.com/KiCad/Transistors_TO-247.pretty
+git clone https://github.com/KiCad/Valves.pretty
+git clone https://github.com/KiCad/Wire_Connections_Bridges.pretty
+git clone https://github.com/KiCad/Wire_Pads.pretty
+git clone https://github.com/KiCad/Pin_Headers.pretty
+git clone https://github.com/KiCad/Socket_Strips.pretty
diff --git a/scripts/library-repos-install.sh b/scripts/library-repos-install.sh
new file mode 100755
index 0000000..759184f
--- /dev/null
+++ b/scripts/library-repos-install.sh
@@ -0,0 +1,273 @@
+#!/bin/bash
+# Git KiCad library repos:
+#
+# The "install_prerequisites" step is the only "distro dependent" one. Could modify
+# that step for other linux distros.
+# This script requires "git". The package bzr-git is not up to the task.
+# The first time you run with option --install-or-update that is the slowest, because
+# git clone from github.com is slow.
+# After that updates should run faster.
+
+# There are two reasons why you might want to run this script:
+#
+# 1) You want to contribute to the KiCad library team maintained libraries and have yet to
+# discover or have chosen not to use the COW feature in the Github "Plugin Type".
+#
+# 2) You want to run with local pretty footprint libraries and not those remotely located
+# on https://github.com using Github plugin. After running this script you should be able to
+# a) $ cp ~/kicad_sources/library-repos/kicad-library/template/fp-lib-table.for-pretty ~/.config/kicad/fp-lib-table
+# and then
+# b) set your environment variable KISYSMOD to "~/kicad_sources/library-repos".
+# Edit /etc/profile.d/kicad.sh, then reboot.
+#
+# This will use the KiCad plugin against the *.pretty dirs in that base dir.
+
+
+# Set where the library repos will go, use a full path
+WORKING_TREES=${WORKING_TREES:-~/kicad_sources}
+
+
+usage()
+{
+ echo ""
+ echo " usage:"
+ echo ""
+ echo "./library-sources-install.sh <cmd>"
+ echo " where <cmd> is one of:"
+ echo " --install-prerequisites (install command tools needed here, run once first.)"
+ echo " --install-or-update (from github, the library sources.)"
+ echo " --remove-all-libraries (remove all *.pretty from $WORKING_TREES/library-repos/. )"
+ echo " --remove-orphaned-libraries (remove local libraries which have been deleted or renamed at github.)"
+ echo " --list-libraries (show the full list of github libraries.)"
+ echo " --create-bat-file (cat a windows batch file, redirect to capture to disk.)"
+ echo ""
+ echo "examples (with --install-prerequisites once first):"
+ echo ' $ ./library-sources-install.sh --install-prerequisites'
+ echo ' $ ./library-sources-install.sh --install-or-update'
+}
+
+
+install_prerequisites()
+{
+ # Find a package manager, PM
+ PM=$( command -v yum || command -v apt-get )
+
+ # assume all these Debian, Mint, Ubuntu systems have same prerequisites
+ if [ "$(expr match "$PM" '.*\(apt-get\)')" == "apt-get" ]; then
+ #echo "debian compatible system"
+ sudo apt-get install \
+ git \
+ curl \
+ sed
+
+ # assume all yum systems have same prerequisites
+ elif [ "$(expr match "$PM" '.*\(yum\)')" == "yum" ]; then
+ #echo "red hat compatible system"
+ # Note: if you find this list not to be accurate, please submit a patch:
+ sudo yum install \
+ git \
+ curl \
+ sed
+ else
+ echo
+ echo "Incompatible System. Neither 'yum' nor 'apt-get' found. Not possible to"
+ echo "continue. Please make sure to install git, curl, and sed before using this"
+ echo "script."
+ echo
+ exit 1
+ fi
+}
+
+
+rm_build_dir()
+{
+ local dir="$1"
+ # this file is often created as root, so remove as root
+ sudo rm "$dir/install_manifest.txt" 2> /dev/null
+ rm -rf "$dir"
+}
+
+
+cmake_uninstall()
+{
+ # assume caller set the CWD, and is only telling us about it in $1
+ local dir="$1"
+
+ cwd=`pwd`
+ if [ "$cwd" != "$dir" ]; then
+ echo "missing dir $dir"
+ elif [ ! -e install_manifest.txt ]; then
+ echo
+ echo "Missing file $dir/install_manifest.txt."
+ else
+ echo "uninstalling from $dir"
+ sudo make uninstall
+ sudo rm install_manifest.txt
+ fi
+}
+
+
+detect_pretty_repos()
+{
+ # Check for the correct option to enable extended regular expressions in
+ # sed. This is '-r' for GNU sed and '-E' for (older) BSD-like sed, as on
+ # Mac OSX.
+ if [ $(echo | sed -r '' &>/dev/null; echo $?) -eq 0 ]; then
+ SED_EREGEXP="-r"
+ elif [ $(echo | sed -E '' &>/dev/null; echo $?) -eq 0 ]; then
+ SED_EREGEXP="-E"
+ else
+ echo "Your sed command does not support extended regular expressions. Cannot continue."
+ exit 1
+ fi
+
+ # Use github API to list repos for org KiCad, then subset the JSON reply for only
+ # *.pretty repos in the "full_name" variable.
+ PRETTY_REPOS=`curl -s "https://api.github.com/orgs/KiCad/repos?per_page=99&page=1" \
+ "https://api.github.com/orgs/KiCad/repos?per_page=99&page=2" 2> /dev/null \
+ | sed $SED_EREGEXP 's:.+ "full_name".*"KiCad/(.+\.pretty)",:\1:p;d'`
+
+ #echo "PRETTY_REPOS:$PRETTY_REPOS"
+
+ PRETTY_REPOS=`echo $PRETTY_REPOS | tr " " "\n" | sort`
+
+ #echo "PRETTY_REPOS sorted:$PRETTY_REPOS"
+}
+
+
+checkout_or_update_libraries()
+{
+ if [ ! -d "$WORKING_TREES" ]; then
+ sudo mkdir -p "$WORKING_TREES"
+ echo " mark $WORKING_TREES as owned by me"
+ sudo chown -R `whoami` "$WORKING_TREES"
+ fi
+ cd $WORKING_TREES
+
+ detect_pretty_repos
+
+ if [ ! -e "$WORKING_TREES/library-repos" ]; then
+ mkdir -p "$WORKING_TREES/library-repos"
+ fi
+
+ for repo in kicad-library $PRETTY_REPOS; do
+ # echo "repo:$repo"
+
+ if [ ! -e "$WORKING_TREES/library-repos/$repo" ]; then
+
+ # Preserve the directory extension as ".pretty".
+ # That way those repos can serve as pretty libraries directly if need be.
+
+ echo "installing $WORKING_TREES/library-repos/$repo"
+ git clone "https://github.com/KiCad/$repo" "$WORKING_TREES/library-repos/$repo"
+ else
+ echo "updating $WORKING_TREES/library-repos/$repo"
+ cd "$WORKING_TREES/library-repos/$repo"
+ git pull
+ fi
+ done
+}
+
+
+listcontains()
+{
+ local list=$1
+ local item=$2
+ local ret=1
+ local OIFS=$IFS
+
+ # omit the space character from internal field separator.
+ IFS=$'\n'
+
+ for word in $list; do
+ if [ "$word" == "$item" ]; then
+ ret=0
+ break
+ fi
+ done
+
+ IFS=$OIFS
+ return $ret
+}
+
+
+remove_orphaned_libraries()
+{
+ cd $WORKING_TREES/library-repos
+
+ if [ $? -ne 0 ]; then
+ echo "Directory $WORKING_TREES/library-repos does not exist."
+ echo "The option --remove-orphaned-libraries should be used only after you've run"
+ echo "the --install-or-update at least once."
+ exit 2
+ fi
+
+ detect_pretty_repos
+
+ for mylib in *.pretty; do
+ echo "checking local lib: $mylib"
+
+ if ! listcontains "$PRETTY_REPOS" "$mylib"; then
+ echo "Removing orphaned local library $WORKING_TREES/library-repos/$mylib"
+ rm -rf "$mylib"
+ fi
+ done
+}
+
+
+if [ $# -eq 1 -a "$1" == "--install-or-update" ]; then
+ checkout_or_update_libraries
+ exit
+fi
+
+
+if [ $# -eq 1 -a "$1" == "--remove-orphaned-libraries" ]; then
+ remove_orphaned_libraries
+ exit
+fi
+
+
+if [ $# -eq 1 -a "$1" == "--remove-all-libraries" ]; then
+ rm -rf "$WORKING_TREES/library-repos"
+ exit
+fi
+
+
+if [ $# -eq 1 -a "$1" == "--install-prerequisites" ]; then
+ install_prerequisites
+ exit
+fi
+
+if [ $# -eq 1 -a "$1" == "--list-libraries" ]; then
+
+ # use github API to get repos into PRETTY_REPOS var
+ detect_pretty_repos
+
+ # add the "schematic parts & 3D model" kicad-library to total
+ for repo in $PRETTY_REPOS; do
+ echo "$repo"
+ done
+
+ echo
+ echo "and the special 'kicad-library' which holds 3D stuff and schematic parts"
+
+ exit
+fi
+
+# may re-direct this output to a disk file for Windows *.BAT file creation.
+if [ $# -eq 1 -a "$1" == "--create-bat-file" ]; then
+
+ # use github API to get repos into PRETTY_REPOS var
+ detect_pretty_repos
+
+ echo "REM This file was created using <kicad_src>/scripts/library-repos-install.sh on linux."
+ echo "REM Run it from a directory you desire as the base for all libraries."
+
+ # add the "schematic parts & 3D model" kicad-library to total
+ for repo in kicad-library $PRETTY_REPOS; do
+ echo "git clone https://github.com/KiCad/$repo"
+ done
+ exit
+fi
+
+usage
diff --git a/scripts/osx_build_wx.sh b/scripts/osx_build_wx.sh
new file mode 100755
index 0000000..d803d4c
--- /dev/null
+++ b/scripts/osx_build_wx.sh
@@ -0,0 +1,166 @@
+#!/bin/bash
+#
+# Small helper script for patching/compiling wxWidgets/wxPython on OSX
+#
+# Params
+# $1 wxWidgets/wxPython source folder (relative to current dir)
+# $2 Target bin folder
+# $3 KiCad source folder (relative to current dir)
+# $4 OSX target version (e.g., "10.8")
+# $5 Extra make options (e.g., "-j4")
+
+createPaths() {
+ echo "*** Creating/wiping build and bin folder..."
+
+ rm -rf wx-build
+ rm -rf $1
+ mkdir wx-build
+ mkdir $1
+}
+
+doPatch() {
+ cwd=$(pwd)
+ cd $1
+
+ patchcmd="patch -p0 -RN --dry-run < $cwd/$2"
+ eval $patchcmd &> /dev/null
+ if [ $? -eq 0 ];
+ then
+ echo "*** Patch '$2' already applied, skipping..."
+ else
+ echo "*** Applying patch '$2'..."
+
+ patch -p0 < $cwd/$2
+ if [ $? -ne 0 ];
+ then
+ cd $cwd
+ exit 1
+ fi
+ fi
+
+ cd $cwd
+}
+
+wxWidgets_configure() {
+ echo "*** Configuring wxWidgets..."
+ cwd=$(pwd)
+ cd wx-build
+
+ ../$1/configure \
+ --prefix=$cwd/$2 \
+ --with-opengl \
+ --enable-aui \
+ --enable-utf8 \
+ --enable-html \
+ --enable-stl \
+ --with-libjpeg=builtin \
+ --with-libpng=builtin \
+ --with-regex=builtin \
+ --with-libtiff=builtin \
+ --with-zlib=builtin \
+ --with-expat=builtin \
+ --without-liblzma \
+ --with-macosx-version-min=$3 \
+ --enable-universal-binary=i386,x86_64 \
+ CC=clang \
+ CXX=clang++
+ if [ $? -ne 0 ];
+ then
+ cd ..
+ exit 1
+ fi
+
+ cd ..
+}
+
+wxWidgets_buildInst() {
+ echo "*** Building wxWidgets..."
+ cd wx-build
+
+ make $1 install
+ if [ $? -ne 0 ];
+ then
+ cd ..
+ exit 1
+ fi
+
+ cd ..
+}
+
+wxPython_buildInst() {
+ cwd=$(pwd)
+ cd $1/wxPython
+
+ # build params
+ WXPYTHON_BUILD_OPTS="WX_CONFIG=$cwd/$2/bin/wx-config \
+ BUILD_BASE=$cwd/wx-build \
+ UNICODE=1 \
+ WXPORT=osx_cocoa"
+
+ # build
+ python setup.py build_ext $WXPYTHON_BUILD_OPTS
+ if [ $? -ne 0 ];
+ then
+ cd $cwd
+ exit 1
+ fi
+
+ # install
+ python setup.py install --prefix=$cwd/$2 $WXPYTHON_BUILD_OPTS
+ if [ $? -ne 0 ];
+ then
+ cd $cwd
+ exit 1
+ fi
+
+ cd $cwd
+}
+
+
+# check parameters
+if [ "$#" -lt 4 ];
+then
+ echo "OSX wxWidgets/wxPython build script"
+ echo
+ echo "Usage:"
+ echo " osx_build_wx.sh <src> <bin> <kicad> <osxtarget> [makeopts]"
+ echo " <src> wxWidgets/wxPython source folder"
+ echo " <bin> Destination folder"
+ echo " <kicad> KiCad folder"
+ echo " <osxtarget> OSX target (e.g., 10.7)"
+ echo " [makeopts] Optional: make options for building wxWidgets (e.g., -j4)"
+ exit 1
+fi
+
+# create build paths
+createPaths "$2"
+
+# patch wxWidgets sources
+echo "*** Patching wxWidgets..."
+doPatch "$1" "$3/patches/wxwidgets-3.0.0_macosx.patch"
+doPatch "$1" "$3/patches/wxwidgets-3.0.0_macosx_bug_15908.patch"
+doPatch "$1" "$3/patches/wxwidgets-3.0.0_macosx_soname.patch"
+# high resolution in OpenGL canvas: http://trac.wxwidgets.org/ticket/15700
+doPatch "$1" "$3/patches/wxwidgets-3.0.2_macosx_retina_opengl.patch"
+# patch to support pinch-to-zoom on trackpads
+doPatch "$1" "$3/patches/wxwidgets-3.0.2_macosx_magnify_event.patch"
+
+# configure and build wxWidgets
+wxWidgets_configure "$1" "$2" "$4"
+wxWidgets_buildInst "$5"
+
+# check if source is wxPython
+if [ -d $1/wxPython ];
+then
+ echo "*** Source is wxPython, now building wxPython stuff..."
+ wxPython_buildInst "$1" "$2"
+fi
+
+# remove build dir
+echo "*** Removing build folder"
+rm -rf wx-build
+
+# done
+echo "*** Finished building!"
+
+
diff --git a/scripts/osx_fixbundle.sh b/scripts/osx_fixbundle.sh
new file mode 100755
index 0000000..a1f21de
--- /dev/null
+++ b/scripts/osx_fixbundle.sh
@@ -0,0 +1,129 @@
+#!/bin/bash
+# v 1.1 Supports migration of links (limited to the same directory) - I should add checks..
+# usage osx_fixbundle.sh <bundle-name> <bzr_root>
+
+if [[ ! -f version.h ]]; then
+ echo "**"
+ echo "** ERROR: $0 doesn't seems to be launched from the kicad's bzr root !!!"
+ echo "** Go in the bzr root directory and launch: scripts/osx_fixbundle.sh"
+ echo "**"
+ exit 1
+fi
+
+EXECUTABLES="`find . -name '*.app'`"
+
+#
+# Copies libraries under <bzr_root> in the bundle and relocates them in the binary
+#
+
+function fixbundle() {
+ exec="$1"
+ bzroot="$2"
+ execpath="$3"
+ binary="$4"
+
+ LIBRARIES="`otool -L ${binary} | cut -d' ' -f1`"
+
+ for library in $LIBRARIES; do
+
+ mkdir -p ${execpath}${exec}.app/Contents/Frameworks
+ if [[ "$library" =~ "$bzroot" ]]; then
+ echo "${exec}: Migrating `basename $library` in the bundle"
+ if [ ! -f ${exec}.app/Contents/Frameworks/`basename $library` ]; then
+ if [ ! -L $library ]; then
+ cp -f $library ${execpath}${exec}.app/Contents/Frameworks
+ else
+ resolvelink "$library" "`dirname $library`" "${execpath}/${exec}.app/Contents/Frameworks"
+ fi
+ fi
+ install_name_tool -change $library @executable_path/../Frameworks/`basename $library` ${binary}
+ fi
+ done
+
+ # Resolve issue in python modules (.so)
+ cd ${execpath}
+ MODULES="`find ${exec}.app -name '*.so'`"
+
+ for module in $MODULES; do
+ LIBRARIES="`otool -L $module | cut -d' ' -f1`"
+ mkdir -p ${exec}.app/Contents/Frameworks
+
+ for library in $LIBRARIES; do
+ if [[ "$library" =~ "$bzroot" ]]; then
+ if [ ! -f ${exec}.app/Contents/Frameworks/`basename $library` ]; then
+ if [ ! -L $library ]; then
+ cp -f $library ${exec}.app/Contents/Frameworks
+ else
+ resolvelink "$library" "`dirname $library`" "${execpath}/${exec}.app/Contents/Frameworks"
+ fi
+ fi
+ install_name_tool -change $library @executable_path/../Frameworks/`basename $library` $module
+ fi
+ done
+ echo "${exec}: elaborated module `basename ${module}`"
+ done
+
+ # Resolve issue between DYNLIBS
+ dynlib_migrate="1";
+ dynlib_cycle="0";
+
+ while [ $dynlib_migrate -gt 0 ]; do
+ dynlib_migrate="0";
+ (( dynlib_cycle += 1 ))
+ DYNLIBS="`find ${exec}.app -name '*.dylib'`"
+
+ for dynlib in $DYNLIBS; do
+ LIBRARIES="`otool -L $dynlib | cut -d' ' -f1`"
+ mkdir -p ${exec}.app/Contents/Frameworks
+
+ for library in $LIBRARIES; do
+ if [[ "$library" =~ "$bzroot" ]]; then
+ if [ ! -f ${exec}.app/Contents/Frameworks/`basename $library` ]; then
+ if [ ! -L $library ]; then
+ cp -f $library ${exec}.app/Contents/Frameworks
+ else
+ resolvelink "$library" "`dirname $library`" "${execpath}/${exec}.app/Contents/Frameworks"
+ fi
+ echo "copied `basename $library` into bundle"
+ (( dynlib_migrate += 1))
+ fi
+
+ install_name_tool -change $library @executable_path/../Frameworks/`basename $library` $dynlib
+ fi
+ done
+ done
+ echo "${exec}: bundle dynlib dependencies migration Pass $dynlib_cycle: Migrated $dynlib_migrate libraries in bundle"
+ done
+ cd - >/dev/null
+}
+
+#
+# This supports only links on the same dir (TODO ?)
+#
+
+function resolvelink() {
+ local srclib="`basename $1`"
+ local srcpath="$2"
+ local destpath="$3"
+
+ #if is a file i expect a pointed ""
+ local pointed="`readlink ${srcpath}/${srclib}`"
+
+ if [ ! -f ${pointed} ]; then
+ resolvelink "${pointed}" "${srcpath}" "${destpath}"
+ echo "Link ${srclib} -> ${pointed} "
+ (cd "${destpath}"; ln -s "${pointed}" "${srclib}" )
+ else
+ echo "Copy ${srcpath}/${srclib} -> ${destpath} "
+ cp "${srcpath}/${srclib}" ${destpath}
+ fi
+}
+
+for executable in $EXECUTABLES;
+do
+ myexecpath="`dirname ${executable}`/"
+ myexec="`basename ${executable}|sed -e 's/\.app//'`"
+
+ fixbundle "${myexec}" "$1" "${myexecpath}" "${myexecpath}${myexec}.app/Contents/MacOS/${myexec}"
+ fixbundle "${myexec}" "$1" "${myexecpath}" "${myexecpath}${myexec}.app/Contents/MacOS/_${myexec}.kiface"
+done
diff --git a/scripts/test_kicad_plugin.py b/scripts/test_kicad_plugin.py
new file mode 100755
index 0000000..3bb20cc
--- /dev/null
+++ b/scripts/test_kicad_plugin.py
@@ -0,0 +1,85 @@
+#!/usr/bin/python
+
+# Test the KiCad plugin regarding some expected features.
+
+# 1) Build target _pcbnew after enabling scripting in cmake.
+# $ make _pcbnew
+
+# 2) Changed dir to pcbnew
+# $ cd pcbnew
+# $ pwd
+# build/pcbnew
+
+# 3) Entered following command line, script takes no arguments
+# $ PYTHONPATH=. <path_to>/test_kicad_plugin.py
+
+from pcbnew import IO_MGR, BOARD, MODULE, FPID, UTF8
+from os import rename as mv
+
+tmp_path = '/tmp'
+lib_path1 = "%s/lib1.pretty" % tmp_path
+lib_path2 = "%s/lib2.pretty" % tmp_path
+
+plugin = IO_MGR.PluginFind( IO_MGR.KICAD )
+
+# Expecting "KiCad":
+print( "Plugin Type: %s" % plugin.PluginName() )
+
+try:
+ plugin.FootprintLibDelete( lib_path1 )
+except:
+ pass # ignore, new may not exist if first run
+
+try:
+ plugin.FootprintLibDelete( lib_path2 )
+except:
+ pass # ignore, new may not exist if first run
+
+plugin.FootprintLibCreate( lib_path1 )
+
+# Verify that the same plugin instance can edge trigger on a lib_path change
+# for a FootprintLibCreate()
+plugin.FootprintLibCreate( lib_path2 )
+
+board = BOARD()
+
+# The only way to construct a MODULE is to pass it a BOARD? Yep.
+module = MODULE( board )
+
+fpid = FPID( 'mine' )
+
+module.SetFPID( fpid )
+
+plugin.FootprintSave( lib_path2, module )
+
+# Verify that the same plugin instance can edge trigger on a lib_path change
+# for a FootprintSave()
+plugin.FootprintSave( lib_path1, module )
+
+# create a disparity between the library's name ("footprint"),
+# and the module's internal useless name ("mine"). Module is officially named "footprint" now
+# but has (module mine ...) internally:
+mv( "%s/mine.kicad_mod" % lib_path2, "%s/footprint.kicad_mod" % lib_path2 )
+
+footprint = plugin.FootprintLoad( lib_path2, 'footprint' )
+
+fpid = footprint.GetFPID()
+fpid.SetLibNickname( UTF8( 'mylib' ) )
+name = fpid.Format().GetChars() # example to get the UTF8 char buffer
+
+# Always after a FootprintLoad() the internal name should match the one used to load it.
+print( "Internal name should be 'footprint': '%s'" % name )
+
+# Verify that the same plugin instance can edge trigger on a lib_path change
+# for FootprintLoad()
+footprint = plugin.FootprintLoad( lib_path1, 'mine' )
+
+fpid = footprint.GetFPID()
+fpid.SetLibNickname( UTF8( 'other_mylib' ) )
+
+# Always after a FootprintLoad() the internal name should match the one used to load it.
+# Example to print an UTF8 string
+print( "Internal name should be 'mine': '%s'" % fpid.Format() )
+
+# As of 3-Dec-2013 this test is passed by KICAD_PLUGIN and Wayne is owed an atta boy!
+
diff --git a/scripts/test_plugin.py b/scripts/test_plugin.py
new file mode 100755
index 0000000..3755607
--- /dev/null
+++ b/scripts/test_plugin.py
@@ -0,0 +1,48 @@
+#!/usr/bin/python
+
+# Test a basic back to back FootprintLoad() of a single footprint, and FootprintEnumerate()
+
+# 1) Build target _pcbnew after enabling scripting in cmake.
+# $ make _pcbnew
+
+# 2) Changed dir to pcbnew
+# $ cd pcbnew
+# $ pwd
+# build/pcbnew
+
+# 3) Entered following command line, script takes to arguments: library_path [footprint_name]
+# $ PYTHONPATH=. <path_to>/test_plugin.py https://github.com/liftoff-sr/pretty_footprints [100-LQFP]
+
+
+from __future__ import print_function
+from pcbnew import *
+import sys
+
+if len( sys.argv ) < 2 :
+ print( "usage: script <library_path> [<footprint_name>]" )
+ sys.exit(1)
+
+
+src_libpath = sys.argv[1]
+
+
+src_type = IO_MGR.GuessPluginTypeFromLibPath( src_libpath );
+
+src_plugin = IO_MGR.PluginFind( src_type )
+
+if len( sys.argv ) == 2:
+ list_of_footprints = src_plugin.FootprintEnumerate( src_libpath )
+ for fp in list_of_footprints:
+ print( fp )
+
+elif len( sys.argv ) == 3:
+ # I had some concerns about back to back reads, this verifies it is no problem:
+ module = src_plugin.FootprintLoad( src_libpath, sys.argv[2] )
+ if not module:
+ print( "1st try: module", sys.argv[2], "not found" )
+ module = src_plugin.FootprintLoad( src_libpath, sys.argv[2] )
+ if not module:
+ print( "2nd try: module", sys.argv[2], "not found" )
+ print( module )
+
+