CopperSpice Overview  1.5.2
CopperSpice Project Using Autotools

An Autotools project requires two files, configure.ac and Makefile.am which are used to generate the build files for a given application.

For many applications the source and compiled files reside in the same folder however we prefer to have them in separate folders. In our sample HelloLunch project we have added two additional Autotools files so your application source can reside in myApp and the compiled files will be located in myApp/bin. This requires four Autotools files, most of which never change from project to project.

Directory File Purpose
myApp Makefile.am Exact same for every project
myApp configure.ac Only line two of this file is modified for each project
myApp/bin copperspice.am Exact same for every project
myApp/bin Makefile.am Modified per project, contains a list of source files and libraries to include

The following sections show the converted Qt HelloLunch project files rewritten using Autotools. There are two parts to compiling and building the HelloLunch application.

Note
Before building HelloLunch you will need to add a environment variable called CS_HOME. Ensure this variable is set to the exact path where the CopperSpice libraries were installed.

File 1: same for every project

The first file specified in the table above is shown below. It will be used by Autotools and does not need to be modified.

myApp/Makefile.am

1 ACLOCAL_AMFLAGS= -I autotools/m4 --install
2 SUBDIRS=. bin
3 
4 .PHONY: deploy
5 
6 deploy:
7  $(MAKE) -C bin deploy

File 2: configure

The second file requires almost no changes between your projects. The only modifications will be on line two for the application name, version, and your email address.

myApp/configure.ac

1 # project name, version, email
2 AC_INIT([HelloLunch], 1.0, [barbara@copperspice.com])
3 
4 AC_CONFIG_AUX_DIR([autotools/build-aux])
5 AC_CONFIG_MACRO_DIR([autotools/m4])
6 
7 AC_CANONICAL_BUILD
8 AC_CANONICAL_HOST
9 AC_CANONICAL_TARGET
10 
11 # name of one source file
12 AC_CONFIG_SRCDIR([main.cpp])
13 
14 AM_INIT_AUTOMAKE( [foreign] )
15 
16 LT_INIT
17 AC_PROG_INSTALL
18 AC_PROG_CC_C99
19 AC_PROG_CC_C_O
20 AC_PROG_CXX
21 
22 # set flags for c++14
23 AC_LANG([C++])
24 AX_CXX_COMPILE_STDCXX(14, [noext])
25 
26 case "$target" in
27  -*-mingw*)
28  prefix=`pwd`/install
29  OSTYPE=WIN ;;
30  -*-linux-*)
31  OSTYPE=LINUX ;;
32  -*-darwin*)
33  OSTYPE=DARWIN ;;
34 esac
35 
36 AM_CONDITIONAL(OSTYPE_WIN, test "$OSTYPE" == WIN)
37 AM_CONDITIONAL(OSTYPE_LINUX, test "$OSTYPE" == LINUX)
38 AM_CONDITIONAL(OSTYPE_DARWIN, test "$OSTYPE" == DARWIN)
39 
40 AC_CONFIG_FILES( [Makefile bin/Makefile ] )
41 AC_OUTPUT
42 
43 # display 32-bit or 64-bit
44 m4_pushdef([AS_MESSAGE_FD],[/dev/null])
45 AC_CHECK_SIZEOF(size_t)
46 
47 case "$ac_cv_sizeof_size_t" in
48 4)
49  BITSIZE="a 32" ;;
50 8)
51  BITSIZE="a 64" ;;
52  )
53  BITSIZE="an unknown" ;;
54 esac
55 m4_popdef([AS_MESSAGE_FD])
56 
57 echo
58 echo "Application configured for "$BITSIZE"-bit system"
59 echo

File 3: same for every project

The content of the third file is shown below. This file will be used by Autotools and does not need to be modified.

myApp/bin/copperspice.am

1 AUTOMAKE_OPTIONS=subdir-objects
2 
3 # location where CopperSpice libraries are installed
4 CS_HOME:=$(shell cd $(CS_HOME); pwd)
5 
6 # location of includes, libs, defines for compiling
7 AM_CXXFLAGS=$(AM_CFLAGS) -I$(CS_HOME)/include $(patsubst %,-I$(CS_HOME)/include/Qt%,$(cslibs))
8 
9 # location of CopperSpice libraries for linking
10 AM_LDFLAGS=-L$(CS_HOME)/lib
11 
12 # location of CopperSpice programs
13 LRELEASE=$(CS_HOME)/bin/lrelease
14 RCC=$(CS_HOME)/bin/rcc
15 UIC=$(CS_HOME)/bin/uic
16 
17 # 'deploy' is the folder for "make deploy"
18 deploydir=$(abs_top_builddir)/deploy
19 
20 BUILT_SOURCES=$(patsubst forms/%.ui, ui_%.h,$(FORMS))
21 EXTRA_DIST=$(FORMS)
22 
23 BUILT_SOURCES+=$(patsubst %.qrc,qrc_%.cpp,$(RESOURCES))
24 EXTRA_DIST+=$(RESOURCES)
25 
26 BUILT_SOURCES+=$(patsubst %.ts,%.qm,$(TRANSLATIONS))
27 EXTRA_DIST+=$(TRANSLATIONS)
28 
29 %.qm: %.ts
30  $(LRELEASE) $< $@
31 
32 qrc_%.cpp: %.qrc
33  $(RCC) $< -o $@ -name $(notdir $(basename $<))
34 
35 ui_%.h: forms/%.ui
36  $(UIC) $< -o $@
37 
38 clean-local:
39  -rm qrc_*.cpp
40  -rm ui_*.h

File 4: Makefile

The content for the last file is shown below. This file needs to be updated to indicate which libraries to include, list of source files, and any other rules required to build your application.

myApp/bin/Makefile.am

1 include copperspice.am
2 
3 # path to gcc retrieved from configure (windows)
4 gccpath=$(dir $(shell which $(word 1,$(CC))))
5 
6 # list of gcc libraries (windows)
7 gcclibs=libgcc_s_sjlj-1 libstdc++-6 libwinpthread-1
8 
9 # list of CopperSpice libraries
10 cslibs=Core Gui
11 csver=1.4
12 
13 # location of includes
14 AM_CXXFLAGS+=-I..
15 
16 if OSTYPE_WIN
17  # disable console on window
18  AM_CXXFLAGS+=-mwindows
19 
20  # location for 'make install'
21  installdir=$(abs_top_builddir)/install
22 endif
23 
24 # target app name
25 bin_PROGRAMS = HelloLunch
26 
27 # copy required CopperSpice and gcc files for deployment
28 .PHONY: deploy
29 
30 if OSTYPE_LINUX
31 deploy : all
32  mkdir -p $(deploydir)
33 
34  $(LIBTOOL) --mode=install cp $(bin_PROGRAMS) $(deploydir)
35  rsync -W -a $(patsubst %,$(CS_HOME)/lib/libCs%$(csver).so*,$(cslibs)) $(deploydir)
36 endif
37 
38 if OSTYPE_DARWIN
39 deployapp=$(deploydir)/$(bin_PROGRAMS).app/Contents
40 
41 deploy : all
42  mkdir -p $(deployapp)/Frameworks
43  mkdir -p $(deployapp)/MacOS
44  mkdir -p $(deployapp)/Resources
45 
46  $(LIBTOOL) --mode=install cp $(bin_PROGRAMS) $(deployapp)/MacOS
47 
48  rm -f $(deployapp)/Info.plist
49  sed -e "s,@ICON@,,g"
50  -e "s,@TYPEINFO@,????,g"
51  -e "s,@EXECUTABLE@,$(bin_PROGRAMS),g"
52  $(CS_HOME)/mac/Info.plist.app > $(deployapp)/Info.plist
53 
54  rm -f $(deployapp)/PkgInfo
55  echo "APPL????" > $(deployapp)/PkgInfo
56 
57  touch $(deployapp)/Resources/empty.lproj
58  cp -r $(CS_HOME)/mac/qt_menu.nib $(deployapp)/Resources
59 
60  rsync -W -a $(patsubst %,$(CS_HOME)/lib/libCs%$(csver).dylib,$(cslibs)) $(deployapp)/Frameworks
61 
62  for libname in $(patsubst %,libCs%$(csver).dylib,$(cslibs)) ; do
63 
64  install_name_tool -change $(CS_HOME)/lib/$$libname
65  @executable_path/../Frameworks/$$libname $(deployapp)/MacOS/$(bin_PROGRAMS);
66 
67  for templib in $(patsubst %,libCs%$(csver).dylib,$(cslibs)) ; do
68  install_name_tool -change $(CS_HOME)/lib/$$templib
69  @executable_path/../Frameworks/$$templib $(deployapp)/Frameworks/$$libname
70  ; done
71 
72  ; done
73 
74  hdiutil create -ov -srcfolder $(deploydir) -format UDBZ
75  -volname $(bin_PROGRAMS) ../$(bin_PROGRAMS).dmg
76 
77  hdiutil internet-enable -yes ../$(bin_PROGRAMS).dmg
78 
79 endif
80 
81 if OSTYPE_WIN
82 deploy : all
83  mkdir -p $(deploydir)
84 
85  $(LIBTOOL) --mode=install cp $(bin_PROGRAMS) $(deploydir)
86 
87  rsync -W -a --modify-window=2 $(patsubst %,$(gccpath)/%.dll,$(gcclibs)) $(deploydir)
88  rsync -W -a --modify-window=2 $(patsubst %,$(CS_HOME)/bin/libCs%$(csver).dll,$(cslibs)) $(deploydir)
89 endif
90 
91 # search path for source
92 VPATH = ../
93 
94 # linking
95 HelloLunch_LDFLAGS=$(AM_LDFLAGS) $(patsubst %,-lCs%$(csver),$(cslibs))
96 
97 # source
98 HelloLunch_SOURCES = main.cpp lunch.cpp
99 
100 noinst_HEADERS = lunch.h
101 
102 FORMS = forms/lunch.ui
103 
104 TRANSLATIONS =
105 
106 RESOURCES = hellolunch.qrc
107 
108 # use wilcard to obtain the dependency list
109 qrc_hellolunch.cpp: hellolunch.qrc $(wildcard ../resources/*)
110 
111 # required to compile qrc
112 nodist_HelloLunch_SOURCES+=qrc_hellolunch.cpp

Commands to Configure and Build

Note
For information about installing a Bourne shell (Bash) on Windows, refer to Building for Windows (MinGW).
For Mac OS X, refer to Compiling on Mac OS X for additional configure requirements.

The following steps are required to configure, compile, and link an Autotools project. These commands must be entered from a bash prompt. As with any build system, Autotools needs to create the actual Makefile before you can compile and link your application. This is done in steps one and two.


(1)  Run Autoreconf from your project directory with the syntax shown below. This step is run once or anytime configure.ac file is modified.

autoreconf -i


(2)  Run configure from your project directory with the syntax shown below. This step is run once or anytime the configure.ac file is changed.

./configure


(3)  To build your application from your project directory use the syntax shown below. This step is run every time your project source is modified or a new build is required.

make

To build your application and deploy to the location specified in your bin/Makefile.am use the following command.

make install

This following command is run from your project directory. It will delete all of the object and intermediate files in the bin folder. The next time you run 'make' every file will be compiled, since they were deleted.

make clean


Compiling on Mac OS X

On Mac OS X clang must be used to compile your application. To use clang you will need to add the following environment variables.

  • CC=clang
  • CXX=clang++
  • OBJCXX=clang++

Alternatively, you can create a file like config-myApp in your project folder. This file can pass the prefix and any other required options to configure. The following is a sample of a typical config-myApp file.

./configure CC=clang CXX=clang++ OBJCXX=clang++ --prefix $HOME/cs_lib

To run configure using the config-myApp file, use the following command and syntax from your project folder.

./config-myApp