@@ -154,8 +154,45 @@ subroutine build_model(model, settings, package, error)
154
154
end do
155
155
if (allocated (error)) return
156
156
157
+ ! Check for duplicate modules
158
+ call check_modules(model)
157
159
end subroutine build_model
158
160
161
+ ! Check for duplicate modules
162
+ subroutine check_modules (model )
163
+ type (fpm_model_t), intent (in ) :: model
164
+ integer :: maxsize
165
+ integer :: i,j,k,modi
166
+ type (string_t), allocatable :: modules(:)
167
+ ! Initialise the size of array
168
+ maxsize = 0
169
+ ! Get number of modules provided by each source file
170
+ do i= 1 ,size (model% packages(1 )% sources)
171
+ if (allocated (model% packages(1 )% sources(j)% modules_provided)) then
172
+ maxsize = maxsize + size (model% packages(1 )% sources(i)% modules_provided)
173
+ end if
174
+ end do
175
+ ! Allocate array to contain distinct names of modules
176
+ allocate (modules(1 :maxsize))
177
+
178
+ ! Initialise index to point at start of the newly allocated array
179
+ modi = 1
180
+
181
+ ! Loop through modules provided by each source file
182
+ ! Add it to the array if it is not already there
183
+ ! Otherwise print out warning about duplicates
184
+ do j= 1 ,size (model% packages(1 )% sources)
185
+ if (allocated (model% packages(1 )% sources(j)% modules_provided)) then
186
+ do k= 1 ,size (model% packages(1 )% sources(j)% modules_provided)
187
+ if (model% packages(1 )% sources(j)% modules_provided(k)% s.in .modules) then
188
+ print * ," Warning: Module " ,model% packages(1 )% sources(j)% modules_provided(k)% s," is duplicate"
189
+ else
190
+ modules(modi) = model% packages(1 )% sources(j)% modules_provided(k)
191
+ end if
192
+ end do
193
+ end if
194
+ end do
195
+ end subroutine check_modules
159
196
160
197
subroutine cmd_build (settings )
161
198
type (fpm_build_settings), intent (in ) :: settings
0 commit comments