You deal with three kinds of packages: wrapping headers and libraries, building custom libraries, and wrapping Swift. This is the first type.
- Create a new folder. Name it, e.g. BasePackage
- Add four text files: base.h, Makefile, module.modulemap, Package.swift
import PackageDescription
let package = Package(
name: "BasePackage"
)
- Adjust the package name as desired. Here it is BasePackage.
Rename as desired, add any system includes
// Add required includes
#include <math.h>
Thanks, aciidb, for cleaning up the module.map's header line
module BasePackage {
header "base.h"
link "m"
export *
}
- adjust the module name as needed
- change the folder path to match the path to the header file
- include all libraries to link (here -lm)
Makefile for Package
You can just copy and use this as-is
all:
git init ; git add . ; git commit -m "Commit" ; git tag 1.0.0
clean:
rm -rf .git
rm *~
tidy:
rm *~
- Create a directory
- Add Package.swift text file
- Create Sources folder. Add main.swift text file to sources.
- Add Makefile text file
import PackageDescription
let package = Package (
name: "test",
dependencies: [
.Package(url: "/home/erica/Packages/BasePackage", majorVersion:1)
]
)
- Change the executable name from test
- Change the url to point to the custom module folder
Use the package you actually want
import BasePackage
print("Hello world")
Here's a basic Makefile for building your app. Edit the target name.
TARGET=test
all:
swift build
install:
cp .build/debug/$(TARGET) .
clean :
rm -rf Packages
rm -rf .build
rm *~ Sources/*~ $(TARGET)
tidy:
rm *~ Sources/*~